grafana/public/app/features/commandPalette/actions/dashboard.nav.actions.ts
Ryan McKinley c8f814196a
CommandPalette: Populate dashboard search when the palette is opened (#51293)
Co-authored-by: Kristina Durivage <kristina.durivage@grafana.com>
2022-06-24 23:08:29 +02:00

33 lines
919 B
TypeScript

import { Action } from 'kbar';
import { locationUtil } from '@grafana/data';
import { locationService } from '@grafana/runtime';
import { getGrafanaSearcher } from 'app/features/search/service';
async function getDashboardNav(parentId: string): Promise<Action[]> {
const data = await getGrafanaSearcher().search({
kind: ['dashboard'],
query: '*',
limit: 500,
});
const goToDashboardActions: Action[] = data.view.map((item) => {
const { url, name } = item; // items are backed by DataFrameView, so must hold the url in a closure
return {
parent: parentId,
id: `go/dashboard/${url}`,
name: `${name}`,
perform: () => {
locationService.push(locationUtil.stripBaseFromUrl(url));
},
};
});
return goToDashboardActions;
}
export default async (parentId: string) => {
const dashboardNav = await getDashboardNav(parentId);
return dashboardNav;
};