: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(logs): close logs viewer modal when navigating away (#62147)
Paul D'Ambra253f4c01b836
diff --git a/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.test.ts b/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.test.tsindex 41f52dfd76f9..c74056066f0c 100644--- a/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.test.ts+++ b/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.test.ts@@ -1,3 +1,4 @@+import { router } from 'kea-router'import { expectLogic } from 'kea-test-utils'import { initKeaTests } from '~/test/init'@@ -114,6 +115,34 @@ describe('logsViewerModalLogic', () => {})})+ describe('closes on navigation', () => {+ it.each([+ { description: 'when open', openFirst: true },+ { description: 'when already closed', openFirst: false },+ ])('modal is closed after scene navigation ($description)', async ({ openFirst }) => {+ if (openFirst) {+ logic.actions.openLogsViewerModal()+ await expectLogic(logic).toFinishAllListeners()+ }++ await expectLogic(logic, () => {+ router.actions.push('/project/1/dashboard')+ }).toMatchValues({ isOpen: false })+ })++ it('does not react to query/hash-only changes on the same pathname', async () => {+ router.actions.push('/project/1/logs')+ await expectLogic(logic).toFinishAllListeners()++ logic.actions.openLogsViewerModal()+ await expectLogic(logic).toFinishAllListeners()++ await expectLogic(logic, () => {+ router.actions.push('/project/1/logs', { search: 'foo' })+ }).toMatchValues({ isOpen: true })+ })+ })+describe('open/close cycle', () => {it('restores all state on reopen with different options', async () => {logic.actions.openLogsViewerModal({ id: 'first', fullScreen: false })diff --git a/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.ts b/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.tsindex 43df9d444f8a..4fca6c7ddc38 100644--- a/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.ts+++ b/products/logs/frontend/components/LogsViewer/LogsViewerModal/logsViewerModalLogic.ts@@ -1,4 +1,5 @@-import { actions, kea, path, reducers } from 'kea'+import { actions, afterMount, connect, kea, listeners, path, reducers } from 'kea'+import { router } from 'kea-router'import { LogsViewerFilters } from 'products/logs/frontend/components/LogsViewer/config/types'@@ -12,6 +13,9 @@ export interface OpenLogsViewerModalOptions {export const logsViewerModalLogic = kea<logsViewerModalLogicType>([path(['products', 'logs', 'frontend', 'components', 'LogsViewer', 'LogsViewerModal', 'logsViewerModalLogic']),+ connect(() => ({+ actions: [router, ['locationChanged']],+ })),actions({openLogsViewerModal: (options?: OpenLogsViewerModalOptions) => ({id: options?.id ?? 'modal',@@ -48,4 +52,21 @@ export const logsViewerModalLogic = kea<logsViewerModalLogicType>([},],}),+ listeners(({ values, actions, cache }) => ({+ locationChanged: ({ pathname }) => {+ // close the (often full-screen) modal when navigating to a new scene, e.g. via cmd+k.+ // query/hash-only changes fire locationChanged too (the viewer syncs filters to the+ // URL), so only react to an actual pathname change.+ if (pathname === cache.lastPathname) {+ return+ }+ cache.lastPathname = pathname+ if (values.isOpen) {+ actions.closeLogsViewerModal()+ }+ },+ })),+ afterMount(({ cache }) => {+ cache.lastPathname = router.values.location.pathname+ }),])