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(dashboards): apply default tile sizes by insight query kind (#116821)

Thomas Obermüller939f8b9b36c9
diff --git a/frontend/src/scenes/dashboard/tileLayouts.test.ts b/frontend/src/scenes/dashboard/tileLayouts.test.ts
index 9776d9b83737..287b3e19530e 100644
--- a/frontend/src/scenes/dashboard/tileLayouts.test.ts
+++ b/frontend/src/scenes/dashboard/tileLayouts.test.ts
@@ -60,22 +60,59 @@ describe('calculating tile layouts', () => {
expect(calculateLayouts(tiles).sm?.[0]).toMatchObject({ w: 2, h: 1 })
})
- it('defaults SQL metric tiles without a stored layout to 3 by 3', () => {
- const tiles: DashboardTile[] = [
- {
- id: 1,
- insight: {
- query: {
- kind: NodeKind.DataVisualizationNode,
- source: { kind: NodeKind.HogQLQuery, query: 'SELECT count() FROM events' },
- display: ChartDisplayType.Metric,
- },
+ it.each([
+ {
+ name: 'SQL metric',
+ query: {
+ kind: NodeKind.DataVisualizationNode,
+ source: { kind: NodeKind.HogQLQuery, query: 'SELECT count() FROM events' },
+ display: ChartDisplayType.Metric,
+ },
+ expected: { w: 3, h: 3 },
+ },
+ {
+ name: 'funnel',
+ query: { kind: NodeKind.InsightVizNode, source: { kind: NodeKind.FunnelsQuery, series: [] } },
+ expected: { w: 4, h: 4 },
+ },
+ {
+ name: 'retention',
+ query: { kind: NodeKind.InsightVizNode, source: { kind: NodeKind.RetentionQuery, retentionFilter: {} } },
+ expected: { w: 6, h: 7 },
+ },
+ {
+ name: 'paths',
+ query: { kind: NodeKind.InsightVizNode, source: { kind: NodeKind.PathsQuery, pathsFilter: {} } },
+ expected: { w: 12, h: 7 },
+ },
+ {
+ name: 'bold number trends',
+ query: {
+ kind: NodeKind.InsightVizNode,
+ source: {
+ kind: NodeKind.TrendsQuery,
+ series: [],
+ trendsFilter: { display: ChartDisplayType.BoldNumber },
},
- layouts: {},
- } as unknown as DashboardTile,
- ]
+ },
+ expected: { w: 2, h: 2 },
+ },
+ {
+ name: 'line graph trends',
+ query: {
+ kind: NodeKind.InsightVizNode,
+ source: {
+ kind: NodeKind.TrendsQuery,
+ series: [],
+ trendsFilter: { display: ChartDisplayType.ActionsLineGraph },
+ },
+ },
+ expected: { w: 6, h: 5 },
+ },
+ ])('sizes $name tiles without a stored layout by their query kind', ({ query, expected }) => {
+ const tiles: DashboardTile[] = [{ id: 1, insight: { query }, layouts: {} } as unknown as DashboardTile]
- expect(calculateLayouts(tiles).sm?.[0]).toMatchObject({ w: 3, h: 3 })
+ expect(calculateLayouts(tiles).sm?.[0]).toMatchObject(expected)
})
it('when the tiles have only 2-col layouts, 1 col layout is calculated', () => {
diff --git a/frontend/src/scenes/dashboard/tileLayouts.ts b/frontend/src/scenes/dashboard/tileLayouts.ts
index 1791f280952e..85685b99d2cf 100644
--- a/frontend/src/scenes/dashboard/tileLayouts.ts
+++ b/frontend/src/scenes/dashboard/tileLayouts.ts
@@ -9,8 +9,14 @@ import {
import { textCardConverter } from 'lib/components/Cards/TextCard/textCardMarkdown'
import { BREAKPOINT_COLUMN_COUNTS } from 'scenes/dashboard/dashboardUtils'
-import { getQueryBasedInsightModel } from '~/queries/nodes/InsightViz/utils'
-import { isFunnelsQuery, isMetricInsightQuery, isPathsQuery, isRetentionQuery, isTrendsQuery } from '~/queries/utils'
+import {
+ isFunnelsQuery,
+ isInsightVizNode,
+ isMetricInsightQuery,
+ isPathsQuery,
+ isRetentionQuery,
+ isTrendsQuery,
+} from '~/queries/utils'
import { ChartDisplayType, DashboardLayoutSize, DashboardTile } from '~/types'
import { getImageOnlyTextCardImage } from 'products/dashboards/frontend/components/ImageTile/imageTileUtils'
@@ -243,7 +249,8 @@ export const calculateLayouts = (tiles: DashboardTile[]): Partial<Record<Dashboa
}
const layouts = (sortedDashboardTiles || []).map((tile) => {
- const query = tile.insight ? getQueryBasedInsightModel(tile.insight) : null
+ const query = tile.insight?.query
+ const source = isInsightVizNode(query) ? query.source : query
// Base constraints
let defaultW = 6
let defaultH = 5
@@ -251,19 +258,19 @@ export const calculateLayouts = (tiles: DashboardTile[]): Partial<Record<Dashboa
if (tile.text) {
defaultW = 2
defaultH = 2
- } else if (isFunnelsQuery(query)) {
+ } else if (isFunnelsQuery(source)) {
defaultW = 4
defaultH = 4
- } else if (isRetentionQuery(query)) {
+ } else if (isRetentionQuery(source)) {
defaultW = 6
defaultH = 7
- } else if (isPathsQuery(query)) {
+ } else if (isPathsQuery(source)) {
defaultW = columnCount // Paths take up so much space that they need to be full width to be readable
defaultH = 7
- } else if (isTrendsQuery(query) && query.trendsFilter?.display === ChartDisplayType.BoldNumber) {
+ } else if (isTrendsQuery(source) && source.trendsFilter?.display === ChartDisplayType.BoldNumber) {
defaultW = 2
defaultH = 2
- } else if (isMetricInsightQuery(query?.query)) {
+ } else if (isMetricInsightQuery(query)) {
defaultW = 3
defaultH = 3
}