Skip to content

Commit

Permalink
fix(hogql): fix explore tab for trends queries (#22293)
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed May 15, 2024
1 parent 73676bc commit 9dc3e0e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 43 deletions.
37 changes: 18 additions & 19 deletions frontend/src/queries/nodes/DataTable/InsightActorsQueryOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useMountedLogic, useValues } from 'kea'
import { LemonSelect } from 'lib/lemon-ui/LemonSelect'
import { cleanedInsightActorsQueryOptions } from 'scenes/trends/persons-modal/persons-modal-utils'

import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { insightActorsQueryOptionsLogic } from '~/queries/nodes/DataTable/insightActorsQueryOptionsLogic'
Expand All @@ -20,25 +21,23 @@ export function InsightActorsQueryOptions({ setQuery, query }: InsightActorsQuer

return query && insightActorsQueryOptions ? (
<>
{Object.entries(insightActorsQueryOptions)
.filter(([, value]) => !!value)
.map(([key, options]) => (
<div key={key}>
<LemonSelect
fullWidth
className="min-w-32"
placeholder={key}
value={query?.[key] ?? null}
onChange={(v) =>
setQuery?.({
...query,
[key]: v,
})
}
options={options}
/>
</div>
))}
{cleanedInsightActorsQueryOptions(insightActorsQueryOptions).map(([key, options]) => (
<div key={key}>
<LemonSelect
fullWidth
className="min-w-32"
placeholder={key}
value={query?.[key] ?? null}
onChange={(v) =>
setQuery?.({
...query,
[key]: v,
})
}
options={options}
/>
</div>
))}
</>
) : null
}
31 changes: 12 additions & 19 deletions frontend/src/scenes/trends/persons-modal/PersonsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
SessionRecordingType,
} from '~/types'

import { cleanedInsightActorsQueryOptions } from './persons-modal-utils'
import { PersonModalLogicProps, personsModalLogic } from './personsModalLogic'
import { SaveCohortModal } from './SaveCohortModal'

Expand Down Expand Up @@ -160,25 +161,17 @@ export function PersonsModal({
) : null}

{query &&
Object.entries(insightActorsQueryOptions ?? {})
.filter(([, value]) => {
if (Array.isArray(value)) {
return !!value.length
}

return !!value
})
.map(([key, options]) => (
<div key={key}>
<LemonSelect
fullWidth
className="mb-2"
value={query?.[key] ?? null}
onChange={(v) => updateActorsQuery({ [key]: v })}
options={options}
/>
</div>
))}
cleanedInsightActorsQueryOptions(insightActorsQueryOptions).map(([key, options]) => (
<div key={key}>
<LemonSelect
fullWidth
className="mb-2"
value={query?.[key] ?? null}
onChange={(v) => updateActorsQuery({ [key]: v })}
options={options}
/>
</div>
))}

<div className="flex items-center gap-2 text-muted">
{actorsResponseLoading ? (
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/scenes/trends/persons-modal/persons-modal-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { formatBreakdownLabel } from 'scenes/insights/utils'
import { cleanFilters } from 'scenes/insights/utils/cleanFilters'

import { FormatPropertyValueForDisplayFunction } from '~/models/propertyDefinitionsModel'
import { InsightActorsQueryOptionsResponse } from '~/queries/schema'
import {
CohortType,
FunnelsFilterType,
Expand Down Expand Up @@ -191,12 +192,11 @@ export const buildPeopleUrl = ({
const cleanedParams = cleanFilters(params)
const funnelParams = toParams(cleanedParams)
return `api/person/funnel/?${funnelParams}&cache_invalidation_key=${cacheInvalidationKey}`
} else {
// TODO: We should never land in this case; Remove this if Sentry doesn't unexpectedly capture this.
Sentry.captureException(new Error('buildPeopleUrl used for non-trends funnel'), {
extra: { filters },
})
}
// TODO: We should never land in this case; Remove this if Sentry doesn't unexpectedly capture this.
Sentry.captureException(new Error('buildPeopleUrl used for non-trends funnel'), {
extra: { filters },
})
} else if (isPathsFilter(filters)) {
const cleanedParams = cleanFilters(filters)
const pathParams = toParams(cleanedParams)
Expand All @@ -208,3 +208,11 @@ export const buildPeopleUrl = ({
})
}
}

export const cleanedInsightActorsQueryOptions = (
insightActorsQueryOptions: InsightActorsQueryOptionsResponse | null
): [string, any[]][] => {
return Object.entries(insightActorsQueryOptions ?? {}).filter(([, value]) => {
return Array.isArray(value) && !!value.length
})
}

0 comments on commit 9dc3e0e

Please sign in to comment.