import React, { useState } from 'react'; import { connect, ConnectedProps } from 'react-redux'; import { useAsync } from 'react-use'; import Page from '../../core/components/Page/Page'; import { GrafanaRouteComponentProps } from '../../core/navigation/types'; import { getNavModel } from '../../core/selectors/navModel'; import { StoreState } from '../../types'; import { LibraryPanelsSearch } from '../library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch'; import { OpenLibraryPanelModal } from '../library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal'; import { LibraryElementDTO } from '../library-panels/types'; import { getFolderByUid } from './state/actions'; import { getLoadingNav } from './state/navModel'; export interface OwnProps extends GrafanaRouteComponentProps<{ uid: string }> {} const mapStateToProps = (state: StoreState, props: OwnProps) => { const uid = props.match.params.uid; return { navModel: getNavModel(state.navIndex, `folder-library-panels-${uid}`, getLoadingNav(1)), folderUid: uid, folder: state.folder, }; }; const mapDispatchToProps = { getFolderByUid, }; const connector = connect(mapStateToProps, mapDispatchToProps); export type Props = OwnProps & ConnectedProps; export function FolderLibraryPanelsPage({ navModel, getFolderByUid, folderUid, folder }: Props): JSX.Element { const { loading } = useAsync(async () => await getFolderByUid(folderUid), [getFolderByUid, folderUid]); const [selected, setSelected] = useState(undefined); return ( {selected ? setSelected(undefined)} libraryPanel={selected} /> : null} ); } export default connector(FolderLibraryPanelsPage);