Skip to content

Commit

Permalink
feat: more warnings on common test account filter mistakes (#13852)
Browse files Browse the repository at this point in the history
* feat: more warnings on common test account filter mistakes

* export the interface
  • Loading branch information
pauldambra authored Jan 20, 2023
1 parent c30e399 commit 49c29c4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { AlertMessage } from 'lib/components/AlertMessage'
export function TestAccountFiltersConfig(): JSX.Element {
const { updateCurrentTeam } = useActions(teamLogic)
const { reportTestAccountFiltersUpdated } = useActions(eventUsageLogic)
const { currentTeam, currentTeamLoading, testAccountFilterWarningLabels } = useValues(teamLogic)
const { currentTeam, currentTeamLoading, testAccountFilterWarningLabels, testAccountFilterFrequentMistakes } =
useValues(teamLogic)
const { groupsTaxonomicTypes } = useValues(groupsModel)

const handleChange = (filters: AnyPropertyFilter[]): void => {
Expand Down Expand Up @@ -39,6 +40,18 @@ export function TestAccountFiltersConfig(): JSX.Element {
</ul>
</AlertMessage>
)}
{!!testAccountFilterFrequentMistakes && testAccountFilterFrequentMistakes.length > 0 && (
<AlertMessage type="warning" className="m-2">
<p>Your filter contains a setting that is likely to exclude or include unexpected users.</p>
<ul className="list-disc">
{testAccountFilterFrequentMistakes.map(({ key, type, fix }, i) => (
<li key={i} className="ml-4">
{key} is a {type} property, but {fix}.
</li>
))}
</ul>
</AlertMessage>
)}
{currentTeam && (
<PropertyFilters
pageKey="testaccountfilters"
Expand Down
26 changes: 26 additions & 0 deletions frontend/src/scenes/teamLogic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ const parseUpdatedAttributeName = (attr: string | null): string => {
return attr ? identifierToHuman(attr) : 'Project'
}

export interface FrequentMistakeAdvice {
key: string
type: 'event' | 'person'
fix: string
}

export const teamLogic = kea<teamLogicType>([
path(['scenes', 'teamLogic']),
connect({
Expand Down Expand Up @@ -172,6 +178,26 @@ export const teamLogic = kea<teamLogicType>([
})
},
],
testAccountFilterFrequentMistakes: [
(selectors) => [selectors.currentTeam],
(currentTeam): FrequentMistakeAdvice[] => {
if (!currentTeam) {
return []
}
const frequentMistakes: FrequentMistakeAdvice[] = []

for (const filter of currentTeam.test_account_filters) {
if (filter.key === 'email' && filter.type === 'event') {
frequentMistakes.push({
key: 'email',
type: 'event',
fix: 'it is more common to filter email by person properties, not event properties',
})
}
}
return frequentMistakes
},
],
}),
listeners(({ actions }) => ({
deleteTeam: async ({ team }) => {
Expand Down

0 comments on commit 49c29c4

Please sign in to comment.