diff --git a/locales/de.json b/locales/de.json index 2f2dc79e..f52624af 100644 --- a/locales/de.json +++ b/locales/de.json @@ -104,5 +104,5 @@ "open-file-for-importing-error": "Die Importfunktion sollte nicht ausgeführt werden, wenn das Hauptfesnter nicht geöffnet ist.", "yes": "Ja", "no": "Nein", - "custom-fields-title-empty-info": "Du hast vergessen den Titel bei einem oder mehreren benutzerdefinierten Feldern anzugeben." + "custom-fields-label-empty-info": "Du hast vergessen den Titel bei einem oder mehreren benutzerdefinierten Feldern anzugeben." } diff --git a/src/renderer/components/tree-view/index.js b/src/renderer/components/tree-view/index.js index 647eb2dc..0fc72931 100644 --- a/src/renderer/components/tree-view/index.js +++ b/src/renderer/components/tree-view/index.js @@ -81,7 +81,7 @@ class TreeView extends Component { } handleRightClick = (node, groups, e) => { - const { id: groupId, isTrash } = node; + const { id: groupId, isTrash, depth } = node; const { intl } = this.props; // Prevent righ click from propagation to parent @@ -98,6 +98,35 @@ class TreeView extends Component { } ]); } else { + const nonRootContextMenu = + depth > 0 + ? [ + { + label: intl.formatMessage({ + id: 'move-to-root', + defaultMessage: 'Move to Root' + }), + click: () => this.props.onMoveGroup(groupId, null) + } + ] + : []; + + const availableGroups = createMenuFromGroups( + groups, + groupId, + selectedGroupId => { + this.props.onMoveGroup(groupId, selectedGroupId); + }, + false + ); + + const groupsMenu = + availableGroups.items.length > 0 + ? { + submenu: availableGroups + } + : {}; + showContextMenu([ { label: intl.formatMessage({ @@ -106,34 +135,22 @@ class TreeView extends Component { }), click: () => this.handleAddClick(null, groupId) }, - { - label: intl.formatMessage({ - id: 'rename', - defaultMessage: 'Rename' - }), - click: () => this.props.onRenameClick(groupId) - }, { type: 'separator' }, + ...nonRootContextMenu, { label: intl.formatMessage({ - id: 'move-to-root', - defaultMessage: 'Move to Root' + id: 'move-to-group', + defaultMessage: 'Move to Group' }), - click: () => this.props.onMoveGroup(groupId, null) + enabled: availableGroups.items, + ...groupsMenu }, { label: intl.formatMessage({ - id: 'move-to-group', - defaultMessage: 'Move to Group' + id: 'rename', + defaultMessage: 'Rename' }), - submenu: createMenuFromGroups( - groups, - groupId, - selectedGroupId => { - this.props.onMoveGroup(groupId, selectedGroupId); - }, - false - ) + click: () => this.props.onRenameClick(groupId) }, { type: 'separator' }, { diff --git a/src/shared/selectors.js b/src/shared/selectors.js index 2cf59232..d2c4a371 100644 --- a/src/shared/selectors.js +++ b/src/shared/selectors.js @@ -95,6 +95,22 @@ export const getGroups = createSelector( (groups, sortMode) => { const trashGroups = groups.filter(g => g.isTrash); const rest = groups.filter(g => !g.isTrash); - return [...sortDeepByKey(rest, sortMode, 'groups'), ...trashGroups]; + + // set depth key in group object + const setGroupDepth = (restGroups, depth = 0) => + Array.isArray(restGroups) && restGroups.length > 0 + ? restGroups.map(group => { + return { + depth, + ...group, + groups: setGroupDepth(group.groups, depth + 1) + }; + }) + : []; + + return [ + ...sortDeepByKey(setGroupDepth(rest), sortMode, 'groups'), + ...trashGroups + ]; } );