RestoreDashboard: Avoid overwrite when saving dashboard triggers a 'name-exists' error (#91881)

This commit is contained in:
Laura Fernández 2024-08-19 11:31:40 +02:00 committed by GitHub
parent 41fc6ab89e
commit 84e0aa1ccd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 72 additions and 20 deletions

View File

@ -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 ? (
<Alert title={t('save-dashboards.name-exists.title', 'Dashboard name already exists')} severity="error">
<p>
<Trans i18nKey="save-dashboards.name-exists.message-info">
A dashboard with the same name in the selected folder already exists, including recently deleted dashboards.
</Trans>
</p>
<p>
<Trans i18nKey="save-dashboards.name-exists.message-suggestion">
Please choose a different name or folder.
</Trans>
</p>
</Alert>
) : (
<Alert title="Name already exists" severity="error">
<p>
A dashboard with the same name in selected folder already exists. Would you still like to save this dashboard?

View File

@ -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' && (
<ConfirmModal
isOpen={true}
title="Conflict"
body={
<div>
A dashboard with the same name in selected folder already exists. <br />
<small>Would you still like to save this dashboard?</small>
</div>
}
confirmText="Save and overwrite"
onConfirm={async () => {
await onDashboardSave(dashboardSaveModel, { overwrite: true }, dashboard);
onDismiss();
}}
onDismiss={onDismiss}
/>
<>
{isRestoreDashboardsEnabled ? (
<Modal
isOpen={true}
title={t('save-dashboards.name-exists.title', 'Dashboard name already exists')}
onDismiss={onDismiss}
>
<p>
<Trans i18nKey="save-dashboards.name-exists.message-info">
A dashboard with the same name in the selected folder already exists, including recently deleted
dashboards.
</Trans>
</p>
<p>
<Trans i18nKey="save-dashboards.name-exists.message-suggestion">
Please choose a different name or folder.
</Trans>
</p>
</Modal>
) : (
<ConfirmModal
isOpen={true}
title="Conflict"
body={
<div>
A dashboard with the same name in selected folder already exists. <br />
<small>Would you still like to save this dashboard?</small>
</div>
}
confirmText="Save and overwrite"
onConfirm={async () => {
await onDashboardSave(dashboardSaveModel, { overwrite: true }, dashboard);
onDismiss();
}}
onDismiss={onDismiss}
/>
)}
</>
)}
{error.data && error.data.status === 'plugin-dashboard' && (
<ConfirmPluginDashboardSaveModal

View File

@ -1978,6 +1978,13 @@
},
"dismissable-button": "Close"
},
"save-dashboards": {
"name-exists": {
"message-info": "A dashboard with the same name in the selected folder already exists, including recently deleted dashboards.",
"message-suggestion": "Please choose a different name or folder.",
"title": "Dashboard name already exists"
}
},
"scopes": {
"dashboards": {
"loading": "Loading dashboards",

View File

@ -1978,6 +1978,13 @@
},
"dismissable-button": "Cľőşę"
},
"save-dashboards": {
"name-exists": {
"message-info": "Å đäşĥþőäřđ ŵįŧĥ ŧĥę şämę ʼnämę įʼn ŧĥę şęľęčŧęđ ƒőľđęř äľřęäđy ęχįşŧş, įʼnčľūđįʼnģ řęčęʼnŧľy đęľęŧęđ đäşĥþőäřđş.",
"message-suggestion": "Pľęäşę čĥőőşę ä đįƒƒęřęʼnŧ ʼnämę őř ƒőľđęř.",
"title": "Đäşĥþőäřđ ʼnämę äľřęäđy ęχįşŧş"
}
},
"scopes": {
"dashboards": {
"loading": "Ŀőäđįʼnģ đäşĥþőäřđş",