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(customer-analytics): select all / clear all for billing chart series (#78519)

jake sciotto6a5981cbc5b0
diff --git a/products/customer_analytics/frontend/components/Accounts/AGENTS.md b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
index cc012979212b..3de9f76193a9 100644
--- a/products/customer_analytics/frontend/components/Accounts/AGENTS.md
+++ b/products/customer_analytics/frontend/components/Accounts/AGENTS.md
@@ -114,7 +114,7 @@ The Users tab reads its loaded data straight off `accountRelatedUsersLogic`, so
The Usage and Spend tabs render existing saved billing insights — **point users to them, don't rebuild billing as new insights.**
-**Customer analytics owns the billing chart render.** Each billing chart is multi-series on one shared axis, so a small-magnitude series (e.g. feature flag requests) is a flat sliver against large ones (events/enhanced persons) and can't be read. To offer per-series show/hide **without touching shared data-viz code**, `AccountBillingChart` renders the saved insight's SQL chart directly via `@posthog/quill-charts` instead of an embedded `<Query>`/DataVisualization. It reuses `dataVisualizationLogic` read-only for fetch + SQL-results→series parsing, and renders via `sqlLineGraphAdapter.ts`'s pure builders — the same series building, render dispatch, and line/bar/combo config building (per-column formatting, area fills, right-axis routing, goal and trend lines, percent stacks, plus the 200-series render cap applied locally) the SQL insight chart uses — while staying off that chart's React layer (`SqlChart`/`useSqlChartModel`). Chart-semantics changes belong in the adapter (covered by `sqlLineGraphAdapter.test.ts`), not here. Hidden series are injected into quill's controlled `legend.hiddenKeys` (excluded from drawing and scales; the rest rescale into the freed space). `AccountBillingSeriesToggle` is the control: a compact chip row under each chart, one chip per series colored to match its line/bar (items come from `legendItemsFromSeries` over the same `buildSeries` output the chart draws, so keys and colors can't drift). The hidden-keys state lives in `accountBillingLogic` (`ephemeralHiddenSeriesKeysByShortId`, keyed per insight because the spend tab renders two) — per-view only: never written to the saved insight, reset on date change, gone on row collapse. Queries whose shape `AccountBillingChart` can't render (non-DataViz, table/number/pie displays, series breakdowns — see `canRenderBillingChart`) fall back to the embedded `<Query>` with no chips.
+**Customer analytics owns the billing chart render.** Each billing chart is multi-series on one shared axis, so a small-magnitude series (e.g. feature flag requests) is a flat sliver against large ones (events/enhanced persons) and can't be read. To offer per-series show/hide **without touching shared data-viz code**, `AccountBillingChart` renders the saved insight's SQL chart directly via `@posthog/quill-charts` instead of an embedded `<Query>`/DataVisualization. It reuses `dataVisualizationLogic` read-only for fetch + SQL-results→series parsing, and renders via `sqlLineGraphAdapter.ts`'s pure builders — the same series building, render dispatch, and line/bar/combo config building (per-column formatting, area fills, right-axis routing, goal and trend lines, percent stacks, plus the 200-series render cap applied locally) the SQL insight chart uses — while staying off that chart's React layer (`SqlChart`/`useSqlChartModel`). Chart-semantics changes belong in the adapter (covered by `sqlLineGraphAdapter.test.ts`), not here. Hidden series are injected into quill's controlled `legend.hiddenKeys` (excluded from drawing and scales; the rest rescale into the freed space). `AccountBillingSeriesToggle` is the control: a compact chip row under each chart, one chip per series colored to match its line/bar (items come from `legendItemsFromSeries` over the same `buildSeries` output the chart draws, so keys and colors can't drift), plus Select all / Clear all buttons at the end of the row that show or hide every series at once (`setAllSeriesHidden`, dispatched with the chart's own key list). The hidden-keys state lives in `accountBillingLogic` (`ephemeralHiddenSeriesKeysByShortId`, keyed per insight because the spend tab renders two) — per-view only: never written to the saved insight, reset on date change, gone on row collapse. Queries whose shape `AccountBillingChart` can't render (non-DataViz, table/number/pie displays, series breakdowns — see `canRenderBillingChart`) fall back to the embedded `<Query>` with no chips.
The Opportunities tab lists the account's Salesforce opportunities from the data-warehouse `salesforce.opportunity` table (joined by the account's `sfdc_id`). The query runs in `accountOpportunitiesLogic` rather than via a bare `<Query>` so the tab owns every state: a missing `sfdc_id` shows a "not linked to Salesforce" empty state, and because `salesforce.opportunity` is **access-gated and production-only**, a failed query degrades to a pretty hog empty state instead of a red error box. The expected denied/absent-table `QueryError` (`You don't have access to table …` / `Unknown table …`) is **not** captured to PostHog — it's the normal empty state, not a bug — while genuine, unexpected query failures are still reported (`isExpectedMissingTableError` in `accountOpportunitiesLogic`). Each opportunity name links to its Salesforce record (`SALESFORCE_ORIGIN/<id>` in `constants.ts`, the same origin the Useful links sidebar uses).
@@ -260,6 +260,7 @@ We track user actions on the Accounts list with `posthog.capture()`. Conventions
| `customer analytics accounts notes sorted` | `accountNotebooksLogic` `setSorting` listener | `column` (`created_at` \| `created_by` \| null), `direction` (`asc` \| `desc` \| `cleared`) |
| `customer analytics account tab viewed` | `accountsExpansionLogic` `setActiveTab` listener (genuine tab clicks only; programmatic `openAccountTab` navigation does not fire it) | `tab` (`notes` \| `users` \| `relationships` \| `usage` \| `spend` \| `opportunities` \| `summaries` \| `support_tickets` \| `event_stream`) |
| `customer analytics account usage series toggled` | `accountBillingLogic` `toggleHiddenSeriesKey` listener (dispatched by the `AccountBillingSeriesToggle` chips) | `kind` (`usage` \| `spend`), `is_hidden` (the post-click state), `series_count` (no series label / no PII) |
+| `customer analytics account usage series bulk toggled` | `accountBillingLogic` `setAllSeriesHidden` listener (dispatched by the Select all / Clear all buttons in `AccountBillingSeriesToggle`) | `kind` (`usage` \| `spend`), `is_hidden` (`true` when hiding all, `false` when showing all), `series_count` (no series label / no PII) |
| `customer analytics account related user clicked` | `AccountRelatedUsersExpansion.tsx` user `<Link>` `onClick` | _(none — customer end-user PII kept out)_ |
| `customer analytics account opportunity clicked` | `AccountOpportunitiesExpansion.tsx` opportunity name `<Link>` `onClick` | _(none — CRM record id/url kept out)_ |
| `customer analytics account summary cadence changed` | `accountSummariesLogic` `setCadence` listener (after the PATCH succeeds) | `cadence` (`daily` \| `weekly` \| `monthly` \| `off`) |
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountBillingChart.tsx b/products/customer_analytics/frontend/components/Accounts/AccountBillingChart.tsx
index 5f03841d359c..5a48d0575f4d 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountBillingChart.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountBillingChart.tsx
@@ -220,7 +220,7 @@ export function AccountBillingChart({
}): JSX.Element {
const billingLogic = accountBillingLogic(logicProps)
const { ephemeralHiddenSeriesKeysByShortId } = useValues(billingLogic)
- const { toggleHiddenSeriesKey } = useActions(billingLogic)
+ const { toggleHiddenSeriesKey, setAllSeriesHidden } = useActions(billingLogic)
const vizLogic = dataVisualizationLogic({
key: queryKey,
@@ -272,6 +272,13 @@ export function AccountBillingChart({
series={chipItems}
hiddenKeys={hiddenKeys}
onToggle={(seriesKey) => toggleHiddenSeriesKey(shortId, seriesKey, chipItems.length)}
+ onToggleAll={(hidden) =>
+ setAllSeriesHidden(
+ shortId,
+ chipItems.map(({ key }) => key),
+ hidden
+ )
+ }
/>
)}
</div>
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountBillingSeriesToggle.tsx b/products/customer_analytics/frontend/components/Accounts/AccountBillingSeriesToggle.tsx
index 261c42b54a3e..32c1c700c052 100644
--- a/products/customer_analytics/frontend/components/Accounts/AccountBillingSeriesToggle.tsx
+++ b/products/customer_analytics/frontend/components/Accounts/AccountBillingSeriesToggle.tsx
@@ -1,4 +1,4 @@
-import { LemonSnack } from '@posthog/lemon-ui'
+import { LemonButton, LemonSnack } from '@posthog/lemon-ui'
import type { LegendItem } from '@posthog/quill-charts'
import { LemonColorGlyph } from 'lib/lemon-ui/LemonColor/LemonColorGlyph'
@@ -11,16 +11,20 @@ export function AccountBillingSeriesToggle({
hiddenKeys,
kind,
onToggle,
+ onToggleAll,
}: {
series: LegendItem[]
hiddenKeys: string[]
kind: AccountBillingKind
onToggle: (seriesKey: string) => void
+ onToggleAll: (hidden: boolean) => void
}): JSX.Element {
const hidden = new Set(hiddenKeys)
+ // Counted against the current series, not hiddenKeys.length, because the state can hold keys the data no longer has.
+ const hiddenCount = series.filter(({ key }) => hidden.has(key)).length
return (
- <div className="flex flex-wrap gap-1" data-attr={`account-billing-series-toggle-${kind}`}>
+ <div className="flex flex-wrap items-center gap-1" data-attr={`account-billing-series-toggle-${kind}`}>
{series.map(({ key, label, color }) => {
const isHidden = hidden.has(key)
return (
@@ -37,6 +41,24 @@ export function AccountBillingSeriesToggle({
</LemonSnack>
)
})}
+ <LemonButton
+ size="xsmall"
+ type="tertiary"
+ onClick={() => onToggleAll(false)}
+ disabledReason={hiddenCount === 0 ? 'All series are already shown' : undefined}
+ data-attr="account-billing-series-select-all"
+ >
+ Select all
+ </LemonButton>
+ <LemonButton
+ size="xsmall"
+ type="tertiary"
+ onClick={() => onToggleAll(true)}
+ disabledReason={hiddenCount === series.length ? 'All series are already hidden' : undefined}
+ data-attr="account-billing-series-clear-all"
+ >
+ Clear all
+ </LemonButton>
</div>
)
}
diff --git a/products/customer_analytics/frontend/components/Accounts/accountBillingLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountBillingLogic.test.ts
index b5f1f631be38..74bcacabfead 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountBillingLogic.test.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountBillingLogic.test.ts
@@ -137,6 +137,34 @@ describe('accountBillingLogic', () => {
expect(logic.values.ephemeralHiddenSeriesKeysByShortId).toEqual({})
})
+ it('hides and shows all series at once without touching the other insight, and reports the bulk toggle', () => {
+ const captureSpy = jest.spyOn(posthog, 'capture').mockImplementation(() => undefined)
+ mountForKind()
+
+ logic.actions.toggleHiddenSeriesKey('insight-b', 'Recordings-1', 2)
+ logic.actions.setAllSeriesHidden('insight-a', ['Events-0', 'Recordings-1', 'Flags-2'], true)
+ expect(logic.values.ephemeralHiddenSeriesKeysByShortId).toEqual({
+ 'insight-a': ['Events-0', 'Recordings-1', 'Flags-2'],
+ 'insight-b': ['Recordings-1'],
+ })
+ expect(captureSpy).toHaveBeenLastCalledWith('customer analytics account usage series bulk toggled', {
+ kind,
+ is_hidden: true,
+ series_count: 3,
+ })
+
+ logic.actions.setAllSeriesHidden('insight-a', ['Events-0', 'Recordings-1', 'Flags-2'], false)
+ expect(logic.values.ephemeralHiddenSeriesKeysByShortId).toEqual({
+ 'insight-a': [],
+ 'insight-b': ['Recordings-1'],
+ })
+ expect(captureSpy).toHaveBeenLastCalledWith('customer analytics account usage series bulk toggled', {
+ kind,
+ is_hidden: false,
+ series_count: 3,
+ })
+ })
+
// Environments without the saved billing insight (or a failing fetch) must degrade to an
// empty list, which is what drives the tab's not-found state instead of a crash or broken chart.
it.each([
diff --git a/products/customer_analytics/frontend/components/Accounts/accountBillingLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountBillingLogic.ts
index 7b2e286dde96..677491a38ceb 100644
--- a/products/customer_analytics/frontend/components/Accounts/accountBillingLogic.ts
+++ b/products/customer_analytics/frontend/components/Accounts/accountBillingLogic.ts
@@ -138,6 +138,15 @@ export interface accountBillingLogicActions {
savedInsights: QueryBasedInsightModel<Node<Record<string, any>>>[]
payload?: any
}
+ setAllSeriesHidden: (
+ shortId: string,
+ seriesKeys: string[],
+ hidden: boolean
+ ) => {
+ hidden: boolean
+ seriesKeys: string[]
+ shortId: string
+ }
setDateRange: (
dateFrom: string | null,
dateTo: string | null
@@ -188,6 +197,11 @@ export const accountBillingLogic = kea<accountBillingLogicType>([
seriesKey,
seriesCount,
}),
+ setAllSeriesHidden: (shortId: string, seriesKeys: string[], hidden: boolean) => ({
+ shortId,
+ seriesKeys,
+ hidden,
+ }),
}),
reducers(({ props }) => ({
dateRange: [
@@ -208,6 +222,10 @@ export const accountBillingLogic = kea<accountBillingLogicType>([
: [...current, seriesKey],
}
},
+ setAllSeriesHidden: (state, { shortId, seriesKeys, hidden }) => ({
+ ...state,
+ [shortId]: hidden ? seriesKeys : [],
+ }),
setDateRange: () => ({}),
},
],
@@ -220,6 +238,13 @@ export const accountBillingLogic = kea<accountBillingLogicType>([
series_count: seriesCount,
})
},
+ setAllSeriesHidden: ({ seriesKeys, hidden }) => {
+ posthog.capture(AccountsEvents.UsageSeriesBulkToggled, {
+ kind: props.kind,
+ is_hidden: hidden,
+ series_count: seriesKeys.length,
+ })
+ },
})),
loaders(({ props }) => ({
savedInsights: [
diff --git a/products/customer_analytics/frontend/components/Accounts/constants.ts b/products/customer_analytics/frontend/components/Accounts/constants.ts
index bbc69c095248..a4a64418586a 100644
--- a/products/customer_analytics/frontend/components/Accounts/constants.ts
+++ b/products/customer_analytics/frontend/components/Accounts/constants.ts
@@ -49,6 +49,7 @@ export const AccountsEvents = {
NotesSorted: 'customer analytics accounts notes sorted',
TabViewed: 'customer analytics account tab viewed',
UsageSeriesToggled: 'customer analytics account usage series toggled',
+ UsageSeriesBulkToggled: 'customer analytics account usage series bulk toggled',
RelatedUserClicked: 'customer analytics account related user clicked',
OpportunityClicked: 'customer analytics account opportunity clicked',
SummaryCadenceChanged: 'customer analytics account summary cadence changed',