: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
feat(customer-analytics): limit accounts overview tiles to five (#61449)
Arthur Moreira de Deusd7cf6ae8bac1
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsOverviewTilesEditor.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsOverviewTilesEditor.tsxindex ef785bdf6d91..d5946db3fb25 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountsOverviewTilesEditor.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountsOverviewTilesEditor.tsx@@ -13,13 +13,16 @@ import { Tooltip } from 'lib/lemon-ui/Tooltip'import { AccountColumnOption } from './accountsColumnConfigLogic'import {- ACCOUNTS_OVERVIEW_THRESHOLD_OPERATORS,- AccountsOverviewThresholdOperator,accountsOverviewTilesLogic,AccountsOverviewTile,AccountsOverviewTileMetric,AccountsOverviewTileMetricType,} from './accountsOverviewTilesLogic'+import {+ ACCOUNTS_OVERVIEW_THRESHOLD_OPERATORS,+ AccountsOverviewThresholdOperator,+ MAX_ACCOUNTS_OVERVIEW_TILES,+} from './constants'const METRIC_TYPE_LABELS: Record<AccountsOverviewTileMetricType, string> = {count: 'Count of accounts',@@ -147,6 +150,11 @@ export function AccountsOverviewTilesEditor({type="secondary"icon={<IconPlus />}onClick={handleAddTile}+ disabledReason={+ tiles.length >= MAX_ACCOUNTS_OVERVIEW_TILES+ ? `You can add up to ${MAX_ACCOUNTS_OVERVIEW_TILES} tiles`+ : undefined+ }data-attr="accounts-overview-tiles-add">Add tilediff --git a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.test.tsindex 5c99145ccf29..9a3fe8f7ae75 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.test.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.test.ts@@ -1,6 +1,10 @@+import { expectLogic } from 'kea-test-utils'+import { NodeKind } from '~/queries/schema/schema-general'+import { initKeaTests } from '~/test/init'import {+ accountsOverviewTilesLogic,AccountsOverviewTile,isNumericColumnType,isTileClickable,@@ -11,6 +15,7 @@ import {tileMetricExpression,tileToRowFilter,} from './accountsOverviewTilesLogic'+import { MAX_ACCOUNTS_OVERVIEW_TILES } from './constants'describe('stripHogqlAlias', () => {it('strips a trailing AS alias', () => {@@ -180,3 +185,25 @@ describe('parseTileValues', () => {expect(parseTileValues(responseWith([null, null]), tiles)).toEqual({ a: null, b: null })})})++describe('addTile limit', () => {+ let logic: ReturnType<typeof accountsOverviewTilesLogic.build>++ beforeEach(() => {+ initKeaTests()+ logic = accountsOverviewTilesLogic()+ logic.mount()+ })++ afterEach(() => {+ logic.unmount()+ })++ it(`stops adding tiles once ${MAX_ACCOUNTS_OVERVIEW_TILES} exist`, async () => {+ for (let i = 0; i < MAX_ACCOUNTS_OVERVIEW_TILES + 2; i++) {+ logic.actions.addTile({ label: `Tile ${i}`, metric: { type: 'count' } })+ }+ await expectLogic(logic).toFinishAllListeners()+ expect(logic.values.tiles).toHaveLength(MAX_ACCOUNTS_OVERVIEW_TILES)+ })+})diff --git a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.tsindex 841eb9aa141b..f9b983957405 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsOverviewTilesLogic.ts@@ -7,9 +7,13 @@ import { AccountsQueryResponse, DataNode } from '~/queries/schema/schema-generalimport { ACCOUNTS_HOGQL_DATA_NODE_KEY } from '../../constants'import { AccountColumnGroup, AccountColumnOption, accountsColumnConfigLogic } from './accountsColumnConfigLogic'import type { accountsOverviewTilesLogicType } from './accountsOverviewTilesLogicType'--export const ACCOUNTS_OVERVIEW_THRESHOLD_OPERATORS = ['>', '>=', '<', '<=', '=', '!='] as const-export type AccountsOverviewThresholdOperator = (typeof ACCOUNTS_OVERVIEW_THRESHOLD_OPERATORS)[number]+import {+ ACCOUNTS_OVERVIEW_PERSIST_CONFIG,+ AccountsOverviewThresholdOperator,+ DEFAULT_TILES,+ MAX_ACCOUNTS_OVERVIEW_TILES,+ NUMERIC_FIELD_TYPES,+} from './constants'export type AccountsOverviewTileMetric =| { type: 'count' }@@ -36,16 +40,6 @@ export interface TileFilter {expression: string}-const NUMERIC_FIELD_TYPES = new Set(['integer', 'float', 'decimal'])--const DEFAULT_TILES: AccountsOverviewTile[] = [{ id: 'default-accounts', label: 'Accounts', metric: { type: 'count' } }]--const teamIdForPersistence = window.POSTHOG_APP_CONTEXT?.current_team?.id-const persistConfig = {- persist: true,- prefix: `${teamIdForPersistence}_customer_analytics_accounts_overview__`,-}-// Strip a trailing `AS alias` from a HogQL fragment — column entries in the// account column groups carry aliases (e.g. `accounts.health.score AS score`)// so the data table can address them by name, but aggregation expressions@@ -162,12 +156,15 @@ export const accountsOverviewTilesLogic = kea<accountsOverviewTilesLogicType>([reducers(() => ({tiles: [DEFAULT_TILES,- persistConfig,+ ACCOUNTS_OVERVIEW_PERSIST_CONFIG,{addTile: (state: AccountsOverviewTile[],{ tile }: { tile: Omit<AccountsOverviewTile, 'id'> & { id?: string } }- ) => [...state, { ...tile, id: tile.id || uuidv4() }],+ ) =>+ state.length >= MAX_ACCOUNTS_OVERVIEW_TILES+ ? state+ : [...state, { ...tile, id: tile.id || uuidv4() }],updateTile: (state: AccountsOverviewTile[],{ id, tile }: { id: string; tile: Omit<AccountsOverviewTile, 'id'> }diff --git a/products/customer_analytics/frontend/components/Accounts/constants.ts b/products/customer_analytics/frontend/components/Accounts/constants.tsnew file mode 100644index 000000000000..99702d8bd3f0--- /dev/null+++ b/products/customer_analytics/frontend/components/Accounts/constants.ts@@ -0,0 +1,18 @@+import type { AccountsOverviewTile } from './accountsOverviewTilesLogic'++export const ACCOUNTS_OVERVIEW_THRESHOLD_OPERATORS = ['>', '>=', '<', '<=', '=', '!='] as const+export type AccountsOverviewThresholdOperator = (typeof ACCOUNTS_OVERVIEW_THRESHOLD_OPERATORS)[number]++export const NUMERIC_FIELD_TYPES = new Set(['integer', 'float', 'decimal'])++export const MAX_ACCOUNTS_OVERVIEW_TILES = 5++export const DEFAULT_TILES: AccountsOverviewTile[] = [+ { id: 'default-accounts', label: 'Accounts', metric: { type: 'count' } },+]++const teamIdForPersistence = window.POSTHOG_APP_CONTEXT?.current_team?.id+export const ACCOUNTS_OVERVIEW_PERSIST_CONFIG = {+ persist: true,+ prefix: `${teamIdForPersistence}_customer_analytics_accounts_overview__`,+}