Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
populate missing node ids and displaynames (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
mariakleiner authored Dec 9, 2022
1 parent 499725d commit bc19e98
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions pkg/Library/NodeGraph/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ connectionDelimiter: ':',

async update(inputs, state) {
const {layout, graph} = inputs;
try {
state.graph = typeof graph === 'string' ? JSON.parse(graph) : graph;
} catch(x) {
state.graph = null;
}
state.graph = this.parseGraph(graph);
state.layout = layout;
const results = this.handleEvents(inputs, state);
return {
Expand All @@ -24,6 +20,23 @@ async update(inputs, state) {
};
},

parseGraph(graph) {
try {
const graphObj = typeof graph === 'string' ? JSON.parse(graph) : graph;
return this.finalizeGraph(graphObj);
} catch(x) {
return null;
}
},

finalizeGraph(graph) {
entries(graph?.nodes).forEach(([id, node]) => {
node.id = id;
node.displayName = node.displayName || node.id;
});
return graph;
},

handleEvents(inputs, state) {
const {event} = inputs;
if (event !== state.event) {
Expand Down

0 comments on commit bc19e98

Please sign in to comment.