Skip to content

Commit

Permalink
fix(editor): Extend menu item and use it as a recursive component (#6618
Browse files Browse the repository at this point in the history
)
  • Loading branch information
cstuncsik committed Jul 10, 2023
1 parent a95862b commit d617f63
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
42 changes: 20 additions & 22 deletions packages/design-system/src/components/N8nMenuItem/MenuItem.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div :class="['n8n-menu-item', $style.item]">
<el-submenu
v-if="item.children && item.children.length > 0"
v-if="item.children?.length"
:id="item.id"
:class="{
[$style.submenu]: true,
Expand All @@ -21,25 +21,16 @@
/>
<span :class="$style.label">{{ item.label }}</span>
</template>
<el-menu-item
v-for="child in availableChildren"
:key="child.id"
:id="child.id"
:class="{
[$style.menuItem]: true,
[$style.disableActiveStyle]: !isItemActive(child),
[$style.active]: isItemActive(child),
}"
data-test-id="menu-item"
:index="child.id"
@click="onItemClick(child, $event)"
>
<n8n-icon v-if="child.icon" :class="$style.icon" :icon="child.icon" />
<span :class="$style.label">{{ child.label }}</span>
<span v-if="child.secondaryIcon" :class="$style.secondaryIcon">
<n8n-icon :icon="child.secondaryIcon.name" :size="child.secondaryIcon.size || 'small'" />
</span>
</el-menu-item>
<n8n-menu-item
v-for="item in availableChildren"
:key="item.id"
:item="item"
:compact="compact"
:tooltipDelay="tooltipDelay"
:popperClass="popperClass"
:mode="mode"
:activeTab="activeTab"
/>
</el-submenu>
<n8n-tooltip
v-else
Expand Down Expand Up @@ -68,9 +59,16 @@
:size="item.customIconSize || 'large'"
/>
<span :class="$style.label">{{ item.label }}</span>
<span v-if="item.secondaryIcon" :class="$style.secondaryIcon">
<n8n-tooltip
v-if="item.secondaryIcon"
:class="$style.secondaryIcon"
:placement="item.tooltip?.placement || 'right'"
:content="item.tooltip?.content"
:disabled="compact || !item.tooltip?.content || item.tooltip?.bindTo !== 'secondaryIcon'"
:open-delay="tooltipDelay"
>
<n8n-icon :icon="item.secondaryIcon.name" :size="item.secondaryIcon.size || 'small'" />
</span>
</n8n-tooltip>
</el-menu-item>
</n8n-tooltip>
</div>
Expand Down
3 changes: 3 additions & 0 deletions packages/design-system/src/types/menu.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Tooltip } from 'element-ui';

export type IMenuItem = {
id: string;
label: string;
Expand All @@ -14,6 +16,7 @@ export type IMenuItem = {
// For more specific matching, we can use paths
activateOnRoutePaths?: string[];
children?: IMenuItem[];
tooltip?: Tooltip & { bindTo?: 'menuItem' | 'secondaryIcon' };
};

export type ILinkMenuItemProperties = {
Expand Down
27 changes: 17 additions & 10 deletions packages/editor-ui/src/components/MainSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,22 @@ export default defineComponent({
const items: IMenuItem[] = [];
const injectedItems = this.uiStore.sidebarMenuItems;
const workflows: IMenuItem = {
id: 'workflows',
icon: 'network-wired',
label: this.$locale.baseText('mainSidebar.workflows'),
position: 'top',
activateOnRouteNames: [VIEWS.WORKFLOWS],
};
if (this.sourceControlStore.preferences.branchReadOnly) {
workflows.secondaryIcon = { name: 'lock' };
workflows.tooltip = {
content: this.$locale.baseText('mainSidebar.workflows.readOnlyEnv.tooltip'),
bindTo: 'secondaryIcon',
};
}
if (injectedItems && injectedItems.length > 0) {
for (const item of injectedItems) {
items.push({
Expand All @@ -209,16 +225,7 @@ export default defineComponent({
}
const regularItems: IMenuItem[] = [
{
id: 'workflows',
icon: 'network-wired',
secondaryIcon: this.sourceControlStore.preferences.branchReadOnly
? { name: 'lock' }
: undefined,
label: this.$locale.baseText('mainSidebar.workflows'),
position: 'top',
activateOnRouteNames: [VIEWS.WORKFLOWS],
},
workflows,
{
id: 'templates',
icon: 'box-open',
Expand Down
1 change: 1 addition & 0 deletions packages/editor-ui/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@
"mainSidebar.showMessage.stopExecution.title": "Execution stopped",
"mainSidebar.templates": "Templates",
"mainSidebar.workflows": "Workflows",
"mainSidebar.workflows.readOnlyEnv.tooltip": "Protected mode is active, so no workflows changes are allowed. Change this in Settings, under 'Source Control'",
"mainSidebar.executions": "All executions",
"menuActions.duplicate": "Duplicate",
"menuActions.download": "Download",
Expand Down

0 comments on commit d617f63

Please sign in to comment.