import { useState } from 'react'; import { selectors } from '@grafana/e2e-selectors'; import { Button, Checkbox, TextArea, Stack, Alert, Box, Field } from '@grafana/ui'; import { Trans, t } from 'app/core/internationalization'; import { SaveDashboardOptions } from 'app/features/dashboard/components/SaveDashboard/types'; import { DashboardScene } from '../scene/DashboardScene'; import { SaveDashboardDrawer } from './SaveDashboardDrawer'; import { DashboardChangeInfo, NameAlreadyExistsError, SaveButton, isNameExistsError, isPluginDashboardError, isVersionMismatchError, } from './shared'; import { useSaveDashboard } from './useSaveDashboard'; export interface Props { dashboard: DashboardScene; drawer: SaveDashboardDrawer; changeInfo: DashboardChangeInfo; } export function SaveDashboardForm({ dashboard, drawer, changeInfo }: Props) { const { hasChanges, changedSaveModel } = changeInfo; const { state, onSaveDashboard } = useSaveDashboard(false); const [options, setOptions] = useState({ folderUid: dashboard.state.meta.folderUid, // we need to set the uid here in order to save the dashboard // in schema v2 we don't have the uid in the spec k8s: { ...dashboard.state.meta.k8s, }, }); const onSave = async (overwrite: boolean) => { const result = await onSaveDashboard(dashboard, { ...options, rawDashboardJSON: changedSaveModel, overwrite }); if (result.status === 'success') { dashboard.closeModal(); drawer.state.onSaveSuccess?.(); } }; const cancelButton = ( ); const saveButton = (overwrite: boolean) => ( ); const isMessageTooLongError = (message?: string) => { return message && message.length > 500; }; function renderFooter(error?: Error) { if (isMessageTooLongError(options.message)) { const messageLength = options.message?.length ?? 0; return (

The message is {{ messageLength }} characters, which exceeds the maximum length of 500 characters. Please shorten it before saving.

); } if (isVersionMismatchError(error)) { return (

Would you still like to save this dashboard?

{cancelButton} {saveButton(true)}
); } if (isNameExistsError(error)) { return ; } if (isPluginDashboardError(error)) { return (

Your changes will be lost when you update the plugin. Use Save As to create custom version.

{cancelButton} {saveButton(true)}
); } return ( <> {error && (

{error.message}

)} {cancelButton} {saveButton(false)} {!hasChanges &&
No changes to save
}
); } return (