From d531f5ab42e5d1e33d69785588fa4b5944bff27a Mon Sep 17 00:00:00 2001 From: Ivan Ortega Alba Date: Fri, 22 Sep 2023 04:07:56 +0200 Subject: [PATCH] Dashboards: Auto-generate dashboard title and description from settings (#75240) Co-authored-by: nmarrs --- .../DashboardSettings/GeneralSettings.tsx | 74 ++++++++++++++++--- .../GenAI/GenAIDashDescriptionButton.tsx | 45 +++++++++++ .../components/GenAI/GenAIDashTitleButton.tsx | 43 +++++++++++ 3 files changed, 151 insertions(+), 11 deletions(-) create mode 100644 public/app/features/dashboard/components/GenAI/GenAIDashDescriptionButton.tsx create mode 100644 public/app/features/dashboard/components/GenAI/GenAIDashTitleButton.tsx diff --git a/public/app/features/dashboard/components/DashboardSettings/GeneralSettings.tsx b/public/app/features/dashboard/components/DashboardSettings/GeneralSettings.tsx index 778b2fd8ddf..5ef795de84f 100644 --- a/public/app/features/dashboard/components/DashboardSettings/GeneralSettings.tsx +++ b/public/app/features/dashboard/components/DashboardSettings/GeneralSettings.tsx @@ -1,13 +1,25 @@ -import React, { useState } from 'react'; +import React, { ChangeEvent, useState } from 'react'; import { connect, ConnectedProps } from 'react-redux'; import { TimeZone } from '@grafana/data'; -import { CollapsableSection, Field, Input, RadioButtonGroup, TagsInput } from '@grafana/ui'; +import { config } from '@grafana/runtime'; +import { + CollapsableSection, + Field, + Input, + RadioButtonGroup, + TagsInput, + Label, + HorizontalGroup, + TextArea, +} from '@grafana/ui'; import { Page } from 'app/core/components/Page/Page'; import { FolderPicker } from 'app/core/components/Select/FolderPicker'; 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'; @@ -27,6 +39,8 @@ export function GeneralSettingsUnconnected({ sectionNav, }: Props): JSX.Element { const [renderCounter, setRenderCounter] = useState(0); + const [dashboardTitle, setDashboardTitle] = useState(dashboard.title); + const [dashboardDescription, setDashboardDescription] = useState(dashboard.description); const onFolderChange = (newUID: string, newTitle: string) => { dashboard.meta.folderUid = newUID; @@ -35,11 +49,21 @@ export function GeneralSettingsUnconnected({ setRenderCounter(renderCounter + 1); }; - const onBlur = (event: React.FocusEvent) => { - if (event.currentTarget.name === 'title' || event.currentTarget.name === 'description') { - dashboard[event.currentTarget.name] = event.currentTarget.value; - } - }; + const onTitleChange = React.useCallback( + (title: string) => { + dashboard.title = title; + setDashboardTitle(title); + }, + [setDashboardTitle, dashboard] + ); + + const onDescriptionChange = React.useCallback( + (description: string) => { + dashboard.description = description; + setDashboardDescription(description); + }, + [setDashboardDescription, dashboard] + ); const onTooltipChange = (graphTooltip: number) => { dashboard.graphTooltip = graphTooltip; @@ -95,11 +119,39 @@ export function GeneralSettingsUnconnected({
- - + + + {config.featureToggles.dashgpt && ( + + )} + + } + > + ) => onTitleChange(e.target.value)} + /> - - + + + {config.featureToggles.dashgpt && ( + + )} + + } + > +