Folders: Make listFolders call correct API and fix tags sorting (#114181)

This commit is contained in:
Tom Ratcliffe
2025-11-20 14:00:33 +00:00
committed by GitHub
parent a4cbbe10c0
commit 3999d108f7
2 changed files with 13 additions and 10 deletions
@@ -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<DashboardViewItem[]> {
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<NestedFolderDTO[]>('/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,
@@ -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