Skip to content

Commit

Permalink
simplified null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jomarko committed Sep 18, 2024
1 parent b28961d commit 1b7d807
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/dmn-editor/src/diagram/Diagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
const sourceBounds = sourceNode.data.shape["dc:Bounds"];
const targetBounds = targetNode.data.shape["dc:Bounds"];
if (!sourceBounds || !targetBounds) {
throw new Error("Cannot create connection without target bounds!");
throw new Error("Cannot create connection without source and target bounds!");
}

// --------- This is where we draw the line between the diagram and the model.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,9 @@ export function usePotentialWaypointControls(
dmnEditorStoreApi.setState((state) => {
const nodesById = state.computed(state).getDiagramData(externalModelsByNamespace).nodesById;
const edge = state.computed(state).getDiagramData(externalModelsByNamespace).edgesById.get(edgeId);
if (
edge === undefined ||
edge.type === undefined ||
edge.data === undefined ||
edge.data?.dmnShapeSource === undefined ||
edge.data?.dmnShapeTarget == undefined
) {
if (edge === undefined || edge.data?.dmnShapeSource === undefined || edge.data?.dmnShapeTarget == undefined) {
console.debug(
`DMN MUTATION: We can not add DMNEdge for '${edgeId}' edge into diagram. There are missing data edge: ${edge}, edge.type: ${edge?.type}, edge.data: ${edge?.data}`
`DMN MUTATION: We can not add DMNEdge for '${edgeId}' edge into diagram. There are missing data edge: ${edge}, edge.data: ${edge?.data}`
);
return;
}
Expand All @@ -115,19 +109,12 @@ export function usePotentialWaypointControls(
return;
}

const sourceData = nodesById.get(edge.source)?.data;
const sourceType = nodesById.get(edge.source)?.type;
const targetData = nodesById.get(edge.target)?.data;
const targetType = nodesById.get(edge.target)?.type;
const sourceNode = nodesById.get(edge.source);
const targetNode = nodesById.get(edge.target);

if (
sourceData === undefined ||
sourceType === undefined ||
targetData === undefined ||
targetType === undefined
) {
if (sourceNode === undefined || targetNode === undefined) {
console.debug(
`DMN MUTATION: We can not add DMNEdge for '${edgeId}' edge into diagram. There are missing data sourceData: ${sourceData}, sourceType: ${sourceType}, targetData: ${targetData}, targetType: ${targetType}`
`DMN MUTATION: We can not add DMNEdge for '${edgeId}' edge into diagram. There are missing data sourceNode: ${sourceNode}, targetNode: ${targetNode}`
);
return;
}
Expand All @@ -144,22 +131,24 @@ export function usePotentialWaypointControls(
autoPositionedEdgeMarker: undefined,
},
sourceNode: {
type: sourceType as NodeType,
data: sourceData,
type: sourceNode.type as NodeType,
data: sourceNode.data,
href: edge.source,
bounds: edgeSourceBounds,
shapeId: edge.data?.dmnShapeSource["@_id"],
},
targetNode: {
type: targetType as NodeType,
type: targetNode.type as NodeType,
href: edge.target,
data: targetData,
data: targetNode.data,
bounds: edgeTargetBounds,
index: nodesById.get(edge.target)?.data.index ?? 0,
shapeId: edge.data?.dmnShapeTarget["@_id"],
},
keepWaypoints: false,
extraArg: { requirementEdgeTargetingExternalNodeId: targetData.dmnObjectQName.prefix ? edgeId : undefined },
extraArg: {
requirementEdgeTargetingExternalNodeId: targetNode.data.dmnObjectQName.prefix ? edgeId : undefined,
},
});

console.debug(`DMN MUTATION: DMNEdge for '${edgeId}' edge was added into diagram.`);
Expand Down

0 comments on commit 1b7d807

Please sign in to comment.