dashboard.nav.actions.ts 823 B

1234567891011121314151617181920212223242526
  1. import { Action } from 'kbar';
  2. import { locationUtil } from '@grafana/data';
  3. import { locationService, getBackendSrv } from '@grafana/runtime';
  4. async function getDashboardNav(parentId: string): Promise<Action[]> {
  5. const data: Array<{ type: string; title: string; url: string }> = await getBackendSrv().get('/api/search');
  6. const goToDashboardActions: Action[] = data
  7. .filter((item) => item.type === 'dash-db')
  8. .map((item) => ({
  9. parent: parentId,
  10. id: `go/dashboard/${item.url}`,
  11. name: `Go to dashboard ${item.title}`,
  12. perform: () => {
  13. locationService.push(locationUtil.stripBaseFromUrl(item.url));
  14. },
  15. }));
  16. return goToDashboardActions;
  17. }
  18. export default async (parentId: string) => {
  19. const dashboardNav = await getDashboardNav(parentId);
  20. return dashboardNav;
  21. };