: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(insights): make funnel bars open persons outside the insight scene (#91395)
Aleksander Błaszkiewiczbbf20f428507
diff --git a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.test.tsx b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.test.tsxnew file mode 100644index 000000000000..28f9e9b11a17--- /dev/null+++ b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.test.tsx@@ -0,0 +1,86 @@+import '@testing-library/jest-dom'++import { cleanup, render, screen, waitFor } from '@testing-library/react'+import { BindLogic } from 'kea'++import { clickAtIndex, ensureJsdom, hoverUntilTooltip } from '@posthog/quill-charts/testing'++import { insightLogic } from 'scenes/insights/insightLogic'++import funnelTopToBottomFixture from '~/mocks/fixtures/api/projects/team_id/insights/funnelTopToBottom.json'+import { groupsModel } from '~/models/groupsModel'+import { dataNodeLogic, type DataNodeLogicProps } from '~/queries/nodes/DataNode/dataNodeLogic'+import { insightVizDataNodeKey } from '~/queries/nodes/InsightViz/InsightViz'+import { getCachedResults } from '~/queries/nodes/InsightViz/utils'+import { NodeKind } from '~/queries/schema/schema-general'+import { initKeaTests } from '~/test/init'+import { InsightLogicProps, InsightShortId } from '~/types'++import { FunnelBarHorizontalChart } from './FunnelBarHorizontalChart'++jest.mock('scenes/trends/persons-modal/PersonsModal', () => ({ openPersonsModal: jest.fn() }))+// eslint-disable-next-line @typescript-eslint/no-var-requires+const { openPersonsModal } = require('scenes/trends/persons-modal/PersonsModal')++ensureJsdom()++let uniqueNode = 0++/** Mounts the chart and returns the event wrapper of the first step's bar. */+async function renderFirstStepBar(inCardView: boolean): Promise<HTMLElement> {+ const dashboardItemId = `FunnelBarHorizontalChartTest.${uniqueNode++}` as InsightShortId+ const fixture = funnelTopToBottomFixture as any+ const source = fixture.query.source+ const cachedInsight = { ...fixture, short_id: dashboardItemId }+ const insightProps: InsightLogicProps = { dashboardItemId, doNotLoad: true, cachedInsight }+ const dataNodeLogicProps: DataNodeLogicProps = {+ query: source,+ key: insightVizDataNodeKey(insightProps),+ cachedResults: getCachedResults(cachedInsight, source),+ doNotLoad: true,+ }++ render(+ <BindLogic logic={insightLogic} props={insightProps}>+ <BindLogic logic={dataNodeLogic} props={dataNodeLogicProps}>+ <FunnelBarHorizontalChart inCardView={inCardView} />+ </BindLogic>+ </BindLogic>+ )++ await waitFor(() => expect(screen.getAllByLabelText(/chart with/i).length).toBeGreaterThan(0), { timeout: 4000 })+ return screen.getAllByLabelText(/chart with/i)[0].parentElement!+}++describe('FunnelBarHorizontalChart', () => {+ beforeEach(() => {+ initKeaTests()+ groupsModel.mount()+ ;(openPersonsModal as jest.Mock).mockClear()+ })++ afterEach(() => {+ cleanup()+ })++ // A card-view bar used to render the hint while its click handler was withheld, so the tooltip+ // promised a drill-in that never happened on dashboards, notebooks, and PostHog AI answers.+ describe.each([+ ['the insight scene', false],+ ['a card view', true],+ ])('in %s', (_surface, inCardView) => {+ it('opens the persons modal for the bar it invites the user to click', async () => {+ const bar = await renderFirstStepBar(inCardView)++ const tooltip = await hoverUntilTooltip(bar, 0, 1)+ expect(tooltip.textContent).toContain('Click to view')++ await clickAtIndex(bar, 0, 1)+ await waitFor(() => expect(openPersonsModal).toHaveBeenCalled())+ expect((openPersonsModal as jest.Mock).mock.calls[0][0].query).toMatchObject({+ kind: NodeKind.FunnelsActorsQuery,+ funnelStep: 1,+ })+ })+ })+})diff --git a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.tsx b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.tsxindex d3a2a2e2af95..eea1fba43efe 100644--- a/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.tsx+++ b/products/product_analytics/frontend/insights/funnels/FunnelBarHorizontalChart/FunnelBarHorizontalChart.tsx@@ -40,7 +40,6 @@ const handleChartError = (error: Error, info: ErrorInfo): void => {export function FunnelBarHorizontalChart({showPersonsModal: showPersonsModalProp = true,- inCardView,}: ChartParams): JSX.Element | null {const { isDarkModeOn } = useValues(themeLogic)const theme = useChartTheme()@@ -63,8 +62,9 @@ export function FunnelBarHorizontalChart({const { aggregationLabel } = useValues(groupsModel)const steps = visibleStepsWithConversionMetrics+ // One flag drives both the bar's click handler and the tooltip's "Click to view …" hint, so the+ // hint can never promise a drill-in the bar doesn't do.const showPersonsModal = canOpenPersonModal && showPersonsModalProp- const interactive = showPersonsModal && !inCardViewconst isUnordered = funnelsFilter?.funnelOrderType === StepOrderValue.UNORDEREDconst hasOptionalSteps = steps.some((_, stepIndex) => isStepOptional(stepIndex + 1))const groupTypeLabel = aggregationLabel(querySource?.aggregation_group_type_index).plural@@ -187,7 +187,7 @@ export function FunnelBarHorizontalChart({key={bar.series[0].key}stepData={bar}theme={theme}- interactive={interactive}+ interactive={showPersonsModal}onSegmentClick={onSegmentClick}renderTooltip={renderTooltip}onError={handleChartError}@@ -198,7 +198,7 @@ export function FunnelBarHorizontalChart({<SingleStepBarstepData={stepsData[stepIndex]}theme={theme}- interactive={interactive}+ interactive={showPersonsModal}onSegmentClick={onSegmentClick}renderTooltip={renderTooltip}onError={handleChartError}