Skip to content

Commit

Permalink
allowExternalTarget refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jomarko committed Sep 13, 2024
1 parent fb13967 commit dda9611
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ export function _checkIsValidConnection(
sourceNode: { type?: string; data: DmnDiagramNodeData } | undefined,
targetNode: { type?: string; data: DmnDiagramNodeData } | undefined,
edgeType: string | null | undefined,
allowExternalTarget?: boolean
extraArg?: {
allowExternalTarget: boolean;
}
) {
if (!sourceNode?.type || !targetNode?.type || !edgeType) {
return false;
}

// External nodes cannot be targeted by default
// However there are exceptions, for example adding a waypoint on the edge
if (!allowExternalTarget && targetNode.data.dmnObjectQName.prefix) {
if (!extraArg?.allowExternalTarget && targetNode.data.dmnObjectQName.prefix) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/dmn-editor/src/mutations/addEdge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export function addEdgeTargetingExternalNode({
keepWaypoints: boolean;
existingEdgeId?: string;
}) {
if (!_checkIsValidConnection(sourceNode, targetNode, edge.type, true)) {
if (!_checkIsValidConnection(sourceNode, targetNode, edge.type, { allowExternalTarget: true })) {
throw new Error(`DMN MUTATION: Invalid structure: (${sourceNode.type}) --${edge.type}--> (${targetNode.type}) `);
}

Expand Down

0 comments on commit dda9611

Please sign in to comment.