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(bi): filter dashboards from the exploration dialog (#124734)

Marius Andrae62e229e0c4c
diff --git a/docs/published/handbook/engineering/data-warehouse.md b/docs/published/handbook/engineering/data-warehouse.md
index 01ce85ce1174..0b8e3fa7f573 100644
--- a/docs/published/handbook/engineering/data-warehouse.md
+++ b/docs/published/handbook/engineering/data-warehouse.md
@@ -139,7 +139,7 @@ In the worksheet editor, click a bar, line point, table cell, or pivot cell to e
On authenticated dashboards in view mode, right-clicking a chart result opens a context menu beside the pointer. A left click keeps its usual action, such as opening the people modal, pinning a multi-series tooltip, or opening the BI drill-down dialog. Right-clicking a link or an input keeps the browser menu. Chart tooltips stay hidden until the menu closes. BI worksheets offer **View underlying rows**, then **Open in SQL editor**. Product analytics datapoints offer **View people**, **View recordings** when the existing drilldown selects matched recordings, then **Open in SQL editor**. Lifecycle results offer people and SQL only: their actor query identifies bucket members without projecting matched events. The people and SQL actions preserve the selected date, breakdown, and aggregation. SQL and recording links become available after the selected actor rows load. Selecting another result or closing the menu cancels any pending query. Recordings use matched session IDs; when no sessions match, the recordings action stays disabled. A left click, Escape, or a click outside closes the menu. Right-clicking another result moves the menu to it. Native links support opening actions in another tab. Exploration actions do not change dashboard filters or create saved insights. Public shares, embeds, exports, and layout editing retain their existing behavior.
-BI worksheet menus also offer **Filter dashboard by this result** for current-period dimension values. The selection filters other BI worksheets using the same table and connection, combining with their existing conditions before aggregation. The source worksheet retains its full results. Each insight card header shows its filter status beside the title, before the menu; the status stays visible when the title is truncated. Cards unaffected by the active BI filter dim to 30% opacity; the source and matching worksheets remain fully visible. Clearing the filter restores all cards. The BI selection appears beside the existing dashboard filters and unsaved-filter controls. Click it to see the source worksheet and affected count, or use **Clear BI filters** or **Remove filter** to restore the saved results. Selections persist in the dashboard URL without changing saved insights, including when dashboard dates or variables change. Changing the source worksheet's table, dimensions, comparison period, or Top N configuration clears the selection. Product analytics, raw SQL visualizations, query snapshots, public shares, embeds, exports, and layout editing do not participate. Grand totals, previous-period results, and Top N **Other** remain available for exploration only.
+BI worksheet menus and the left-click **Explore this result** dialog offer **Filter dashboard by this result** for current-period dimension values. The dialog offers **Remove filter** when that result is already selected, and disables filtering for unsupported results. The selection filters other BI worksheets using the same table and connection, combining with their existing conditions before aggregation. The source worksheet retains its full results. Each insight card header shows its filter status beside the title, before the menu; the status stays visible when the title is truncated. Cards unaffected by the active BI filter dim to 30% opacity; the source and matching worksheets remain fully visible. Clearing the filter restores all cards. The BI selection appears beside the existing dashboard filters and unsaved-filter controls. Click it to see the source worksheet and affected count, or use **Clear BI filters** or **Remove filter** to restore the saved results. Selections persist in the dashboard URL without changing saved insights, including when dashboard dates or variables change. Changing the source worksheet's table, dimensions, comparison period, or Top N configuration clears the selection. Product analytics, raw SQL visualizations, query snapshots, public shares, embeds, exports, and layout editing do not participate. Grand totals, previous-period results, and Top N **Other** remain available for exploration only.
**Compare previous period** turns date comparison on or off in one click. The adjacent comparison picker still supports custom offsets. Select a bounded date range before enabling comparison.
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 6b2d973c0a4a..6b4c48a6c46e 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6884,6 +6884,18 @@ snapshots:
hash: v1.k794b7964.4d9cb89cf4df116ff3e473c6484b641d675a0ea9c42f05bf132ae946b8fb5ca8.7gZROaPmb_dBk2rRnqWl_FEMGXi-hHVdsl42uYiZE44
products-business-intelligence-comparison-summary--table--light:
hash: v1.k794b7964.2476db083ec4c26dd53dab30351f38104c63d9578cd30eae620b60e8cc22a438.plfjAxTsZmL_nRDwhmqufs8yWeTX0wXrr0u5Is8_RUw
+ products-business-intelligence-dashboard-exploration--filter-dashboard--dark:
+ hash: v1.k794b7964.2eb10d7a9e348a8e414356260e1793a7245df043e6c2213bc92dbd3e5b1fdc3f.MboqBtts0URcagK_J8HvP69CPQsCEyjE9hhPRHXQwM8
+ products-business-intelligence-dashboard-exploration--filter-dashboard--light:
+ hash: v1.k794b7964.9386381c7fc5aa3a0662616e1106a86e8d30c8e56c4be5d0b3001e954fc06951.Lv20Ykswqvy-ygBcDICdrFJwFPnGpc2tKQz2NQ5JlYM
+ products-business-intelligence-dashboard-exploration--unsupported-total--dark:
+ hash: v1.k794b7964.810d1d25c042a02b3a7f730e3a6a11debe08bf33ba5e5ea2fba427b642105d88.qRuYs1TWqmzRHTiYtB_6Gey8mQrLiU0IQkn4DK5AkXk
+ products-business-intelligence-dashboard-exploration--unsupported-total--light:
+ hash: v1.k794b7964.b1532775272d29f07c59761a8422ebc210d9b62ac64775cb4e5bf46961bdba8c.DS8M7H00lMA8vC2WXBP9xuJ9nNtix3HR6gaICJhu0Bw
+ products-business-intelligence-dashboard-exploration--worksheet-only--dark:
+ hash: v1.k794b7964.fe39d7d2013936f9c08ded1eac07d8da50c5b2a6cc65fab315597b4f3cbbe3d9.kixiZc25Cwu1_yF8lHC9NnelSPxeUYKVCMdXa-dYmCs
+ products-business-intelligence-dashboard-exploration--worksheet-only--light:
+ hash: v1.k794b7964.f764e6f2344959ec17121e1f64fe4b887fcf966e5b0adfc7d89ff52b60a68ef4.RElYCfTi_lIfohUkvrxI0pRkWjLRxzfW4jwefpWzNsI
products-business-intelligence-dashboard-filter-bar--active--dark:
hash: v1.k794b7964.bb6d728290bfcbe4f44c55861165e8a8fd4cdfa854d01ddd22557595d9392ab7.9QnB2QMMrSzzYAU8JOmq0Rzmlw6tdZTmI9Manf6rZec
products-business-intelligence-dashboard-filter-bar--active--light:
diff --git a/products/business_intelligence/frontend/BIDrilldownMenu.test.tsx b/products/business_intelligence/frontend/BIDrilldownMenu.test.tsx
index f81af280b21e..1d7425909c85 100644
--- a/products/business_intelligence/frontend/BIDrilldownMenu.test.tsx
+++ b/products/business_intelligence/frontend/BIDrilldownMenu.test.tsx
@@ -10,6 +10,7 @@ import { initKeaTests } from '~/test/init'
import { biDrilldownLogic } from './biDrilldownLogic'
import { BIDrilldownMenu } from './BIDrilldownMenu'
+import { BIDrilldownModal } from './BIDrilldownModal'
import { buildBIQuery, DEFAULT_BI_CONFIG } from './biEditorTypes'
describe('native result-menu links', () => {
@@ -97,6 +98,44 @@ describe('native result-menu links', () => {
}
fireEvent.keyDown(screen.getByRole('menu'), { key: 'Escape' })
expect(logic.values.record).toBeNull()
+ act(() => {
+ logic.actions.close()
+ logic.actions.inspect({ status: 'refunded' })
+ })
+ render(<BIDrilldownModal logicProps={props} />)
+ await screen.findByText('Explore this result')
+ if (filtering) {
+ const link = screen.getByText('Filter dashboard by this result').closest('a')!
+ expect(link).toHaveAttribute('href', '/project/1/dashboard/1#bi_filter=selection')
+ const callsBeforeModifiedClicks = onFilterDashboard.mock.calls.length
+ for (const modifier of [
+ { metaKey: true },
+ { ctrlKey: true },
+ { shiftKey: true },
+ { altKey: true },
+ ]) {
+ const modified = new MouseEvent('click', { bubbles: true, cancelable: true, ...modifier })
+ act(() => {
+ link.dispatchEvent(modified)
+ })
+ expect(modified.defaultPrevented).toBe(false)
+ expect(logic.values.record).toEqual({ status: 'refunded' })
+ expect(onFilterDashboard).toHaveBeenCalledTimes(callsBeforeModifiedClicks)
+ }
+ fireEvent.click(link)
+ expect(onFilterDashboard).toHaveBeenLastCalledWith({ status: 'refunded' })
+ expect(logic.values.record).toBeNull()
+ act(() => logic.actions.inspect({ status: 'paid' }))
+ expect(screen.getByText('Remove filter')).toBeInTheDocument()
+ act(() => logic.actions.inspect({ count: 8 }))
+ const disabledFilter = screen.getByText('Filter dashboard by this result').closest('button')!
+ expect(disabledFilter).toHaveAttribute('aria-disabled', 'true')
+ const calls = onFilterDashboard.mock.calls.length
+ fireEvent.click(disabledFilter)
+ expect(onFilterDashboard).toHaveBeenCalledTimes(calls)
+ } else {
+ expect(screen.queryByText('Filter dashboard by this result')).not.toBeInTheDocument()
+ }
} finally {
unmount()
}
diff --git a/products/business_intelligence/frontend/BIDrilldownModal.stories.tsx b/products/business_intelligence/frontend/BIDrilldownModal.stories.tsx
new file mode 100644
index 000000000000..5ebe90fbac44
--- /dev/null
+++ b/products/business_intelligence/frontend/BIDrilldownModal.stories.tsx
@@ -0,0 +1,50 @@
+import { Meta, StoryObj } from '@storybook/react'
+import { useEffect } from 'react'
+
+import { BIVisualizationNode } from '~/queries/schema/schema-business-intelligence'
+import { NodeKind } from '~/queries/schema/schema-general'
+
+import { BIDrilldownProps, biDrilldownLogic } from './biDrilldownLogic'
+import { BIDrilldownModal } from './BIDrilldownModal'
+import { buildBIQuery, DEFAULT_BI_CONFIG } from './biEditorTypes'
+
+const config = {
+ ...DEFAULT_BI_CONFIG,
+ source: { table: 'example_orders' },
+ rows: [
+ {
+ id: 'status',
+ name: 'Status',
+ expression: 'status',
+ type: 'string' as const,
+ source: { table: 'example_orders' },
+ },
+ ],
+}
+const query: BIVisualizationNode = { ...buildBIQuery(config)!.node, kind: NodeKind.BIVisualizationNode, config }
+const dashboardProps: BIDrilldownProps = {
+ key: 'dashboard-exploration-story',
+ query,
+ onFilterDashboard: () => {},
+ getDashboardFilterUrl: () => '/project/1/dashboard/1#bi_filter=example',
+}
+
+function ExploreResult({ filtering = true, total = false }: { filtering?: boolean; total?: boolean }): JSX.Element {
+ const props = filtering ? dashboardProps : { ...dashboardProps, onFilterDashboard: undefined }
+ useEffect(() => {
+ const logic = biDrilldownLogic(props)
+ const unmount = logic.mount()
+ logic.actions.inspect(total ? { count: 42 } : { status: 'paid' })
+ return unmount
+ }, [filtering, total])
+ return <BIDrilldownModal logicProps={props} />
+}
+
+const meta: Meta = {
+ title: 'Products/Business intelligence/Dashboard exploration',
+ parameters: { layout: 'fullscreen', testOptions: { waitForSelector: '[role="dialog"]' } },
+}
+export default meta
+export const FilterDashboard: StoryObj = { render: () => <ExploreResult /> }
+export const UnsupportedTotal: StoryObj = { render: () => <ExploreResult total /> }
+export const WorksheetOnly: StoryObj = { render: () => <ExploreResult filtering={false} /> }
diff --git a/products/business_intelligence/frontend/BIDrilldownModal.tsx b/products/business_intelligence/frontend/BIDrilldownModal.tsx
index c6115c52e8c8..19e5afd35ccc 100644
--- a/products/business_intelligence/frontend/BIDrilldownModal.tsx
+++ b/products/business_intelligence/frontend/BIDrilldownModal.tsx
@@ -20,8 +20,9 @@ export function BIDrilldownModal({
onNavigate?: (worksheet: BIVisualizationNode) => void
navigationDisabledReason?: string
}): JSX.Element {
- const { selection, queries, showRows, hierarchyDrills, interaction } = useValues(biDrilldownLogic(props))
- const { close, viewRows } = useActions(biDrilldownLogic(props))
+ const { selection, queries, showRows, hierarchyDrills, interaction, record, dashboardFilterDisabledReason } =
+ useValues(biDrilldownLogic(props))
+ const { close, viewRows, filterDashboard } = useActions(biDrilldownLogic(props))
return (
<LemonModal
title="Explore this result"
@@ -45,6 +46,35 @@ export function BIDrilldownModal({
</ul>
) : null}
<div className="flex flex-wrap gap-2">
+ {!interaction && props.onFilterDashboard && (
+ <LemonButton
+ type="primary"
+ disabledReason={dashboardFilterDisabledReason}
+ to={
+ record && !dashboardFilterDisabledReason
+ ? props.getDashboardFilterUrl?.(record)
+ : undefined
+ }
+ disableClientSideRouting
+ onClick={(event) => {
+ if (
+ event.button !== 0 ||
+ event.metaKey ||
+ event.ctrlKey ||
+ event.shiftKey ||
+ event.altKey
+ ) {
+ return
+ }
+ event.preventDefault()
+ filterDashboard()
+ }}
+ >
+ {record && props.isDashboardFilterSelected?.(record)
+ ? 'Remove filter'
+ : 'Filter dashboard by this result'}
+ </LemonButton>
+ )}
{!interaction &&
hierarchyDrills.map(({ hierarchy, next, worksheet }) => (
<LemonButton