import React, { ChangeEvent } from 'react'; import { PageLayoutType } from '@grafana/data'; import { behaviors, SceneComponentProps, SceneObjectBase, SceneObjectRef, SceneTimePicker, sceneGraph, } from '@grafana/scenes'; import { TimeZone } from '@grafana/schema'; import { Box, CollapsableSection, Field, HorizontalGroup, Input, Label, RadioButtonGroup, TagsInput, TextArea, } 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 { DeleteDashboardButton } from 'app/features/dashboard/components/DeleteDashboard/DeleteDashboardButton'; import { DashboardControls } from '../scene/DashboardControls'; import { DashboardScene } from '../scene/DashboardScene'; import { NavToolbarActions } from '../scene/NavToolbarActions'; import { dashboardSceneGraph } from '../utils/dashboardSceneGraph'; import { DashboardEditView, DashboardEditViewState, useDashboardEditPageNav } from './utils'; export interface GeneralSettingsEditViewState extends DashboardEditViewState { dashboardRef: SceneObjectRef; } 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 this.state.dashboardRef.resolve(); } public getUrlKey(): string { return 'settings'; } public getDashboard(): DashboardScene { return this._dashboard; } public getTimeRange() { return sceneGraph.getTimeRange(this._dashboard); } public getRefreshPicker() { return dashboardSceneGraph.getRefreshPicker(this._dashboard); } public getCursorSync() { const cursorSync = this._dashboard.state.$behaviors?.find((b) => b instanceof behaviors.CursorSync); if (cursorSync instanceof behaviors.CursorSync) { return cursorSync; } return; } 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 = (newUID: string, newTitle: string) => { const newMeta = { ...this._dashboard.state.meta, folderUid: newUID || this._dashboard.state.meta.folderUid, folderTitle: newTitle || this._dashboard.state.meta.folderTitle, hasUnsavedFolderChange: true, }; 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: string) => { this.getTimeRange().setState({ weekStart: value, }); }; public onRefreshIntervalChange = (value: string[]) => { const control = this.getRefreshPicker(); control?.setState({ intervals: value, }); }; public onNowDelayChange = (value: string) => { // TODO: Figure out how to store nowDelay in Dashboard Scene }; public onHideTimePickerChange = (value: boolean) => { if (this._dashboard.state.controls instanceof DashboardControls) { for (const control of this._dashboard.state.controls.state.timeControls) { if (control instanceof SceneTimePicker) { control.setState({ // TODO: Control visibility from DashboardControls // hidden: value, }); } } } }; public onLiveNowChange = (value: boolean) => { // TODO: Figure out how to store liveNow in Dashboard Scene }; public onTooltipChange = (value: number) => { this.getCursorSync()?.setState({ sync: value }); }; static Component = ({ model }: SceneComponentProps) => { const { navModel, pageNav } = useDashboardEditPageNav(model.getDashboard(), model.getUrlKey()); const { title, description, tags, meta, editable, overlay } = model.getDashboard().useState(); const { sync: graphTooltip } = model.getCursorSync()?.useState() || {}; const { timeZone, weekStart } = model.getTimeRange().useState(); const { intervals } = model.getRefreshPicker()?.useState() || {}; return (
{/* TODO: Make the component use persisted model */} {/* {config.featureToggles.dashgpt && ( )} */} } > ) => model.onTitleChange(e.target.value)} /> {/* {config.featureToggles.dashgpt && ( )} */} } >