Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(dashboards): add interval filter override (#71063)

Thomas Obermülleraac2d2667955
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 7e6f70b0c564..ef3d100940f5 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -5431,9 +5431,9 @@ snapshots:
scenes-app-customer-analytics-journeys-nodes-profileflownode--optional-not-completed--light:
hash: v1.k794b7964.165b884e9e737c00707811f9efa7d348927a432402c544b41495eac9722a1fca.wqLWQTzb1O7RBTeeyTR5l_hUeX0IpJXkgexpAQbuNWs
scenes-app-dashboards--access-control-dashboard--dark:
- hash: v1.k794b7964.6bbc5cd2acac63e7f9fba6f2aa33d7e2d52a8352127fed8d428219540a49b890.omqO-GOryjeLGk99ofm9J4gqx_CQWdMPupmPU6WW278
+ hash: v1.k794b7964.11fd596aad9a5ed51c4486b64828e1416573b34c63a10b2ed37b08d25da48d91.jj69suHKiPBYs2VMR83Q_FMRnb4Pg7C4lU0Pra6VdYE
scenes-app-dashboards--access-control-dashboard--light:
- hash: v1.k794b7964.d101d57a6d623f754e7c62f7f79c78968822118050421f72c802718fa493a933.6pV1ojpc6ehy_SZd9xEHNQ0b8ZPGi1c-nuFHYebBLI8
+ hash: v1.k794b7964.a29a85daeff98faa6ea496a8485323ea965ee6fce98e2f1f67a032cd7bd38f31.VIhetTOlL6LTRVS-ALs4f7DOMCWcDomR7fgQAlRZUvo
scenes-app-dashboards--edit--dark:
hash: v1.k794b7964.b85e622d121e2edfb031fec73921ba7d775a50124f5d68c8c82ad28a51985434.eFMlXYTQdWLdvwn7YobjvgCNrFbx2IMXMt2Lzs0yyo4
scenes-app-dashboards--edit--light:
@@ -5459,9 +5459,9 @@ snapshots:
scenes-app-dashboards--not-found--light:
hash: v1.k794b7964.ed4b8e9397bf960ff4b19b54e722c74962b25a2ec0270ecc090eda9b6d5d7f7b.XiealyyQzU_NqFX_PQmkZiIkJcX0h_joVE0Wbl-1twc
scenes-app-dashboards--view-only-dashboard--dark:
- hash: v1.k794b7964.1ee0dc03f9575313eba452798bd1a1ad195840099ab6c8beb535cdec8e2a62bf.X8vY6iak_BgscSHRrhbaAYQClcpTT5TcQerf5ZA1CME
+ hash: v1.k794b7964.a65acee97de57aeef30368365580e0e2c962193d6215acf55dac639823cb0ca8.zkO7nnEw6JoWOSq1KJ1DQrXzCI1FSmD0yzRsrMwcfA0
scenes-app-dashboards--view-only-dashboard--light:
- hash: v1.k794b7964.47528e5f78b66dbf0a83e44d5d106dbc868b39ee6e9e00e3b2ba72094803d5af.9qvvPG9BfTZFU1dJw7jR1QvEQz7atIMP_EppulGxk9w
+ hash: v1.k794b7964.7ebc4aa50c00cbfa580fd96d32ef6565a6bd399e1ae6289278d36309c89e87f1.9xwqldb2HI9IewJABGeU3kmuyGXS-hwbloJgjznVypQ
scenes-app-dashboards-add-insight-to-dashboard-modal--default--dark:
hash: v1.k794b7964.65a26ab25825086d5463677deec55324c7ada5ad92d46976038a9334748fdafd.-icTyqvvUjLQRZfthpF9m2gJ513_nxn6zhe-ChRyTrI
scenes-app-dashboards-add-insight-to-dashboard-modal--default--light:
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index 7454bb02e881..7d2b1fc1a9e2 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -99,7 +99,7 @@ export enum DashboardEventSource {
DashboardVariableOverride = 'dashboard_variable_override',
}
-export type DashboardFilterChangeType = 'date' | 'properties' | 'breakdown' | 'variable'
+export type DashboardFilterChangeType = 'date' | 'properties' | 'breakdown' | 'variable' | 'interval'
export enum InsightEventSource {
LongPress = 'long_press',
diff --git a/frontend/src/scenes/dashboard/DashboardEditBar.tsx b/frontend/src/scenes/dashboard/DashboardEditBar.tsx
index 587e55c7f159..6233eb3ed6c6 100644
--- a/frontend/src/scenes/dashboard/DashboardEditBar.tsx
+++ b/frontend/src/scenes/dashboard/DashboardEditBar.tsx
@@ -2,6 +2,7 @@ import clsx from 'clsx'
import { BindLogic, useActions, useValues } from 'kea'
import { IconCalendar } from '@posthog/icons'
+import { LemonSelect } from '@posthog/lemon-ui'
import { DateFilter } from 'lib/components/DateFilter/DateFilter'
import { PropertyFilters } from 'lib/components/PropertyFilters/PropertyFilters'
@@ -18,13 +19,42 @@ import { Scene } from 'scenes/sceneTypes'
import { groupsModel } from '~/models/groupsModel'
import { VariablesForDashboard } from '~/queries/nodes/DataVisualization/Components/Variables/Variables'
import { BreakdownFilter, NodeKind } from '~/queries/schema/schema-general'
-import { DashboardMode, InsightLogicProps } from '~/types'
+import { DashboardMode, InsightLogicProps, IntervalType } from '~/types'
interface DashboardEditBarProps {
showDateFilter?: boolean
className?: string
}
+export function DashboardIntervalFilter(): JSX.Element {
+ const { dashboardMode, effectiveEditBarFilters } = useValues(dashboardLogic)
+ const { setInterval, setDashboardMode } = useActions(dashboardLogic)
+
+ return (
+ <span className="flex items-center gap-2">
+ <span className="hidden md:inline">grouped by</span>
+ <LemonSelect<IntervalType | null>
+ size="small"
+ value={effectiveEditBarFilters.interval ?? null}
+ dropdownMatchSelectWidth={false}
+ onChange={(interval) => {
+ if (dashboardMode !== DashboardMode.Edit) {
+ setDashboardMode(DashboardMode.Edit, DashboardEventSource.DashboardFilters)
+ }
+ setInterval(interval)
+ }}
+ options={[
+ { value: null, label: "each insight's interval" },
+ { value: 'hour', label: 'hour' },
+ { value: 'day', label: 'day' },
+ { value: 'week', label: 'week' },
+ { value: 'month', label: 'month' },
+ ]}
+ />
+ </span>
+ )
+}
+
export function DashboardEditBar({ showDateFilter = true, className }: DashboardEditBarProps): JSX.Element {
const { dashboard, dashboardMode, hasVariables, effectiveEditBarFilters } = useValues(dashboardLogic)
const { setDates, setProperties, setBreakdownFilter, setDashboardMode } = useActions(dashboardLogic)
@@ -90,6 +120,11 @@ export function DashboardEditBar({ showDateFilter = true, className }: Dashboard
</Shortcut>
</div>
)}
+ {showDateFilter && (
+ <div className={clsx('content-end', { 'h-[61px]': hasVariables })}>
+ <DashboardIntervalFilter />
+ </div>
+ )}
<div className={clsx('content-end', { 'h-[61px]': hasVariables })}>
<PropertyFilters
onChange={(properties) => {
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsx
index b197e84eb360..b5a60070181a 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx
+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx
@@ -99,6 +99,7 @@ import {
InsightColor,
InsightModel,
InsightShortId,
+ IntervalType,
ProjectTreeRef,
QueryBasedInsightModel,
TextModel,
@@ -333,6 +334,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
}),
setProperties: (properties: AnyPropertyFilter[] | null) => ({ properties }),
setBreakdownFilter: (breakdown_filter: BreakdownFilter | null) => ({ breakdown_filter }),
+ setInterval: (interval: IntervalType | null) => ({ interval }),
setExternalFilters: (filters: DashboardFilter) => ({ filters }),
saveEditModeChanges: () => true,
resetUrlFilters: () => true,
@@ -799,6 +801,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
setDates: () => false,
setProperties: () => false,
setBreakdownFilter: () => false,
+ setInterval: () => false,
loadDashboardSuccess: () => false,
loadDashboardFailure: () => false,
applyFilters: () => true,
@@ -1270,6 +1273,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
properties: undefined,
breakdown_filter: undefined,
explicitDate: undefined,
+ interval: undefined,
} as DashboardFilter,
{
setDates: (state, { date_from, date_to, explicitDate }) => ({
@@ -1286,12 +1290,17 @@ export const dashboardLogic = kea<dashboardLogicType>([
...state,
breakdown_filter,
}),
+ setInterval: (state, { interval }) => ({
+ ...state,
+ interval,
+ }),
resetIntermittentFilters: () => ({
date_from: undefined,
date_to: undefined,
properties: undefined,
breakdown_filter: undefined,
explicitDate: undefined,
+ interval: undefined,
}),
},
],
@@ -3008,6 +3017,18 @@ export const dashboardLogic = kea<dashboardLogicType>([
})
}
},
+ setInterval: ({ interval }) => {
+ eventUsageLogic.actions.reportDashboardFiltersChanged(values.dashboard, 'interval', {
+ interval,
+ })
+
+ if (values.canAutoPreview) {
+ actions.refreshDashboardItems({
+ action: RefreshDashboardItemsAction.Preview,
+ forceRefresh: false,
+ })
+ }
+ },
setExternalFilters: () => {
if (values.tiles.length > 0) {
actions.refreshDashboardItems({
@@ -3200,6 +3221,25 @@ export const dashboardLogic = kea<dashboardLogicType>([
currentLocation.hashParams,
]
},
+ setInterval: ({ interval }) => {
+ if (!values.canAutoPreview) {
+ return
+ }
+
+ const { currentLocation } = router.values
+
+ const urlFilters = parseURLFilters(currentLocation.searchParams)
+ const newUrlFilters: DashboardFilter = {
+ ...urlFilters,
+ interval,
+ }
+
+ return [
+ currentLocation.pathname,
+ { ...currentLocation.searchParams, ...encodeURLFilters(newUrlFilters) },
+ currentLocation.hashParams,
+ ]
+ },
overrideVariableValue: ({ variableId, value }) => {
const { currentLocation } = router.values