-
Notifications
You must be signed in to change notification settings - Fork 175
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
kie-issues#886: On the DMN Editor, adding waypoints to edges that don't have a corresponding DMNEdge associated with it should create the DMNEdge and add the waypoint normally #2546
base: main
Are you sure you want to change the base?
Changes from 34 commits
efa4577
8eac192
7a79145
de4b79f
5b1f21f
05c48a2
dc80ddc
94db899
8cfc2f5
eadc55e
b25ca85
babe9a2
c2cbace
632adeb
f650d0a
d95740b
ff2c7fc
77c96e5
fb13967
dda9611
ba8b40d
e3d0b79
4ea5a26
8a2b8eb
411814d
5bad3f8
8b98787
3de7056
b28961d
1b7d807
dd67a91
302ec19
cb56865
63c9187
269d5a5
20ebd51
e5eb1a0
f4207a8
bc8495e
1da182f
4ac0a99
8eaa8b9
6d6cc5b
9be924f
a5044c8
d3fc589
79f64d2
38ce320
006000e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,11 @@ import { snapPoint } from "../SnapGrid"; | |
import { DC__Point } from "@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/ts-gen/types"; | ||
import { DmnDiagramNodeData } from "../nodes/Nodes"; | ||
import { DmnDiagramEdgeData } from "./Edges"; | ||
import { useExternalModels } from "../../includedModels/DmnEditorDependenciesContext"; | ||
import { addEdge } from "../../mutations/addEdge"; | ||
import { EdgeType, NodeType } from "../connections/graphStructure"; | ||
import { PositionalNodeHandleId } from "../connections/PositionalNodeHandles"; | ||
import { getHandlePosition } from "../maths/DmnMaths"; | ||
|
||
export function usePotentialWaypointControls( | ||
waypoints: DC__Point[], | ||
|
@@ -38,6 +43,7 @@ export function usePotentialWaypointControls( | |
const isDraggingWaypoint = useDmnEditorStore((s) => !!s.diagram.draggingWaypoints.find((e) => e === edgeId)); | ||
const dmnEditorStoreApi = useDmnEditorStoreApi(); | ||
const reactFlowInstance = RF.useReactFlow<DmnDiagramNodeData, DmnDiagramEdgeData>(); | ||
const { externalModelsByNamespace } = useExternalModels(); | ||
|
||
const [potentialWaypoint, setPotentialWaypoint] = useState<ReturnType<typeof approximateClosestPoint> | undefined>( | ||
undefined | ||
|
@@ -74,10 +80,81 @@ export function usePotentialWaypointControls( | |
}, [snapGrid, potentialWaypoint]); | ||
|
||
const onDoubleClick = useCallback(() => { | ||
if (!potentialWaypoint || !snappedPotentialWaypoint || edgeIndex === undefined) { | ||
if (!potentialWaypoint || !snappedPotentialWaypoint) { | ||
return; | ||
} | ||
|
||
if (edgeIndex === undefined) { | ||
/** | ||
* This means we are adding a first waypoint to one of following edges: | ||
* - an edge in a non default DRD | ||
* - an edge targeting an external node | ||
*/ | ||
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.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.data: ${edge?.data}` | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a mutation error. Please adjust the logs. |
||
return; | ||
} | ||
const edgeSourceBounds = edge.data?.dmnShapeSource["dc:Bounds"]; | ||
const edgeTargetBounds = edge.data?.dmnShapeTarget["dc:Bounds"]; | ||
|
||
if (edgeSourceBounds === undefined || edgeTargetBounds === undefined) { | ||
tiagobento marked this conversation as resolved.
Show resolved
Hide resolved
jomarko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
console.debug( | ||
`DMN MUTATION: We can not add DMNEdge for '${edgeId}' edge into diagram. There are missing data edgeSourceBounds: ${edgeSourceBounds}, edgeTargetBounds: ${edgeTargetBounds}` | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in a mutation. Please adjust the logs. |
||
return; | ||
} | ||
|
||
const sourceNode = nodesById.get(edge.source); | ||
const targetNode = nodesById.get(edge.target); | ||
|
||
if (sourceNode === undefined || targetNode === undefined) { | ||
console.debug( | ||
`DMN MUTATION: We can not add DMNEdge for '${edgeId}' edge into diagram. There are missing data sourceNode: ${sourceNode}, targetNode: ${targetNode}` | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in a mutation. Please adjust the logs. |
||
return; | ||
} | ||
|
||
const isTargetExternalNode = targetNode.data.dmnObjectQName.prefix !== undefined; | ||
jomarko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
addEdge({ | ||
definitions: state.dmn.model.definitions, | ||
drdIndex: state.computed(state).getDrdIndex(), | ||
edge: { | ||
type: edge.type as EdgeType, | ||
targetHandle: getHandlePosition({ shapeBounds: edgeTargetBounds, waypoint: snappedPotentialWaypoint }) | ||
.handlePosition as PositionalNodeHandleId, | ||
sourceHandle: getHandlePosition({ shapeBounds: edgeSourceBounds, waypoint: snappedPotentialWaypoint }) | ||
.handlePosition as PositionalNodeHandleId, | ||
autoPositionedEdgeMarker: undefined, | ||
}, | ||
sourceNode: { | ||
type: sourceNode.type as NodeType, | ||
data: sourceNode.data, | ||
href: edge.source, | ||
bounds: edgeSourceBounds, | ||
shapeId: edge.data?.dmnShapeSource["@_id"], | ||
}, | ||
targetNode: { | ||
type: targetNode.type as NodeType, | ||
href: edge.target, | ||
data: targetNode.data, | ||
bounds: edgeTargetBounds, | ||
index: nodesById.get(edge.target)?.data.index ?? 0, | ||
shapeId: edge.data?.dmnShapeTarget["@_id"], | ||
}, | ||
keepWaypoints: false, | ||
requirementEdgeTargetingExternalNodeId: isTargetExternalNode ? edgeId : undefined, | ||
}); | ||
|
||
console.debug(`DMN MUTATION: DMNEdge for '${edgeId}' edge was added into diagram.`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not inside a mutation. |
||
}); | ||
} | ||
|
||
if (isExistingWaypoint(snappedPotentialWaypoint)) { | ||
console.debug("Preventing overlapping waypoint creation."); | ||
return; | ||
|
@@ -96,18 +173,27 @@ export function usePotentialWaypointControls( | |
} | ||
|
||
dmnEditorStoreApi.setState((state) => { | ||
const dmnEdgeIndex = state.computed(state).indexedDrd().dmnEdgesByDmnElementRef.get(edgeId)?.index; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth to add a comment here explaining why you're getting |
||
if (dmnEdgeIndex === undefined) { | ||
console.debug(`DMN MUTATION: DMNEdge for '${edgeId}' edge has missing index.`); | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should |
||
addEdgeWaypoint({ | ||
definitions: state.dmn.model.definitions, | ||
drdIndex, | ||
beforeIndex: i - 1, | ||
edgeIndex, | ||
edgeIndex: dmnEdgeIndex, | ||
waypoint: snappedPotentialWaypoint, | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth changing the name of this parameter to |
||
|
||
console.debug(`DMN MUTATION: Waypoint on the DMNEdge for '${edgeId}' edge was added.`); | ||
}); | ||
}, [ | ||
drdIndex, | ||
dmnEditorStoreApi, | ||
edgeId, | ||
edgeIndex, | ||
externalModelsByNamespace, | ||
isExistingWaypoint, | ||
potentialWaypoint, | ||
snappedPotentialWaypoint, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
*/ | ||
|
||
import { switchExpression } from "@kie-tools-core/switch-expression-ts"; | ||
import { DmnBuiltInDataType, generateUuid } from "@kie-tools/boxed-expression-component/dist/api"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been doing that kind of cleanup every time I see it. Nice! |
||
import { generateUuid } from "@kie-tools/boxed-expression-component/dist/api"; | ||
import { DC__Bounds, DMN15__tDefinitions } from "@kie-tools/dmn-marshaller/dist/schemas/dmn-1_5/ts-gen/types"; | ||
import { NodeType } from "../diagram/connections/graphStructure"; | ||
import { NODE_TYPES } from "../diagram/nodes/NodeTypes"; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -140,7 +140,13 @@ export function computeDiagramData( | |||||||||
}; | ||||||||||
|
||||||||||
// requirements | ||||||||||
ackRequirementEdges(definitions["@_namespace"], definitions["@_namespace"], definitions.drgElement, ackEdge); | ||||||||||
ackRequirementEdges( | ||||||||||
definitions, | ||||||||||
definitions["@_namespace"], | ||||||||||
definitions["@_namespace"], | ||||||||||
definitions.drgElement, | ||||||||||
ackEdge | ||||||||||
); | ||||||||||
|
||||||||||
// associations | ||||||||||
(definitions.artifact ?? []).forEach((dmnObject, index) => { | ||||||||||
|
@@ -270,6 +276,7 @@ export function computeDiagramData( | |||||||||
(acc, [namespace, externalDmn]) => { | ||||||||||
// Taking advantage of the loop to add the edges here... | ||||||||||
ackRequirementEdges( | ||||||||||
definitions, | ||||||||||
definitions["@_namespace"], | ||||||||||
externalDmn.model.definitions["@_namespace"], | ||||||||||
externalDmn.model.definitions.drgElement, | ||||||||||
|
@@ -390,6 +397,7 @@ export function computeDiagramData( | |||||||||
} | ||||||||||
|
||||||||||
function ackRequirementEdges( | ||||||||||
definitions: State["dmn"]["model"]["definitions"], | ||||||||||
thisDmnsNamespace: string, | ||||||||||
drgElementsNamespace: string, | ||||||||||
drgElements: Normalized<DMN15__tDefinitions>["drgElement"], | ||||||||||
|
@@ -402,8 +410,13 @@ function ackRequirementEdges( | |||||||||
if (dmnObject.__$$element === "decision") { | ||||||||||
(dmnObject.informationRequirement ?? []).forEach((ir, index) => { | ||||||||||
const irHref = parseXmlHref((ir.requiredDecision ?? ir.requiredInput)!["@_href"]); | ||||||||||
// Search for definitions[`@_xmlns:included${includedIndex}`] that holds proper namespace | ||||||||||
// and store the proper prefix: `included${includedIndex}` value | ||||||||||
const namespaceIncludedPrefix = Object.entries(definitions) | ||||||||||
.find(([key, val]) => val === namespace)?.[0] | ||||||||||
?.replace("@_xmlns:", ""); | ||||||||||
ackEdge({ | ||||||||||
id: ir["@_id"]!, | ||||||||||
id: (namespaceIncludedPrefix ? `${namespaceIncludedPrefix}:` : "") + ir["@_id"]!, | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not
Suggested change
? External nodes are currently using an HREF ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tiagobento thank you for this topic. actually, nodes/shapes, currently uses Applying your suggestion produces xml like attached:
from this discussion my understanding is, I should update the code to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, so let's take a step back. This Now, you're correct to say that it is wrong to have an HREF in the The only place that adds DMNEdges to the XML is the A. See how the B. Hmm... something is not right :) Now, all this is really confusing, because there are multiple ""types"" of
They're all "ids" in some way, so it's really hard to name things properly. Ok, let's go back. I'd say:
And I believe we should rename Let me know if you have questions :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, we have |
||||||||||
dmnObject: { | ||||||||||
namespace: drgElementsNamespace, | ||||||||||
type: dmnObject.__$$element, | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This way, it is clear that
false
is the default for whenextraArg
isundefined
.