: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
fix(customer-analytics): apply saved views before the first fetch (#92005)
jake sciotto53703e07d607
diff --git a/products/customer_analytics/frontend/components/Accounts/AccountsTable.tsx b/products/customer_analytics/frontend/components/Accounts/AccountsTable.tsxindex cdfeb1258b13..7d22235112a3 100644--- a/products/customer_analytics/frontend/components/Accounts/AccountsTable.tsx+++ b/products/customer_analytics/frontend/components/Accounts/AccountsTable.tsx@@ -886,7 +886,7 @@ export function AccountsTable(): JSX.Element {const { responseLoading, response } = useValues(dataNodeLogic({key: ACCOUNTS_TABLE_DATA_NODE_KEY,- query: accountsQuerySource ?? accountsDataTableQuery.source,+ query: accountsQuerySource,} as DataNodeLogicProps))const { featureFlags } = useValues(featureFlagLogic)diff --git a/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountsLogic.tsindex c37e37797469..679756d9e3e0 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsLogic.ts@@ -175,6 +175,7 @@ export interface accountsLogicValues {allRolesUnassigned: booleanassignedToCurrentUser: booleanassignedToFilter: RoleFilterValue+ awaitingSavedView: booleancanSortClientSide: booleancurrentUserId: number | nullcustomPropertyOverrides: Record<string, CustomPropertyValueWriteApi['value']>@@ -403,6 +404,9 @@ export interface accountsLogicActions {setAssignedToFilter: (value: RoleFilterValue) => {value: RoleFilterValue}+ setAwaitingSavedView: (awaiting: boolean) => {+ awaiting: boolean+ }setCustomPropertyOverride: (accountId: string,definitionId: string,@@ -535,7 +539,8 @@ export interface accountsLogicMeta {) => AccountsTableQueryPlanaccountsQuerySource: (accountsTableQueryPlan: AccountsTableQueryPlan,- relationshipDefinitionsLoaded: boolean+ relationshipDefinitionsLoaded: boolean,+ awaitingSavedView: boolean) => AccountsTableQuery | nullaccountsDataTableQuery: (accountsTableQueryPlan: AccountsTableQueryPlan,@@ -544,7 +549,8 @@ export interface accountsLogicMeta {metricsQuery: (overviewMetrics: AccountsTableMetric[],accountsTableQueryPlan: AccountsTableQueryPlan,- relationshipDefinitionsLoaded: boolean+ relationshipDefinitionsLoaded: boolean,+ awaitingSavedView: boolean) => AccountsTableQuery | null}}@@ -671,6 +677,7 @@ export const accountsLogic = kea<accountsLogicType>([// Restrict the list to a single account by id — drives the `/accounts/:accountId/:tab`// path route. null clears it (back to the full list).setAccountIdFilter: (accountId: string | null) => ({ accountId }),+ setAwaitingSavedView: (awaiting: boolean) => ({ awaiting }),}),reducers({searchInput: [@@ -716,6 +723,12 @@ export const accountsLogic = kea<accountsLogicType>([setAccountIdFilter: (_, { accountId }) => accountId,},],+ awaitingSavedView: [+ false,+ {+ setAwaitingSavedView: (_, { awaiting }) => awaiting,+ },+ ],sortOrder: [null as AccountSortOrder,{@@ -991,11 +1004,13 @@ export const accountsLogic = kea<accountsLogicType>([(input: BuildAccountsTableQueryPlanInput): AccountsTableQueryPlan => buildAccountsTableQueryPlan(input),],accountsQuerySource: [- (s) => [s.accountsTableQueryPlan, s.relationshipDefinitionsLoaded],+ (s) => [s.accountsTableQueryPlan, s.relationshipDefinitionsLoaded, s.awaitingSavedView],(accountsTableQueryPlan: AccountsTableQueryPlan,- relationshipDefinitionsLoaded: boolean- ): AccountsTableQuery | null => (relationshipDefinitionsLoaded ? accountsTableQueryPlan.query : null),+ relationshipDefinitionsLoaded: boolean,+ awaitingSavedView: boolean+ ): AccountsTableQuery | null =>+ relationshipDefinitionsLoaded && !awaitingSavedView ? accountsTableQueryPlan.query : null,],accountsDataTableQuery: [(s) => [s.accountsTableQueryPlan, s.accountsQuerySource],@@ -1011,13 +1026,14 @@ export const accountsLogic = kea<accountsLogicType>([}),],metricsQuery: [- (s) => [s.overviewMetrics, s.accountsTableQueryPlan, s.relationshipDefinitionsLoaded],+ (s) => [s.overviewMetrics, s.accountsTableQueryPlan, s.relationshipDefinitionsLoaded, s.awaitingSavedView],(overviewMetrics: AccountsTableMetric[],accountsTableQueryPlan: AccountsTableQueryPlan,- relationshipDefinitionsLoaded: boolean+ relationshipDefinitionsLoaded: boolean,+ awaitingSavedView: boolean): AccountsTableQuery | null => {- if (overviewMetrics.length === 0 || !relationshipDefinitionsLoaded) {+ if (overviewMetrics.length === 0 || !relationshipDefinitionsLoaded || awaitingSavedView) {return null}return {diff --git a/products/customer_analytics/frontend/components/Accounts/accountsViewsLogic.test.ts b/products/customer_analytics/frontend/components/Accounts/accountsViewsLogic.test.tsindex 05e6339f58e1..1e597fbb586f 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsViewsLogic.test.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsViewsLogic.test.ts@@ -4,6 +4,7 @@ import { expectLogic } from 'kea-test-utils'import { userLogic } from 'scenes/userLogic'+import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'import { useMocks } from '~/mocks/jest'import type { AccountsTableQuery } from '~/queries/schema/schema-general'import { initKeaTests } from '~/test/init'@@ -71,6 +72,42 @@ describe('accountsViewsLogic', () => {})})+ it('holds the first accounts fetch until the persisted view is applied', async () => {+ useMocks({ get: { '/api/environments/:team_id/column_configurations/': { count: 1, results: [buildView()] } } })+ localStorage.setItem(+ `customerAnalytics.accounts.accountsViewsLogic.${MOCK_DEFAULT_TEAM.id}.currentViewId`,+ JSON.stringify('view-1')+ )+ mountAll()++ expect(accountsLogic.values.awaitingSavedView).toBe(true)+ expect(accountsLogic.values.accountsQuerySource).toBeNull()+ expect(accountsLogic.values.metricsQuery).toBeNull()++ await expectLogic(logic).toDispatchActions(['loadViewsSuccess', 'applyView']).toFinishAllListeners()++ expect(accountsLogic.values.awaitingSavedView).toBe(false)+ expect(accountsColumnConfigLogic.values.selectColumns).toEqual(['name', 'csm'])+ expect(accountsLogic.values.searchQuery).toEqual('acme')+ })++ it('opens the gate when loading views fails, so the list still fetches', async () => {+ useMocks({ get: { '/api/environments/:team_id/column_configurations/': () => [500, {}] } })+ localStorage.setItem(+ `customerAnalytics.accounts.accountsViewsLogic.${MOCK_DEFAULT_TEAM.id}.currentViewId`,+ JSON.stringify('view-1')+ )+ silenceKeaLoadersErrors()+ try {+ mountAll()+ expect(accountsLogic.values.awaitingSavedView).toBe(true)+ await expectLogic(logic).toDispatchActions(['loadViewsFailure'])+ expect(accountsLogic.values.awaitingSavedView).toBe(false)+ } finally {+ resumeKeaLoadersErrors()+ }+ })+it('applyView hydrates columns, filters, sort, and tiles', async () => {useMocks({ get: { '/api/environments/:team_id/column_configurations/': { count: 0, results: [] } } })mountAll()diff --git a/products/customer_analytics/frontend/components/Accounts/accountsViewsLogic.ts b/products/customer_analytics/frontend/components/Accounts/accountsViewsLogic.tsindex d55650070bbe..1e41998a74d7 100644--- a/products/customer_analytics/frontend/components/Accounts/accountsViewsLogic.ts+++ b/products/customer_analytics/frontend/components/Accounts/accountsViewsLogic.ts@@ -128,6 +128,9 @@ export interface accountsViewsLogicActions {setAssignedToFilter: (value: RoleFilterValue) => {value: RoleFilterValue} // accountsLogic+ setAwaitingSavedView: (awaiting: boolean) => {+ awaiting: boolean+ } // accountsLogicsetSearchQuery: (query: string) => {query: string} // accountsLogic@@ -410,6 +413,7 @@ export const accountsViewsLogic = kea<accountsViewsLogicType>(['setAssignedToFilter','setSortOrder','setAccountFilters',+ 'setAwaitingSavedView',],accountsOverviewTilesLogic,['setTiles', 'setTileFilter'],@@ -648,6 +652,7 @@ export const accountsViewsLogic = kea<accountsViewsLogicType>([loadViewsFailure: ({ error }) => {posthog.captureException(error)lemonToast.error('Failed to load views')+ actions.setAwaitingSavedView(false)},submitNewViewFormFailure: ({ error }) => {posthog.captureException(error)@@ -683,9 +688,13 @@ export const accountsViewsLogic = kea<accountsViewsLogicType>([actions.applyView(view)}}+ actions.setAwaitingSavedView(false)},})),- afterMount(({ actions }) => {+ afterMount(({ actions, values }) => {+ if (values.currentViewId && !router.values.hashParams?.view) {+ actions.setAwaitingSavedView(true)+ }actions.loadViews()}),])