Skip to content

Commit

Permalink
feat: support setting audienceMatch as a filter from list of existing…
Browse files Browse the repository at this point in the history
… audiences (#217)
  • Loading branch information
jsalaber authored Jul 11, 2023
1 parent f18e5d9 commit a53914a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/ui/prompts/listPrompts/filterListPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
filterDataKeyTypePrompt,
filterSubTypePrompt,
filterTypePrompt,
filterValuesPrompt
filterValuesPrompt,
reusableAudienceFilterPrompt
} from '../targetingPrompts'
import { Audience, Filter } from '../../../api/schemas'
import { Prompt } from '../types'
Expand Down Expand Up @@ -38,9 +39,14 @@ export class FilterListOptions extends ListOptionsPrompt<Filter> {
value: { item: filter }
}
} else if (type === 'audienceMatch') {
const { comparator, audiences } = await inquirer.prompt([filterComparatorPrompt, filterAudiencesPrompt])
const audiencesList = audiences.split(',').map((audience: string) => audience.trim())
const filter = { type: 'audienceMatch' as const, comparator, _audiences: audiencesList }
const { comparator, reusableAudiences } = await inquirer.prompt(
[
filterComparatorPrompt,
reusableAudienceFilterPrompt(this.audiences)
]
)
const reusableAudiencesList = reusableAudiences.map((audience: Audience) => audience._id)
const filter = { type: 'audienceMatch' as const, comparator, _audiences: reusableAudiencesList }
return {
name: JSON.stringify(filter),
value: { item: filter }
Expand Down
11 changes: 11 additions & 0 deletions src/ui/prompts/targetingPrompts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Audience } from '../../api/schemas'
import { DataKeyType, filterTypes, userSubTypes } from '../../api/targeting'
import { isRequired } from '../../utils/validators'
import { variationChoices } from './variationPrompts'
Expand Down Expand Up @@ -64,6 +65,16 @@ export const filterAudiencesPrompt = {
type: 'input'
}

export const reusableAudienceFilterPrompt = (audiences: Audience[]) => ({
name: 'reusableAudiences',
message: 'List of reusable audiences',
type: 'checkbox',
choices: audiences.map((audience: Audience) => ({
name: audience.name,
value: audience
}))
})

export const filterDataKeyPrompt = {
name: 'dataKey',
message: 'Data key for definition',
Expand Down

0 comments on commit a53914a

Please sign in to comment.