mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
RestoreDashboard: Avoid overwrite when saving dashboard triggers a 'name-exists' error (#91881)
This commit is contained in:
parent
41fc6ab89e
commit
84e0aa1ccd
@ -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?
|
||||
|
@ -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
|
||||
|
@ -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",
|
||||
|
@ -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ģ đäşĥþőäřđş",
|
||||
|
Loading…
Reference in New Issue
Block a user