Alerting: adds additional command palette actions (#51393)
Co-authored-by: Kristina Durivage <kristina.durivage@grafana.com>
This commit is contained in:
co-authored by
Kristina Durivage
parent
26424260ca
commit
bcc43aa0bc
@@ -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 };
|
||||||
@@ -1,8 +1,16 @@
|
|||||||
import { Action, Priority } from 'kbar';
|
import { Action, Priority } from 'kbar';
|
||||||
|
import { flatMapDeep } from 'lodash';
|
||||||
|
|
||||||
import { NavModelItem } from '@grafana/data';
|
import { NavModelItem } from '@grafana/data';
|
||||||
import { locationService } from '@grafana/runtime';
|
import { locationService } from '@grafana/runtime';
|
||||||
|
|
||||||
|
import { alertingCommandPaletteStaticActions } from './alerting.static.actions';
|
||||||
|
|
||||||
|
export interface NavBarActions {
|
||||||
|
url: string;
|
||||||
|
actions: Action[];
|
||||||
|
}
|
||||||
|
|
||||||
export default (navBarTree: NavModelItem[]) => {
|
export default (navBarTree: NavModelItem[]) => {
|
||||||
const globalActions: Action[] = [
|
const globalActions: Action[] = [
|
||||||
{
|
{
|
||||||
@@ -52,7 +60,7 @@ export default (navBarTree: NavModelItem[]) => {
|
|||||||
|
|
||||||
// this maps actions to navbar by URL items for showing/hiding
|
// 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
|
// actions is an array for multiple child actions that would be under one navbar item
|
||||||
const navBarActionMap = [
|
const navBarActionMap: NavBarActions[] = [
|
||||||
{
|
{
|
||||||
url: '/dashboard/new',
|
url: '/dashboard/new',
|
||||||
actions: [
|
actions: [
|
||||||
@@ -99,19 +107,7 @@ export default (navBarTree: NavModelItem[]) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
...alertingCommandPaletteStaticActions,
|
||||||
url: '/alerting',
|
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
id: 'go/alerting',
|
|
||||||
name: 'Go to alerting',
|
|
||||||
keywords: 'navigate notification',
|
|
||||||
perform: () => locationService.push('/alerting'),
|
|
||||||
section: 'Navigation',
|
|
||||||
priority: Priority.NORMAL,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
url: '/profile',
|
url: '/profile',
|
||||||
actions: [
|
actions: [
|
||||||
@@ -141,9 +137,12 @@ export default (navBarTree: NavModelItem[]) => {
|
|||||||
];
|
];
|
||||||
|
|
||||||
const navBarActions: Action[] = [];
|
const navBarActions: Action[] = [];
|
||||||
|
const navBarFlatUrls = flatMapDeep(navBarTree, (nbt) => nbt.children)
|
||||||
|
.map((nbf) => nbf?.url)
|
||||||
|
.filter((url) => url !== undefined);
|
||||||
|
|
||||||
navBarActionMap.forEach((navBarAction) => {
|
navBarActionMap.forEach((navBarAction) => {
|
||||||
const navBarItem = navBarTree.find((navBarItem) => navBarItem.url === navBarAction.url);
|
const navBarItem = navBarFlatUrls.find((url) => navBarAction.url === url);
|
||||||
if (navBarItem) {
|
if (navBarItem) {
|
||||||
navBarActions.push(...navBarAction.actions);
|
navBarActions.push(...navBarAction.actions);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user