: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
import { MakeLogicType, actions, kea, path, reducers } from 'kea'
import { getCurrentUserIdOrNone } from 'lib/utils/getAppContext'
/** Whether each group is collapsed, keyed by dashboard id and then by group key. */
export type TileGroupChoices = Record<string, Record<string, boolean>>
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface dashboardTileGroupChoicesLogicValues {
tileGroupChoices: TileGroupChoices
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface dashboardTileGroupChoicesLogicActions {
setTileGroupCollapsed: (
dashboardId: number,
groupKey: string,
collapsed: boolean
) => {
collapsed: boolean
dashboardId: number
groupKey: string
}
}
export type dashboardTileGroupChoicesLogicType = MakeLogicType<
dashboardTileGroupChoicesLogicValues,
dashboardTileGroupChoicesLogicActions
>
// One persisted map for every dashboard in this browser, so a viewer's open or closed groups outlive the page.
export const dashboardTileGroupChoicesLogic = kea<dashboardTileGroupChoicesLogicType>([
path(['products', 'dashboards', 'frontend', 'dashboardTileGroupChoicesLogic']),
actions({
setTileGroupCollapsed: (dashboardId: number, groupKey: string, collapsed: boolean) => ({
dashboardId,
groupKey,
collapsed,
}),
}),
reducers(() => ({
tileGroupChoices: [
{} as TileGroupChoices,
// Keyed by user, so a person who signs in after another one in this browser does not get their choices.
// Not keyed by project, because dashboard ids are unique across projects and shared dashboards can have no project.
{ persist: true, prefix: `${getCurrentUserIdOrNone() ?? 'anonymous'}__` },
{
setTileGroupCollapsed: (state, { dashboardId, groupKey, collapsed }) => ({
...state,
[dashboardId]: { ...state[dashboardId], [groupKey]: collapsed },
}),
},
],
})),
])