mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Command Palette: don't register dashboards as actions in the command palette (#61271)
* don't register dashboards as actions in the command palette * create ActionImpls in RenderResults, memoize some array creation * extract dashboard results out into separate hook * remove unnecessary memoization from useActions * move useDashboardResults into dashboardActions
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
import debounce from 'debounce-promise';
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
import { locationUtil } from '@grafana/data';
|
||||
import { locationService } from '@grafana/runtime';
|
||||
import { t } from 'app/core/internationalization';
|
||||
@@ -10,6 +13,8 @@ import { RECENT_DASHBOARDS_PRORITY, SEARCH_RESULTS_PRORITY } from '../values';
|
||||
const MAX_SEARCH_RESULTS = 100;
|
||||
const MAX_RECENT_DASHBOARDS = 5;
|
||||
|
||||
const debouncedDashboardSearch = debounce(getDashboardSearchResultActions, 200);
|
||||
|
||||
export async function getRecentDashboardActions(): Promise<CommandPaletteAction[]> {
|
||||
const recentUids = (await impressionSrv.getDashboardOpened()).slice(0, MAX_RECENT_DASHBOARDS);
|
||||
const resultsDataFrame = await getGrafanaSearcher().search({
|
||||
@@ -70,7 +75,17 @@ export async function getDashboardSearchResultActions(searchQuery: string): Prom
|
||||
return goToDashboardActions;
|
||||
}
|
||||
|
||||
// export default async (parentId: string) => {
|
||||
// const dashboardNav = await getDashboardNav(parentId);
|
||||
// return dashboardNav;
|
||||
// };
|
||||
export function useDashboardResults(searchQuery: string, isShowing: boolean) {
|
||||
const [dashboardResults, setDashboardResults] = useState<CommandPaletteAction[]>([]);
|
||||
|
||||
// Hit dashboards API
|
||||
useEffect(() => {
|
||||
if (isShowing && searchQuery.length > 0) {
|
||||
debouncedDashboardSearch(searchQuery).then((resultActions) => {
|
||||
setDashboardResults(resultActions);
|
||||
});
|
||||
}
|
||||
}, [isShowing, searchQuery]);
|
||||
|
||||
return dashboardResults;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user