diff --git a/frontend/src/scenes/insights/InsightNav/insightNavLogic.tsx b/frontend/src/scenes/insights/InsightNav/insightNavLogic.tsx index d2f28906bfe95..9dff8c87eeb8c 100644 --- a/frontend/src/scenes/insights/InsightNav/insightNavLogic.tsx +++ b/frontend/src/scenes/insights/InsightNav/insightNavLogic.tsx @@ -1,4 +1,5 @@ import { actions, afterMount, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea' +import { urlToAction } from 'kea-router' import { FEATURE_FLAGS } from 'lib/constants' import { LemonTag } from 'lib/lemon-ui/LemonTag/LemonTag' import { featureFlagLogic } from 'lib/logic/featureFlagLogic' @@ -41,7 +42,7 @@ import { isStickinessQuery, isTrendsQuery, } from '~/queries/utils' -import { BaseMathType, InsightLogicProps, InsightType } from '~/types' +import { BaseMathType, FilterType, InsightLogicProps, InsightType } from '~/types' import { MathAvailability } from '../filters/ActionFilter/ActionFilterRow/ActionFilterRow' import type { insightNavLogicType } from './insightNavLogicType' @@ -278,6 +279,23 @@ export const insightNavLogic = kea([ } }, })), + urlToAction(({ actions }) => ({ + '/insights/:shortId(/:mode)(/:subscriptionId)': ( + _, // url params + { dashboard, ...searchParams }, // search params + { filters: _filters } // hash params + ) => { + // capture any filters from the URL, either #filters={} or ?insight=X&bla=foo&bar=baz + const filters: Partial | null = + Object.keys(_filters || {}).length > 0 ? _filters : searchParams.insight ? searchParams : null + + if (!filters?.insight) { + return + } + + actions.setActiveView(filters?.insight) + }, + })), afterMount(({ values, actions }) => { if (values.query && isInsightVizNode(values.query)) { actions.updateQueryPropertyCache(cachePropertiesFromQuery(values.query.source, values.queryPropertyCache))