mirror of
https://github.com/grafana/grafana.git
synced 2026-07-30 00:08:10 -05:00
DasbhoardScene: Fixes panel menu new alert rule action (#82366)
* DasbhoardScene: Fixes panel menu new alert rule action * Update
This commit is contained in:
+2
-3
@@ -2588,10 +2588,9 @@ exports[`better eslint`] = {
|
|||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||||
],
|
],
|
||||||
"public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [
|
"public/app/features/dashboard-scene/scene/PanelMenuBehavior.tsx:5381": [
|
||||||
[0, 0, 0, "Do not use any type assertions.", "0"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
|
[0, 0, 0, "Do not use any type assertions.", "2"]
|
||||||
[0, 0, 0, "Do not use any type assertions.", "3"]
|
|
||||||
],
|
],
|
||||||
"public/app/features/dashboard-scene/scene/setDashboardPanelContext.test.ts:5381": [
|
"public/app/features/dashboard-scene/scene/setDashboardPanelContext.test.ts:5381": [
|
||||||
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
[0, 0, 0, "Unexpected any. Specify a different type.", "0"]
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { config, getPluginLinkExtensions, locationService } from '@grafana/runti
|
|||||||
import {
|
import {
|
||||||
LocalValueVariable,
|
LocalValueVariable,
|
||||||
SceneFlexLayout,
|
SceneFlexLayout,
|
||||||
SceneGridItem,
|
|
||||||
SceneGridLayout,
|
SceneGridLayout,
|
||||||
SceneGridRow,
|
SceneGridRow,
|
||||||
SceneObject,
|
SceneObject,
|
||||||
@@ -22,16 +21,14 @@ import {
|
|||||||
import { DataQuery, OptionsWithLegend } from '@grafana/schema';
|
import { DataQuery, OptionsWithLegend } from '@grafana/schema';
|
||||||
import appEvents from 'app/core/app_events';
|
import appEvents from 'app/core/app_events';
|
||||||
import { t } from 'app/core/internationalization';
|
import { t } from 'app/core/internationalization';
|
||||||
import { panelToRuleFormValues } from 'app/features/alerting/unified/utils/rule-form';
|
import { scenesPanelToRuleFormValues } from 'app/features/alerting/unified/utils/rule-form';
|
||||||
import { shareDashboardType } from 'app/features/dashboard/components/ShareModal/utils';
|
import { shareDashboardType } from 'app/features/dashboard/components/ShareModal/utils';
|
||||||
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
|
|
||||||
import { InspectTab } from 'app/features/inspector/types';
|
import { InspectTab } from 'app/features/inspector/types';
|
||||||
import { getScenePanelLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers';
|
import { getScenePanelLinksSupplier } from 'app/features/panel/panellinks/linkSuppliers';
|
||||||
import { createExtensionSubMenu } from 'app/features/plugins/extensions/utils';
|
import { createExtensionSubMenu } from 'app/features/plugins/extensions/utils';
|
||||||
import { addDataTrailPanelAction } from 'app/features/trails/dashboardIntegration';
|
import { addDataTrailPanelAction } from 'app/features/trails/dashboardIntegration';
|
||||||
import { ShowConfirmModalEvent } from 'app/types/events';
|
import { ShowConfirmModalEvent } from 'app/types/events';
|
||||||
|
|
||||||
import { gridItemToPanel, transformSceneToSaveModel } from '../serialization/transformSceneToSaveModel';
|
|
||||||
import { ShareModal } from '../sharing/ShareModal';
|
import { ShareModal } from '../sharing/ShareModal';
|
||||||
import { DashboardInteractions } from '../utils/interactions';
|
import { DashboardInteractions } from '../utils/interactions';
|
||||||
import { getEditPanelUrl, getInspectUrl, getViewPanelUrl, tryGetExploreUrlForPanel } from '../utils/urlBuilders';
|
import { getEditPanelUrl, getInspectUrl, getViewPanelUrl, tryGetExploreUrlForPanel } from '../utils/urlBuilders';
|
||||||
@@ -56,11 +53,6 @@ export function panelMenuBehavior(menu: VizPanelMenu) {
|
|||||||
const panelId = getPanelIdForVizPanel(panel);
|
const panelId = getPanelIdForVizPanel(panel);
|
||||||
const dashboard = getDashboardSceneFor(panel);
|
const dashboard = getDashboardSceneFor(panel);
|
||||||
const { isEmbedded } = dashboard.state.meta;
|
const { isEmbedded } = dashboard.state.meta;
|
||||||
const panelJson = gridItemToPanel(panel.parent as SceneGridItem);
|
|
||||||
const panelModel = new PanelModel(panelJson);
|
|
||||||
const dashboardJson = transformSceneToSaveModel(dashboard);
|
|
||||||
const dashboardModel = new DashboardModel(dashboardJson);
|
|
||||||
|
|
||||||
const exploreMenuItem = await getExploreMenuItem(panel);
|
const exploreMenuItem = await getExploreMenuItem(panel);
|
||||||
|
|
||||||
// For embedded dashboards we only have explore action for now
|
// For embedded dashboards we only have explore action for now
|
||||||
@@ -138,7 +130,7 @@ export function panelMenuBehavior(menu: VizPanelMenu) {
|
|||||||
|
|
||||||
moreSubMenu.push({
|
moreSubMenu.push({
|
||||||
text: t('panel.header-menu.new-alert-rule', `New alert rule`),
|
text: t('panel.header-menu.new-alert-rule', `New alert rule`),
|
||||||
onClick: (e) => onCreateAlert(e, panelModel, dashboardModel),
|
onClick: (e) => onCreateAlert(panel),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (hasLegendOptions(panel.state.options)) {
|
if (hasLegendOptions(panel.state.options)) {
|
||||||
@@ -431,21 +423,18 @@ export function removePanel(dashboard: DashboardScene, panel: VizPanel, ask: boo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const onCreateAlert = (event: React.MouseEvent, panel: PanelModel, dashboard: DashboardModel) => {
|
const onCreateAlert = async (panel: VizPanel) => {
|
||||||
event.preventDefault();
|
|
||||||
createAlert(panel, dashboard);
|
|
||||||
DashboardInteractions.panelMenuItemClicked('create-alert');
|
DashboardInteractions.panelMenuItemClicked('create-alert');
|
||||||
};
|
|
||||||
|
|
||||||
const createAlert = async (panel: PanelModel, dashboard: DashboardModel) => {
|
|
||||||
const formValues = await panelToRuleFormValues(panel, dashboard);
|
|
||||||
|
|
||||||
|
const formValues = await scenesPanelToRuleFormValues(panel);
|
||||||
const ruleFormUrl = urlUtil.renderUrl('/alerting/new', {
|
const ruleFormUrl = urlUtil.renderUrl('/alerting/new', {
|
||||||
defaults: JSON.stringify(formValues),
|
defaults: JSON.stringify(formValues),
|
||||||
returnTo: location.pathname + location.search,
|
returnTo: location.pathname + location.search,
|
||||||
});
|
});
|
||||||
|
|
||||||
locationService.push(ruleFormUrl);
|
locationService.push(ruleFormUrl);
|
||||||
|
|
||||||
|
DashboardInteractions.panelMenuItemClicked('create-alert');
|
||||||
};
|
};
|
||||||
|
|
||||||
export function toggleVizPanelLegend(vizPanel: VizPanel): void {
|
export function toggleVizPanelLegend(vizPanel: VizPanel): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user