grafana/public/app/features/browse-dashboards/BrowseFolderLibraryPanelsPage.tsx
Ashley Harrison 10adebd7b3
Page: Add inline rename functionality (#68828)
* initial attempt at inline rename

* handle version correctly

* refactor

* minor tweaks

* add unit tests

* prettier...

* add to other tabs, remove settings tab when feature toggle is enabled

* fix truncation

* allow title to span full width of page

* fix h1 styling when no renderTitle/onEditTitle is present

* better layout

* use input from grafana/ui, fix imports

* fix unit test

* better error handling

* don't use autosavefield

* undo changes to AutoSaveField

* remove timeout

* remove maxWidth now we're not using AutoSaveField

* rename isEditInProgress to isLoading

* sync localValue with value

* better responsive css
2023-05-31 17:03:54 +01:00

73 lines
2.4 KiB
TypeScript

import React, { useMemo, useState } from 'react';
import { Page } from 'app/core/components/Page/Page';
import { GrafanaRouteComponentProps } from '../../core/navigation/types';
import { FolderActionsButton } from '../browse-dashboards/components/FolderActionsButton';
import { buildNavModel, getLibraryPanelsTabID } from '../folders/state/navModel';
import { LibraryPanelsSearch } from '../library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch';
import { OpenLibraryPanelModal } from '../library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal';
import { LibraryElementDTO } from '../library-panels/types';
import { useGetFolderQuery, useSaveFolderMutation } from './api/browseDashboardsAPI';
export interface OwnProps extends GrafanaRouteComponentProps<{ uid: string }> {}
export function BrowseFolderLibraryPanelsPage({ match }: OwnProps) {
const { uid: folderUID } = match.params;
const { data: folderDTO } = useGetFolderQuery(folderUID);
const [selected, setSelected] = useState<LibraryElementDTO | undefined>(undefined);
const [saveFolder] = useSaveFolderMutation();
const navModel = useMemo(() => {
if (!folderDTO) {
return undefined;
}
const model = buildNavModel(folderDTO);
// Set the "Library panels" tab to active
const libraryPanelsTabID = getLibraryPanelsTabID(folderDTO.uid);
const libraryPanelsTab = model.children?.find((child) => child.id === libraryPanelsTabID);
if (libraryPanelsTab) {
libraryPanelsTab.active = true;
}
return model;
}, [folderDTO]);
const onEditTitle = folderUID
? async (newValue: string) => {
if (folderDTO) {
const result = await saveFolder({
...folderDTO,
title: newValue,
});
if ('error' in result) {
throw result.error;
}
}
}
: undefined;
return (
<Page
navId="dashboards/browse"
pageNav={navModel}
onEditTitle={onEditTitle}
actions={<>{folderDTO && <FolderActionsButton folder={folderDTO} />}</>}
>
<Page.Contents>
<LibraryPanelsSearch
onClick={setSelected}
currentFolderUID={folderUID}
showSecondaryActions
showSort
showPanelFilter
/>
{selected ? <OpenLibraryPanelModal onDismiss={() => setSelected(undefined)} libraryPanel={selected} /> : null}
</Page.Contents>
</Page>
);
}
export default BrowseFolderLibraryPanelsPage;