clean up some of the cruft from review
This commit is contained in:
+1
-1
@@ -27,7 +27,7 @@ export const AddToDashboardFormExposedComponent = (props: Partial<Props<Absolute
|
||||
buildPanel={
|
||||
props.buildPanel ??
|
||||
(() => ({
|
||||
type: 'timeseries',
|
||||
type: 'timeseries', // TODO: should this be `getDefaultPluginId()`?
|
||||
title: t('dashboard-scene.add-to-dashboard-form-exposed.title.new-panel', 'New panel'),
|
||||
targets: [],
|
||||
}))
|
||||
|
||||
@@ -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<PanelEditorState> {
|
||||
// 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<PanelEditorState> {
|
||||
// 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<PanelEditorState> {
|
||||
})
|
||||
);
|
||||
|
||||
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<PanelEditorState> {
|
||||
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<PanelEditorState> {
|
||||
}
|
||||
}
|
||||
|
||||
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<PanelEditorState> {
|
||||
.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,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user