mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 06:12:59 +08:00
Command palette: Include help links (#70234)
enrich help node with frontend links
This commit is contained in:
@ -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,
|
||||
};
|
||||
|
Reference in New Issue
Block a user