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(today): keep today report url on page refresh (#113075)

Shy Altere80420117021
diff --git a/frontend/src/scenes/project-homepage/projectHomepageLogic.test.ts b/frontend/src/scenes/project-homepage/projectHomepageLogic.test.ts
index 77ab07149bf0..7bc3a3206f9f 100644
--- a/frontend/src/scenes/project-homepage/projectHomepageLogic.test.ts
+++ b/frontend/src/scenes/project-homepage/projectHomepageLogic.test.ts
@@ -1,5 +1,10 @@
+import { router } from 'kea-router'
import { expectLogic } from 'kea-test-utils'
+import { FEATURE_FLAGS } from 'lib/constants'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { urls } from 'scenes/urls'
+
import { useMocks } from '~/mocks/jest'
import { initKeaTests } from '~/test/init'
import { DashboardType } from '~/types'
@@ -28,4 +33,16 @@ describe('projectHomepageLogic', () => {
it('does not load recent insights onMount', async () => {
await expectLogic(logic).toNotHaveDispatchedActions(['loadRecentInsights', 'loadRecentInsightsSuccess'])
})
+
+ it.each([
+ [true, '/home/reports/report-1'],
+ [false, '/inbox/reports/report-1'],
+ ])('waits for the flags before it leaves a Today report (today on: %s)', async (todayOn, expectedPath) => {
+ router.actions.push(urls.todayReport('report-1'))
+ expect(router.values.location.pathname).toContain('/home/reports/report-1')
+
+ featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.TODAY_RAIL_NAV]: todayOn })
+
+ expect(router.values.location.pathname).toContain(expectedPath)
+ })
})
diff --git a/frontend/src/scenes/project-homepage/projectHomepageLogic.tsx b/frontend/src/scenes/project-homepage/projectHomepageLogic.tsx
index b7606c4ed3cb..5dbebae324da 100644
--- a/frontend/src/scenes/project-homepage/projectHomepageLogic.tsx
+++ b/frontend/src/scenes/project-homepage/projectHomepageLogic.tsx
@@ -1,4 +1,4 @@
-import { MakeLogicType, actions, connect, kea, path, reducers, selectors } from 'kea'
+import { MakeLogicType, actions, connect, kea, listeners, path, reducers, selectors } from 'kea'
import { loaders } from 'kea-loaders'
import { router, urlToAction } from 'kea-router'
@@ -13,10 +13,12 @@ import { getQueryBasedInsightModel } from '~/queries/nodes/InsightViz/utils'
import { Breadcrumb, InsightModel } from '~/types'
import type { Node } from '../../queries/schema/schema-general'
+import { reportIdFromPath } from './today/todayLogic'
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface projectHomepageLogicValues {
featureFlags: FeatureFlagsSet // featureFlagLogic
+ receivedFeatureFlags: boolean // featureFlagLogic
currentProjectId: number | null // projectLogic
breadcrumbs: Breadcrumb[]
expandedInsightIds: Set<string>
@@ -28,6 +30,13 @@ export interface projectHomepageLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface projectHomepageLogicActions {
+ setFeatureFlags: (
+ flags: string[],
+ variants: Record<string, boolean | string>
+ ) => {
+ flags: string[]
+ variants: Record<string, boolean | string>
+ } // featureFlagLogic
loadRecentInsights: () => any
loadRecentInsightsFailure: (
error: string,
@@ -65,7 +74,8 @@ export type projectHomepageLogicType = MakeLogicType<
export const projectHomepageLogic = kea<projectHomepageLogicType>([
path(['scenes', 'project-homepage', 'projectHomepageLogic']),
connect(() => ({
- values: [projectLogic, ['currentProjectId'], featureFlagLogic, ['featureFlags']],
+ values: [projectLogic, ['currentProjectId'], featureFlagLogic, ['featureFlags', 'receivedFeatureFlags']],
+ actions: [featureFlagLogic, ['setFeatureFlags']],
})),
actions({
@@ -123,10 +133,19 @@ export const projectHomepageLogic = kea<projectHomepageLogicType>([
],
}),
+ listeners(({ values }) => ({
+ setFeatureFlags: () => {
+ const reportId = reportIdFromPath(router.values.location.pathname)
+ if (reportId && !values.todayHomeEnabled) {
+ router.actions.replace(urls.inboxReport('reports', reportId))
+ }
+ },
+ })),
+
urlToAction(({ values }) => ({
// A Today report link opened where Today is off lands on the same report in the Inbox.
[urls.todayReport(':reportId')]: ({ reportId }) => {
- if (reportId && !values.todayHomeEnabled) {
+ if (reportId && values.receivedFeatureFlags && !values.todayHomeEnabled) {
router.actions.replace(urls.inboxReport('reports', reportId))
}
},