Skip to content

Commit

Permalink
Merge pull request buttercup#423 from ph1p/bugfixes/root-folder
Browse files Browse the repository at this point in the history
Fix root folder context menu
  • Loading branch information
perry-mitchell authored Nov 18, 2017
2 parents da13112 + 7e21543 commit 248d986
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
2 changes: 1 addition & 1 deletion locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
59 changes: 38 additions & 21 deletions src/renderer/components/tree-view/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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({
Expand All @@ -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' },
{
Expand Down
18 changes: 17 additions & 1 deletion src/shared/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
}
);

0 comments on commit 248d986

Please sign in to comment.