import { ChangeEvent } from 'react'; import { PageLayoutType } from '@grafana/data'; import { config } from '@grafana/runtime'; import { SceneComponentProps, SceneObjectBase, behaviors, sceneGraph } from '@grafana/scenes'; import { TimeZone } from '@grafana/schema'; import { Box, CollapsableSection, Field, Input, Label, RadioButtonGroup, Stack, Switch, TagsInput, TextArea, WeekStart, } from '@grafana/ui'; import { Page } from 'app/core/components/Page/Page'; import { FolderPicker } from 'app/core/components/Select/FolderPicker'; import { t, Trans } from 'app/core/internationalization'; import { TimePickerSettings } from 'app/features/dashboard/components/DashboardSettings/TimePickerSettings'; import { GenAIDashDescriptionButton } from 'app/features/dashboard/components/GenAI/GenAIDashDescriptionButton'; import { GenAIDashTitleButton } from 'app/features/dashboard/components/GenAI/GenAIDashTitleButton'; import { updateNavModel } from '../pages/utils'; import { DashboardScene } from '../scene/DashboardScene'; import { NavToolbarActions } from '../scene/NavToolbarActions'; import { dashboardSceneGraph } from '../utils/dashboardSceneGraph'; import { getDashboardSceneFor } from '../utils/utils'; import { DeleteDashboardButton } from './DeleteDashboardButton'; import { DashboardEditView, DashboardEditViewState, useDashboardEditPageNav } from './utils'; export interface GeneralSettingsEditViewState extends DashboardEditViewState {} const EDITABLE_OPTIONS = [ { label: 'Editable', value: true }, { label: 'Read-only', value: false }, ]; const GRAPH_TOOLTIP_OPTIONS = [ { value: 0, label: 'Default' }, { value: 1, label: 'Shared crosshair' }, { value: 2, label: 'Shared Tooltip' }, ]; export class GeneralSettingsEditView extends SceneObjectBase implements DashboardEditView { private get _dashboard(): DashboardScene { return getDashboardSceneFor(this); } public getUrlKey(): string { return 'settings'; } public getDashboard(): DashboardScene { return this._dashboard; } public getTimeRange() { return sceneGraph.getTimeRange(this._dashboard); } public getRefreshPicker() { return this.getDashboardControls().state.refreshPicker; } public getCursorSync() { return dashboardSceneGraph.getCursorSync(this._dashboard); } public getLiveNowTimer(): behaviors.LiveNowTimer { const liveNowTimer = sceneGraph.findObject(this._dashboard, (s) => s instanceof behaviors.LiveNowTimer); if (liveNowTimer instanceof behaviors.LiveNowTimer) { return liveNowTimer; } else { throw new Error('LiveNowTimer could not be found'); } } public getDashboardControls() { return this._dashboard.state.controls!; } public onTitleChange = (value: string) => { this._dashboard.setState({ title: value }); }; public onDescriptionChange = (value: string) => { this._dashboard.setState({ description: value }); }; public onTagsChange = (value: string[]) => { this._dashboard.setState({ tags: value }); }; public onFolderChange = async (newUID: string | undefined, newTitle: string | undefined) => { const newMeta = { ...this._dashboard.state.meta, folderUid: newUID || this._dashboard.state.meta.folderUid, folderTitle: newTitle || this._dashboard.state.meta.folderTitle, }; if (newMeta.folderUid) { await updateNavModel(newMeta.folderUid); } this._dashboard.setState({ meta: newMeta }); }; public onEditableChange = (value: boolean) => { this._dashboard.setState({ editable: value }); }; public onTimeZoneChange = (value: TimeZone) => { this.getTimeRange().setState({ timeZone: value, }); }; public onWeekStartChange = (value?: WeekStart) => { this.getTimeRange().setState({ weekStart: value }); }; public onRefreshIntervalChange = (value: string[]) => { const control = this.getRefreshPicker(); control?.setState({ intervals: value, }); }; public onNowDelayChange = (value: string) => { const timeRange = this.getTimeRange(); timeRange?.setState({ UNSAFE_nowDelay: value, }); }; public onHideTimePickerChange = (value: boolean) => { this.getDashboardControls()?.setState({ hideTimeControls: value, }); }; public onLiveNowChange = (enable: boolean) => { try { const liveNow = this.getLiveNowTimer(); enable ? liveNow.enable() : liveNow.disable(); } catch (err) { console.error(err); } }; public onTooltipChange = (value: number) => { this.getCursorSync()?.setState({ sync: value }); }; public onPreloadChange = (preload: boolean) => { this._dashboard.setState({ preload }); }; public onDeleteDashboard = () => {}; static Component = ({ model }: SceneComponentProps) => { const dashboard = model.getDashboard(); const { navModel, pageNav } = useDashboardEditPageNav(dashboard, model.getUrlKey()); const { title, description, tags, meta, editable } = dashboard.useState(); const { sync: graphTooltip } = model.getCursorSync()?.useState() || {}; const { timeZone, weekStart, UNSAFE_nowDelay: nowDelay } = model.getTimeRange().useState(); const { intervals } = model.getRefreshPicker().useState(); const { hideTimeControls } = model.getDashboardControls().useState(); const { enabled: liveNow } = model.getLiveNowTimer().useState(); return (
{config.featureToggles.dashgpt && ( model.onTitleChange(title)} /> )} } > ) => model.onTitleChange(e.target.value)} /> {config.featureToggles.dashgpt && ( model.onDescriptionChange(description)} /> )} } >