FolderLibraryPanelsPage.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React, { useState } from 'react';
  2. import { connect, ConnectedProps } from 'react-redux';
  3. import { useAsync } from 'react-use';
  4. import Page from '../../core/components/Page/Page';
  5. import { GrafanaRouteComponentProps } from '../../core/navigation/types';
  6. import { getNavModel } from '../../core/selectors/navModel';
  7. import { StoreState } from '../../types';
  8. import { LibraryPanelsSearch } from '../library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch';
  9. import { OpenLibraryPanelModal } from '../library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal';
  10. import { LibraryElementDTO } from '../library-panels/types';
  11. import { getFolderByUid } from './state/actions';
  12. import { getLoadingNav } from './state/navModel';
  13. export interface OwnProps extends GrafanaRouteComponentProps<{ uid: string }> {}
  14. const mapStateToProps = (state: StoreState, props: OwnProps) => {
  15. const uid = props.match.params.uid;
  16. return {
  17. navModel: getNavModel(state.navIndex, `folder-library-panels-${uid}`, getLoadingNav(1)),
  18. folderUid: uid,
  19. folder: state.folder,
  20. };
  21. };
  22. const mapDispatchToProps = {
  23. getFolderByUid,
  24. };
  25. const connector = connect(mapStateToProps, mapDispatchToProps);
  26. export type Props = OwnProps & ConnectedProps<typeof connector>;
  27. export function FolderLibraryPanelsPage({ navModel, getFolderByUid, folderUid, folder }: Props): JSX.Element {
  28. const { loading } = useAsync(async () => await getFolderByUid(folderUid), [getFolderByUid, folderUid]);
  29. const [selected, setSelected] = useState<LibraryElementDTO | undefined>(undefined);
  30. return (
  31. <Page navModel={navModel}>
  32. <Page.Contents isLoading={loading}>
  33. <LibraryPanelsSearch
  34. onClick={setSelected}
  35. currentFolderId={folder.id}
  36. showSecondaryActions
  37. showSort
  38. showPanelFilter
  39. />
  40. {selected ? <OpenLibraryPanelModal onDismiss={() => setSelected(undefined)} libraryPanel={selected} /> : null}
  41. </Page.Contents>
  42. </Page>
  43. );
  44. }
  45. export default connector(FolderLibraryPanelsPage);