import React, { useState } from 'react'; import { connect, ConnectedProps } from 'react-redux'; import { TimeZone } from '@grafana/data'; import { selectors } from '@grafana/e2e-selectors'; import { config } from '@grafana/runtime'; import { CollapsableSection, Field, Input, RadioButtonGroup, TagsInput } from '@grafana/ui'; import { FolderPicker } from 'app/core/components/Select/FolderPicker'; import { updateTimeZoneDashboard, updateWeekStartDashboard } from 'app/features/dashboard/state/actions'; import { DashboardModel } from '../../state/DashboardModel'; import { DeleteDashboardButton } from '../DeleteDashboard/DeleteDashboardButton'; import { PreviewSettings } from './PreviewSettings'; import { TimePickerSettings } from './TimePickerSettings'; interface OwnProps { dashboard: DashboardModel; } export type Props = OwnProps & 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 }: Props): JSX.Element { const [renderCounter, setRenderCounter] = useState(0); const onFolderChange = (folder: { id: number; title: string }) => { dashboard.meta.folderId = folder.id; dashboard.meta.folderTitle = folder.title; dashboard.meta.hasUnsavedFolderChange = true; }; const onBlur = (event: React.FocusEvent) => { dashboard[event.currentTarget.name as 'title' | 'description'] = event.currentTarget.value; }; 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: string) => { 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 (

General

{config.featureToggles.dashboardPreviews && config.featureToggles.dashboardPreviewsAdmin && ( )}
{dashboard.meta.canDelete && }
); } const mapDispatchToProps = { updateTimeZone: updateTimeZoneDashboard, updateWeekStart: updateWeekStartDashboard, }; const connector = connect(null, mapDispatchToProps); export const GeneralSettings = connector(GeneralSettingsUnconnected);