Skip to content

Commit

Permalink
replace intervalFilterLogic with insightVizDataLogic
Browse files Browse the repository at this point in the history
  • Loading branch information
thmsobrmlr committed Oct 29, 2023
1 parent eed58c7 commit bb3f9ff
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 60 deletions.
10 changes: 5 additions & 5 deletions frontend/src/lib/components/IntervalFilter/IntervalFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ import { useActions, useValues } from 'kea'
import { IntervalType } from '~/types'
import { insightLogic } from 'scenes/insights/insightLogic'
import { LemonSelect } from '@posthog/lemon-ui'
import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
import { InsightQueryNode } from '~/queries/schema'

interface IntervalFilterProps {
disabled?: boolean
}

export function IntervalFilter({ disabled }: IntervalFilterProps): JSX.Element {
const { insightProps } = useValues(insightLogic)
const { interval, enabledIntervals } = useValues(intervalFilterLogic(insightProps))
const { setInterval } = useActions(intervalFilterLogic(insightProps))
const { interval, enabledIntervals } = useValues(insightVizDataLogic(insightProps))
const { updateQuerySource } = useActions(insightVizDataLogic(insightProps))

return (
<>
Expand All @@ -24,9 +26,7 @@ export function IntervalFilter({ disabled }: IntervalFilterProps): JSX.Element {
value={interval || 'day'}
dropdownMatchSelectWidth={false}
onChange={(value) => {
if (value) {
setInterval(String(value) as IntervalType)
}
updateQuerySource({ interval: value } as Partial<InsightQueryNode>)
}}
data-attr="interval-filter"
options={Object.entries(enabledIntervals).map(([value, { label, disabledReason }]) => ({
Expand Down
55 changes: 0 additions & 55 deletions frontend/src/lib/components/IntervalFilter/intervalFilterLogic.ts

This file was deleted.

28 changes: 28 additions & 0 deletions frontend/src/scenes/insights/insightVizDataLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
getShowValueOnSeries,
} from '~/queries/nodes/InsightViz/utils'
import { DISPLAY_TYPES_WITHOUT_LEGEND } from 'lib/components/InsightLegend/utils'
import { intervals } from 'lib/components/IntervalFilter/intervals'
import { insightDataLogic, queryFromKind } from 'scenes/insights/insightDataLogic'

import { sceneLogic } from 'scenes/sceneLogic'
Expand Down Expand Up @@ -195,6 +196,33 @@ export const insightVizDataLogic = kea<insightVizDataLogicType>([
(series): BaseMathType.MonthlyActiveUsers | BaseMathType.WeeklyActiveUsers | null =>
getActiveUsersMath(series),
],
enabledIntervals: [
(s) => [s.activeUsersMath],
(activeUsersMath) => {
console.debug('enabledIntervals', activeUsersMath)
const enabledIntervals: Intervals = { ...intervals }

if (activeUsersMath) {
// Disallow grouping by hour for WAUs/MAUs as it's an expensive query that produces a view that's not useful for users
enabledIntervals.hour = {
...enabledIntervals.hour,
disabledReason:
'Grouping by hour is not supported on insights with weekly or monthly active users series.',
}

// Disallow grouping by month for WAUs as the resulting view is misleading to users
if (activeUsersMath === BaseMathType.WeeklyActiveUsers) {
enabledIntervals.month = {
...enabledIntervals.month,
disabledReason:
'Grouping by month is not supported on insights with weekly active users series.',
}
}
}

return enabledIntervals
},
],

erroredQueryId: [
(s) => [s.insightDataError],
Expand Down

0 comments on commit bb3f9ff

Please sign in to comment.