diff --git a/public/app/features/browse-dashboards/api/services.ts b/public/app/features/browse-dashboards/api/services.ts index 98be615583b..2bb1ec6d39e 100644 --- a/public/app/features/browse-dashboards/api/services.ts +++ b/public/app/features/browse-dashboards/api/services.ts @@ -1,8 +1,7 @@ -import { getBackendSrv } from '@grafana/runtime'; import { contextSrv } from 'app/core/services/context_srv'; import { GENERAL_FOLDER_UID } from 'app/features/search/constants'; import { getGrafanaSearcher } from 'app/features/search/service/searcher'; -import { NestedFolderDTO } from 'app/features/search/service/types'; +import { DashboardQueryResult } from 'app/features/search/service/types'; import { queryResultToViewItem } from 'app/features/search/service/utils'; import { DashboardViewItem } from 'app/features/search/types'; import { AccessControlAction } from 'app/types/accessControl'; @@ -17,22 +16,24 @@ export async function listFolders( page = 1, pageSize = PAGE_SIZE ): Promise { - const backendSrv = getBackendSrv(); + const searcher = getGrafanaSearcher(); - // TODO: what to do here for unified search? - let folders: NestedFolderDTO[] = []; + let folders: DashboardQueryResult[] = []; if (contextSrv.hasPermission(AccessControlAction.FoldersRead)) { - folders = await backendSrv.get('/api/folders', { - parentUid: parentUID, - page, + const foldersResults = await searcher.search({ + kind: ['folder'], + location: parentUID || 'general', + from: (page - 1) * pageSize, // our pages are 1-indexed, so we need to -1 to convert that to correct value to skip limit: pageSize, + offset: (page - 1) * pageSize, }); + folders = foldersResults.view.toArray(); } return folders.map((item) => ({ kind: 'folder', uid: item.uid, - title: item.title, + title: item.name, parentTitle, parentUID, managedBy: item.managedBy, diff --git a/public/app/features/search/service/unified.ts b/public/app/features/search/service/unified.ts index 4ab551997a3..8d1af58f9d9 100644 --- a/public/app/features/search/service/unified.ts +++ b/public/app/features/search/service/unified.ts @@ -386,7 +386,9 @@ export function toDashboardResults(rsp: SearchAPIResponse, sort: string): DataFr ...hit, uid: hit.name, url: toURL(hit.resource, hit.name, hit.title), - tags: hit.tags || [], + // Sort tags so we aren't reliant on the backend having done this for us + // Sorting order can be different between APIs/search implementations + tags: (hit.tags || []).sort(), folder: hit.folder || 'general', location, name: hit.title, // 🤯 FIXME hit.name is k8s name, eg grafana dashboards UID