import { useCallback, ChangeEvent, useState } from 'react'; import { connect, ConnectedProps } from 'react-redux'; import { TimeZone } from '@grafana/data'; import { config } from '@grafana/runtime'; import { CollapsableSection, Field, Input, RadioButtonGroup, TagsInput, Label, TextArea, Box, Stack, 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 { updateTimeZoneDashboard, updateWeekStartDashboard } from 'app/features/dashboard/state/actions'; import { DeleteDashboardButton } from '../DeleteDashboard/DeleteDashboardButton'; import { GenAIDashDescriptionButton } from '../GenAI/GenAIDashDescriptionButton'; import { GenAIDashTitleButton } from '../GenAI/GenAIDashTitleButton'; import { TimePickerSettings } from './TimePickerSettings'; import { SettingsPageProps } from './types'; export type Props = SettingsPageProps & ConnectedProps; const GRAPH_TOOLTIP_OPTIONS = [ { value: 0, label: 'Default' }, { value: 1, label: 'Shared crosshair' }, { value: 2, label: 'Shared Tooltip' }, ]; export function GeneralSettingsUnconnected({ dashboard, updateTimeZone, updateWeekStart, sectionNav, }: Props): JSX.Element { const [renderCounter, setRenderCounter] = useState(0); const [dashboardTitle, setDashboardTitle] = useState(dashboard.title); const [dashboardDescription, setDashboardDescription] = useState(dashboard.description); const pageNav = sectionNav.node.parentItem; const onFolderChange = (newUID: string | undefined, newTitle: string | undefined) => { dashboard.meta.folderUid = newUID; dashboard.meta.folderTitle = newTitle; dashboard.meta.hasUnsavedFolderChange = true; setRenderCounter(renderCounter + 1); }; const onTitleChange = useCallback( (title: string) => { dashboard.title = title; setDashboardTitle(title); }, [setDashboardTitle, dashboard] ); const onDescriptionChange = useCallback( (description: string) => { dashboard.description = description; setDashboardDescription(description); }, [setDashboardDescription, dashboard] ); const onTooltipChange = (graphTooltip: number) => { dashboard.graphTooltip = graphTooltip; setRenderCounter(renderCounter + 1); }; const onRefreshIntervalChange = (intervals: string[]) => { dashboard.timepicker.refresh_intervals = intervals.filter((i) => i.trim() !== ''); }; const onNowDelayChange = (nowDelay: string) => { dashboard.timepicker.nowDelay = nowDelay; }; const onHideTimePickerChange = (hide: boolean) => { dashboard.timepicker.hidden = hide; setRenderCounter(renderCounter + 1); }; const onLiveNowChange = (v: boolean) => { dashboard.liveNow = v; setRenderCounter(renderCounter + 1); }; const onTimeZoneChange = (timeZone: TimeZone) => { dashboard.timezone = timeZone; setRenderCounter(renderCounter + 1); updateTimeZone(timeZone); }; const onWeekStartChange = (weekStart?: WeekStart) => { dashboard.weekStart = weekStart; setRenderCounter(renderCounter + 1); updateWeekStart(weekStart); }; const onTagsChange = (tags: string[]) => { dashboard.tags = tags; setRenderCounter(renderCounter + 1); }; const onEditableChange = (value: boolean) => { dashboard.editable = value; setRenderCounter(renderCounter + 1); }; const editableOptions = [ { label: 'Editable', value: true }, { label: 'Read-only', value: false }, ]; return (
{config.featureToggles.dashgpt && } } > ) => onTitleChange(e.target.value)} /> {config.featureToggles.dashgpt && } } >