mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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"
|
||||
|
||||
@@ -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}
|
||||
|
||||
Reference in New Issue
Block a user