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.

fix(insights): only cap dashboard bar rows on tiles, not the insight page (#61388)

Sam Pennington074a0c2c1175
diff --git a/frontend/src/scenes/trends/Trends.tsx b/frontend/src/scenes/trends/Trends.tsx
index e4374d7b225d..0f0a3d39125a 100644
--- a/frontend/src/scenes/trends/Trends.tsx
+++ b/frontend/src/scenes/trends/Trends.tsx
@@ -112,7 +112,7 @@ export function TrendInsight({ view, context, embedded, inSharedMode, editMode }
}
if (display === ChartDisplayType.ActionsBar || display === ChartDisplayType.ActionsUnstackedBar) {
if (hogChartsTrendsEnabled) {
- return <TrendsBarChart context={context} inSharedMode={inSharedMode} />
+ return <TrendsBarChart context={context} inSharedMode={inSharedMode} embedded={embedded} />
}
if (hogChartsStickinessEnabled) {
return <StickinessBarChart context={context} />
@@ -143,7 +143,7 @@ export function TrendInsight({ view, context, embedded, inSharedMode, editMode }
}
if (display === ChartDisplayType.ActionsBarValue) {
if (hogChartsTrendsEnabled) {
- return <TrendsBarChart context={context} inSharedMode={inSharedMode} />
+ return <TrendsBarChart context={context} inSharedMode={inSharedMode} embedded={embedded} />
}
return <ActionsHorizontalBar {...commonProps} />
}
diff --git a/frontend/src/test/insight-testing/render-insight.tsx b/frontend/src/test/insight-testing/render-insight.tsx
index 224fdf229c4b..4cbd77971aae 100644
--- a/frontend/src/test/insight-testing/render-insight.tsx
+++ b/frontend/src/test/insight-testing/render-insight.tsx
@@ -86,6 +86,8 @@ export interface RenderInsightProps {
featureFlags?: Record<string, string | boolean>
context?: QueryContext<InsightVizNode>
inSharedMode?: boolean
+ /** Render as a fixed-height dashboard/card tile rather than the full insight page. */
+ embedded?: boolean
}
function InsightWrapper({
@@ -93,11 +95,13 @@ function InsightWrapper({
showFilters = false,
context,
inSharedMode,
+ embedded,
}: {
query: InsightQuery
showFilters: boolean
context?: QueryContext<InsightVizNode>
inSharedMode?: boolean
+ embedded?: boolean
}): JSX.Element {
const [vizQuery, setVizQuery] = useState<InsightVizNode>({
kind: NodeKind.InsightVizNode,
@@ -119,6 +123,7 @@ function InsightWrapper({
setQuery={setVizQuery}
context={context}
inSharedMode={inSharedMode}
+ embedded={embedded}
/>
)
}
@@ -132,6 +137,7 @@ export function renderInsight(props: RenderInsightProps = {}): ReturnType<typeof
showFilters={props.showFilters ?? true}
context={props.context}
inSharedMode={props.inSharedMode}
+ embedded={props.embedded}
/>
)
}
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
index a09f52cfb48b..dab290a12f06 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.test.tsx
@@ -345,6 +345,57 @@ describe('TrendsBarChart (ActionsBarValue)', () => {
)
})
+ // A dashboard/card tile is a fixed height, so the chart caps the breakdown rows to those that
+ // fit. The full insight page is `embedded: false` — even when opened from a dashboard, where
+ // `dashboardId` is in the URL — so it must keep growing to render every breakdown row.
+ it.each([
+ { name: 'insight page (not embedded) renders every breakdown bar', embedded: false, expectAllRows: true },
+ {
+ name: 'dashboard tile (embedded) caps bars to those that fit the tile',
+ embedded: true,
+ expectAllRows: false,
+ },
+ ])('$name', async ({ embedded, expectAllRows }) => {
+ const totalRows = 20
+ const manyBreakdowns = {
+ results: Array.from({ length: totalRows }, (_, i) => ({
+ action: { id: '$napped', type: 'events', name: 'Napped', order: 0 },
+ label: `value ${i}`,
+ count: totalRows - i,
+ aggregated_value: totalRows - i,
+ data: [totalRows - i],
+ labels: ['Day 1'],
+ days: ['2024-01-01'],
+ breakdown_value: `value-${i}`,
+ })),
+ }
+ renderInsight({
+ query: aggregatedBar({
+ series: [{ kind: NodeKind.EventsNode, event: 'Napped', name: 'Napped' }],
+ breakdownFilter: { breakdown: 'hedgehog', breakdown_type: 'event' },
+ }),
+ embedded,
+ featureFlags: HOG_CHARTS_FLAG,
+ mocks: {
+ additionalMockResponses: [{ match: (q) => q.kind === NodeKind.TrendsQuery, response: manyBreakdowns }],
+ },
+ })
+ await screen.findByRole('img', { name: /chart with/i }, { timeout: 5000 })
+
+ await waitFor(
+ () => {
+ const ticks = getHogChart().yTicks()
+ if (expectAllRows) {
+ expect(ticks).toHaveLength(totalRows)
+ } else {
+ expect(ticks.length).toBeGreaterThan(0)
+ expect(ticks.length).toBeLessThan(totalRows)
+ }
+ },
+ { timeout: 5000 }
+ )
+ })
+
it('omits the header from the tooltip', async () => {
renderInsight({
query: aggregatedBar(),
diff --git a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
index cefdbee97b8e..bd68b88b8e3a 100644
--- a/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
+++ b/products/product_analytics/frontend/insights/trends/TrendsBarChart/TrendsBarChart.tsx
@@ -50,6 +50,8 @@ import {
interface TrendsBarChartProps {
context?: QueryContext<InsightVizNode>
inSharedMode?: boolean
+ /** True when rendered as a fixed-height dashboard/card tile, false on the full insight page. */
+ embedded?: boolean
}
const EMPTY_LABELS: string[] = []
@@ -77,9 +79,13 @@ const resolveGroupTypeLabel = (
const handleChartError = makeChartErrorHandler('trends-bar-chart')
-export function TrendsBarChart({ context, inSharedMode = false }: TrendsBarChartProps): JSX.Element | null {
+export function TrendsBarChart({
+ context,
+ inSharedMode = false,
+ embedded = false,
+}: TrendsBarChartProps): JSX.Element | null {
const theme = useMemo(() => buildTheme(), [])
- const { insightProps, insight, isInDashboardContext } = useValues(insightLogic)
+ const { insightProps, insight } = useValues(insightLogic)
const {
indexedResults,
@@ -242,9 +248,10 @@ export function TrendsBarChart({ context, inSharedMode = false }: TrendsBarChart
// Breakdown values become category (y-axis) labels here; truncate long ones (e.g. URLs)
// so they don't grow the margin and push the plot off screen. Full value shows on hover.
maxCategoryLabelWidth: MAX_CATEGORY_LABEL_WIDTH,
- // On a dashboard the tile is a fixed height: fit the rows that fit instead of growing
- // the tile and scrolling. On the full insight page, keep the grow-to-fit-all behavior.
- bars: { fitToHeight: isInDashboardContext },
+ // Dashboard/card tiles are a fixed height, so cap the rows to those that fit. The full
+ // insight page is `embedded: false` — even when opened from a dashboard (dashboardId in
+ // the URL) — so it keeps the grow-to-fit-all behavior and renders every breakdown row.
+ bars: { fitToHeight: embedded },
}
}, [
yAxisScaleType,
@@ -253,7 +260,7 @@ export function TrendsBarChart({ context, inSharedMode = false }: TrendsBarChart
trendsFilter?.yAxisLabel,
displayLabels,
labels,
- isInDashboardContext,
+ embedded,
])
const canHandleClick = !!context?.onDataPointClick || !!hasPersonsModal