Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Correctly display trigger nodes without actions and with related regular node in the "On App Events" category #4976

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 34 additions & 25 deletions packages/editor-ui/src/stores/nodeCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,31 +305,40 @@ export const useNodeCreatorStore = defineStore(STORES.NODE_CREATOR, {
return nodesWithActions;
},
mergedAppNodes(): INodeTypeDescription[] {
const mergedNodes = this.visibleNodesWithActions.reduce(
(acc: Record<string, INodeTypeDescription>, node: INodeTypeDescription) => {
const clonedNode = deepCopy(node);
const isCoreNode = node.codex?.categories?.includes(CORE_NODES_CATEGORY);
const actions = node.actions || [];
// Do not merge core nodes
const normalizedName = isCoreNode
? node.name
: node.name.toLowerCase().replace('trigger', '');
const existingNode = acc[normalizedName];

if (existingNode) existingNode.actions?.push(...actions);
else acc[normalizedName] = clonedNode;

if (!isCoreNode) {
acc[normalizedName].displayName = node.displayName.replace('Trigger', '');
}

acc[normalizedName].actions = filterSinglePlaceholderAction(
acc[normalizedName].actions || [],
);
return acc;
},
{},
);
const mergedNodes = [...this.visibleNodesWithActions]
// Sort triggers so they are always on top and when later get merged
// they won't be disacrded if they have the same name as a core node which doesn't contain actions
.sort((a, b) => {
netroy marked this conversation as resolved.
Show resolved Hide resolved
if (a.group.includes('trigger')) return -1;
if (b.group.includes('trigger')) return 1;

return 0;
})
.reduce(
(acc: Record<string, INodeTypeDescription>, node: INodeTypeDescription) => {
const clonedNode = deepCopy(node);
const isCoreNode = node.codex?.categories?.includes(CORE_NODES_CATEGORY);
const actions = node.actions || [];
// Do not merge core nodes
const normalizedName = isCoreNode
? node.name
: node.name.toLowerCase().replace('trigger', '');
const existingNode = acc[normalizedName];

if (existingNode) existingNode.actions?.push(...actions);
else acc[normalizedName] = clonedNode;

if (!isCoreNode) {
acc[normalizedName].displayName = node.displayName.replace('Trigger', '');
}

acc[normalizedName].actions = filterSinglePlaceholderAction(
acc[normalizedName].actions || [],
);
return acc;
},
{},
);
return Object.values(mergedNodes);
},
getNodeTypesWithManualTrigger:
Expand Down