: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
feat(dashboards): inline experiment picker + clearer widget save UX (#65873)
Matt Pua48d189cafd5f
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 7aaefba104c3..06d6f2bbf01a 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -1821,9 +1821,9 @@ snapshots:dashboards-dashboard-widgets-widget-types-experiments-experiment-results--loading--light:hash: v1.k794b7964.028e0bafb6bdfb17412b93032ba75a65c90349f3695d594e45a7411c9e13551a.9SVtMI2pcn9JIb4coDMBYJ1_EbI59o1-7iiNxPZxAOodashboards-dashboard-widgets-widget-types-experiments-experiment-results--not-configured--dark:- hash: v1.k794b7964.d29f72447339bae8b61f77359c15e17e9f3bc5f73f36049fe84f26825608ac12.y9URGys_J0AqlasEqTCOiO3ivhES6ojfdYmJ-ytoWKs+ hash: v1.k794b7964.445f545cb2242863f8a19826a8105ed8476a079722204b0f438a1619a3030228.aXLcKbbfUidFuY7NPImq_hyRW9toyIUPmVIXzuar0Ccdashboards-dashboard-widgets-widget-types-experiments-experiment-results--not-configured--light:- hash: v1.k794b7964.23d27257841a7d79a91e42ea03a1fa70a3654c70c32982dbe4bfef3ce2892a75.4DTjVKlJIQO6fsarI2l0BzXnIgK5LvDfji0nkOe591Q+ hash: v1.k794b7964.c63db9601744949c2225fbeb9bbadd1c667058966cbc49da820058c24ba0a0da.f3vGyCT9HiHYwMv7HnuHL-aqIw2jZN5yCHJWH0k_Cpwdashboards-dashboard-widgets-widget-types-experiments-experiment-results--tile-filters-read-only--dark:hash: v1.k794b7964.5138796491d335a71e834a58ced475838270336f92cb04b75749d87338940296.ZNrsJ1MU8FK4X88UNfuky096h8jSp2-LQ7phuYO8STIdashboards-dashboard-widgets-widget-types-experiments-experiment-results--tile-filters-read-only--light:diff --git a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsxindex 2ca397a2fa7e..9e6e8c68af2b 100644--- a/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx+++ b/frontend/src/scenes/dashboard/DashboardHeaderActions.tsx@@ -82,6 +82,7 @@ export function DashboardAddTileButton(): JSX.Element | null {: {label: 'Widget',tag: 'beta' as const,+ tooltip: 'Opens settings to enable the Dashboard widgets beta',onClick: () => push(urls.featurePreview(FEATURE_FLAGS.DASHBOARD_WIDGETS)),'data-attr': 'dashboard-add-widget-preview',},diff --git a/frontend/src/scenes/dashboard/dashboardLogic.test.ts b/frontend/src/scenes/dashboard/dashboardLogic.test.tsindex 27d012fd1149..09d39506fd7a 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.test.ts+++ b/frontend/src/scenes/dashboard/dashboardLogic.test.ts@@ -432,6 +432,43 @@ describe('dashboardLogic', () => {)})+ it('confirms a real save with a success toast', async () => {+ await expectLogic(logic).toFinishAllListeners()++ const firstTile = logic.values.dashboard!.tiles[0]+ const currentLayouts = logic.values.layouts+ const modifiedLayouts: any = {+ ...currentLayouts,+ sm: currentLayouts.sm?.map((layout) =>+ layout.i === String(firstTile.id) ? { ...layout, x: (layout.x ?? 0) + 1 } : layout+ ),+ }++ await expectLogic(logic, () => {+ logic.actions.updateLayouts(modifiedLayouts)+ }).toFinishAllListeners()++ const successToast = jest.spyOn(lemonToast, 'success')++ await expectLogic(logic, () => {+ logic.actions.saveEditModeChanges()+ }).toFinishAllListeners()++ expect(successToast).toHaveBeenCalledWith('Dashboard saved')+ })++ it('does not show a success toast when exiting edit mode with no changes', async () => {+ await expectLogic(logic).toFinishAllListeners()++ const successToast = jest.spyOn(lemonToast, 'success')++ await expectLogic(logic, () => {+ logic.actions.saveEditModeChanges()+ }).toFinishAllListeners()++ expect(successToast).not.toHaveBeenCalled()+ })+it('discarding edit mode restores original layouts', async () => {await expectLogic(logic).toFinishAllListeners()diff --git a/frontend/src/scenes/dashboard/dashboardLogic.tsx b/frontend/src/scenes/dashboard/dashboardLogic.tsxindex 5f76ebce44f8..bd73569bd0f1 100644--- a/frontend/src/scenes/dashboard/dashboardLogic.tsx+++ b/frontend/src/scenes/dashboard/dashboardLogic.tsx@@ -491,6 +491,7 @@ export const dashboardLogic = kea<dashboardLogicType>([return null},saveEditModeChanges: async (_, breakpoint) => {+ cache.dashboardChangesPersisted = falsetry {// Only persist sm layouts; xs layouts are derived on the flyconst layoutsToUpdate = (values.dashboard?.tiles || []).map((tile) => ({@@ -558,6 +559,7 @@ export const dashboardLogic = kea<dashboardLogicType>([if (shouldRefreshTilesAfterSave) {cache.shouldRefreshTilesAfterSave = true}+ cache.dashboardChangesPersisted = truereturn getQueryBasedDashboard(updatedDashboard)} catch (e) {lemonToast.error('Could not update dashboard: ' + String(e))@@ -2664,6 +2666,11 @@ export const dashboardLogic = kea<dashboardLogicType>([// dashboardsModel so the sidebar and other global views stay up to datedashboardsModel.actions.updateDashboardSuccess(dashboard)}+ // Only toast when changes were actually persisted — the no-op exit path skips the PATCH.+ if (cache.dashboardChangesPersisted) {+ cache.dashboardChangesPersisted = false+ lemonToast.success('Dashboard saved')+ }if (cache.shouldRefreshTilesAfterSave) {cache.shouldRefreshTilesAfterSave = falseactions.refreshDashboardItems({diff --git a/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.test.tsx b/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.test.tsxnew file mode 100644index 000000000000..a5a5cbb12c99--- /dev/null+++ b/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.test.tsx@@ -0,0 +1,58 @@+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'++import '@testing-library/jest-dom'++import { cleanup, render, screen } from '@testing-library/react'++import { teamLogic } from 'scenes/teamLogic'++import { useMocks } from '~/mocks/jest'+import { initKeaTests } from '~/test/init'++import { ExperimentResultsWidget } from './ExperimentResultsWidget'++describe('ExperimentResultsWidget', () => {+ afterEach(() => {+ cleanup()+ })++ beforeEach(() => {+ useMocks({+ get: {+ '/api/projects/:team_id/experiments/': () => [200, { results: [], count: 0 }],+ },+ })+ initKeaTests(true, { ...MOCK_DEFAULT_TEAM })+ teamLogic.mount()+ })++ const noExperimentSelected = { needsConfiguration: true, hasExperiments: true, metrics: [] }++ it('lets an editor pick an experiment inline when none is selected', () => {+ const { container } = render(+ <ExperimentResultsWidget+ tileId={1}+ config={{}}+ loading={false}+ result={noExperimentSelected}+ onUpdateConfig={jest.fn()}+ />+ )++ expect(screen.getByText('No experiment selected')).toBeInTheDocument()+ expect(+ container.querySelector('[data-attr="experiment-results-widget-empty-state-select"]')+ ).toBeInTheDocument()+ })++ it('does not expose the inline picker on a read-only (shared) tile', () => {+ const { container } = render(+ <ExperimentResultsWidget tileId={1} config={{}} loading={false} result={noExperimentSelected} />+ )++ expect(screen.getByText('No experiment has been selected for this tile yet.')).toBeInTheDocument()+ expect(+ container.querySelector('[data-attr="experiment-results-widget-empty-state-select"]')+ ).not.toBeInTheDocument()+ })+})diff --git a/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.tsx b/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.tsxindex e733e2671b89..430fc6d2c4c3 100644--- a/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.tsx+++ b/products/dashboards/frontend/widgets/experiments/ExperimentResultsWidget.tsx@@ -15,6 +15,8 @@ import type { ExperimentStatus } from '~/types'import { WidgetCardBodyMessage, WidgetCardContent } from '../../components/WidgetCard'import type { DashboardWidgetComponentProps } from '../registry'+import { ExperimentPickerSelect } from './ExperimentPickerSelect'+import { patchExperimentResultsWidgetConfig } from './experimentsWidgetConfigValidation'import { NotebookCompactTable } from './LazyNotebookCompactTable'export type ExperimentResultsWidgetMetricEntry = {@@ -163,6 +165,7 @@ function ExperimentResultsLoadingSkeleton(): JSX.Element {export function ExperimentResultsWidget({tileId,+ config,result,loading,onUpdateConfig,@@ -199,14 +202,29 @@ export function ExperimentResultsWidget({/>)}+ // Editable tile, no experiment chosen yet — let the user pick one inline (shares the tile picker's key).+ const inlinePicker = onUpdateConfig ? (+ <div className="w-64 max-w-full">+ <ExperimentPickerSelect+ pickerKey={`results-tile-${tileId}`}+ value={null}+ fullWidth+ onChange={(value) => {+ void onUpdateConfig(patchExperimentResultsWidgetConfig(config, value))+ }}+ dataAttr="experiment-results-widget-empty-state-select"+ />+ </div>+ ) : undefinedreturn (<ExperimentResultsWidgetMessagetitle="No experiment selected"message={onUpdateConfig- ? 'Pick an experiment from the selector above to see its results here.'+ ? 'Pick an experiment to see its results here.': 'No experiment has been selected for this tile yet.'}+ cta={inlinePicker}/>)}