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

View File

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