-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flags): restrict dynamic behavioral cohort targeting in the FF UI (
#25529) Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
6d7a20b
commit 34f3eae
Showing
10 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
Binary file modified
BIN
+1.61 KB
(100%)
frontend/__snapshots__/scenes-app-feature-flags--new-feature-flag--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+1.66 KB
(100%)
frontend/__snapshots__/scenes-app-feature-flags--new-feature-flag--light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
frontend/src/lib/components/TaxonomicFilter/cohortFilterUtils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { BehavioralFilterKey } from 'scenes/cohorts/CohortFilters/types' | ||
|
||
import { AnyCohortCriteriaType, CohortCriteriaGroupFilter, CohortType } from '~/types' | ||
|
||
function isCohortCriteriaGroupFilter( | ||
value: AnyCohortCriteriaType | CohortCriteriaGroupFilter | ||
): value is CohortCriteriaGroupFilter { | ||
return (value as CohortCriteriaGroupFilter).type === 'AND' || (value as CohortCriteriaGroupFilter).type === 'OR' | ||
} | ||
|
||
const hasBehavioralFilter = (cohort: CohortType, allCohorts: CohortType[]): boolean => { | ||
const checkCriteriaGroup = (group: CohortCriteriaGroupFilter): boolean => { | ||
return group.values.some((value) => { | ||
if (isCohortCriteriaGroupFilter(value)) { | ||
return checkCriteriaGroup(value) | ||
} | ||
if (value.type === BehavioralFilterKey.Behavioral) { | ||
return true | ||
} | ||
if (value.type === BehavioralFilterKey.Cohort) { | ||
// the first time we load the page we haven't transformed the cohort data, | ||
// so there's no value_property, and we need to use `value.value` instead. | ||
const cohortId = value.value_property || value.value | ||
const nestedCohort = allCohorts.find((item) => item.id === cohortId) | ||
if (nestedCohort) { | ||
return hasBehavioralFilter(nestedCohort, allCohorts) | ||
} | ||
return false | ||
} | ||
return false | ||
}) | ||
} | ||
|
||
return cohort.filters?.properties ? checkCriteriaGroup(cohort.filters.properties) : false | ||
} | ||
|
||
export const filterOutBehavioralCohorts = (items: CohortType[], hideBehavioralCohorts?: boolean): CohortType[] => { | ||
if (!hideBehavioralCohorts) { | ||
return items | ||
} | ||
|
||
return items.filter((item) => !hasBehavioralFilter(item, items)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters