grafana/public/app/features/search/service/folders.ts
Josh Hunt 394ff9fcde
NestedFolders: Improve performance of Browse Dashboards by loading one page at a time (#68617)
* wip for pagination

* kind of doing pagination, but only for the root folder

* wip

* wip

* refactor paginated fetchChildren

* make sure dashboards are loaded if a folder contains only dashboards

* rename lastKindHasMoreItems

* load additional root pages

* undo accidental commit

* return promise from loadMoreChildren, and prevent loading additional page while a request is already in flight

* rename browseDashboards/fetchChildren action so it's more clear

* starting to revalidate children after an action

* unset general uid

* comment

* clean up

* fix tests omg

* cleanup

* fix items not loading after invalidating loaded cache

* comment

* fix lints
2023-06-05 10:21:45 +00:00

42 lines
1.2 KiB
TypeScript

import config from 'app/core/config';
import { listFolders } from 'app/features/browse-dashboards/api/services';
import { DashboardViewItem } from '../types';
import { getGrafanaSearcher } from './searcher';
import { queryResultToViewItem } from './utils';
export async function getFolderChildren(
parentUid?: string,
parentTitle?: string,
dashboardsAtRoot = false
): Promise<DashboardViewItem[]> {
if (!config.featureToggles.nestedFolders) {
console.error('getFolderChildren requires nestedFolders feature toggle');
return [];
}
if (!dashboardsAtRoot && !parentUid) {
// We don't show dashboards at root in folder view yet - they're shown under a dummy 'general'
// folder that FolderView adds in
const folders = await listFolders();
return folders;
}
const searcher = getGrafanaSearcher();
const dashboardsResults = await searcher.search({
kind: ['dashboard'],
query: '*',
location: parentUid || 'general',
limit: 1000,
});
const dashboardItems = dashboardsResults.view.map((item) => {
return queryResultToViewItem(item, dashboardsResults.view);
});
const folders = await listFolders(parentUid, parentTitle);
return [...folders, ...dashboardItems];
}