NestedFolders: API improvements for NestedFolderPicker (#72093)

* NestedFolders: Prepare nested folder picker for more usage

* fix betterer results

* Update usage of NestedFolderPicker

* fix tests

* fix betterer
This commit is contained in:
Josh Hunt
2023-07-21 14:40:39 +00:00
committed by GitHub
parent cfa1a2c55f
commit a5016c9e88
7 changed files with 50 additions and 53 deletions

View File

@@ -5,7 +5,6 @@ import { TimeZone } from '@grafana/data';
import { config } from '@grafana/runtime';
import { CollapsableSection, Field, Input, RadioButtonGroup, TagsInput } from '@grafana/ui';
import { NestedFolderPicker } from 'app/core/components/NestedFolderPicker/NestedFolderPicker';
import { FolderChange } from 'app/core/components/NestedFolderPicker/types';
import { Page } from 'app/core/components/Page/Page';
import { OldFolderPicker } from 'app/core/components/Select/OldFolderPicker';
import { updateTimeZoneDashboard, updateWeekStartDashboard } from 'app/features/dashboard/state/actions';
@@ -31,13 +30,20 @@ export function GeneralSettingsUnconnected({
}: Props): JSX.Element {
const [renderCounter, setRenderCounter] = useState(0);
const onFolderChange = (newFolder: FolderChange) => {
const onFolderChange = (newFolder: { uid: string; title: string }) => {
dashboard.meta.folderUid = newFolder.uid;
dashboard.meta.folderTitle = newFolder.title;
dashboard.meta.hasUnsavedFolderChange = true;
setRenderCounter(renderCounter + 1);
};
const onNestedFolderChange = (newUID: string, newTitle: string) => {
dashboard.meta.folderUid = newUID;
dashboard.meta.folderTitle = newTitle;
dashboard.meta.hasUnsavedFolderChange = true;
setRenderCounter(renderCounter + 1);
};
const onBlur = (event: React.FocusEvent<HTMLInputElement>) => {
if (event.currentTarget.name === 'title' || event.currentTarget.name === 'description') {
dashboard[event.currentTarget.name] = event.currentTarget.value;
@@ -110,7 +116,7 @@ export function GeneralSettingsUnconnected({
<Field label="Folder">
{config.featureToggles.nestedFolderPicker ? (
<NestedFolderPicker value={dashboard.meta.folderUid} onChange={onFolderChange} />
<NestedFolderPicker value={dashboard.meta.folderUid} onChange={onNestedFolderChange} />
) : (
<OldFolderPicker
inputId="dashboard-folder-input"

View File

@@ -112,7 +112,11 @@ export const SaveDashboardAsForm = ({
<InputControl
render={({ field: { ref, ...field } }) =>
config.featureToggles.nestedFolderPicker ? (
<NestedFolderPicker {...field} value={field.value?.uid} />
<NestedFolderPicker
{...field}
onChange={(uid: string, title: string) => field.onChange({ uid, title })}
value={field.value?.uid}
/>
) : (
<OldFolderPicker
{...field}