From 1d644eb0926680a5130f929acf7fceb42c1ba8b9 Mon Sep 17 00:00:00 2001 From: Paul Marbach Date: Wed, 14 Jan 2026 14:21:43 -0500 Subject: [PATCH] clean up some of the cruft from review --- .../AddToDashboardFormExposedComponent.tsx | 2 +- .../panel-edit/PanelEditor.tsx | 58 +++++++++---------- .../scene/DashboardSceneUrlSync.ts | 7 ++- .../transformSaveModelToScene.ts | 2 +- .../features/dashboard-scene/utils/utils.ts | 11 ++-- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/public/app/features/dashboard-scene/addToDashboard/AddToDashboardFormExposedComponent.tsx b/public/app/features/dashboard-scene/addToDashboard/AddToDashboardFormExposedComponent.tsx index 3111700e1ee..7f899ee8bc4 100644 --- a/public/app/features/dashboard-scene/addToDashboard/AddToDashboardFormExposedComponent.tsx +++ b/public/app/features/dashboard-scene/addToDashboard/AddToDashboardFormExposedComponent.tsx @@ -27,7 +27,7 @@ export const AddToDashboardFormExposedComponent = (props: Partial ({ - type: 'timeseries', + type: 'timeseries', // TODO: should this be `getDefaultPluginId()`? title: t('dashboard-scene.add-to-dashboard-form-exposed.title.new-panel', 'New panel'), targets: [], })) diff --git a/public/app/features/dashboard-scene/panel-edit/PanelEditor.tsx b/public/app/features/dashboard-scene/panel-edit/PanelEditor.tsx index 6803652849b..e5a1e1db952 100644 --- a/public/app/features/dashboard-scene/panel-edit/PanelEditor.tsx +++ b/public/app/features/dashboard-scene/panel-edit/PanelEditor.tsx @@ -34,6 +34,7 @@ import { vizPanelToPanel } from '../serialization/transformSceneToSaveModel'; import { activateSceneObjectAndParentTree, getDashboardSceneFor, + getDefaultVizPanel, getLibraryPanelBehavior, getPanelIdForVizPanel, } from '../utils/utils'; @@ -91,12 +92,9 @@ export class PanelEditor extends SceneObjectBase { // Need to clear selection here since selection is activated when panel edit mode is entered through the panel actions menu. This causes sidebar panel editor to be open when exiting panel edit mode dashboard.state.editPane.clearSelection(); - if (panel.state.pluginId === UNCONFIGURED_PANEL_PLUGIN_ID) { - if (config.featureToggles.newVizSuggestions) { - this._autoSelectVisualization(panel); - } else { - panel.changePluginType('timeseries'); - } + // this will be deleted when suggestions is fully rolled out. + if (panel.state.pluginId === UNCONFIGURED_PANEL_PLUGIN_ID && !config.featureToggles.newVizSuggestions) { + panel.changePluginType('timeseries'); } this._subs.add( @@ -242,7 +240,6 @@ export class PanelEditor extends SceneObjectBase { // First time initialization if (this.state.isInitializing) { this.setOriginalState(this.state.panelRef); - this._setupChangeDetection(); this._updateDataPane(plugin); @@ -255,21 +252,13 @@ export class PanelEditor extends SceneObjectBase { }) ); - const isUnconfigured = Boolean( - config.featureToggles.newVizSuggestions && panel.state.pluginId === UNCONFIGURED_PANEL_PLUGIN_ID - ); - - if (isUnconfigured) { - this._setupEditPreview(); - } - // Setup options pane const optionsPane = new PanelOptionsPane({ panelRef: this.state.panelRef, editPreviewRef: this.state.editPreview?.getRef(), searchQuery: '', listMode: OptionFilter.All, - isVizPickerOpen: isUnconfigured, + isVizPickerOpen: this.state.isNewPanel, isNewPanel: this.state.isNewPanel, }); @@ -278,11 +267,20 @@ export class PanelEditor extends SceneObjectBase { isInitializing: false, }); + this._subs.add( + this.subscribeToState((newState, oldState) => { + if (newState.editPreview !== oldState.editPreview) { + optionsPane.setState({ editPreviewRef: newState.editPreview?.getRef() }); + } + }) + ); this._subs.add( optionsPane.subscribeToState((newState, oldState) => { if (newState.isVizPickerOpen !== oldState.isVizPickerOpen) { if (newState.isVizPickerOpen) { - this._setupEditPreview(); + const panel = this.state.panelRef.resolve(); + const editPreview = PanelEditor.buildEditPreview(panel); + this.setState({ editPreview }); } else { this.setState({ editPreview: undefined }); } @@ -296,21 +294,6 @@ export class PanelEditor extends SceneObjectBase { } } - private _setupEditPreview() { - const panel = this.state.panelRef.resolve(); - - // we just "pick" timeseries, viz type will likely be overridden by Suggestions. - const editPreviewBuilder = PanelBuilders.timeseries() - .setTitle(panel.state.title) - .setDescription(panel.state.description); - if (panel.state.$data) { - editPreviewBuilder.setData(new DataProviderSharer({ source: panel.state.$data.getRef() })); - } - const editPreview = editPreviewBuilder.build(); - this.setState({ editPreview }); - this.state.optionsPane?.setState({ editPreviewRef: editPreview.getRef() }); - } - private _updateDataPane(plugin: PanelPlugin) { const skipDataQuery = plugin.meta.skipDataQuery; @@ -452,6 +435,16 @@ export class PanelEditor extends SceneObjectBase { .build(), }); }; + + public static buildEditPreview(panel: VizPanel): VizPanel { + const editPreview = getDefaultVizPanel(); + editPreview.setState({ + title: panel.state.title, + description: panel.state.description, + $data: panel.state.$data ? new DataProviderSharer({ source: panel.state.$data.getRef() }) : undefined, + }); + return editPreview; + } } export function buildPanelEditScene(panel: VizPanel, isNewPanel = false): PanelEditor { @@ -459,5 +452,6 @@ export function buildPanelEditScene(panel: VizPanel, isNewPanel = false): PanelE isInitializing: true, panelRef: panel.getRef(), isNewPanel, + editPreview: isNewPanel ? PanelEditor.buildEditPreview(panel) : undefined, }); } diff --git a/public/app/features/dashboard-scene/scene/DashboardSceneUrlSync.ts b/public/app/features/dashboard-scene/scene/DashboardSceneUrlSync.ts index 45b35c3d57f..3fe96d8bb9d 100644 --- a/public/app/features/dashboard-scene/scene/DashboardSceneUrlSync.ts +++ b/public/app/features/dashboard-scene/scene/DashboardSceneUrlSync.ts @@ -8,6 +8,7 @@ import { findEditPanel, getLibraryPanelBehavior } from '../utils/utils'; import { DashboardScene, DashboardSceneState } from './DashboardScene'; import { LibraryPanelBehavior } from './LibraryPanelBehavior'; +import { UNCONFIGURED_PANEL_PLUGIN_ID } from './UnconfiguredPanel'; import { DefaultGridLayoutManager } from './layout-default/DefaultGridLayoutManager'; export class DashboardSceneUrlSync implements SceneObjectUrlSyncHandler { @@ -91,7 +92,7 @@ export class DashboardSceneUrlSync implements SceneObjectUrlSyncHandler { return; } - update.editPanel = buildPanelEditScene(panel); + update.editPanel = buildPanelEditScene(panel, panel.state.pluginId === UNCONFIGURED_PANEL_PLUGIN_ID); } else if (editPanel && values.editPanel === null) { update.editPanel = undefined; } @@ -126,7 +127,9 @@ export class DashboardSceneUrlSync implements SceneObjectUrlSyncHandler { private _waitForLibPanelToLoadBeforeEnteringPanelEdit(panel: VizPanel, libPanel: LibraryPanelBehavior) { const sub = libPanel.subscribeToState((state) => { if (state.isLoaded) { - this._scene.setState({ editPanel: buildPanelEditScene(panel) }); + this._scene.setState({ + editPanel: buildPanelEditScene(panel, panel.state.pluginId === UNCONFIGURED_PANEL_PLUGIN_ID), + }); sub.unsubscribe(); } }); diff --git a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts index 8f80dcc526e..2373e87a11e 100644 --- a/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts +++ b/public/app/features/dashboard-scene/serialization/transformSaveModelToScene.ts @@ -482,7 +482,7 @@ export function buildGridItemForPanel(panel: PanelModel): DashboardGridItem { key: getVizPanelKeyForPanelId(panel.id), title: panel.title?.substring(0, 5000), description: panel.description, - pluginId: panel.type ?? 'timeseries', + pluginId: panel.type ?? 'timeseries', // TODO: should this be `getDefaultPluginId()`? options: panel.options ?? {}, fieldConfig: panel.fieldConfig, pluginVersion: panel.pluginVersion, diff --git a/public/app/features/dashboard-scene/utils/utils.ts b/public/app/features/dashboard-scene/utils/utils.ts index ac656e830c0..11f490530d1 100644 --- a/public/app/features/dashboard-scene/utils/utils.ts +++ b/public/app/features/dashboard-scene/utils/utils.ts @@ -279,11 +279,14 @@ export function getClosestVizPanel(sceneObject: SceneObject): VizPanel | null { return null; } +export function getDefaultPluginId(): string { + return config.featureToggles.dashboardNewLayouts || config.featureToggles.newVizSuggestions + ? UNCONFIGURED_PANEL_PLUGIN_ID + : 'timeseries'; +} + export function getDefaultVizPanel(): VizPanel { - const defaultPluginId = - config.featureToggles.dashboardNewLayouts || config.featureToggles.newVizSuggestions - ? UNCONFIGURED_PANEL_PLUGIN_ID - : 'timeseries'; + const defaultPluginId = getDefaultPluginId(); const newPanelTitle = config.featureToggles.newVizSuggestions && defaultPluginId === UNCONFIGURED_PANEL_PLUGIN_ID