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 tile density presets (#83909)

Matt Puaa4a8b607982e
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index c9c7b1f18611..de07b2eb8d0c 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -287,6 +287,7 @@ export const FEATURE_FLAGS = {
CUSTOMER_PROFILE_CONFIG_BUTTON: 'customer-profile-config-button', // owner: @arthurdedeus #team-customer-analytics
DASHBOARD_AUTO_PREVIEW_LIMIT: 'dashboard-auto-preview-limit', // owner: @pauldambra #team-product-analytics
DASHBOARD_EXPORT_NUDGE: 'dashboard-export-nudge', // owner: #team-analytics-platform multivariate=control,test, nudges people who just exported a dashboard toward a recurring subscription
+ DASHBOARD_CUSTOMIZATION: 'dashboard-customization', // owner: @MattPua #team-analytics-platform
DASHBOARD_INLINE_TILE_INSERTION: 'dashboard-inline-tile-insertion', // owner: @MattPua #team-analytics-platform
DASHBOARD_LAYOUT_DISCARD_PROMPT: 'dashboard-layout-discard-prompt', // owner: @cory.s #team-analytics-platform
DASHBOARD_TEMPLATE_CHOOSER_EXPERIMENT: 'dashboard-template-chooser-experiment', // owner: @mattp #team-analytics-platform multivariate=control,simple,new
diff --git a/frontend/src/lib/utils/eventUsageLogic.ts b/frontend/src/lib/utils/eventUsageLogic.ts
index e3bbdc907131..e8fbc506f7d4 100644
--- a/frontend/src/lib/utils/eventUsageLogic.ts
+++ b/frontend/src/lib/utils/eventUsageLogic.ts
@@ -52,6 +52,7 @@ import { PROPERTY_KEYS } from '~/taxonomy/taxonomy'
import {
ChartDisplayType,
CohortType,
+ DashboardTileSpacing,
DashboardMode,
DashboardTemplateScope,
DashboardTile,
@@ -871,6 +872,9 @@ export interface eventUsageLogicActions {
dashboardId: number | undefined
isShared: boolean
}
+ reportDashboardTileDensityConfigured: (tileDensity: DashboardTileSpacing) => {
+ tileDensity: DashboardTileSpacing
+ }
reportDashboardTileIgnoreDashboardFiltersToggled: (
dashboardId: number | undefined,
insightId: number | null,
@@ -2327,6 +2331,7 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
layoutZoom: number,
source: 'button' | 'shortcut'
) => ({ dashboard, layoutZoom, source }),
+ reportDashboardTileDensityConfigured: (tileDensity: DashboardTileSpacing) => ({ tileDensity }),
reportDashboardEditModeDiscardPrompt: (
dashboard: DashboardType<QueryBasedInsightModel> | null,
action: 'shown' | 'discarded' | 'kept_editing'
@@ -3368,6 +3373,9 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
source,
})
},
+ reportDashboardTileDensityConfigured: async ({ tileDensity }) => {
+ posthog.capture('dashboard tile density configured', { tile_density: tileDensity })
+ },
reportDashboardEditModeDiscardPrompt: async ({ dashboard, action }) => {
posthog.capture('dashboard edit mode discard prompt', {
dashboard_id: dashboard?.id,
diff --git a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
index d427a66f9e7b..b44dd07ca629 100644
--- a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
+++ b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx
@@ -7,8 +7,9 @@ import { AccessControlAction } from 'lib/components/AccessControlAction'
import { Shortcut } from 'lib/components/Shortcuts/Shortcut'
import { keyBinds } from 'lib/components/Shortcuts/shortcuts'
import { FEATURE_FLAGS } from 'lib/constants'
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
-import { LemonMenu, LemonMenuItem, LemonMenuItems } from 'lib/lemon-ui/LemonMenu'
+import { LemonMenu, LemonMenuItem, LemonMenuItems, LemonMenuOverlay } from 'lib/lemon-ui/LemonMenu'
import { getAccessControlDisabledReason } from 'lib/utils/accessControlUtils'
import { DashboardEventSource, eventUsageLogic } from 'lib/utils/eventUsageLogic'
import { MaxTool } from 'scenes/max/MaxTool'
@@ -18,6 +19,8 @@ import { urls } from 'scenes/urls'
import { iconForType } from '~/layout/panel-layout/ProjectTree/defaultTree'
import { AccessControlLevel, AccessControlResourceType, DashboardMode } from '~/types'
+import { DashboardCustomizeMenu } from 'products/dashboards/frontend/components/DashboardCustomizeMenu/DashboardCustomizeMenu'
+
import { DashboardLoadAction, dashboardLogic } from './dashboardLogic'
import { DashboardSubscribeButton } from './DashboardSubscribeButton'
@@ -250,6 +253,7 @@ export function FullscreenModeActions(): JSX.Element {
export function ViewModeActions(): JSX.Element {
const { dashboard, canEditDashboard, tiles } = useValues(dashboardLogic)
const { setDashboardMode } = useActions(dashboardLogic)
+ const dashboardCustomizationEnabled = useFeatureFlag('DASHBOARD_CUSTOMIZATION')
const { push } = useActions(router)
if (!dashboard) {
return <></>
@@ -292,11 +296,31 @@ export function ViewModeActions(): JSX.Element {
onClick={() => setDashboardMode(DashboardMode.Edit, DashboardEventSource.SceneCommonButtons)}
size="small"
icon={<IconGridMasonry fontSize="16" />}
- tooltip="Edit layout"
+ tooltip="Customize dashboard"
tooltipPlacement="top"
- disabledReason={tiles.length === 0 ? 'Add at least one tile to edit layout' : undefined}
+ disabledReason={
+ tiles.length === 0 ? 'Add at least one tile to customize this dashboard' : undefined
+ }
+ sideAction={
+ dashboardCustomizationEnabled
+ ? {
+ 'data-attr': 'dashboard-edit-layout-customize-dropdown',
+ disabledReason:
+ tiles.length === 0
+ ? 'Add at least one tile to customize this dashboard'
+ : undefined,
+ dropdown: {
+ closeOnClickInside: false,
+ placement: 'bottom-end',
+ overlay: (
+ <LemonMenuOverlay items={[{ label: () => <DashboardCustomizeMenu /> }]} />
+ ),
+ },
+ }
+ : undefined
+ }
>
- Edit layout
+ Customize
</LemonButton>
</Shortcut>
)}
diff --git a/frontend/src/scenes/dashboard/DashboardItems.scss b/frontend/src/scenes/dashboard/DashboardItems.scss
index 349aed9d8d1e..5403d392629f 100644
--- a/frontend/src/scenes/dashboard/DashboardItems.scss
+++ b/frontend/src/scenes/dashboard/DashboardItems.scss
@@ -15,9 +15,13 @@
position: relative;
transition: height 100ms ease;
- /* remove initial loading animation, animations are only needed in edit mode */
+ /* Preserve the tile border transition while spacing changes animate. */
&.dashboard-view-mode .react-grid-item {
- transition: border-color 100ms ease;
+ transition:
+ transform 220ms ease-out,
+ width 220ms ease-out,
+ height 220ms ease-out,
+ border-color 100ms ease;
/* Skip rendering for off-screen tiles during resize/reflow */
content-visibility: auto;
@@ -81,8 +85,10 @@
.react-grid-item {
box-sizing: border-box;
- transition: all 100ms ease;
- transition-property: left, top;
+ transition:
+ transform 220ms ease-out,
+ width 220ms ease-out,
+ height 220ms ease-out;
// Drop InsightCard's fixed 30rem so RGL's inline height is the only constraint.
&.DashboardTileCard.InsightCard {
@@ -242,3 +248,10 @@
cursor: sw-resize;
}
}
+
+@media (prefers-reduced-motion: reduce) {
+ .react-grid-layout.dashboard-view-mode .react-grid-item,
+ .react-grid-layout .react-grid-item {
+ transition: none;
+ }
+}
diff --git a/frontend/src/scenes/dashboard/DashboardItems.test.tsx b/frontend/src/scenes/dashboard/DashboardItems.test.tsx
index 60803d667893..b633c2c90ebf 100644
--- a/frontend/src/scenes/dashboard/DashboardItems.test.tsx
+++ b/frontend/src/scenes/dashboard/DashboardItems.test.tsx
@@ -271,6 +271,79 @@ describe('DashboardItems', () => {
expect(container.firstChild).toMatchSnapshot()
})
+ it.each([
+ ['tight', '8,8'],
+ ['condensed', '12,12'],
+ ['relaxed', '32,32'],
+ ] as const)('uses %s tile spacing for tiles and the edit grid', (tileSpacing, margin) => {
+ mockedUseValues.mockImplementation((logic) => {
+ if (logic === dashboardLogic) {
+ return {
+ dashboard: { id: 5, customization: { tile_spacing: tileSpacing } },
+ tiles: [],
+ layouts: { sm: [] },
+ dashboardMode: DashboardMode.Edit,
+ layoutEditMode: true,
+ placement: DashboardPlacement.Dashboard,
+ isRefreshingQueued: () => false,
+ isRefreshing: () => false,
+ highlightedInsightId: null,
+ refreshStatus: {},
+ dashboardStreaming: false,
+ effectiveEditBarFilters: {},
+ effectiveDashboardVariableOverrides: {},
+ dataColorThemeId: null,
+ canEditDashboard: true,
+ layoutZoom: 1,
+ widgetResultsByTileId: {},
+ widgetRefreshStatus: {},
+ }
+ }
+ if (logic === dashboardsModel) {
+ return { nameSortedDashboards: [] }
+ }
+ return {}
+ })
+
+ const { container } = render(<DashboardItems />)
+ expect(container.querySelector('[data-attr="grid-background"]')).toHaveAttribute('data-margin', margin)
+ expect(container.querySelector('[data-attr="react-grid-layout"]')).toHaveAttribute('data-margin', margin)
+ })
+
+ it('uses standard spacing when persisted customization is invalid', () => {
+ mockedUseValues.mockImplementation((logic) => {
+ if (logic === dashboardLogic) {
+ return {
+ dashboard: { id: 5, customization: { tile_spacing: 'unknown' } },
+ tiles: [],
+ layouts: { sm: [] },
+ dashboardMode: DashboardMode.Edit,
+ layoutEditMode: true,
+ placement: DashboardPlacement.Dashboard,
+ isRefreshingQueued: () => false,
+ isRefreshing: () => false,
+ highlightedInsightId: null,
+ refreshStatus: {},
+ dashboardStreaming: false,
+ effectiveEditBarFilters: {},
+ effectiveDashboardVariableOverrides: {},
+ dataColorThemeId: null,
+ canEditDashboard: true,
+ layoutZoom: 1,
+ widgetResultsByTileId: {},
+ widgetRefreshStatus: {},
+ }
+ }
+ if (logic === dashboardsModel) {
+ return { nameSortedDashboards: [] }
+ }
+ return {}
+ })
+
+ const { container } = render(<DashboardItems />)
+ expect(container.querySelector('[data-attr="react-grid-layout"]')).toHaveAttribute('data-margin', '16,16')
+ })
+
it('shows widget tiles on public dashboards', () => {
const widgetTile = {
id: 2,
diff --git a/frontend/src/scenes/dashboard/DashboardItems.tsx b/frontend/src/scenes/dashboard/DashboardItems.tsx
index da8e08c9c81a..157d7718e486 100644
--- a/frontend/src/scenes/dashboard/DashboardItems.tsx
+++ b/frontend/src/scenes/dashboard/DashboardItems.tsx
@@ -38,6 +38,8 @@ import { getCurrentExporterData } from '~/exporter/exporterViewLogic'
import { insightsModel } from '~/models/insightsModel'
import { DashboardLayoutSize, DashboardMode, DashboardPlacement, DashboardType } from '~/types'
+import { getDashboardTileSpacingGap } from 'products/dashboards/frontend/dashboardCustomization'
+
import { DashboardButtonTileItem } from './items/DashboardButtonTileItem'
import { DashboardErrorTileItem } from './items/DashboardErrorTileItem'
import { DashboardTextItem } from './items/DashboardTextItem'
@@ -244,7 +246,12 @@ export function DashboardItems({ showCreateAnomalyAlertButton }: DashboardItemsP
const effectiveZoom = layoutEditMode ? layoutZoom : 1
const rowHeight = BASE_ROW_HEIGHT * effectiveZoom
const spacingFactor = effectiveZoom < 1 ? 0.9 : 1
- const margin = useMemo(() => BASE_MARGIN.map((m) => m * spacingFactor) as [number, number], [spacingFactor])
+ const gridGap = getDashboardTileSpacingGap(dashboard?.customization?.tile_spacing)
+ const margin = useMemo(
+ () => BASE_MARGIN.map(() => gridGap * spacingFactor) as [number, number],
+ [gridGap, spacingFactor]
+ )
+
const getInsertMenuItems = useCallback(
(targetX: number, targetY: number, targetW?: number): LemonMenuItems =>
dashboard
diff --git a/frontend/src/scenes/dashboard/dashboardActivityDescriber.tsx b/frontend/src/scenes/dashboard/dashboardActivityDescriber.tsx
index 33ca00f5ba8a..d411967abd6a 100644
--- a/frontend/src/scenes/dashboard/dashboardActivityDescriber.tsx
+++ b/frontend/src/scenes/dashboard/dashboardActivityDescriber.tsx
@@ -2,6 +2,7 @@ import posthog from 'posthog-js'
import { DashboardFilter, HogQLVariable } from 'src/queries/schema/schema-general'
import { Link } from '@posthog/lemon-ui'
+import { DASHBOARD_TILE_SPACING_LABELS } from '@posthog/products-dashboards/frontend/dashboardCustomization'
import {
ActivityChange,
@@ -159,6 +160,19 @@ const dashboardActionsMapping: Record<
tiles: () => null,
last_viewed_at: () => null,
quick_filter_ids: () => null,
+ customization: function onChangedCustomization(change) {
+ const customization = change?.after as DashboardType['customization']
+ if (!customization?.tile_spacing) {
+ return null
+ }
+ return {
+ description: [
+ <>
+ changed tile density to <strong>{DASHBOARD_TILE_SPACING_LABELS[customization.tile_spacing]}</strong>
+ </>,
+ ],
+ }
+ },
}
export function dashboardActivityDescriber(logItem: ActivityLogItem, asNotification?: boolean): HumanizedChange {
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
index ed888c14e8e1..dc498c03d392 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts
+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts
@@ -364,6 +364,57 @@ describe('dashboardLogic', () => {
expect(logic.values.layouts).toBe(initialLayouts)
})
+ it('previews tile spacing immediately and persists only the final choice', async () => {
+ await expectLogic(logic).toFinishAllListeners()
+ ;(api.update as jest.Mock).mockClear()
+ const reportTileDensityConfigured = jest.spyOn(
+ eventUsageLogic.actions,
+ 'reportDashboardTileDensityConfigured'
+ )
+ jest.useFakeTimers()
+
+ try {
+ logic.actions.setDashboardTileSpacing('tight')
+ logic.actions.saveDashboardTileSpacing('tight')
+ logic.actions.setDashboardTileSpacing('relaxed')
+ logic.actions.saveDashboardTileSpacing('relaxed')
+
+ expect(logic.values.dashboard?.customization?.tile_spacing).toBe('relaxed')
+ expect(api.update).not.toHaveBeenCalled()
+
+ await jest.advanceTimersByTimeAsync(750)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(api.update).toHaveBeenCalledTimes(1)
+ expect(api.update).toHaveBeenCalledWith(`api/environments/${MOCK_TEAM_ID}/dashboards/5`, {
+ grid_spacing: 'relaxed',
+ })
+ expect(reportTileDensityConfigured).toHaveBeenCalledWith('relaxed')
+ } finally {
+ jest.useRealTimers()
+ }
+ })
+
+ it('does not report the default tile density', async () => {
+ await expectLogic(logic).toFinishAllListeners()
+ const reportTileDensityConfigured = jest.spyOn(
+ eventUsageLogic.actions,
+ 'reportDashboardTileDensityConfigured'
+ )
+ jest.useFakeTimers()
+
+ try {
+ logic.actions.saveDashboardTileSpacing('standard')
+
+ await jest.advanceTimersByTimeAsync(750)
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(reportTileDensityConfigured).not.toHaveBeenCalled()
+ } finally {
+ jest.useRealTimers()
+ }
+ })
+
it('saving without changes does not call api', async () => {
await expectLogic(logic).toFinishAllListeners()
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsx
index 19f1da994952..f46b05944fd5 100644
--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx
+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx
@@ -99,6 +99,7 @@ import {
DashboardTemplateEditorType,
DashboardTile,
DashboardTileBasicType,
+ DashboardTileSpacing,
DashboardType,
DashboardWidgetType,
InsightColor,
@@ -280,6 +281,7 @@ export interface dashboardLogicValues {
dashboardLoading: boolean
dashboardMode: DashboardMode | null
dashboardStreaming: boolean
+ dashboardTileSpacingSaving: boolean
dashboardWidgetsEnabled: boolean
dataColorTheme: DataColorTheme | null
dataColorThemeId: number | null
@@ -667,6 +669,9 @@ export interface dashboardLogicActions {
variables?: unknown
} | null
}
+ saveDashboardTileSpacing: (tileSpacing: DashboardTileSpacing) => {
+ tileSpacing: DashboardTileSpacing
+ }
saveEditModeChanges: () => boolean
saveEditModeChangesFailure: (
error: string,
@@ -737,6 +742,12 @@ export interface dashboardLogicActions {
setDashboardStreamFailed: () => {
value: true
}
+ setDashboardTileSpacing: (tileSpacing: DashboardTileSpacing) => {
+ tileSpacing: DashboardTileSpacing
+ }
+ setDashboardTileSpacingSaving: (saving: boolean) => {
+ saving: boolean
+ }
setDataColorThemeId: (dataColorThemeId: number | null) => {
dataColorThemeId: number | null
}
@@ -1299,6 +1310,7 @@ export const dashboardLogic = kea<dashboardLogicType>([
setAccessDeniedToDashboard: true,
/** Update the dashboard in dashboardsModel with given payload. */
triggerDashboardUpdate: (payload) => ({ payload }),
+ saveDashboardTileSpacing: (tileSpacing: DashboardTileSpacing) => ({ tileSpacing }),
updateDashboardTags: (tags: string[]) => ({ tags }),
/** Update page visibility for virtualized rendering. */
setPageVisibility: (visible: boolean) => ({ visible }),
@@ -1370,6 +1382,8 @@ export const dashboardLogic = kea<dashboardLogicType>([
*/
setBreakdownColorConfig: (config: BreakdownColorConfig) => ({ config }),
setDataColorThemeId: (dataColorThemeId: number | null) => ({ dataColorThemeId }),
+ setDashboardTileSpacing: (tileSpacing: DashboardTileSpacing) => ({ tileSpacing }),
+ setDashboardTileSpacingSaving: (saving: boolean) => ({ saving }),
restoreTemporaryColorState: (colors: BreakdownColorConfig[], themeId: { themeId: number | null } | null) => ({
colors,
themeId,
@@ -1776,6 +1790,12 @@ export const dashboardLogic = kea<dashboardLogicType>([
tileStreamingFailure: () => false,
},
],
+ dashboardTileSpacingSaving: [
+ false,
+ {
+ setDashboardTileSpacingSaving: (_, { saving }) => saving,
+ },
+ ],
loadingPreview: [
false,
{
@@ -1902,6 +1922,13 @@ export const dashboardLogic = kea<dashboardLogicType>([
tiles: state?.tiles?.map((tile) => (tile.id === tileId ? { ...tile, ...properties } : tile)),
} as DashboardType<QueryBasedInsightModel>
},
+ setDashboardTileSpacing: (state, { tileSpacing }) =>
+ state
+ ? {
+ ...state,
+ customization: { ...state.customization, tile_spacing: tileSpacing },
+ }
+ : state,
removeTile: (state, { tile }) => {
// Optimistically drop the tile so the grid reflows immediately; the loader rolls back on failure.
return {
@@ -3676,6 +3703,48 @@ export const dashboardLogic = kea<dashboardLogicType>([
dashboardsModel.actions.updateDashboard({ id: values.dashboard.id, ...payload })
}
},
+ saveDashboardTileSpacing: async ({ tileSpacing }, breakpoint) => {
+ await breakpoint(750)
+
+ if (cache.dashboardTileSpacingSaveInFlight) {
+ cache.pendingDashboardTileSpacing = tileSpacing
+ return
+ }
+
+ const persistedDashboard = dashboardsModel.values.rawDashboards[props.id]
+ const persistedTileSpacing =
+ persistedDashboard && 'customization' in persistedDashboard
+ ? (persistedDashboard.customization?.tile_spacing ?? 'standard')
+ : 'standard'
+ cache.dashboardTileSpacingSaveInFlight = true
+ actions.setDashboardTileSpacingSaving(true)
+ try {
+ const dashboard = await api.update<DashboardType<QueryBasedInsightModel>>(
+ `api/environments/${values.currentTeamId}/dashboards/${props.id}`,
+ { grid_spacing: tileSpacing }
+ )
+ dashboardsModel.actions.updateDashboardSuccess(getQueryBasedDashboard(dashboard))
+ if (tileSpacing !== 'standard') {
+ eventUsageLogic.actions.reportDashboardTileDensityConfigured(tileSpacing)
+ }
+ } catch {
+ if (!cache.pendingDashboardTileSpacing) {
+ actions.setDashboardTileSpacing(persistedTileSpacing)
+ actions.loadDashboard({ action: DashboardLoadAction.Update })
+ lemonToast.error("Couldn't update tile density. Try again.")
+ }
+ } finally {
+ cache.dashboardTileSpacingSaveInFlight = false
+ const pendingTileSpacing = cache.pendingDashboardTileSpacing as DashboardTileSpacing | undefined
+ cache.pendingDashboardTileSpacing = undefined
+ if (pendingTileSpacing) {
+ actions.setDashboardTileSpacing(pendingTileSpacing)
+ actions.saveDashboardTileSpacing(pendingTileSpacing)
+ } else {
+ actions.setDashboardTileSpacingSaving(false)
+ }
+ }
+ },
forceRefreshIfStale: () => {
// Dedupe: this listener can be invoked from multiple sources for the same
// freshness state — the post-load auto-trigger in refreshDashboardItems and
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 089ce6a5df26..5974d4186b18 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -2703,8 +2703,13 @@ export interface DashboardType<T = InsightModel> extends DashboardBasicType {
breakdown_colors?: BreakdownColorConfig[]
data_color_theme_id?: number | null
quick_filter_ids?: string[] | null
+ customization?: {
+ tile_spacing?: DashboardTileSpacing
+ }
}
+export type DashboardTileSpacing = 'tight' | 'condensed' | 'standard' | 'relaxed' | 'wide'
+
export enum TemplateAvailabilityContext {
GENERAL = 'general',
ONBOARDING = 'onboarding',
diff --git a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
index 0847a47530e0..5bec7f662c4f 100644
--- a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
+++ b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
@@ -109,6 +109,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -352,6 +353,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -918,6 +920,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -1461,6 +1464,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -1532,6 +1536,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -2121,6 +2126,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -2217,6 +2223,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -2353,6 +2360,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -2459,6 +2467,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -2856,6 +2865,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -3414,6 +3424,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -3699,6 +3710,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -3749,6 +3761,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -4185,6 +4198,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -4622,6 +4636,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -4672,6 +4687,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -5081,6 +5097,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -5513,6 +5530,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -6002,6 +6020,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -6089,6 +6108,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -6678,6 +6698,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -6765,6 +6786,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -6901,6 +6923,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -9028,6 +9051,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -9065,6 +9089,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -9128,6 +9153,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -9531,6 +9557,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -9965,6 +9992,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -10015,6 +10043,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -10421,6 +10450,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -10948,6 +10978,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -10998,6 +11029,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -12558,6 +12590,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -14955,6 +14988,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
diff --git a/posthog/api/test/dashboards/test_dashboard.py b/posthog/api/test/dashboards/test_dashboard.py
index 097721938c95..7de229c645df 100644
--- a/posthog/api/test/dashboards/test_dashboard.py
+++ b/posthog/api/test/dashboards/test_dashboard.py
@@ -658,6 +658,56 @@ class TestDashboard(APIBaseTest, QueryMatchingTest):
dashboard.refresh_from_db()
self.assertEqual(dashboard.name, "dashboard new name")
+ @patch("products.dashboards.backend.api.dashboard.dashboard_customization_enabled", return_value=True)
+ def test_dashboard_tile_spacing_is_saved_and_duplicated(self, _mock_enabled: MagicMock):
+ dashboard_id, _ = self.dashboard_api.create_dashboard({"name": "dashboard"})
+
+ _, updated = self.dashboard_api.update_dashboard(dashboard_id, {"grid_spacing": "relaxed"})
+ self.assertEqual(updated["customization"], {"tile_spacing": "relaxed"})
+
+ Dashboard.objects.filter(id=dashboard_id).update(customization={"show_legend": False})
+ _, updated = self.dashboard_api.update_dashboard(dashboard_id, {"grid_spacing": "wide"})
+ self.assertEqual(updated["customization"], {"tile_spacing": "wide"})
+
+ copied_id, copied = self.dashboard_api.create_dashboard({"name": "copy", "use_dashboard": dashboard_id})
+ self.assertEqual(copied["customization"], {"tile_spacing": "wide"})
+ self.assertEqual(
+ Dashboard.objects.get(id=copied_id).customization, {"show_legend": False, "tile_spacing": "wide"}
+ )
+
+ @patch("products.dashboards.backend.api.dashboard.dashboard_customization_enabled", return_value=True)
+ def test_dashboard_tile_spacing_recovers_from_malformed_customization(self, _mock_enabled: MagicMock):
+ dashboard = Dashboard.objects.create(team=self.team, name="dashboard", customization=[])
+
+ retrieved = self.dashboard_api.get_dashboard(dashboard.id)
+ self.assertEqual(retrieved["customization"], {})
+
+ _, updated = self.dashboard_api.update_dashboard(dashboard.id, {"grid_spacing": "condensed"})
+ self.assertEqual(updated["customization"], {"tile_spacing": "condensed"})
+
+ @patch("products.dashboards.backend.api.dashboard.dashboard_customization_enabled", return_value=False)
+ def test_dashboard_tile_spacing_requires_feature_flag(self, _mock_enabled: MagicMock):
+ dashboard_id, _ = self.dashboard_api.create_dashboard({"name": "dashboard"})
+
+ _, response = self.dashboard_api.update_dashboard(
+ dashboard_id,
+ {"grid_spacing": "relaxed"},
+ expected_status=status.HTTP_400_BAD_REQUEST,
+ )
+ self.assertEqual(response["attr"], "grid_spacing")
+ self.assertEqual(response["detail"], "Tile density isn't available.")
+
+ @patch("products.dashboards.backend.api.dashboard.dashboard_customization_enabled", return_value=True)
+ def test_dashboard_tile_spacing_requires_a_known_preset(self, _mock_enabled: MagicMock):
+ dashboard_id, _ = self.dashboard_api.create_dashboard({"name": "dashboard"})
+
+ _, response = self.dashboard_api.update_dashboard(
+ dashboard_id,
+ {"grid_spacing": "extra-wide"},
+ expected_status=status.HTTP_400_BAD_REQUEST,
+ )
+ self.assertEqual(response["attr"], "grid_spacing")
+
@patch("products.product_analytics.backend.api.insight.record_dashboard_cache_outcome")
@patch("posthog.caching.calculate_results.calculate_for_query_based_insight")
def test_update_dashboard_does_not_record_cache_outcomes(
diff --git a/posthog/models/resource_transfer/test/__snapshots__/test_visitor_field_snapshots.ambr b/posthog/models/resource_transfer/test/__snapshots__/test_visitor_field_snapshots.ambr
index 46442c84b22f..c4aad78ba18f 100644
--- a/posthog/models/resource_transfer/test/__snapshots__/test_visitor_field_snapshots.ambr
+++ b/posthog/models/resource_transfer/test/__snapshots__/test_visitor_field_snapshots.ambr
@@ -169,6 +169,7 @@
'breakdown_colors',
'created_at',
'creation_mode',
+ 'customization',
'deleted',
'deprecated_tags',
'deprecated_tags_v2',
diff --git a/posthog/settings/web.py b/posthog/settings/web.py
index 1cb42cee8f31..85d2a92b09d3 100644
--- a/posthog/settings/web.py
+++ b/posthog/settings/web.py
@@ -684,6 +684,7 @@ SPECTACULAR_SETTINGS = {
# and churn subscriptions' generated types.
"TargetTypeEnum": "products.exports.backend.models.subscription.Subscription.SubscriptionTarget",
# --- Inline value lists (type-hint enums, no x-spec-enum-id) ---
+ "TileSpacingEnum": ["tight", "condensed", "standard", "relaxed", "wide"],
"PropertyGroupOperator": ["AND", "OR"],
# `scope`/`state` are generic field names; one shared name for the canvas state scope set.
"CanvasStateScopeEnum": ["user", "shared"],
diff --git a/products/dashboards/backend/api/dashboard.py b/products/dashboards/backend/api/dashboard.py
index 41fcff34b0e8..855ce0f5d088 100644
--- a/products/dashboards/backend/api/dashboard.py
+++ b/products/dashboards/backend/api/dashboard.py
@@ -115,8 +115,8 @@ from products.dashboards.backend.api.widget_openapi_serializers import (
WidgetCatalogResponseSerializer,
)
from products.dashboards.backend.constants import DASHBOARD_GRID_COLUMN_COUNT, MAX_WIDGETS_BATCH_SIZE
-from products.dashboards.backend.feature_flags import dashboard_widgets_enabled
-from products.dashboards.backend.models.dashboard import Dashboard
+from products.dashboards.backend.feature_flags import dashboard_customization_enabled, dashboard_widgets_enabled
+from products.dashboards.backend.models.dashboard import DASHBOARD_GRID_SPACING_GAPS, Dashboard
from products.dashboards.backend.models.dashboard_tile import ButtonTile, DashboardTile, Text
from products.dashboards.backend.models.dashboard_widget import DashboardWidget
from products.dashboards.backend.widget_access import (
@@ -163,6 +163,11 @@ from products.product_analytics.backend.models.insight_variable import InsightVa
from ee.hogai.utils.aio import async_to_sync
+
+def _normalize_dashboard_customization(customization: Any) -> dict[str, Any]:
+ return customization.copy() if isinstance(customization, dict) else {}
+
+
logger = structlog.get_logger(__name__)
DASHBOARD_TILE_ERROR_TYPE = "DashboardTileError"
@@ -236,6 +241,8 @@ DASHBOARD_SHARED_FIELDS = [
"persisted_variables",
"team_id",
"quick_filter_ids",
+ "customization",
+ "grid_spacing",
]
@@ -1167,6 +1174,14 @@ class DashboardBasicSerializer(
return entry.path if entry else None
+class DashboardCustomizationSerializer(serializers.Serializer):
+ tile_spacing = serializers.ChoiceField(
+ choices=tuple(DASHBOARD_GRID_SPACING_GAPS),
+ required=False,
+ help_text="Named tile density preset.",
+ )
+
+
class DashboardMetadataSerializer(DashboardBasicSerializer):
filters = serializers.SerializerMethodField()
variables = serializers.SerializerMethodField()
@@ -1185,6 +1200,13 @@ class DashboardMetadataSerializer(DashboardBasicSerializer):
allow_null=True,
help_text="List of quick filter IDs associated with this dashboard",
)
+ customization = serializers.SerializerMethodField(help_text="Dashboard display settings.")
+ grid_spacing = serializers.ChoiceField(
+ choices=tuple(DASHBOARD_GRID_SPACING_GAPS),
+ required=False,
+ write_only=True,
+ help_text="Named tile density preset. Use tight, condensed, standard, relaxed, or wide.",
+ )
persisted_filters = serializers.SerializerMethodField()
persisted_variables = serializers.SerializerMethodField()
@@ -1198,6 +1220,13 @@ class DashboardMetadataSerializer(DashboardBasicSerializer):
is_shared = self.context.get("is_shared", False)
return filters_override_requested_by_client(request, dashboard, is_shared=is_shared)
+ @extend_schema_field(DashboardCustomizationSerializer)
+ def get_customization(self, dashboard: Dashboard) -> dict[str, str]:
+ tile_spacing = _normalize_dashboard_customization(dashboard.customization).get("tile_spacing")
+ if isinstance(tile_spacing, str) and tile_spacing in DASHBOARD_GRID_SPACING_GAPS:
+ return {"tile_spacing": tile_spacing}
+ return {}
+
def get_variables(self, dashboard: Dashboard) -> dict | None:
request = self.context.get("request")
is_shared = self.context.get("is_shared", False)
@@ -1465,6 +1494,9 @@ class DashboardSerializer(DashboardMetadataSerializer):
validated_data["created_by"] = request.user
team_id = self.context["team_id"]
team = self.context["get_team"]()
+ grid_spacing = validated_data.pop("grid_spacing", None)
+ if grid_spacing is not None and not dashboard_customization_enabled(team=team, user=request.user):
+ raise serializers.ValidationError({"grid_spacing": "Tile density isn't available."})
current_count = Dashboard.objects.filter(team_id=team_id, deleted=False).count()
check_count_limit(
team=team,
@@ -1514,6 +1546,15 @@ class DashboardSerializer(DashboardMetadataSerializer):
existing_dashboard.quick_filter_ids, team_id
)
+ if existing_dashboard:
+ validated_data["customization"] = _normalize_dashboard_customization(existing_dashboard.customization)
+
+ if grid_spacing is not None:
+ validated_data["customization"] = {
+ **validated_data.get("customization", {}),
+ "tile_spacing": grid_spacing,
+ }
+
dashboard = Dashboard.objects.create(team_id=team_id, filters=filters, **validated_data)
if use_template:
@@ -1708,6 +1749,16 @@ class DashboardSerializer(DashboardMetadataSerializer):
)
validated_data.pop("use_template", None) # Remove attribute if present
+ grid_spacing = validated_data.pop("grid_spacing", None)
+ if grid_spacing is not None and not dashboard_customization_enabled(
+ team=instance.team, user=cast(User, self.context["request"].user)
+ ):
+ raise serializers.ValidationError({"grid_spacing": "Tile density isn't available."})
+ if grid_spacing is not None:
+ validated_data["customization"] = {
+ **_normalize_dashboard_customization(instance.customization),
+ "tile_spacing": grid_spacing,
+ }
being_undeleted = instance.deleted and "deleted" in validated_data and not validated_data["deleted"]
if being_undeleted:
diff --git a/products/dashboards/backend/feature_flags.py b/products/dashboards/backend/feature_flags.py
index 72fd6985ca11..384f0afcf79c 100644
--- a/products/dashboards/backend/feature_flags.py
+++ b/products/dashboards/backend/feature_flags.py
@@ -11,6 +11,7 @@ if TYPE_CHECKING:
from posthog.models.user import User
DASHBOARD_WIDGETS_FLAG = "dashboard-widgets"
+DASHBOARD_CUSTOMIZATION_FLAG = "dashboard-customization"
def widget_flag_enabled(flag: str, *, team: Team, user: User | None = None) -> bool:
@@ -36,3 +37,7 @@ def widget_flag_enabled(flag: str, *, team: Team, user: User | None = None) -> b
def dashboard_widgets_enabled(*, team: Team, user: User | None = None) -> bool:
return widget_flag_enabled(DASHBOARD_WIDGETS_FLAG, team=team, user=user)
+
+
+def dashboard_customization_enabled(*, team: Team, user: User | None = None) -> bool:
+ return widget_flag_enabled(DASHBOARD_CUSTOMIZATION_FLAG, team=team, user=user)
diff --git a/products/dashboards/backend/migrations/0015_dashboard_customization.py b/products/dashboards/backend/migrations/0015_dashboard_customization.py
new file mode 100644
index 000000000000..2da1739ee15f
--- /dev/null
+++ b/products/dashboards/backend/migrations/0015_dashboard_customization.py
@@ -0,0 +1,15 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("dashboards", "0014_backfill_dashboardtemplate_button_tile_type"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="dashboard",
+ name="customization",
+ field=models.JSONField(blank=True, db_default={}, default=dict),
+ ),
+ ]
diff --git a/products/dashboards/backend/migrations/max_migration.txt b/products/dashboards/backend/migrations/max_migration.txt
index 413795cece92..57ed3ff27f23 100644
--- a/products/dashboards/backend/migrations/max_migration.txt
+++ b/products/dashboards/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0014_backfill_dashboardtemplate_button_tile_type
+0015_dashboard_customization
diff --git a/products/dashboards/backend/models/dashboard.py b/products/dashboards/backend/models/dashboard.py
index e942fb51ab8b..fb03c44955f2 100644
--- a/products/dashboards/backend/models/dashboard.py
+++ b/products/dashboards/backend/models/dashboard.py
@@ -15,6 +15,15 @@ if TYPE_CHECKING:
from posthog.models.team import Team
+DASHBOARD_GRID_SPACING_GAPS = {
+ "tight": 8,
+ "condensed": 12,
+ "standard": 16,
+ "relaxed": 32,
+ "wide": 48,
+}
+
+
class DashboardManager(RootTeamManager):
def get_queryset(self):
return super().get_queryset().exclude(deleted=True)
@@ -78,6 +87,7 @@ class Dashboard(FileSystemSyncMixin, ModelActivityMixin, RootTeamMixin, models.M
"product_analytics.Insight", related_name="dashboards", through="DashboardTile", blank=True
) # type: models.ManyToManyField
quick_filter_ids = models.JSONField(default=list, blank=True, null=True)
+ customization = models.JSONField(default=dict, db_default={}, blank=True)
# Deprecated in favour of app-wide tagging model. See EnterpriseTaggedItem
deprecated_tags: ArrayField = ArrayField(models.CharField(max_length=32), null=True, blank=True, default=list)
diff --git a/products/dashboards/backend/widget_specs/openapi.py b/products/dashboards/backend/widget_specs/openapi.py
index 67983e923080..905a6fbc47f9 100644
--- a/products/dashboards/backend/widget_specs/openapi.py
+++ b/products/dashboards/backend/widget_specs/openapi.py
@@ -6,6 +6,7 @@ from drf_spectacular.utils import PolymorphicProxySerializer, extend_schema_fiel
from pydantic import BaseModel
from rest_framework import serializers
+from products.dashboards.backend.models.dashboard import DASHBOARD_GRID_SPACING_GAPS
from products.dashboards.backend.widget_specs.pydantic_openapi import pydantic_config_field, pydantic_stub_serializer
from products.dashboards.backend.widget_specs.registry import EXPECTED_WIDGET_TYPES, WIDGET_SPECS
@@ -302,6 +303,11 @@ class PatchedDashboardOpenApiSerializer(serializers.Serializer):
allow_null=True,
help_text="List of quick filter IDs associated with this dashboard.",
)
+ grid_spacing = serializers.ChoiceField(
+ choices=tuple(DASHBOARD_GRID_SPACING_GAPS),
+ required=False,
+ help_text="Named tile density preset. Use tight, condensed, standard, relaxed, or wide.",
+ )
tiles = DashboardPatchTileOpenApiSerializer(
many=True,
required=False,
diff --git a/products/dashboards/frontend/components/DashboardCustomizeMenu/DashboardCustomizeMenu.tsx b/products/dashboards/frontend/components/DashboardCustomizeMenu/DashboardCustomizeMenu.tsx
new file mode 100644
index 000000000000..5512d5e01f7e
--- /dev/null
+++ b/products/dashboards/frontend/components/DashboardCustomizeMenu/DashboardCustomizeMenu.tsx
@@ -0,0 +1,50 @@
+import { useActions, useValues } from 'kea'
+
+import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
+import { LemonRadio } from 'lib/lemon-ui/LemonRadio'
+import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'
+
+import { DashboardTileSpacing } from '~/types'
+
+import { DASHBOARD_TILE_SPACING_LABELS } from '../../dashboardCustomization'
+
+const TILE_SPACING_OPTIONS: { value: DashboardTileSpacing; label: string }[] = [
+ { value: 'tight', label: DASHBOARD_TILE_SPACING_LABELS.tight },
+ { value: 'condensed', label: DASHBOARD_TILE_SPACING_LABELS.condensed },
+ { value: 'standard', label: DASHBOARD_TILE_SPACING_LABELS.standard },
+ { value: 'relaxed', label: DASHBOARD_TILE_SPACING_LABELS.relaxed },
+ { value: 'wide', label: DASHBOARD_TILE_SPACING_LABELS.wide },
+]
+
+export function DashboardCustomizeMenu(): JSX.Element | null {
+ const { dashboard, canEditDashboard } = useValues(dashboardLogic)
+ const { setDashboardTileSpacing, saveDashboardTileSpacing } = useActions(dashboardLogic)
+ const dashboardCustomizationEnabled = useFeatureFlag('DASHBOARD_CUSTOMIZATION')
+
+ if (!dashboard || !canEditDashboard || !dashboardCustomizationEnabled) {
+ return null
+ }
+
+ const tileSpacing = dashboard.customization?.tile_spacing ?? 'standard'
+ const setTileSpacing = (value: DashboardTileSpacing): void => {
+ if (value === tileSpacing) {
+ return
+ }
+ setDashboardTileSpacing(value)
+ saveDashboardTileSpacing(value)
+ }
+
+ return (
+ <div className="flex flex-wrap items-center gap-x-3 gap-y-1 p-2">
+ <span className="text-xs text-muted whitespace-nowrap">Tile density</span>
+ <LemonRadio<DashboardTileSpacing>
+ value={tileSpacing}
+ onChange={setTileSpacing}
+ options={TILE_SPACING_OPTIONS}
+ orientation="horizontal"
+ className="flex-1 flex-wrap gap-x-3 gap-y-1"
+ aria-label="Tile density"
+ />
+ </div>
+ )
+}
diff --git a/products/dashboards/frontend/dashboardCustomization.ts b/products/dashboards/frontend/dashboardCustomization.ts
new file mode 100644
index 000000000000..b9aeeb923358
--- /dev/null
+++ b/products/dashboards/frontend/dashboardCustomization.ts
@@ -0,0 +1,21 @@
+import type { DashboardTileSpacing } from '~/types'
+
+export const DASHBOARD_TILE_SPACING_GAPS: Record<DashboardTileSpacing, number> = {
+ tight: 8,
+ condensed: 12,
+ standard: 16,
+ relaxed: 32,
+ wide: 48,
+}
+
+export const DASHBOARD_TILE_SPACING_LABELS: Record<DashboardTileSpacing, string> = {
+ tight: 'Tight',
+ condensed: 'Compact',
+ standard: 'Standard',
+ relaxed: 'Relaxed',
+ wide: 'Wide',
+}
+
+export function getDashboardTileSpacingGap(tileSpacing?: string): number {
+ return DASHBOARD_TILE_SPACING_GAPS[tileSpacing as DashboardTileSpacing] ?? DASHBOARD_TILE_SPACING_GAPS.standard
+}
diff --git a/products/dashboards/frontend/generated/api.schemas.ts b/products/dashboards/frontend/generated/api.schemas.ts
index c003c21025a8..e19d3d916d4c 100644
--- a/products/dashboards/frontend/generated/api.schemas.ts
+++ b/products/dashboards/frontend/generated/api.schemas.ts
@@ -319,6 +319,34 @@ export type DashboardApiPersistedVariables = { [key: string]: unknown } | null
export type DashboardApiTilesItem = { [key: string]: unknown }
+/**
+ * * `tight` - tight
+ * * `condensed` - condensed
+ * * `standard` - standard
+ * * `relaxed` - relaxed
+ * * `wide` - wide
+ */
+export type TileSpacingEnumApi = (typeof TileSpacingEnumApi)[keyof typeof TileSpacingEnumApi]
+
+export const TileSpacingEnumApi = {
+ Tight: 'tight',
+ Condensed: 'condensed',
+ Standard: 'standard',
+ Relaxed: 'relaxed',
+ Wide: 'wide',
+} as const
+
+export interface DashboardCustomizationApi {
+ /** Named tile density preset.
+ *
+ * * `tight` - tight
+ * * `condensed` - condensed
+ * * `standard` - standard
+ * * `relaxed` - relaxed
+ * * `wide` - wide */
+ tile_spacing?: TileSpacingEnumApi
+}
+
/**
* Serializer mixin that handles tags for objects.
*/
@@ -387,6 +415,16 @@ export interface DashboardApi {
* @nullable
*/
quick_filter_ids?: string[] | null
+ /** Dashboard display settings. */
+ readonly customization: DashboardCustomizationApi
+ /** Named tile density preset. Use tight, condensed, standard, relaxed, or wide.
+ *
+ * * `tight` - tight
+ * * `condensed` - condensed
+ * * `standard` - standard
+ * * `relaxed` - relaxed
+ * * `wide` - wide */
+ grid_spacing?: TileSpacingEnumApi
/** @nullable */
readonly tiles: readonly DashboardApiTilesItem[] | null
/** Template key to create the dashboard from a predefined template. */
@@ -960,6 +998,14 @@ export interface PatchedPatchedDashboardOpenApiApi {
* @nullable
*/
quick_filter_ids?: string[] | null
+ /** Named tile density preset. Use tight, condensed, standard, relaxed, or wide.
+ *
+ * * `tight` - tight
+ * * `condensed` - condensed
+ * * `standard` - standard
+ * * `relaxed` - relaxed
+ * * `wide` - wide */
+ grid_spacing?: TileSpacingEnumApi
/** Dashboard tiles to update. Widget tiles accept nested widget.config patches. */
tiles?: DashboardPatchTileOpenApiApi[]
/** Template key to create the dashboard from a predefined template. */
diff --git a/products/dashboards/frontend/generated/api.zod.ts b/products/dashboards/frontend/generated/api.zod.ts
index 1fdc2339b555..6e17a4dc97da 100644
--- a/products/dashboards/frontend/generated/api.zod.ts
+++ b/products/dashboards/frontend/generated/api.zod.ts
@@ -154,6 +154,15 @@ export const DashboardsCreateBody = /* @__PURE__ */ zod
.array(zod.string())
.nullish()
.describe('List of quick filter IDs associated with this dashboard'),
+ grid_spacing: zod
+ .enum(['tight', 'condensed', 'standard', 'relaxed', 'wide'])
+ .describe(
+ '\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ )
+ .optional()
+ .describe(
+ 'Named tile density preset. Use tight, condensed, standard, relaxed, or wide.\n\n\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ ),
use_template: zod
.string()
.optional()
@@ -201,6 +210,15 @@ export const DashboardsUpdateBody = /* @__PURE__ */ zod
.array(zod.string())
.nullish()
.describe('List of quick filter IDs associated with this dashboard'),
+ grid_spacing: zod
+ .enum(['tight', 'condensed', 'standard', 'relaxed', 'wide'])
+ .describe(
+ '\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ )
+ .optional()
+ .describe(
+ 'Named tile density preset. Use tight, condensed, standard, relaxed, or wide.\n\n\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ ),
use_template: zod
.string()
.optional()
@@ -315,6 +333,15 @@ export const DashboardsPartialUpdateBody = /* @__PURE__ */ zod
.array(zod.string())
.nullish()
.describe('List of quick filter IDs associated with this dashboard.'),
+ grid_spacing: zod
+ .enum(['tight', 'condensed', 'standard', 'relaxed', 'wide'])
+ .describe(
+ '\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ )
+ .optional()
+ .describe(
+ 'Named tile density preset. Use tight, condensed, standard, relaxed, or wide.\n\n\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ ),
tiles: zod
.array(
zod.object({
@@ -3288,6 +3315,15 @@ export const DashboardsCreateFromTemplateJsonCreateBody = /* @__PURE__ */ zod
.array(zod.string())
.nullish()
.describe('List of quick filter IDs associated with this dashboard'),
+ grid_spacing: zod
+ .enum(['tight', 'condensed', 'standard', 'relaxed', 'wide'])
+ .describe(
+ '\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ )
+ .optional()
+ .describe(
+ 'Named tile density preset. Use tight, condensed, standard, relaxed, or wide.\n\n\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ ),
use_template: zod
.string()
.optional()
@@ -3331,6 +3367,15 @@ export const DashboardsCreateUnlistedDashboardCreateBody = /* @__PURE__ */ zod
.array(zod.string())
.nullish()
.describe('List of quick filter IDs associated with this dashboard'),
+ grid_spacing: zod
+ .enum(['tight', 'condensed', 'standard', 'relaxed', 'wide'])
+ .describe(
+ '\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ )
+ .optional()
+ .describe(
+ 'Named tile density preset. Use tight, condensed, standard, relaxed, or wide.\n\n\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ ),
use_template: zod
.string()
.optional()
diff --git a/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr b/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr
index 7cee74b255fc..729387d32c4a 100644
--- a/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr
+++ b/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr
@@ -923,6 +923,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
diff --git a/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr b/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr
index 9aa221d4f6ca..45bd24bfa19e 100644
--- a/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr
+++ b/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr
@@ -628,6 +628,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -1576,6 +1577,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
@@ -1626,6 +1628,7 @@
"posthog_dashboard"."creation_mode",
"posthog_dashboard"."restriction_level",
"posthog_dashboard"."quick_filter_ids",
+ "posthog_dashboard"."customization",
"posthog_dashboard"."deprecated_tags",
"posthog_dashboard"."tags",
"posthog_dashboard"."share_token",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 21ff49560ff9..bee3883b0237 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -19821,6 +19821,35 @@ export namespace Schemas {
Number37: 37,
} as const;
+ /**
+ * * `tight` - tight
+ * * `condensed` - condensed
+ * * `standard` - standard
+ * * `relaxed` - relaxed
+ * * `wide` - wide
+ */
+ export type TileSpacingEnum = typeof TileSpacingEnum[keyof typeof TileSpacingEnum];
+
+
+ export const TileSpacingEnum = {
+ Tight: 'tight',
+ Condensed: 'condensed',
+ Standard: 'standard',
+ Relaxed: 'relaxed',
+ Wide: 'wide',
+ } as const;
+
+ export interface DashboardCustomization {
+ /** Named tile density preset.
+ *
+ * * `tight` - tight
+ * * `condensed` - condensed
+ * * `standard` - standard
+ * * `relaxed` - relaxed
+ * * `wide` - wide */
+ tile_spacing?: TileSpacingEnum;
+ }
+
/**
* Serializer mixin that handles tags for objects.
*/
@@ -19889,6 +19918,16 @@ export namespace Schemas {
* @nullable
*/
quick_filter_ids?: string[] | null;
+ /** Dashboard display settings. */
+ readonly customization: DashboardCustomization;
+ /** Named tile density preset. Use tight, condensed, standard, relaxed, or wide.
+ *
+ * * `tight` - tight
+ * * `condensed` - condensed
+ * * `standard` - standard
+ * * `relaxed` - relaxed
+ * * `wide` - wide */
+ grid_spacing?: TileSpacingEnum;
/** @nullable */
readonly tiles: readonly DashboardTilesItem[] | null;
/** Template key to create the dashboard from a predefined template. */
@@ -60321,6 +60360,14 @@ export namespace Schemas {
* @nullable
*/
quick_filter_ids?: string[] | null;
+ /** Named tile density preset. Use tight, condensed, standard, relaxed, or wide.
+ *
+ * * `tight` - tight
+ * * `condensed` - condensed
+ * * `standard` - standard
+ * * `relaxed` - relaxed
+ * * `wide` - wide */
+ grid_spacing?: TileSpacingEnum;
/** Dashboard tiles to update. Widget tiles accept nested widget.config patches. */
tiles?: DashboardPatchTileOpenApi[];
/** Template key to create the dashboard from a predefined template. */
diff --git a/services/mcp/src/generated/dashboards/api.ts b/services/mcp/src/generated/dashboards/api.ts
index 85215a6849c2..a25b83b5fe9d 100644
--- a/services/mcp/src/generated/dashboards/api.ts
+++ b/services/mcp/src/generated/dashboards/api.ts
@@ -120,6 +120,15 @@ export const DashboardsCreateBody = /* @__PURE__ */ zod
.array(zod.string())
.nullish()
.describe('List of quick filter IDs associated with this dashboard'),
+ grid_spacing: zod
+ .enum(['tight', 'condensed', 'standard', 'relaxed', 'wide'])
+ .describe(
+ '\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ )
+ .optional()
+ .describe(
+ 'Named tile density preset. Use tight, condensed, standard, relaxed, or wide.\n\n\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ ),
use_template: zod
.string()
.optional()
@@ -281,6 +290,15 @@ export const DashboardsPartialUpdateBody = /* @__PURE__ */ zod
.array(zod.string())
.nullish()
.describe('List of quick filter IDs associated with this dashboard.'),
+ grid_spacing: zod
+ .enum(['tight', 'condensed', 'standard', 'relaxed', 'wide'])
+ .describe(
+ '\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ )
+ .optional()
+ .describe(
+ 'Named tile density preset. Use tight, condensed, standard, relaxed, or wide.\n\n\* `tight` - tight\n\* `condensed` - condensed\n\* `standard` - standard\n\* `relaxed` - relaxed\n\* `wide` - wide'
+ ),
tiles: zod
.array(
zod.object({
diff --git a/services/mcp/src/tools/generated/dashboards.ts b/services/mcp/src/tools/generated/dashboards.ts
index ac2f2c169e42..91ecc479c3b8 100644
--- a/services/mcp/src/tools/generated/dashboards.ts
+++ b/services/mcp/src/tools/generated/dashboards.ts
@@ -77,6 +77,9 @@ const dashboardCreate = (): ToolBase<typeof DashboardCreateSchema, WithPostHogUr
if (params.quick_filter_ids !== undefined) {
body['quick_filter_ids'] = params.quick_filter_ids
}
+ if (params.grid_spacing !== undefined) {
+ body['grid_spacing'] = params.grid_spacing
+ }
if (params.use_template !== undefined) {
body['use_template'] = params.use_template
}
@@ -473,6 +476,9 @@ const dashboardUpdate = (): ToolBase<typeof DashboardUpdateSchema, WithPostHogUr
if (params.quick_filter_ids !== undefined) {
body['quick_filter_ids'] = params.quick_filter_ids
}
+ if (params.grid_spacing !== undefined) {
+ body['grid_spacing'] = params.grid_spacing
+ }
if (params.tiles !== undefined) {
body['tiles'] = params.tiles
}
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-create.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-create.json
index acda1e859417..3c38d43edb49 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-create.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-create.json
@@ -23,6 +23,11 @@
"description": {
"type": "string"
},
+ "grid_spacing": {
+ "description": "Named tile density preset. Use tight, condensed, standard, relaxed, or wide.\n\n* `tight` - tight\n* `condensed` - condensed\n* `standard` - standard\n* `relaxed` - relaxed\n* `wide` - wide",
+ "enum": ["tight", "condensed", "standard", "relaxed", "wide"],
+ "type": "string"
+ },
"include_dashboards": {
"description": "Opt in to receiving the deprecated `dashboards` field in insight payloads. Once opt-in enforcement is enabled, API-token callers stop receiving it by default; use `dashboard_tiles` instead.",
"type": "boolean"
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-update.json
index 93e0370be7a5..ff4dc176d6e7 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/dashboard-update.json
@@ -53,6 +53,11 @@
},
"type": "object"
},
+ "grid_spacing": {
+ "description": "Named tile density preset. Use tight, condensed, standard, relaxed, or wide.\n\n* `tight` - tight\n* `condensed` - condensed\n* `standard` - standard\n* `relaxed` - relaxed\n* `wide` - wide",
+ "enum": ["tight", "condensed", "standard", "relaxed", "wide"],
+ "type": "string"
+ },
"id": {
"description": "A unique integer value identifying this dashboard.",
"type": "number"