From 84e0aa1ccdfc59a947304e94bf5b45c4b857436f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laura=20Fern=C3=A1ndez?= Date: Mon, 19 Aug 2024 11:31:40 +0200 Subject: [PATCH] RestoreDashboard: Avoid overwrite when saving dashboard triggers a 'name-exists' error (#91881) --- .../dashboard-scene/saving/shared.tsx | 19 +++++- .../SaveDashboard/SaveDashboardErrorProxy.tsx | 59 +++++++++++++------ public/locales/en-US/grafana.json | 7 +++ public/locales/pseudo-LOCALE/grafana.json | 7 +++ 4 files changed, 72 insertions(+), 20 deletions(-) diff --git a/public/app/features/dashboard-scene/saving/shared.tsx b/public/app/features/dashboard-scene/saving/shared.tsx index d06ffb55463..23c7fc22e00 100644 --- a/public/app/features/dashboard-scene/saving/shared.tsx +++ b/public/app/features/dashboard-scene/saving/shared.tsx @@ -1,9 +1,10 @@ import * as React from 'react'; import { selectors } from '@grafana/e2e-selectors'; -import { isFetchError } from '@grafana/runtime'; +import { config, isFetchError } from '@grafana/runtime'; import { Dashboard } from '@grafana/schema'; import { Alert, Box, Button, Stack } from '@grafana/ui'; +import { t, Trans } from 'app/core/internationalization'; import { Diffs } from '../settings/version-history/utils'; @@ -38,7 +39,21 @@ export interface NameAlreadyExistsErrorProps { } export function NameAlreadyExistsError({ cancelButton, saveButton }: NameAlreadyExistsErrorProps) { - return ( + const isRestoreDashboardsEnabled = config.featureToggles.dashboardRestore && config.featureToggles.dashboardRestoreUI; + return isRestoreDashboardsEnabled ? ( + +

+ + A dashboard with the same name in the selected folder already exists, including recently deleted dashboards. + +

+

+ + Please choose a different name or folder. + +

+
+ ) : (

A dashboard with the same name in selected folder already exists. Would you still like to save this dashboard? diff --git a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardErrorProxy.tsx b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardErrorProxy.tsx index de6e5d81606..2a5941c82e9 100644 --- a/public/app/features/dashboard/components/SaveDashboard/SaveDashboardErrorProxy.tsx +++ b/public/app/features/dashboard/components/SaveDashboard/SaveDashboardErrorProxy.tsx @@ -2,9 +2,10 @@ import { css } from '@emotion/css'; import * as React from 'react'; import { GrafanaTheme2 } from '@grafana/data'; -import { FetchError } from '@grafana/runtime'; +import { config, FetchError } from '@grafana/runtime'; import { Dashboard } from '@grafana/schema'; import { Button, ConfirmModal, Modal, useStyles2 } from '@grafana/ui'; +import { t, Trans } from 'app/core/internationalization'; import { DashboardModel } from '../../state/DashboardModel'; @@ -30,7 +31,7 @@ export const SaveDashboardErrorProxy = ({ setErrorIsHandled, }: SaveDashboardErrorProxyProps) => { const { onDashboardSave } = useDashboardSave(); - + const isRestoreDashboardsEnabled = config.featureToggles.dashboardRestore && config.featureToggles.dashboardRestoreUI; return ( <> {error.data && error.data.status === 'version-mismatch' && ( @@ -51,22 +52,44 @@ export const SaveDashboardErrorProxy = ({ /> )} {error.data && error.data.status === 'name-exists' && ( - - A dashboard with the same name in selected folder already exists.
- Would you still like to save this dashboard? - - } - confirmText="Save and overwrite" - onConfirm={async () => { - await onDashboardSave(dashboardSaveModel, { overwrite: true }, dashboard); - onDismiss(); - }} - onDismiss={onDismiss} - /> + <> + {isRestoreDashboardsEnabled ? ( + +

+ + A dashboard with the same name in the selected folder already exists, including recently deleted + dashboards. + +

+

+ + Please choose a different name or folder. + +

+ + ) : ( + + A dashboard with the same name in selected folder already exists.
+ Would you still like to save this dashboard? + + } + confirmText="Save and overwrite" + onConfirm={async () => { + await onDashboardSave(dashboardSaveModel, { overwrite: true }, dashboard); + onDismiss(); + }} + onDismiss={onDismiss} + /> + )} + )} {error.data && error.data.status === 'plugin-dashboard' && (