2023-04-17 05:08:24 -05:00
|
|
|
import { css } from '@emotion/css';
|
2023-04-12 04:44:01 -05:00
|
|
|
import React, { memo, useMemo } from 'react';
|
2023-04-17 05:08:24 -05:00
|
|
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
2023-04-12 04:44:01 -05:00
|
|
|
|
2023-04-21 09:18:40 -05:00
|
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
2023-04-12 04:44:01 -05:00
|
|
|
import { locationSearchToObject } from '@grafana/runtime';
|
2023-04-21 09:18:40 -05:00
|
|
|
import { Input, useStyles2 } from '@grafana/ui';
|
2023-04-12 04:44:01 -05:00
|
|
|
import { Page } from 'app/core/components/Page/Page';
|
|
|
|
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
|
|
|
|
|
|
|
import { buildNavModel } from '../folders/state/navModel';
|
|
|
|
import { parseRouteParams } from '../search/utils';
|
|
|
|
|
|
|
|
import { skipToken, useGetFolderQuery } from './api/browseDashboardsAPI';
|
2023-04-25 11:08:40 -05:00
|
|
|
import { BrowseActions } from './components/BrowseActions/BrowseActions';
|
2023-04-21 09:18:40 -05:00
|
|
|
import { BrowseFilters } from './components/BrowseFilters';
|
2023-04-12 04:44:01 -05:00
|
|
|
import { BrowseView } from './components/BrowseView';
|
|
|
|
import { SearchView } from './components/SearchView';
|
2023-04-21 09:18:40 -05:00
|
|
|
import { useHasSelection } from './state';
|
2023-04-12 04:44:01 -05:00
|
|
|
|
|
|
|
export interface BrowseDashboardsPageRouteParams {
|
|
|
|
uid?: string;
|
|
|
|
slug?: string;
|
|
|
|
}
|
|
|
|
|
2023-04-21 09:18:40 -05:00
|
|
|
export interface Props extends GrafanaRouteComponentProps<BrowseDashboardsPageRouteParams> {}
|
2023-04-12 04:44:01 -05:00
|
|
|
|
|
|
|
// New Browse/Manage/Search Dashboards views for nested folders
|
|
|
|
|
2023-04-13 04:46:24 -05:00
|
|
|
const BrowseDashboardsPage = memo(({ match, location }: Props) => {
|
2023-04-17 05:08:24 -05:00
|
|
|
const styles = useStyles2(getStyles);
|
2023-04-12 04:44:01 -05:00
|
|
|
const { uid: folderUID } = match.params;
|
|
|
|
|
|
|
|
const searchState = useMemo(() => {
|
|
|
|
return parseRouteParams(locationSearchToObject(location.search));
|
|
|
|
}, [location.search]);
|
|
|
|
|
|
|
|
const { data: folderDTO } = useGetFolderQuery(folderUID ?? skipToken);
|
|
|
|
const navModel = useMemo(() => (folderDTO ? buildNavModel(folderDTO) : undefined), [folderDTO]);
|
2023-04-21 09:18:40 -05:00
|
|
|
const hasSelection = useHasSelection();
|
2023-04-12 04:44:01 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Page navId="dashboards/browse" pageNav={navModel}>
|
2023-04-17 05:08:24 -05:00
|
|
|
<Page.Contents className={styles.pageContents}>
|
2023-04-21 09:18:40 -05:00
|
|
|
<Input placeholder="Search box" />
|
|
|
|
|
|
|
|
{hasSelection ? <BrowseActions /> : <BrowseFilters />}
|
2023-04-12 04:44:01 -05:00
|
|
|
|
2023-04-17 05:08:24 -05:00
|
|
|
<div className={styles.subView}>
|
|
|
|
<AutoSizer>
|
|
|
|
{({ width, height }) =>
|
|
|
|
searchState.query ? (
|
2023-04-24 10:32:04 -05:00
|
|
|
<SearchView width={width} height={height} folderUID={folderUID} />
|
2023-04-17 05:08:24 -05:00
|
|
|
) : (
|
|
|
|
<BrowseView width={width} height={height} folderUID={folderUID} />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</AutoSizer>
|
|
|
|
</div>
|
2023-04-12 04:44:01 -05:00
|
|
|
</Page.Contents>
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2023-04-21 09:18:40 -05:00
|
|
|
const getStyles = (theme: GrafanaTheme2) => ({
|
2023-04-17 05:08:24 -05:00
|
|
|
pageContents: css({
|
|
|
|
display: 'grid',
|
2023-04-21 09:18:40 -05:00
|
|
|
gridTemplateRows: 'auto auto 1fr',
|
2023-04-17 05:08:24 -05:00
|
|
|
height: '100%',
|
2023-04-21 09:18:40 -05:00
|
|
|
rowGap: theme.spacing(1),
|
2023-04-17 05:08:24 -05:00
|
|
|
}),
|
|
|
|
|
|
|
|
// AutoSizer needs an element to measure the full height available
|
|
|
|
subView: css({
|
|
|
|
height: '100%',
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2023-04-12 04:44:01 -05:00
|
|
|
BrowseDashboardsPage.displayName = 'BrowseDashboardsPage';
|
2023-04-13 04:46:24 -05:00
|
|
|
export default BrowseDashboardsPage;
|