Command palette: Include help links (#70234)

enrich help node with frontend links
This commit is contained in:
Ashley Harrison
2023-06-19 13:29:26 +01:00
committed by GitHub
parent 06a4b6da62
commit db44ba305e

View File

@ -1,4 +1,5 @@
import { NavModelItem } from '@grafana/data';
import { enrichHelpItem } from 'app/core/components/AppChrome/MegaMenu/utils';
import { t } from 'app/core/internationalization';
import { changeTheme } from 'app/core/services/theme';
@ -13,11 +14,16 @@ function idForNavItem(navItem: NavModelItem) {
function navTreeToActions(navTree: NavModelItem[], parents: NavModelItem[] = []): CommandPaletteAction[] {
const navActions: CommandPaletteAction[] = [];
for (const navItem of navTree) {
const { url, target, text, isCreateAction, children } = navItem;
for (let navItem of navTree) {
// help node needs enriching with the frontend links
if (navItem.id === 'help') {
navItem = enrichHelpItem({ ...navItem });
delete navItem.url;
}
const { url, target, text, isCreateAction, children, onClick } = navItem;
const hasChildren = Boolean(children?.length);
if (!(url || hasChildren)) {
if (!(url || onClick || hasChildren)) {
continue;
}
@ -28,13 +34,14 @@ function navTreeToActions(navTree: NavModelItem[], parents: NavModelItem[] = [])
const priority = isCreateAction ? ACTIONS_PRIORITY : DEFAULT_PRIORITY;
const subtitle = parents.map((parent) => parent.text).join(' > ');
const action = {
const action: CommandPaletteAction = {
id: idForNavItem(navItem),
name: text,
section: section,
url,
target,
parent: parents.length > 0 && !isCreateAction ? idForNavItem(parents[parents.length - 1]) : undefined,
perform: onClick,
priority: priority,
subtitle: isCreateAction ? undefined : subtitle,
};