: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(dashboards): warn before navigating away from unsaved layout edits (#68943)
Xandere2111d443dd5
diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex df8a7acf583d..3ae623cdfb55 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -14,7 +14,8 @@ import {sharedListeners,} from 'kea'import { loaders } from 'kea-loaders'-import { actionToUrl, router, urlToAction } from 'kea-router'+import { actionToUrl, beforeUnload, router, urlToAction } from 'kea-router'+import { CombinedLocation } from 'kea-router/lib/utils'import uniqBy from 'lodash.uniqby'import { ResponsiveLayouts } from 'react-grid-layout'@@ -3262,6 +3263,23 @@ export const dashboardLogic = kea<dashboardLogicType>([},})),+ beforeUnload(({ values, actions }) => ({+ enabled: (newLocation?: CombinedLocation) => {+ if (values.dashboardMode !== DashboardMode.Edit || !values.hasUnsavedLayoutChanges) {+ return false+ }+ // Ignore in-page navigations such as opening a side panel+ if (newLocation && newLocation.pathname === router.values.location.pathname) {+ return false+ }+ return true+ },+ message: 'Leave dashboard?\nChanges you made to the layout will be discarded.',+ onConfirm: () => {+ actions.setDashboardMode(null, DashboardEventSource.DashboardHeaderDiscardChanges)+ },+ })),+actionToUrl(({ values }) => ({applyFilters: () => {const { currentLocation } = router.values