2021-05-04 06:59:40 -05:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import { connect, ConnectedProps } from 'react-redux';
|
2021-05-05 04:09:12 -05:00
|
|
|
import { useAsync } from 'react-use';
|
2021-05-04 06:59:40 -05:00
|
|
|
|
2022-07-06 10:00:56 -05:00
|
|
|
import { Page } from 'app/core/components/Page/Page';
|
|
|
|
|
2021-05-04 06:59:40 -05:00
|
|
|
import { GrafanaRouteComponentProps } from '../../core/navigation/types';
|
|
|
|
import { getNavModel } from '../../core/selectors/navModel';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { StoreState } from '../../types';
|
2021-05-04 06:59:40 -05:00
|
|
|
import { LibraryPanelsSearch } from '../library-panels/components/LibraryPanelsSearch/LibraryPanelsSearch';
|
|
|
|
import { OpenLibraryPanelModal } from '../library-panels/components/OpenLibraryPanelModal/OpenLibraryPanelModal';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { LibraryElementDTO } from '../library-panels/types';
|
|
|
|
|
2021-05-04 06:59:40 -05:00
|
|
|
import { getFolderByUid } from './state/actions';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { getLoadingNav } from './state/navModel';
|
2021-05-04 06:59:40 -05:00
|
|
|
|
|
|
|
export interface OwnProps extends GrafanaRouteComponentProps<{ uid: string }> {}
|
|
|
|
|
|
|
|
const mapStateToProps = (state: StoreState, props: OwnProps) => {
|
|
|
|
const uid = props.match.params.uid;
|
|
|
|
return {
|
2022-07-20 10:26:52 -05:00
|
|
|
pageNav: getNavModel(state.navIndex, `folder-library-panels-${uid}`, getLoadingNav(1)),
|
2021-05-04 06:59:40 -05:00
|
|
|
folderUid: uid,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
getFolderByUid,
|
|
|
|
};
|
|
|
|
|
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
export type Props = OwnProps & ConnectedProps<typeof connector>;
|
|
|
|
|
2022-11-02 10:49:02 -05:00
|
|
|
export function FolderLibraryPanelsPage({ pageNav, getFolderByUid, folderUid }: Props): JSX.Element {
|
2021-08-05 07:32:51 -05:00
|
|
|
const { loading } = useAsync(async () => await getFolderByUid(folderUid), [getFolderByUid, folderUid]);
|
2021-05-11 00:10:19 -05:00
|
|
|
const [selected, setSelected] = useState<LibraryElementDTO | undefined>(undefined);
|
2021-05-04 06:59:40 -05:00
|
|
|
|
|
|
|
return (
|
2022-07-20 10:26:52 -05:00
|
|
|
<Page navId="dashboards/browse" pageNav={pageNav.main}>
|
2021-05-04 06:59:40 -05:00
|
|
|
<Page.Contents isLoading={loading}>
|
|
|
|
<LibraryPanelsSearch
|
|
|
|
onClick={setSelected}
|
2022-11-02 10:49:02 -05:00
|
|
|
currentFolderUID={folderUid}
|
2021-05-04 06:59:40 -05:00
|
|
|
showSecondaryActions
|
|
|
|
showSort
|
|
|
|
showPanelFilter
|
|
|
|
/>
|
|
|
|
{selected ? <OpenLibraryPanelModal onDismiss={() => setSelected(undefined)} libraryPanel={selected} /> : null}
|
|
|
|
</Page.Contents>
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connector(FolderLibraryPanelsPage);
|