diff --git a/public/app/core/components/FolderFilter/FolderFilter.tsx b/public/app/core/components/FolderFilter/FolderFilter.tsx index 12a4be1c3c3..5547a9bec91 100644 --- a/public/app/core/components/FolderFilter/FolderFilter.tsx +++ b/public/app/core/components/FolderFilter/FolderFilter.tsx @@ -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>> { 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; } diff --git a/public/app/features/manage-dashboards/state/actions.ts b/public/app/features/manage-dashboards/state/actions.ts index 60fb84442bb..adab7a4746c 100644 --- a/public/app/features/manage-dashboards/state/actions.ts +++ b/public/app/features/manage-dashboards/state/actions.ts @@ -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