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.

fix(customer-analytics): make the b2b dashboard story render b2b every time (#114809)

Paul D'Ambra6eadef18fbda
diff --git a/products/customer_analytics/frontend/CustomerAnalyticsScene.stories.tsx b/products/customer_analytics/frontend/CustomerAnalyticsScene.stories.tsx
index 1ba9533af971..c5880d12d149 100644
--- a/products/customer_analytics/frontend/CustomerAnalyticsScene.stories.tsx
+++ b/products/customer_analytics/frontend/CustomerAnalyticsScene.stories.tsx
@@ -6,7 +6,7 @@ import userEvent from '@testing-library/user-event'
import posthog from 'posthog-js'
import { FEATURE_FLAGS } from 'lib/constants'
-import { useDelayedOnMountEffect } from 'lib/hooks/useOnMountEffect'
+import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'
import { App } from 'scenes/App'
import { urls } from 'scenes/urls'
@@ -18,10 +18,17 @@ import type { CustomerTaskApi } from 'products/customer_analytics/frontend/gener
import { BusinessType, customerAnalyticsSceneLogic } from './customerAnalyticsSceneLogic'
-function setBusinessTypeOnMountedLogic(businessType: BusinessType): void {
- for (const logic of customerAnalyticsSceneLogic.findAllMounted()) {
- logic.actions.setBusinessType(businessType)
- }
+// Mount the scene logic in an effect, so that App has already mounted sceneLogic with its scenes.
+// The effect runs before the lazy scene loads, so the first scene render uses this business type.
+function useBusinessType(businessType: BusinessType, groupType?: number): void {
+ useOnMountEffect(() => {
+ const unmount = customerAnalyticsSceneLogic.mount()
+ customerAnalyticsSceneLogic.actions.setBusinessType(businessType)
+ if (groupType !== undefined) {
+ customerAnalyticsSceneLogic.actions.setSelectedGroupType(groupType)
+ }
+ return unmount
+ })
}
const meta: Meta = {
@@ -40,6 +47,7 @@ const meta: Meta = {
mswDecorator({
get: {
'api/environments/:team_id/customer_profile_configs/': { count: 0, results: [] },
+ 'api/environments/:team_id/customer_journeys/': { count: 0, results: [] },
},
}),
],
@@ -50,9 +58,7 @@ type Story = StoryObj<{}>
export const B2CMode: Story = {
render: () => {
- useDelayedOnMountEffect(() => {
- setBusinessTypeOnMountedLogic('b2c')
- })
+ useBusinessType('b2c')
return <App />
},
@@ -75,17 +81,15 @@ export const B2BModeWithGroupsEnabled: Story = {
},
})
- useDelayedOnMountEffect(() => {
- setBusinessTypeOnMountedLogic('b2b')
- for (const logic of customerAnalyticsSceneLogic.findAllMounted()) {
- logic.actions.setSelectedGroupType(0)
- }
- })
+ useBusinessType('b2b', 0)
return <App />
},
parameters: {
pageUrl: urls.customerAnalyticsDashboard(),
+ testOptions: {
+ waitForSelector: '[data-attr="customer-analytics-group-type"]',
+ },
},
}
@@ -93,9 +97,7 @@ export const B2BModeWithoutGroups: Story = {
render: () => {
useAvailableFeatures([])
- useDelayedOnMountEffect(() => {
- setBusinessTypeOnMountedLogic('b2b')
- })
+ useBusinessType('b2b')
return <App />
},