mirror of https://github.com/grafana/grafana
NestedFolders: Show nested folders in Browse folder view (#63746)
* dirty dirty code for showing nested folders in folder view refactor to NestedFolderItem Update dashboard grid view to new types update tests REBASE OUT OF THIS BRANCH - joshhunt/star-by-uid merged into this Squashed commit of the following: commitpull/65274/headd0f046ccd3
Author: joshhunt <josh@trtr.co> Date: Wed Feb 8 18:35:56 2023 +0000 undo async commitabe2777a1f
Author: joshhunt <josh@trtr.co> Date: Wed Feb 8 18:34:11 2023 +0000 Dashboards: Star dashboards by UID add type for dashboard search dto clean DashboardSearchItem type simplify DashboardSearchHit type remove unused properties from DashboardSearchHit make uid non-optional rename + move NestedFolderItem type to DashboardViewItem clean up * wip * fix checkbox selection of nested folders * show folder's parent correctly * Add dashboard result kind * don't render folder empty view in SearchView * call nested folders api only if feature flag enabled * remove unused import * un-rename variable to reduce PR diff * fix typo in comment * fix order of pseudoFolders * Fix General folder not showing in browse * rename folder view tests --------- Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
parent
da97139489
commit
d13488a435
@ -0,0 +1,52 @@ |
||||
import { getBackendSrv } from '@grafana/runtime'; |
||||
import config from 'app/core/config'; |
||||
|
||||
import { DashboardViewItem } from '../types'; |
||||
|
||||
import { getGrafanaSearcher } from './searcher'; |
||||
import { NestedFolderDTO } from './types'; |
||||
import { queryResultToViewItem } from './utils'; |
||||
|
||||
export async function getFolderChildren(parentUid?: string, parentTitle?: string): Promise<DashboardViewItem[]> { |
||||
if (!config.featureToggles.nestedFolders) { |
||||
console.error('getFolderChildren requires nestedFolders feature toggle'); |
||||
return []; |
||||
} |
||||
|
||||
if (!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 getChildFolders(); |
||||
return folders; |
||||
} |
||||
|
||||
const searcher = getGrafanaSearcher(); |
||||
const dashboardsResults = await searcher.search({ |
||||
kind: ['dashboard'], |
||||
query: '*', |
||||
location: parentUid, |
||||
limit: 1000, |
||||
}); |
||||
|
||||
const dashboardItems = dashboardsResults.view.map((item) => { |
||||
return queryResultToViewItem(item, dashboardsResults.view); |
||||
}); |
||||
|
||||
const folders = await getChildFolders(parentUid, parentTitle); |
||||
|
||||
return [...folders, ...dashboardItems]; |
||||
} |
||||
|
||||
async function getChildFolders(parentUid?: string, parentTitle?: string): Promise<DashboardViewItem[]> { |
||||
const backendSrv = getBackendSrv(); |
||||
|
||||
const folders = await backendSrv.get<NestedFolderDTO[]>('/api/folders', { parentUid }); |
||||
|
||||
return folders.map((item) => ({ |
||||
kind: 'folder', |
||||
uid: item.uid, |
||||
title: item.title, |
||||
parentTitle, |
||||
url: `/dashboards/f/${item.uid}/`, |
||||
})); |
||||
} |
Loading…
Reference in new issue