mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
a0f27caff2
commit
e6c2db82e0
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user