fix(search): use the right services when unfied search is enabled for folders (#99661)

Co-authored-by: Scott Lepper <scott.lepper@gmail.com>
Co-authored-by: joshhunt <josh@trtr.co>
This commit is contained in:
Jean-Philippe Quéméner 2025-01-29 11:45:24 +01:00 committed by GitHub
parent a0f27caff2
commit e6c2db82e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 6 deletions

View File

@ -4,9 +4,10 @@ import { useCallback, useMemo, useState } from 'react';
import { GrafanaTheme2, SelectableValue } from '@grafana/data';
import { AsyncMultiSelect, Icon, Button, useStyles2 } from '@grafana/ui';
import { config } from 'app/core/config';
import { Trans } from 'app/core/internationalization';
import { getBackendSrv } from 'app/core/services/backend_srv';
import { DashboardSearchItemType } from 'app/features/search/types';
import { getGrafanaSearcher } from 'app/features/search/service/searcher';
import { FolderInfo, PermissionLevelString } from 'app/types';
export interface FolderFilterProps {
@ -66,21 +67,47 @@ async function getFoldersAsOptions(
): Promise<Array<SelectableValue<FolderInfo>>> {
setLoading(true);
// Use Unified Storage API behind toggle
if (config.featureToggles.unifiedStorageSearchUI) {
const searcher = getGrafanaSearcher();
const queryResponse = await searcher.search({
query: searchString,
kind: ['folder'],
limit: 100,
permission: PermissionLevelString.View,
});
const options = queryResponse.view.map((item) => ({
label: item.name,
value: { uid: item.uid, title: item.name },
}));
if (!searchString || 'dashboards'.includes(searchString.toLowerCase())) {
options.unshift({ label: 'Dashboards', value: { uid: 'general', title: 'Dashboards' } });
}
setLoading(false);
return options;
}
// Use existing backend service search
const params = {
query: searchString,
type: DashboardSearchItemType.DashFolder,
type: 'folder',
permission: PermissionLevelString.View,
};
// FIXME: stop using id from search and use UID instead
const searchHits = await getBackendSrv().search(params);
const options = searchHits.map((d) => ({ label: d.title, value: { uid: d.uid, title: d.title } }));
const options = searchHits.map((d) => ({
label: d.title,
value: { uid: d.uid, title: d.title },
}));
if (!searchString || 'dashboards'.includes(searchString.toLowerCase())) {
options.unshift({ label: 'Dashboards', value: { uid: 'general', title: 'Dashboards' } });
}
setLoading(false);
return options;
}

View File

@ -267,7 +267,7 @@ export function createFolder(payload: any) {
export const SLICE_FOLDER_RESULTS_TO = 1000;
export function searchFolders(
export async function searchFolders(
query: any,
permission?: PermissionLevelString,
type: SearchQueryType = SearchQueryType.Folder