Skip to content

Commit

Permalink
fix(persons-modal): Correct series names in persons modal (#23723)
Browse files Browse the repository at this point in the history
Co-authored-by: balanxiao <[email protected]>
Co-authored-by: KrispyKris905 <[email protected]>
Co-authored-by: Michael Matloka <[email protected]>
  • Loading branch information
4 people authored Jul 16, 2024
1 parent 95e2e2c commit 42add0e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function InsightActorsQueryOptions({ setQuery, query }: InsightActorsQuer

return query && insightActorsQueryOptions ? (
<>
{cleanedInsightActorsQueryOptions(insightActorsQueryOptions).map(([key, options]) => (
{cleanedInsightActorsQueryOptions(insightActorsQueryOptions, query).map(([key, options]) => (
<div key={key}>
<LemonSelect
fullWidth
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/scenes/trends/persons-modal/PersonsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function PersonsModal({
) : null}

{query &&
cleanedInsightActorsQueryOptions(insightActorsQueryOptions).map(([key, options]) =>
cleanedInsightActorsQueryOptions(insightActorsQueryOptions, query).map(([key, options]) =>
key === 'breakdowns' ? (
options.map(({ values }, index) => (
<div key={`${key}_${index}`}>
Expand Down
28 changes: 25 additions & 3 deletions frontend/src/scenes/trends/persons-modal/persons-modal-utils.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { PropertyKeyInfo } from 'lib/components/PropertyKeyInfo'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
import { getCoreFilterDefinition } from 'lib/taxonomy'
import { pluralize } from 'lib/utils'

import { InsightActorsQueryOptionsResponse } from '~/queries/schema'
import { InsightActorsQuery, InsightActorsQueryOptionsResponse } from '~/queries/schema'
import { isTrendsQuery } from '~/queries/utils'
import { StepOrderValue } from '~/types'

export const funnelTitle = (props: {
Expand Down Expand Up @@ -53,9 +55,29 @@ export const pathsTitle = (props: { mode: pathModes; label: string }): React.Rea
}

export const cleanedInsightActorsQueryOptions = (
insightActorsQueryOptions: InsightActorsQueryOptionsResponse | null
insightActorsQueryOptions: InsightActorsQueryOptionsResponse | null,
query: InsightActorsQuery
): [string, any[]][] => {
return Object.entries(insightActorsQueryOptions ?? {}).filter(([, value]) => {
const cleanedOptions = Object.entries(insightActorsQueryOptions ?? {}).filter(([, value]) => {
return Array.isArray(value) && !!value.length
})
const source = query?.source
const seriesNames = isTrendsQuery(source) ? source.series.map((s: any) => s.custom_name) : []
const cleanedOptionsWithAdjustedSeriesNames: [string, any[]][] = cleanedOptions.map(([key, value]) => {
if (key === 'series') {
return [
key,
value.map((v: any, index: number) => ({
...v,
label:
seriesNames[index] ??
getCoreFilterDefinition(v.label, TaxonomicFilterGroupType.Events)?.label ??
v.label,
})),
]
}
return [key, value]
})

return cleanedOptionsWithAdjustedSeriesNames
}

0 comments on commit 42add0e

Please sign in to comment.