Use single forEach instead of multiple filter

This commit is contained in:
Kazuhito Yokoi 2024-01-07 18:40:39 +09:00
parent aaed9882b8
commit 84ed88c8dd

View File

@ -30,12 +30,26 @@ RED.contextMenu = (function () {
const isGroup = hasSelection && selection.nodes.length === 1 && selection.nodes[0].type === 'group'
const canEdit = !RED.workspaces.isLocked()
const canRemoveFromGroup = hasSelection && !!selection.nodes[0].g
const isAllGroups = hasSelection && selection.nodes.filter(n => n.type !== 'group').length === 0
const hasGroup = hasSelection && selection.nodes.filter(n => n.type === 'group').length > 0
const hasDisabledNode = hasSelection && selection.nodes.filter(e => e.d).length > 0;
const hasEnabledNode = hasSelection && selection.nodes.filter(e => !e.d).length > 0;
const hasUnlabeledNode = hasSelection && selection.nodes.filter(e => e.l === false).length > 0;
const hasLabeledNode = hasSelection && selection.nodes.filter(e => e.l || e.l === undefined).length > 0;
let hasGroup, isAllGroups = true, hasDisabledNode, hasEnabledNode, hasLabeledNode, hasUnlabeledNode;
if (hasSelection) {
selection.nodes.forEach(n => {
if (n.type === 'group') {
hasGroup = true;
} else {
isAllGroups = false;
}
if (n.d) {
hasDisabledNode = true;
} else {
hasEnabledNode = true;
}
if (n.l === undefined || n.l) {
hasLabeledNode = true;
} else {
hasUnlabeledNode = true;
}
});
}
const offset = $("#red-ui-workspace-chart").offset()
let addX = options.x - offset.left + $("#red-ui-workspace-chart").scrollLeft()