: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
refactor(customer-analytics): remove REST endpoint tab from accounts (#60717)
Arthur Moreira de Deus1e052767d59b
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex a2cc007da6e9..2d661a6a8124 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -4127,25 +4127,25 @@ snapshots:scenes-app-batchexports--runs-with-data--light:hash: v1.k794b7964.f4a8d5cc4f5447f093d5ddbbcd8572e13f7297a7db8a89504f9290226e60a2bc._CkUe6i49hMMGaDUNDHeNZDgaVp5DJQCay44V8WqfR4scenes-app-customer-analytics-accounts--default--dark:- hash: v1.k794b7964.2f5fdfd19ec46068c974dde60066c24cfe81c010a04b30e7dc2a281e898e4552.n_f6CbLocH6mJ2AeT_GzEby8ZCNjNPBTZ7k4ZvV9p1c+ hash: v1.k794b7964.364fd66cbc1f8550023f9b319456628c98d18ffb0eebf19997e7ea3a6132d203.hiid2MP7Dz7Lz8JT0Whv3SDhpzbJbb5hDldnVXU4dcUscenes-app-customer-analytics-accounts--default--light:- hash: v1.k794b7964.79b97000448cd16b57f3618f0aa88d96e7fa56f873ea991510874c4d38aa8f30.QdV_2IzfgOiwwJ1YpnyBDUdNBOw3-Y6ISjR4jWPRYyw+ hash: v1.k794b7964.fef53cd15f11d0150aba8d57f105c07447e331ed3fcdb0a2b835a05d3ddb78b2.J1w5KgXTLTr_2dgiMGEcaXFS4z0640fuis4GUV-55sMscenes-app-customer-analytics-accounts--empty--dark:- hash: v1.k794b7964.ebf6cdc3ffcd87e1614101beedd2f9165fe87a332977747cae25b332329bb852.uF6reWk9bNsSw7WWEV3KjDFMfEg_s_qpq4S4oo54Bvg+ hash: v1.k794b7964.7f912a40a190873db50f699033fb6a8d012e443e16b4a88402d8feea2537799b.6Uwpljl7-tHmUfhDuxbBI327ghQYyWR6Tly30zwS0Ogscenes-app-customer-analytics-accounts--empty--light:- hash: v1.k794b7964.fb3f3b11f2c297a7b4ed7e26e865f1b0232fb89ee7f64f66156fde1eebc670c2.NqjaSrcZVHoLIkt_S-UuF-JwYI-Itha7Ckuw5GkD4Dg+ hash: v1.k794b7964.ff4a55634887ae1e9623859ec7cd51a73385eae41c1958e4cd6147e8160e8527.bmq9aOg_FellQivzjF2qf73EDiPBs1-9wp63N6hf-AUscenes-app-customer-analytics-accounts--feature-gate-off--dark:hash: v1.k794b7964.7750bce37ad591ab773135ad1a9b8738ac790727774c03d3aa7b5abbfc42fab0.KbXf74dR5pSVh6Wc8mSjrNGqL8LbTcsMl78W7WVvTXUscenes-app-customer-analytics-accounts--feature-gate-off--light:hash: v1.k794b7964.102431e5d999bc15bb9589ef2eccc8d0e44a779b9c820279aa1637d293edf403.AxkbpynMmXkyb0voFylEK03iBfJO43IXPpsGqxgzTkEscenes-app-customer-analytics-accounts--row-expanded-empty--dark:- hash: v1.k794b7964.f4a1756ff3324f5ec87a42c1f6f40d3a19f794da8506c71344c821e8e14cabc6.SzisY-HCjHbQJRDvck4ADTZd60v0IHwfbXI4wlQ9c_E+ hash: v1.k794b7964.bb77d9f11fba85dbcefb46f2221ad55d8da8b31e6e61bd0b8b53d6ea1cea4810.ZTgUhLKoP86MuHer-MHhS027QmFgMtkdp24XxXu6ycYscenes-app-customer-analytics-accounts--row-expanded-empty--light:- hash: v1.k794b7964.d6e84c6da22409b03fd4dd1969f1aef3a2cc7dea0fc44988d2894ef7e0c3bdd2.5Q6N6QSvL1hc02YQRBAOkzrS418sXo87ij7S02ierIQ+ hash: v1.k794b7964.021a1c353b9538e92b53522c2f9f0ce54edfe2128a8d73d2db5a1c18300fd521.ue3Cheto6fAr6I55Hn41DRJ8Ki0uSQydijiiDYjJpJYscenes-app-customer-analytics-accounts--row-expanded-with-note--dark:- hash: v1.k794b7964.0a0d1b32483192fda88dfc775725fe2df00ca6ba0ed969b3a93ab42e02454ba1.K2vJPKWjZ0CtP20CY80Aa0t2vVkBZAmmeM78vqtZx5w+ hash: v1.k794b7964.5766de93c835a93b824169b0d68674fdda0f2370094692ddcf7c7b182a3cfe89.wVjuimww9AOH7VBoaI7Ji07pOrxrW6PmWexYN23lRQcscenes-app-customer-analytics-accounts--row-expanded-with-note--light:- hash: v1.k794b7964.9f478491d60d6c23237f6d9cb118b02a1d4642381d9ddab3d59cc87a94766a26.dSnxPzlQcBDlH-bqMCOGD8AEmcS9dwe-cu3U8oAgUL8+ hash: v1.k794b7964.ddac5516ff9df120ea18a456cf3a3a648dc5b32cb6672a962c73273f384e4ded.J7Gn0iZoA4IIpF7iidcgsnhSuGPe7YssglzpxegJQl0scenes-app-customer-analytics-dashboard--b-2-b-mode-with-groups-enabled--dark:hash: v1.k794b7964.b1e7b3b4db44122983952ce49cdcb2721216d6e09cdda2e03d88250a66f9531d.XEmKGVDBb7ph1xN1zMKNGWDQAkJPR509WPM2orhsrZoscenes-app-customer-analytics-dashboard--b-2-b-mode-with-groups-enabled--light:@@ -4889,7 +4889,7 @@ snapshots:scenes-app-insights-funnels--funnel-left-to-right-edit-viewports--wide--dark:hash: v1.k794b7964.293297b83994468984576e5c15fa2cbbb2c4c0a7a8234959b9deba539efa383b.O7SwG4Drfr3z02hcLNC1LsLsGWddouhybBp4xZaUE-Ascenes-app-insights-funnels--funnel-left-to-right-edit-viewports--wide--light:- hash: v1.k794b7964.6c391cbc05b64230fbd8defdbb960b131fd433409817497873fb9ffc705cd360.EIwByuofuT77yP259A9ffqfjSFwW9MrUDOvsZNA_aZM+ hash: v1.k794b7964.c63132bb5b13cbe97938ebdb2e59e320ebc338bd12b2d3bfd6af81e56270650a.KSiw8WpvjWXIDh87ExL4cPnopVJlTXvzU8N8ruh6Hi8scenes-app-insights-funnels--funnel-time-to-convert--dark:hash: v1.k794b7964.d64808d2bfc36017f89b57feeaa373e20188738a622801207fa1beb59d02fdd9.cFuKF_Ow887Z3X3BoNhtTvkUWY2vips9HDBe-B02eQEscenes-app-insights-funnels--funnel-time-to-convert--light:diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsxindex 8f6c3f6db842..821a9480b0ad 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountsHogQLTable.tsx@@ -1,4 +1,4 @@-import { BindLogic, useActions, useValues } from 'kea'+import { useActions, useValues } from 'kea'import { useMemo } from 'react'import { LemonButton, LemonSkeleton, LemonTable, ProfilePicture } from '@posthog/lemon-ui'@@ -328,6 +328,8 @@ function AccountsHogQLDataTable({ query }: { query: DataTableNode }): JSX.Elemencolumns: contextColumns,expandable,dataNodeLogicKey: ACCOUNTS_HOGQL_DATA_NODE_KEY,+ emptyStateHeading: 'There are no matching accounts for this query',+ emptyStateDetail: 'Try adjusting the filters or refreshing',}}readOnly/>@@ -338,19 +340,11 @@ export function AccountsHogQLTable(): JSX.Element {const { hogqlQuery } = useValues(accountsLogic)return (- <BindLogic- logic={dataNodeLogic}- props={{- key: ACCOUNTS_HOGQL_DATA_NODE_KEY,- query: hogqlQuery.source,- }}- >- <div className="flex flex-col gap-2">- <div className="flex justify-end">- <AccountsColumnConfigurator />- </div>- <AccountsHogQLDataTable query={hogqlQuery} />+ <div className="flex flex-col gap-2">+ <div className="flex justify-end">+ <AccountsColumnConfigurator /></div>- </BindLogic>+ <AccountsHogQLDataTable query={hogqlQuery} />+ </div>)}diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsxindex 27c6ffea9c59..ab82ab1b0b98 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountsTab.stories.tsx@@ -8,24 +8,58 @@ import { urls } from 'scenes/urls'import { mswDecorator } from '~/mocks/browser'-const ACCOUNTS_ENDPOINT = 'api/environments/:team_id/accounts/'+const QUERY_ENDPOINT = '/api/environments/:team_id/query/:kind/'const ACCOUNT_NOTEBOOKS_ENDPOINT = 'api/environments/:team_id/accounts/:account_id/notebooks/'+const WAREHOUSE_VIEW_LINK_ENDPOINT = 'api/environments/:team_id/warehouse_view_link/'-const SINGLE_ACCOUNT_RESULTS = [- {- id: 'acc-1',- name: 'Acme Inc',- external_id: 'cust_acme_001',- properties: {- csm: { id: 1, email: '[email protected]' },- account_executive: { id: 2, email: '[email protected]' },- account_owner: null,- },- tags: ['enterprise', 'priority'],- created_at: '2026-05-01T00:00:00Z',- created_by: 1,- updated_at: '2026-05-20T00:00:00Z',- },+type AccountNameCell = { name: string; external_id: string | null; id: string }+type AccountRoleCell = [number, string] | null+type AccountRow = [AccountNameCell, string[], number, AccountRoleCell, AccountRoleCell, AccountRoleCell]++function buildAccountsQueryResponse(rows: AccountRow[]): Record<string, unknown> {+ return {+ kind: 'AccountsQuery',+ columns: ['name', 'tag_names', 'notebook_count', 'csm', 'account_executive', 'account_owner'],+ results: rows,+ types: [],+ hogql: '',+ timings: [],+ modifiers: {},+ hasMore: false,+ limit: 100,+ offset: 0,+ }+}++const SAMPLE_ROWS: AccountRow[] = [+ [+ { name: 'Acme Inc', external_id: 'cust_acme_001', id: 'acc-1' },+ ['enterprise', 'priority'],+ 0,+ [1, '[email protected]'],+ [2, '[email protected]'],+ null,+ ],+ [{ name: 'Globex', external_id: 'cust_globex_002', id: 'acc-2' }, [], 0, null, null, null],+ [+ { name: 'Hooli', external_id: null, id: 'acc-3' },+ ['scaleup'],+ 0,+ [1, '[email protected]'],+ null,+ [3, '[email protected]'],+ ],+]++const SINGLE_ROW: AccountRow[] = [+ [+ { name: 'Acme Inc', external_id: 'cust_acme_001', id: 'acc-1' },+ ['enterprise', 'priority'],+ 1,+ [1, '[email protected]'],+ [2, '[email protected]'],+ null,+ ],]async function expandFirstRow(canvasElement: HTMLElement): Promise<void> {@@ -34,6 +68,16 @@ async function expandFirstRow(canvasElement: HTMLElement): Promise<void> {await userEvent.click(expandBtn)}+function mockAccountsQuery(rows: AccountRow[]): (req: { body: unknown }) => [number, unknown] | undefined {+ return (req) => {+ const kind = (req.body as { query?: { kind?: string } })?.query?.kind+ if (kind === 'AccountsQuery') {+ return [200, buildAccountsQueryResponse(rows)]+ }+ return undefined+ }+}+const meta: Meta = {component: App,title: 'Scenes-App/Customer Analytics/Accounts',@@ -50,51 +94,10 @@ const meta: Meta = {decorators: [mswDecorator({get: {- [ACCOUNTS_ENDPOINT]: {- count: 3,- next: null,- previous: null,- results: [- {- id: 'acc-1',- name: 'Acme Inc',- external_id: 'cust_acme_001',- properties: {- csm: { id: 1, email: '[email protected]' },- account_executive: { id: 2, email: '[email protected]' },- account_owner: null,- },- tags: ['enterprise', 'priority'],- created_at: '2026-05-01T00:00:00Z',- created_by: 1,- updated_at: '2026-05-20T00:00:00Z',- },- {- id: 'acc-2',- name: 'Globex',- external_id: 'cust_globex_002',- properties: {},- tags: [],- created_at: '2026-05-02T00:00:00Z',- created_by: 1,- updated_at: '2026-05-19T00:00:00Z',- },- {- id: 'acc-3',- name: 'Hooli',- external_id: null,- properties: {- csm: { id: 1, email: '[email protected]' },- account_executive: null,- account_owner: { id: 3, email: '[email protected]' },- },- tags: ['scaleup'],- created_at: '2026-05-03T00:00:00Z',- created_by: 1,- updated_at: '2026-05-18T00:00:00Z',- },- ],- },+ [WAREHOUSE_VIEW_LINK_ENDPOINT]: { count: 0, next: null, previous: null, results: [] },+ },+ post: {+ [QUERY_ENDPOINT]: mockAccountsQuery(SAMPLE_ROWS),},}),],@@ -111,8 +114,8 @@ export const Empty: Story = {render: () => <App />,decorators: [mswDecorator({- get: {- [ACCOUNTS_ENDPOINT]: { count: 0, next: null, previous: null, results: [] },+ post: {+ [QUERY_ENDPOINT]: mockAccountsQuery([]),},}),],@@ -135,14 +138,11 @@ export const RowExpandedEmpty: Story = {decorators: [mswDecorator({get: {- [ACCOUNTS_ENDPOINT]: {- count: SINGLE_ACCOUNT_RESULTS.length,- next: null,- previous: null,- results: SINGLE_ACCOUNT_RESULTS,- },[ACCOUNT_NOTEBOOKS_ENDPOINT]: { count: 0, next: null, previous: null, results: [] },},+ post: {+ [QUERY_ENDPOINT]: mockAccountsQuery(SINGLE_ROW),+ },}),],play: async ({ canvasElement }) => {@@ -155,12 +155,6 @@ export const RowExpandedWithNote: Story = {decorators: [mswDecorator({get: {- [ACCOUNTS_ENDPOINT]: {- count: SINGLE_ACCOUNT_RESULTS.length,- next: null,- previous: null,- results: SINGLE_ACCOUNT_RESULTS,- },[ACCOUNT_NOTEBOOKS_ENDPOINT]: {count: 1,next: null,@@ -195,6 +189,9 @@ export const RowExpandedWithNote: Story = {],},},+ post: {+ [QUERY_ENDPOINT]: mockAccountsQuery(SINGLE_ROW),+ },}),],play: async ({ canvasElement }) => {diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTabContent.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTabContent.tsxindex a5e3173b05da..20a7d224bc7c 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountsTabContent.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountsTabContent.tsx@@ -1,35 +1,26 @@-import { useActions, useValues } from 'kea'+import { BindLogic, useValues } from 'kea'-import { LemonTabs } from 'lib/lemon-ui/LemonTabs'+import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'import { AccountsHogQLTable } from './AccountsHogQLTable'-import { accountsLogic, AccountsView } from './accountsLogic'+import { ACCOUNTS_HOGQL_DATA_NODE_KEY, accountsLogic } from './accountsLogic'import { AccountsTabFilters } from './AccountsTabFilters'-import { AccountsTable } from './AccountsTable'export function AccountsTabContent(): JSX.Element {- const { activeView } = useValues(accountsLogic)- const { setActiveView } = useActions(accountsLogic)+ const { hogqlQuery } = useValues(accountsLogic)return (- <div className="flex flex-col gap-3">- <AccountsTabFilters />- <LemonTabs- activeKey={activeView}- onChange={(key) => setActiveView(key as AccountsView)}- tabs={[- {- key: 'endpoint',- label: 'REST endpoint',- content: <AccountsTable />,- },- {- key: 'hogql',- label: 'HogQL query',- content: <AccountsHogQLTable />,- },- ]}- />- </div>+ <BindLogic+ logic={dataNodeLogic}+ props={{+ key: ACCOUNTS_HOGQL_DATA_NODE_KEY,+ query: hogqlQuery.source,+ }}+ >+ <div className="flex flex-col gap-3">+ <AccountsTabFilters />+ <AccountsHogQLTable />+ </div>+ </BindLogic>)}diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.tsxindex f1a8336a355f..f7a393401f6f 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountsTabFilters.tsx@@ -6,19 +6,14 @@ import { LemonButton, LemonCheckbox, LemonDropdown, LemonInput, LemonInputSelectimport { MemberSelect } from 'lib/components/MemberSelect'import { tagsModel } from '~/models/tagsModel'+import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'import { accountsLogic, RoleFilterValue } from './accountsLogic'export function AccountsTabFilters(): JSX.Element {- const {- searchQuery,- tagsFilter,- allRolesUnassigned,- csmFilter,- accountExecutiveFilter,- accountOwnerFilter,- accountsLoading,- } = useValues(accountsLogic)+ const { searchQuery, tagsFilter, allRolesUnassigned, csmFilter, accountExecutiveFilter, accountOwnerFilter } =+ useValues(accountsLogic)+ const { responseLoading: accountsLoading } = useValues(dataNodeLogic)const {setSearchQuery,setTagsFilter,diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTable.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTable.tsxdeleted file mode 100644index 26f53ec22e08..000000000000--- a/products/customer_analytics/frontend/components/Accounts/AccountsTable.tsx+++ /dev/null@@ -1,139 +0,0 @@-import { useActions, useValues } from 'kea'--import { LemonButton, LemonTable, LemonTableColumns, ProfilePicture } from '@posthog/lemon-ui'--import { CopyToClipboardInline } from 'lib/components/CopyToClipboard'-import { MemberSelect } from 'lib/components/MemberSelect'-import { ObjectTags } from 'lib/components/ObjectTags/ObjectTags'--import type { AccountApi } from 'products/customer_analytics/frontend/generated/api.schemas'--import { AccountNotebooksExpansion } from './AccountNotebooksExpansion'-import { ACCOUNTS_PAGE_SIZE, AccountRoleKey, accountsLogic } from './accountsLogic'--type AccountAssignment = { id: number; email: string } | null--const ROLE_DEFAULT_LABEL = 'Unassigned'--export function AccountsTable(): JSX.Element {- const { results, totalCount, accountsLoading, currentPage } = useValues(accountsLogic)- const { setCurrentPage } = useActions(accountsLogic)-- const columns: LemonTableColumns<AccountApi> = [- {- title: 'Account',- key: 'name',- dataIndex: 'name',- render: (_, account) => (- <div className="flex flex-col min-w-40">- <span className="font-medium">{account.name}</span>- {account.external_id ? (- <CopyToClipboardInline- explicitValue={account.external_id}- iconStyle={{ color: 'var(--color-accent)' }}- description="account ID"- >- {account.external_id}- </CopyToClipboardInline>- ) : null}- </div>- ),- },- {- title: 'Tags',- key: 'tags',- dataIndex: 'tags',- render: (_, account) =>- account.tags && account.tags.length > 0 ? (- <ObjectTags tags={account.tags} staticOnly />- ) : (- <span className="text-muted">—</span>- ),- },- {- title: 'Notes',- key: 'notebooks',- dataIndex: 'notebooks',- render: (_, account) => {- const count = account.notebooks?.length ?? 0- return count > 0 ? <span>{count}</span> : <span className="text-muted">—</span>- },- },- {- title: 'CSM',- key: 'csm',- render: (_, account) => <RoleAssignmentCell account={account} role="csm" />,- },- {- title: 'Account executive',- key: 'account_executive',- render: (_, account) => <RoleAssignmentCell account={account} role="account_executive" />,- },- {- title: 'Account owner',- key: 'account_owner',- render: (_, account) => <RoleAssignmentCell account={account} role="account_owner" />,- },- ]-- return (- <LemonTable<AccountApi>- dataSource={results}- rowKey="id"- loading={accountsLoading}- columns={columns}- expandable={{- noIndent: true,- expandedRowRender: (account) => <AccountNotebooksExpansion accountId={account.id} />,- }}- pagination={{- controlled: true,- currentPage,- pageSize: ACCOUNTS_PAGE_SIZE,- entryCount: totalCount,- onBackward: () => setCurrentPage(Math.max(1, currentPage - 1)),- onForward: () => setCurrentPage(currentPage + 1),- }}- />- )-}--function RoleAssignmentCell({ account, role }: { account: AccountApi; role: AccountRoleKey }): JSX.Element {- const { isRoleSaving } = useValues(accountsLogic)- const { updateAccountRole } = useActions(accountsLogic)-- const assignment: AccountAssignment = account.properties?.[role] ?? null- const saving = isRoleSaving(account.id, role)-- return (- <div data-attr={`accounts-${role}-cell`}>- <MemberSelect- value={assignment?.id ?? null}- defaultLabel={ROLE_DEFAULT_LABEL}- onChange={(user) => updateAccountRole(account.id, role, user)}- >- {(selectedUser) => (- <LemonButton- type="tertiary"- size="small"- loading={saving}- disabledReason={saving ? 'Saving…' : undefined}- icon={- selectedUser ? (- <ProfilePicture user={selectedUser} size="sm" />- ) : assignment ? (- <ProfilePicture user={{ email: assignment.email }} size="sm" />- ) : undefined- }- >- {assignment ? (- <span className="text-sm">{assignment.email}</span>- ) : (- <span className="text-muted">Unassigned</span>- )}- </LemonButton>- )}- </MemberSelect>- </div>- )-}diff --git a/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.tsindex 526cb415d7a9..8750dd319d73 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsLogic.test.ts@@ -6,7 +6,7 @@ import type { AccountsQuery } from '~/queries/schema/schema-general'import { initKeaTests } from '~/test/init'import type { UserBasicType } from '~/types'-import { accountsList, accountsPartialUpdate } from 'products/customer_analytics/frontend/generated/api'+import { accountsPartialUpdate, accountsRetrieve } from 'products/customer_analytics/frontend/generated/api'import type { AccountApi } from 'products/customer_analytics/frontend/generated/api.schemas'import {@@ -14,18 +14,18 @@ import {ACCOUNTS_NAME_COLUMN,accountsColumnConfigLogic,} from './accountsColumnConfigLogic'-import { ACCOUNTS_PAGE_SIZE, accountsLogic, savingRoleKey } from './accountsLogic'+import { accountsLogic, savingRoleKey } from './accountsLogic'// `hogqlQuery.source` is typed as the full DataTableNode source union; this logic// always produces an AccountsQuery, so narrow once for the orderBy assertions.const orderByOf = (source: unknown): AccountsQuery['orderBy'] => (source as AccountsQuery).orderByjest.mock('products/customer_analytics/frontend/generated/api', () => ({- accountsList: jest.fn(),+ accountsRetrieve: jest.fn(),accountsPartialUpdate: jest.fn(),}))-const mockAccountsList = accountsList as jest.MockedFunction<typeof accountsList>+const mockAccountsRetrieve = accountsRetrieve as jest.MockedFunction<typeof accountsRetrieve>const mockAccountsPartialUpdate = accountsPartialUpdate as jest.MockedFunction<typeof accountsPartialUpdate>const buildAccount = (overrides: Partial<AccountApi> = {}): AccountApi => ({@@ -60,12 +60,6 @@ describe('accountsLogic', () => {beforeEach(() => {initKeaTests()jest.resetAllMocks()- mockAccountsList.mockResolvedValue({- count: 0,- next: null,- previous: null,- results: [],- })logic = accountsLogic()logic.mount()})@@ -81,52 +75,16 @@ describe('accountsLogic', () => {expect(logic.values.csmFilter).toBeNull()expect(logic.values.accountExecutiveFilter).toBeNull()expect(logic.values.accountOwnerFilter).toBeNull()- expect(logic.values.currentPage).toBe(1)})- it('loads accounts on mount with default pagination', async () => {- await expectLogic(logic).toFinishAllListeners()-- expect(mockAccountsList).toHaveBeenCalledWith(String(MOCK_DEFAULT_TEAM.id), {- limit: ACCOUNTS_PAGE_SIZE,- offset: 0,- })- })-- it('setTagsFilter updates the reducer and resets to page 1', async () => {- logic.actions.setCurrentPage(3)+ it('setTagsFilter updates the reducer', () => {logic.actions.setTagsFilter(['enterprise'])- await expectLogic(logic).toMatchValues({- tagsFilter: ['enterprise'],- currentPage: 1,- })+ expect(logic.values.tagsFilter).toEqual(['enterprise'])})- it('setSearchQuery updates the reducer and resets to page 1', async () => {- logic.actions.setCurrentPage(3)+ it('setSearchQuery updates the reducer', () => {logic.actions.setSearchQuery('acme')- await expectLogic(logic).toMatchValues({- searchQuery: 'acme',- currentPage: 1,- })- })-- it('loadAccounts sends a trimmed search param', async () => {- logic.actions.setSearchQuery(' acme ')- await expectLogic(logic).toFinishAllListeners()- expect(mockAccountsList).toHaveBeenLastCalledWith(- String(MOCK_DEFAULT_TEAM.id),- expect.objectContaining({ search: 'acme' })- )- })-- it('loadAccounts omits the search param when the query is blank', async () => {- logic.actions.setSearchQuery(' ')- await expectLogic(logic).toFinishAllListeners()- expect(mockAccountsList).toHaveBeenLastCalledWith(- String(MOCK_DEFAULT_TEAM.id),- expect.not.objectContaining({ search: expect.anything() })- )+ expect(logic.values.searchQuery).toBe('acme')})it('setAllRolesUnassigned toggles the flag', () => {@@ -141,36 +99,19 @@ describe('accountsLogic', () => {expect(logic.values.csmFilter).toBeNull()})- it('loadAccounts sends tags as a JSON-encoded array string', async () => {- logic.actions.setTagsFilter(['a', 'b'])- await expectLogic(logic).toFinishAllListeners()-- expect(mockAccountsList).toHaveBeenLastCalledWith(- String(MOCK_DEFAULT_TEAM.id),- expect.objectContaining({ tags: '["a","b"]' })- )- })-it('setting a role filter clears the all_roles_unassigned flag', async () => {logic.actions.setAllRolesUnassigned(true)- await expectLogic(logic).toFinishAllListeners()logic.actions.setCsmFilter(7)await expectLogic(logic).toFinishAllListeners()expect(logic.values.allRolesUnassigned).toBe(false)expect(logic.values.csmFilter).toBe(7)- expect(mockAccountsList).toHaveBeenLastCalledWith(- String(MOCK_DEFAULT_TEAM.id),- expect.objectContaining({ csm: '7', limit: ACCOUNTS_PAGE_SIZE, offset: 0 })- )- expect(mockAccountsList.mock.calls.at(-1)?.[1]).not.toHaveProperty('all_roles_unassigned')})it('enabling all_roles_unassigned clears any active role filters', async () => {logic.actions.setCsmFilter(7)logic.actions.setAccountExecutiveFilter(9)logic.actions.setAccountOwnerFilter(11)- await expectLogic(logic).toFinishAllListeners()logic.actions.setAllRolesUnassigned(true)await expectLogic(logic).toFinishAllListeners()@@ -178,14 +119,6 @@ describe('accountsLogic', () => {expect(logic.values.csmFilter).toBeNull()expect(logic.values.accountExecutiveFilter).toBeNull()expect(logic.values.accountOwnerFilter).toBeNull()-- const lastParams = mockAccountsList.mock.calls.at(-1)?.[1]- expect(lastParams).toEqual(- expect.objectContaining({ all_roles_unassigned: true, limit: ACCOUNTS_PAGE_SIZE, offset: 0 })- )- expect(lastParams).not.toHaveProperty('csm')- expect(lastParams).not.toHaveProperty('account_executive')- expect(lastParams).not.toHaveProperty('account_owner')})describe('sortOrder', () => {@@ -241,12 +174,6 @@ describe('accountsLogic', () => {logic.actions.toggleSort('name')expect(orderByOf(logic.values.hogqlQuery.source)).toEqual(['name DESC'])})-- it('toggleSort resets pagination to page 1', async () => {- logic.actions.setCurrentPage(3)- logic.actions.toggleSort('notebook_count')- await expectLogic(logic).toMatchValues({ currentPage: 1 })- })})describe('selectColumns', () => {@@ -281,40 +208,11 @@ describe('accountsLogic', () => {})})- it('setCurrentPage updates the offset in the next request', async () => {- logic.actions.setCurrentPage(3)- await expectLogic(logic).toFinishAllListeners()- expect(mockAccountsList).toHaveBeenLastCalledWith(- String(MOCK_DEFAULT_TEAM.id),- expect.objectContaining({ limit: ACCOUNTS_PAGE_SIZE, offset: 2 * ACCOUNTS_PAGE_SIZE })- )- })-- it('refresh triggers a fresh request with current filters', async () => {- logic.actions.setTagsFilter(['priority'])- await expectLogic(logic).toFinishAllListeners()- mockAccountsList.mockClear()- logic.actions.refresh()- await expectLogic(logic).toFinishAllListeners()- expect(mockAccountsList).toHaveBeenCalledTimes(1)- expect(mockAccountsList).toHaveBeenLastCalledWith(- String(MOCK_DEFAULT_TEAM.id),- expect.objectContaining({ tags: '["priority"]' })- )- })-describe('updateAccountRole', () => {const existingAccount = buildAccount()- beforeEach(async () => {- mockAccountsList.mockResolvedValue({- count: 1,- next: null,- previous: null,- results: [existingAccount],- })- logic.actions.refresh()- await expectLogic(logic).toFinishAllListeners()+ beforeEach(() => {+ mockAccountsRetrieve.mockResolvedValue(existingAccount)})it('PATCHes the merged properties payload with the new assignment', async () => {@@ -330,13 +228,14 @@ describe('accountsLogic', () => {logic.actions.updateAccountRole('acc-1', 'csm', user)await expectLogic(logic).toFinishAllListeners()+ expect(mockAccountsRetrieve).toHaveBeenCalledWith(String(MOCK_DEFAULT_TEAM.id), 'acc-1')expect(mockAccountsPartialUpdate).toHaveBeenCalledWith(String(MOCK_DEFAULT_TEAM.id), 'acc-1', {properties: {csm: { id: user.id, email: user.email },stripe_customer_id: 'cus_123',},})- expect(logic.values.results[0].properties?.csm).toEqual({ id: user.id, email: user.email })+ expect(logic.values.accountOverrides['acc-1']).toEqual(updated)})it('sends null when clearing an assignment', async () => {@@ -376,13 +275,13 @@ describe('accountsLogic', () => {expect(logic.values.isRoleSaving('acc-1', 'account_executive')).toBe(false)})- it('leaves the row untouched on failure', async () => {+ it('leaves overrides untouched on failure', async () => {mockAccountsPartialUpdate.mockRejectedValueOnce(new Error('boom'))logic.actions.updateAccountRole('acc-1', 'account_owner', buildUser())await expectLogic(logic).toFinishAllListeners()- expect(logic.values.results[0]).toEqual(existingAccount)+ expect(logic.values.accountOverrides['acc-1']).toBeUndefined()expect(logic.values.isRoleSaving('acc-1', 'account_owner')).toBe(false)})diff --git a/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountsLogic.tsindex 2b9240b94a40..8398d2234197 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts@@ -1,5 +1,4 @@-import { actions, afterMount, connect, isBreakpoint, kea, listeners, path, reducers, selectors } from 'kea'-import { loaders } from 'kea-loaders'+import { actions, connect, kea, listeners, path, reducers, selectors } from 'kea'import posthog from 'posthog-js'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'@@ -9,7 +8,7 @@ import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'import { AccountsQuery, DataTableNode, NodeKind } from '~/queries/schema/schema-general'import type { UserBasicType } from '~/types'-import { accountsList, accountsPartialUpdate } from 'products/customer_analytics/frontend/generated/api'+import { accountsPartialUpdate, accountsRetrieve } from 'products/customer_analytics/frontend/generated/api'import type {AccountApi,PatchedAccountApiProperties,@@ -19,8 +18,6 @@ import { CUSTOMER_ANALYTICS_DEFAULT_QUERY_TAGS } from '../../constants'import { accountsColumnConfigLogic } from './accountsColumnConfigLogic'import type { accountsLogicType } from './accountsLogicType'-export const ACCOUNTS_PAGE_SIZE = 20-export const ACCOUNTS_HOGQL_DATA_NODE_KEY = 'customer-analytics-accounts-hogql'interface SortLikeValues {@@ -47,8 +44,6 @@ function clearSortIfColumnRemoved(values: SortLikeValues, actions: SortLikeActioexport type RoleFilterValue = number | null-export type AccountsView = 'endpoint' | 'hogql'-export type AccountRoleKey = 'csm' | 'account_executive' | 'account_owner'// `column` matches the visible column name (alias-stripped) so any selected@@ -83,13 +78,6 @@ const ROLE_LABELS: Record<AccountRoleKey, string> = {export const savingRoleKey = (accountId: string, role: AccountRoleKey): string => `${accountId}:${role}`-export interface AccountsLoadResult {- count: number- results: AccountApi[]-}--const EMPTY_RESULT: AccountsLoadResult = { count: 0, results: [] }-export const accountsLogic = kea<accountsLogicType>([path(['scenes', 'customerAnalytics', 'accounts', 'accountsLogic']),connect(() => ({@@ -103,8 +91,6 @@ export const accountsLogic = kea<accountsLogicType>([setCsmFilter: (value: RoleFilterValue) => ({ value }),setAccountExecutiveFilter: (value: RoleFilterValue) => ({ value }),setAccountOwnerFilter: (value: RoleFilterValue) => ({ value }),- setCurrentPage: (page: number) => ({ page }),- setActiveView: (view: AccountsView) => ({ view }),setSortOrder: (sortOrder: AccountSortOrder) => ({ sortOrder }),toggleSort: (column: AccountSortableColumn) => ({ column }),refresh: true,@@ -116,7 +102,6 @@ export const accountsLogic = kea<accountsLogicType>([roleUpdateStarted: (accountId: string, role: AccountRoleKey) => ({ accountId, role }),roleUpdateFinished: (accountId: string, role: AccountRoleKey) => ({ accountId, role }),replaceAccount: (account: AccountApi) => ({ account }),- revertAccountOverride: (accountId: string) => ({ accountId }),}),reducers({searchQuery: [@@ -155,18 +140,6 @@ export const accountsLogic = kea<accountsLogicType>([setAccountOwnerFilter: (_, { value }) => value,},],- currentPage: [- 1,- {- setCurrentPage: (_, { page }) => page,- },- ],- activeView: [- 'endpoint' as AccountsView,- {- setActiveView: (_, { view }) => view,- },- ],sortOrder: [null as AccountSortOrder,{@@ -191,66 +164,10 @@ export const accountsLogic = kea<accountsLogicType>([{} as Record<string, AccountApi>,{replaceAccount: (state, { account }) => ({ ...state, [account.id]: account }),- revertAccountOverride: (state, { accountId }) => {- const next = { ...state }- delete next[accountId]- return next- },- loadAccountsSuccess: () => ({}),},],}),- loaders(({ values }) => ({- accounts: [- EMPTY_RESULT,- {- loadAccounts: async (_ = null, breakpoint) => {- await breakpoint(300)- const projectId = String(values.currentTeamId)- const params: Record<string, string | number | boolean> = {- limit: ACCOUNTS_PAGE_SIZE,- offset: (values.currentPage - 1) * ACCOUNTS_PAGE_SIZE,- }- if (values.searchQuery.trim()) {- params.search = values.searchQuery.trim()- }- if (values.tagsFilter.length > 0) {- params.tags = JSON.stringify(values.tagsFilter)- }- if (values.allRolesUnassigned) {- params.all_roles_unassigned = true- }- if (values.csmFilter !== null) {- params.csm = String(values.csmFilter)- }- if (values.accountExecutiveFilter !== null) {- params.account_executive = String(values.accountExecutiveFilter)- }- if (values.accountOwnerFilter !== null) {- params.account_owner = String(values.accountOwnerFilter)- }- try {- const response = await accountsList(projectId, params)- breakpoint()- return { count: response.count, results: response.results }- } catch (error) {- if (!isBreakpoint(error as Error)) {- posthog.captureException(error as Error, { scope: 'accountsLogic.loadAccounts' })- lemonToast.error('Failed to load accounts')- }- throw error- }- },- },- ],- })),selectors({- totalCount: [(s) => [s.accounts], (a: AccountsLoadResult): number => a.count],- results: [- (s) => [s.accounts, s.accountOverrides],- (a: AccountsLoadResult, overrides: Record<string, AccountApi>): AccountApi[] =>- a.results.map((account) => overrides[account.id] ?? account),- ],isRoleSaving: [(s) => [s.savingRoles],(savingRoles: Record<string, true>) =>@@ -320,12 +237,6 @@ export const accountsLogic = kea<accountsLogicType>([],}),listeners(({ actions, values }) => ({- setSearchQuery: () => {- actions.setCurrentPage(1)- },- setTagsFilter: () => {- actions.setCurrentPage(1)- },setAllRolesUnassigned: ({ value }) => {if (value) {if (values.csmFilter !== null) {@@ -338,28 +249,21 @@ export const accountsLogic = kea<accountsLogicType>([actions.setAccountOwnerFilter(null)}}- actions.setCurrentPage(1)},setCsmFilter: ({ value }) => {if (value !== null && values.allRolesUnassigned) {actions.setAllRolesUnassigned(false)}- actions.setCurrentPage(1)},setAccountExecutiveFilter: ({ value }) => {if (value !== null && values.allRolesUnassigned) {actions.setAllRolesUnassigned(false)}- actions.setCurrentPage(1)},setAccountOwnerFilter: ({ value }) => {if (value !== null && values.allRolesUnassigned) {actions.setAllRolesUnassigned(false)}- actions.setCurrentPage(1)- },- setCurrentPage: () => {- actions.loadAccounts()},toggleSort: ({ column }) => {const current = values.sortOrder@@ -373,9 +277,6 @@ export const accountsLogic = kea<accountsLogicType>([}actions.setSortOrder(next)},- setSortOrder: () => {- actions.setCurrentPage(1)- },setSelectColumns: () => {clearSortIfColumnRemoved(values, actions)},@@ -386,36 +287,24 @@ export const accountsLogic = kea<accountsLogicType>([clearSortIfColumnRemoved(values, actions)},refresh: () => {- actions.loadAccounts()dataNodeLogic.findMounted({ key: ACCOUNTS_HOGQL_DATA_NODE_KEY })?.actions.loadData('force_async')},updateAccountRole: async ({ accountId, role, user }) => {if (values.isRoleSaving(accountId, role)) {return}- const account = values.results.find((a) => a.id === accountId)- if (!account) {- return- }- const previousOverride = values.accountOverrides[accountId]- const nextProperties: PatchedAccountApiProperties = {- ...account.properties,- [role]: user ? { id: user.id, email: user.email } : null,- }- const optimisticAccount: AccountApi = { ...account, properties: nextProperties }const projectId = String(values.currentTeamId)actions.roleUpdateStarted(accountId, role)- actions.replaceAccount(optimisticAccount)try {+ const current = await accountsRetrieve(projectId, accountId)+ const nextProperties: PatchedAccountApiProperties = {+ ...current.properties,+ [role]: user ? { id: user.id, email: user.email } : null,+ }const updated = await accountsPartialUpdate(projectId, accountId, { properties: nextProperties })actions.replaceAccount(updated)dataNodeLogic.findMounted({ key: ACCOUNTS_HOGQL_DATA_NODE_KEY })?.actions.loadData('force_async')} catch (error) {- if (previousOverride) {- actions.replaceAccount(previousOverride)- } else {- actions.revertAccountOverride(accountId)- }posthog.captureException(error as Error, { scope: 'accountsLogic.updateAccountRole' })lemonToast.error(`Failed to update ${ROLE_LABELS[role]}`)} finally {@@ -423,7 +312,4 @@ export const accountsLogic = kea<accountsLogicType>([}},})),- afterMount(({ actions }) => {- actions.loadAccounts()- }),])