Skip to content

Commit

Permalink
fix(nodetypes): use default when type not found
Browse files Browse the repository at this point in the history
  • Loading branch information
moklick committed Jul 16, 2019
1 parent 53581a8 commit a431148
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/NodeRenderer/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React, { PureComponent } from 'react';

import { Consumer } from '../GraphContext';

class NodeRenderer extends PureComponent {

renderNode(d, onNodeClick) {
const nodeType = d.data.type || 'default';
const NodeComponent = this.props.nodeTypes[nodeType];
if (!this.props.nodeTypes[nodeType]) {
console.warn(`No node type found for type "${nodeType}". Using fallback type "default".`);
}

const NodeComponent = this.props.nodeTypes[nodeType] || this.props.nodeTypes.default;

return (
<NodeComponent
Expand Down
2 changes: 1 addition & 1 deletion src/NodeRenderer/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function createNodeTypes(nodeTypes) {
.keys(nodeTypes)
.filter(k => !['input', 'default', 'output'].includes(k))
.reduce((res, key) => {
res[key] = wrapNode(nodeTypes[key]);
res[key] = wrapNode(nodeTypes[key] || DefaultNode);

return res;
}, {});
Expand Down

0 comments on commit a431148

Please sign in to comment.