From bcc43aa0bc2c424cff3bd9b77f897e1b5960fb58 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Mon, 27 Jun 2022 11:57:37 +0200 Subject: [PATCH] Alerting: adds additional command palette actions (#51393) Co-authored-by: Kristina Durivage --- .../actions/alerting.static.actions.ts | 73 +++++++++++++++++++ .../actions/global.static.actions.ts | 29 ++++---- 2 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 public/app/features/commandPalette/actions/alerting.static.actions.ts diff --git a/public/app/features/commandPalette/actions/alerting.static.actions.ts b/public/app/features/commandPalette/actions/alerting.static.actions.ts new file mode 100644 index 00000000000..d4ceea7e138 --- /dev/null +++ b/public/app/features/commandPalette/actions/alerting.static.actions.ts @@ -0,0 +1,73 @@ +import { Priority } from 'kbar'; + +import { locationService } from '@grafana/runtime'; + +import { NavBarActions } from './global.static.actions'; + +// Grafana Alerting and alerting sub navigation items +const alertingCommandPaletteStaticActions: NavBarActions[] = [ + { + url: '/alerting/list', + actions: [ + { + id: 'go/alerting', + name: 'Go to alerting', + keywords: 'alerting navigate', + perform: () => locationService.push('/alerting'), + section: 'Navigation', + priority: Priority.NORMAL, + }, + ], + }, + { + url: '/alerting/list', + actions: [ + { + id: 'go/alerting/rules', + name: 'Go to alert rules', + keywords: 'alerting navigate rules', + perform: () => locationService.push('/alerting/list'), + section: 'Navigation', + parent: 'go/alerting', + }, + ], + }, + { + url: '/alerting/notifications', + actions: [ + { + id: 'go/alerting/contact-points', + name: 'Go to contact points', + keywords: 'alerting navigate contact-points', + perform: () => locationService.push('/alerting/notifications'), + parent: 'go/alerting', + }, + ], + }, + { + url: '/alerting/routes', + actions: [ + { + id: 'go/alerting/notification-policies', + name: 'Go to notification policies', + keywords: 'alerting navigate notification-policies', + perform: () => locationService.push('/alerting/routes'), + parent: 'go/alerting', + }, + ], + }, + { + url: '/alerting/silences', + actions: [ + { + id: 'go/alerting/silences', + name: 'Go to silences', + keywords: 'alerting navigate silences', + perform: () => locationService.push('/alerting/silences'), + parent: 'go/alerting', + }, + ], + }, +]; + +export { alertingCommandPaletteStaticActions }; diff --git a/public/app/features/commandPalette/actions/global.static.actions.ts b/public/app/features/commandPalette/actions/global.static.actions.ts index 17b3d2a323b..4211a532ac3 100644 --- a/public/app/features/commandPalette/actions/global.static.actions.ts +++ b/public/app/features/commandPalette/actions/global.static.actions.ts @@ -1,8 +1,16 @@ import { Action, Priority } from 'kbar'; +import { flatMapDeep } from 'lodash'; import { NavModelItem } from '@grafana/data'; import { locationService } from '@grafana/runtime'; +import { alertingCommandPaletteStaticActions } from './alerting.static.actions'; + +export interface NavBarActions { + url: string; + actions: Action[]; +} + export default (navBarTree: NavModelItem[]) => { const globalActions: Action[] = [ { @@ -52,7 +60,7 @@ export default (navBarTree: NavModelItem[]) => { // this maps actions to navbar by URL items for showing/hiding // actions is an array for multiple child actions that would be under one navbar item - const navBarActionMap = [ + const navBarActionMap: NavBarActions[] = [ { url: '/dashboard/new', actions: [ @@ -99,19 +107,7 @@ export default (navBarTree: NavModelItem[]) => { }, ], }, - { - url: '/alerting', - actions: [ - { - id: 'go/alerting', - name: 'Go to alerting', - keywords: 'navigate notification', - perform: () => locationService.push('/alerting'), - section: 'Navigation', - priority: Priority.NORMAL, - }, - ], - }, + ...alertingCommandPaletteStaticActions, { url: '/profile', actions: [ @@ -141,9 +137,12 @@ export default (navBarTree: NavModelItem[]) => { ]; const navBarActions: Action[] = []; + const navBarFlatUrls = flatMapDeep(navBarTree, (nbt) => nbt.children) + .map((nbf) => nbf?.url) + .filter((url) => url !== undefined); navBarActionMap.forEach((navBarAction) => { - const navBarItem = navBarTree.find((navBarItem) => navBarItem.url === navBarAction.url); + const navBarItem = navBarFlatUrls.find((url) => navBarAction.url === url); if (navBarItem) { navBarActions.push(...navBarAction.actions); }