[v10.0.x] Command palette: Include help links (#70322)

Command palette: Include help links (#70234)

enrich help node with frontend links

(cherry picked from commit db44ba305e)

Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2023-06-19 12:48:50 +00:00
committed by GitHub
co-authored by Ashley Harrison
parent 080c56b128
commit 77b024bbc3
@@ -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,
};