Skip to content

Commit

Permalink
kie-issues#1298: Decision Services & multiple DRDs: make it possible …
Browse files Browse the repository at this point in the history
…o add external Decisions to a Decision Service (apache#2508)

Co-authored-by: Tiago Bento <[email protected]>
Co-authored-by: Tiago Bento <[email protected]>
Co-authored-by: Luiz João Motta <[email protected]>
  • Loading branch information
4 people authored Sep 30, 2024
1 parent 275c07d commit e53f6b5
Show file tree
Hide file tree
Showing 79 changed files with 1,789 additions and 263 deletions.
230 changes: 180 additions & 50 deletions packages/dmn-editor-envelope/src/DmnEditorRoot.tsx

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/dmn-editor/src/DmnEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ export const DmnEditorInternal = ({
</Tab>

<Tab eventKey={DmnEditorTab.INCLUDED_MODELS} title={tabTitle.includedModels}>
{navigationTab === DmnEditorTab.INCLUDED_MODELS && <IncludedModels />}
<div data-testid={"kie-tools--dmn-editor--included-models-container"}>
{navigationTab === DmnEditorTab.INCLUDED_MODELS && <IncludedModels />}
</div>
</Tab>
</Tabs>
</div>
Expand Down
5 changes: 4 additions & 1 deletion packages/dmn-editor/src/autolayout/AutolayoutButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export function AutolayoutButton() {
__readonly_parentNodesById,
__readonly_drdIndex: s.computed(s).getDrdIndex(),
__readonly_dmnObjectNamespace: s.dmn.model.definitions["@_namespace"],
__readonly_externalDmnsIndex: s.computed(s).getExternalModelTypesByNamespace(externalModelsByNamespace).dmns,
__readonly_externalDmnsIndex: s
.computed(s)
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
__readonly_externalModelsByNamespace: externalModelsByNamespace,
});
});
}, [dmnEditorStoreApi, externalModelsByNamespace]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export function BoxedExpressionScreen({ container }: { container: React.RefObjec
const isPropertiesPanelOpen = useDmnEditorStore((s) => s.boxedExpressionEditor.propertiesPanel.isOpen);

const externalDmnsByNamespace = useDmnEditorStore(
(s) => s.computed(s).getExternalModelTypesByNamespace(externalModelsByNamespace).dmns
(s) => s.computed(s).getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns
);
const dataTypesTree = useDmnEditorStore((s) => s.computed(s).getDataTypes(externalModelsByNamespace).dataTypesTree);
const importsByNamespace = useDmnEditorStore((s) => s.computed(s).importsByNamespace());
const externalPmmlsByNamespace = useDmnEditorStore(
(s) => s.computed(s).getExternalModelTypesByNamespace(externalModelsByNamespace).pmmls
(s) => s.computed(s).getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).pmmls
);
const isAlternativeInputDataShape = useDmnEditorStore((s) => s.computed(s).isAlternativeInputDataShape());
const drdIndex = useDmnEditorStore((s) => s.computed(s).getDrdIndex());
Expand Down
42 changes: 28 additions & 14 deletions packages/dmn-editor/src/diagram/Diagram.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
shapeId: targetNode.data.shape["@_id"],
},
keepWaypoints: false,
externalModelsByNamespace,
});
});
},
Expand Down Expand Up @@ -337,6 +338,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
})["@_height"],
},
},
externalModelsByNamespace,
});
state.diagram._selectedNodes = [newNodeId];
state.focus.consumableId = newNodeId;
Expand All @@ -352,7 +354,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
const state = dmnEditorStoreApi.getState();
const externalDmnsIndex = state
.computed(state)
.getExternalModelTypesByNamespace(externalModelsByNamespace).dmns;
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns;

const externalNodeDmn = externalDmnsIndex.get(externalNode.externalDrgElementNamespace);
const externalDrgElement = (externalNodeDmn?.model.definitions.drgElement ?? []).find(
Expand Down Expand Up @@ -429,7 +431,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
__readonly_drdIndex: drdIndex,
__readonly_externalDmnsIndex: dereferencedState
.computed(dereferencedState)
.getExternalModelTypesByNamespace(externalModelsByNamespace).dmns,
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
__readonly_indexedDrd: dereferencedState.computed(dereferencedState).indexedDrd(),
__readonly_indexedDrdContainingDecisionServiceDepiction: indexedDrdContainingDecisionServiceDepiction!,
__readonly_containedDecisionHrefsRelativeToThisDmn: containedDecisionHrefsRelativeToThisDmn,
Expand Down Expand Up @@ -481,7 +483,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
const drdIndex = dereferencedState.computed(dereferencedState).getDrdIndex();
const externalDmnsIndex = dereferencedState
.computed(dereferencedState)
.getExternalModelTypesByNamespace(externalModelsByNamespace).dmns;
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns;

const {
strategyForAddingDecisionServiceToDrd,
Expand Down Expand Up @@ -528,7 +530,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
__readonly_drdIndex: drdIndex,
__readonly_externalDmnsIndex: dereferencedState
.computed(dereferencedState)
.getExternalModelTypesByNamespace(externalModelsByNamespace).dmns,
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
__readonly_indexedDrd: dereferencedState.computed(dereferencedState).indexedDrd(),
__readonly_indexedDrdContainingDecisionServiceDepiction: indexedDrdContainingDecisionServiceDepiction!,
__readonly_containedDecisionHrefsRelativeToThisDmn: containedDecisionHrefsRelativeToThisDmn,
Expand Down Expand Up @@ -670,6 +672,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
})["@_height"],
},
},
externalModelsByNamespace,
});

state.diagram._selectedNodes = [newDmnObejctHref];
Expand Down Expand Up @@ -754,7 +757,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
__readonly_dmnObjectNamespace: node.data.dmnObjectNamespace,
__readonly_externalDmnsIndex: state
.computed(state)
.getExternalModelTypesByNamespace(externalModelsByNamespace).dmns,
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
change: {
isExternal: !!node.data.dmnObjectQName.prefix,
nodeType: node.type as NodeType,
Expand Down Expand Up @@ -872,10 +875,11 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
__readonly_dmnObjectQName: node.data.dmnObjectQName,
__readonly_dmnObjectId: node.data.dmnObject?.["@_id"],
__readonly_nodeNature: nodeNatures[node.type as NodeType],
mode: NodeDeletionMode.FROM_DRG_AND_ALL_DRDS,
__readonly_externalModelTypesByNamespace: state
__readonly_mode: NodeDeletionMode.FROM_DRG_AND_ALL_DRDS,
__readonly_externalDmnsIndex: state
.computed(state)
.getExternalModelTypesByNamespace(externalModelsByNamespace),
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
__readonly_externalModelsByNamespace: externalModelsByNamespace,
});
state.dispatch(state).diagram.setNodeStatus(node.id, {
selected: false,
Expand All @@ -897,7 +901,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
}
});
},
[reactFlowInstance, dmnEditorStoreApi, externalModelsByNamespace]
[dmnEditorStoreApi, externalModelsByNamespace]
);

const resetToBeforeEditingBegan = useCallback(() => {
Expand Down Expand Up @@ -990,8 +994,9 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
for (let i = 0; i < selectedNodes.length; i++) {
deleteDecisionFromDecisionService({
definitions: state.dmn.model.definitions,
decisionId: selectedNodes[i].data.dmnObject!["@_id"]!, // We can assume that all selected nodes are Decisions because the contaiment was validated above.
decisionHref: selectedNodes[i].id, // We can assume that all selected nodes are Decisions because the contaiment was validated above.
decisionServiceId: p.data.dmnObject!["@_id"]!,
externalModelsByNamespace,
});
}
} else {
Expand All @@ -1007,12 +1012,13 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
addDecisionToDecisionService({
definitions: state.dmn.model.definitions,
drdIndex: state.computed(state).getDrdIndex(),
decisionId: selectedNodes[i].data.dmnObject!["@_id"]!, // We can assume that all selected nodes are Decisions because the contaiment was validated above.
decisionHref: selectedNodes[i].id, // We can assume that all selected nodes are Decisions because the contaiment was validated above.
decisionServiceId: state
.computed(state)
.getDiagramData(externalModelsByNamespace)
.nodesById.get(dropTargetNode.id)!.data.dmnObject!["@_id"]!,
snapGrid: state.diagram.snapGrid,
externalModelsByNamespace,
});
}
} else {
Expand All @@ -1026,7 +1032,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
resetToBeforeEditingBegan();
}
},
[dmnEditorStoreApi, externalModelsByNamespace, resetToBeforeEditingBegan]
[dmnEditorStoreApi, externalModelsByNamespace, resetToBeforeEditingBegan, thisDmn.model.definitions]
);

const onEdgesChange = useCallback<RF.OnEdgesChange>(
Expand All @@ -1047,6 +1053,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
drdIndex: state.computed(state).getDrdIndex(),
edge: { id: change.id, dmnObject: edge.data.dmnObject },
mode: EdgeDeletionMode.FROM_DRG_AND_ALL_DRDS,
externalModelsByNamespace,
});
state.dispatch(state).diagram.setEdgeStatus(change.id, {
selected: false,
Expand Down Expand Up @@ -1125,6 +1132,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
shapeId: targetNode.data.shape["@_id"],
},
keepWaypoints: true,
externalModelsByNamespace,
});

// The DMN Edge changed nodes, so we need to delete the old one, but keep the waypoints on the same DRD.
Expand All @@ -1134,6 +1142,7 @@ export const Diagram = React.forwardRef<DiagramRef, { container: React.RefObject
drdIndex: state.computed(state).getDrdIndex(),
edge: { id: oldEdge.id, dmnObject: oldEdge.data!.dmnObject },
mode: EdgeDeletionMode.FROM_DRG_AND_ALL_DRDS,
externalModelsByNamespace,
});

const deletedWaypoints = deletedDmnEdgeOnCurrentDrd?.["di:waypoint"];
Expand Down Expand Up @@ -1380,7 +1389,7 @@ function DmnDiagramWithoutDrd() {

const externalModelTypesByNamespace = dereferencedState
.computed(dereferencedState)
.getExternalModelTypesByNamespace(externalModelsByNamespace);
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace);

autoGenerateDrd({
model: dereferencedState.dmn.model,
Expand Down Expand Up @@ -1434,7 +1443,8 @@ function DmnDiagramWithoutDrd() {
__readonly_dmnObjectNamespace: dereferencedState.dmn.model.definitions["@_namespace"],
__readonly_externalDmnsIndex: dereferencedState
.computed(dereferencedState)
.getExternalModelTypesByNamespace(externalModelsByNamespace).dmns,
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
__readonly_externalModelsByNamespace: externalModelsByNamespace,
});
s.dmn.model = dereferencedState.dmn.model;
});
Expand Down Expand Up @@ -1463,6 +1473,7 @@ function DmnDiagramEmptyState({
isReadOnly?: boolean;
}) {
const dmnEditorStoreApi = useDmnEditorStoreApi();
const { externalModelsByNamespace } = useExternalModels();

return (
<Bullseye
Expand Down Expand Up @@ -1524,6 +1535,7 @@ function DmnDiagramEmptyState({
})["@_height"],
},
},
externalModelsByNamespace,
});

const drgElementIndex = (state.dmn.model.definitions.drgElement ?? []).length - 1;
Expand Down Expand Up @@ -1584,6 +1596,7 @@ function DmnDiagramEmptyState({
type: NODE_TYPES.inputData,
bounds: inputDataNodeBounds,
},
externalModelsByNamespace,
});

const { href: decisionNodeHref } = addConnectedNode({
Expand All @@ -1609,6 +1622,7 @@ function DmnDiagramEmptyState({
})["@_height"],
},
},
externalModelsByNamespace,
});

state.diagram._selectedNodes = [decisionNodeHref];
Expand Down
49 changes: 35 additions & 14 deletions packages/dmn-editor/src/diagram/DiagramCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export function DiagramCommands(props: {}) {
drdIndex: state.computed(state).getDrdIndex(),
edge: { id: edge.id, dmnObject: edge.data!.dmnObject },
mode: EdgeDeletionMode.FROM_DRG_AND_ALL_DRDS,
externalModelsByNamespace,
});
state.dispatch(state).diagram.setEdgeStatus(edge.id, {
selected: false,
Expand All @@ -156,10 +157,11 @@ export function DiagramCommands(props: {}) {
__readonly_dmnObjectQName: node.data.dmnObjectQName,
__readonly_dmnObjectId: node.data.dmnObject?.["@_id"],
__readonly_nodeNature: nodeNatures[node.type as NodeType],
mode: NodeDeletionMode.FROM_DRG_AND_ALL_DRDS,
__readonly_externalModelTypesByNamespace: state
__readonly_mode: NodeDeletionMode.FROM_DRG_AND_ALL_DRDS,
__readonly_externalDmnsIndex: state
.computed(state)
.getExternalModelTypesByNamespace(externalModelsByNamespace),
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
__readonly_externalModelsByNamespace: externalModelsByNamespace,
});
state.dispatch(state).diagram.setNodeStatus(node.id, {
selected: false,
Expand Down Expand Up @@ -239,12 +241,25 @@ export function DiagramCommands(props: {}) {
definitions: state.dmn.model.definitions,
drdIndex: state.computed(state).getDrdIndex(),
});
diagramElements.push(...clipboard.shapes.map((s) => ({ ...s, __$$element: "dmndi:DMNShape" as const })));
diagramElements.push(...clipboard.edges.map((s) => ({ ...s, __$$element: "dmndi:DMNEdge" as const })));
diagramElements.push(
...clipboard.shapes.map((s) => ({
...s,
__$$element: "dmndi:DMNShape" as const,
}))
);
diagramElements.push(
...clipboard.edges.map((s) => ({
...s,
__$$element: "dmndi:DMNEdge" as const,
}))
);

widths.push(...clipboard.widths);

repopulateInputDataAndDecisionsOnAllDecisionServices({ definitions: state.dmn.model.definitions });
repopulateInputDataAndDecisionsOnAllDecisionServices({
definitions: state.dmn.model.definitions,
externalModelsByNamespace,
});

state.diagram._selectedNodes = [...clipboard.drgElements, ...clipboard.artifacts].map((s) =>
buildXmlHref({ id: s["@_id"]! })
Expand All @@ -256,7 +271,7 @@ export function DiagramCommands(props: {}) {
});
});
};
}, [dmnEditorStoreApi, commandsRef]);
}, [dmnEditorStoreApi, commandsRef, externalModelsByNamespace]);

// Select/deselect all nodes
useEffect(() => {
Expand Down Expand Up @@ -317,12 +332,13 @@ export function DiagramCommands(props: {}) {
padding: CONTAINER_NODES_DESIRABLE_PADDING,
}),
},
externalModelsByNamespace,
});

state.dispatch(state).diagram.setNodeStatus(newNodeId, { selected: true });
});
};
}, [dmnEditorStoreApi, commandsRef, rf]);
}, [dmnEditorStoreApi, commandsRef, rf, externalModelsByNamespace]);

// Toggle hierarchy highlights
useEffect(() => {
Expand Down Expand Up @@ -369,7 +385,7 @@ export function DiagramCommands(props: {}) {
canRemoveNodeFromDrdOnly({
__readonly_externalDmnsIndex: state
.computed(state)
.getExternalModelTypesByNamespace(externalModelsByNamespace).dmns,
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
definitions: state.dmn.model.definitions,
__readonly_drdIndex: state.computed(state).getDrdIndex(),
__readonly_dmnObjectNamespace:
Expand All @@ -380,7 +396,7 @@ export function DiagramCommands(props: {}) {
canRemoveNodeFromDrdOnly({
__readonly_externalDmnsIndex: state
.computed(state)
.getExternalModelTypesByNamespace(externalModelsByNamespace).dmns,
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
definitions: state.dmn.model.definitions,
__readonly_drdIndex: state.computed(state).getDrdIndex(),
__readonly_dmnObjectNamespace:
Expand All @@ -393,8 +409,12 @@ export function DiagramCommands(props: {}) {
drdIndex: state.computed(state).getDrdIndex(),
edge: { id: edge.id, dmnObject: edge.data!.dmnObject },
mode: EdgeDeletionMode.FROM_CURRENT_DRD_ONLY,
externalModelsByNamespace,
});
state.dispatch(state).diagram.setEdgeStatus(edge.id, {
selected: false,
draggingWaypoint: false,
});
state.dispatch(state).diagram.setEdgeStatus(edge.id, { selected: false, draggingWaypoint: false });
}
}

Expand All @@ -406,15 +426,16 @@ export function DiagramCommands(props: {}) {
const { deletedDmnShapeOnCurrentDrd: deletedShape } = deleteNode({
definitions: state.dmn.model.definitions,
__readonly_drgEdges: [], // Deleting from DRD only.
__readonly_externalModelTypesByNamespace: state
__readonly_externalDmnsIndex: state
.computed(state)
.getExternalModelTypesByNamespace(externalModelsByNamespace),
.getDirectlyIncludedExternalModelsByNamespace(externalModelsByNamespace).dmns,
__readonly_drdIndex: state.computed(state).getDrdIndex(),
__readonly_dmnObjectNamespace: node.data.dmnObjectNamespace ?? state.dmn.model.definitions["@_namespace"],
__readonly_dmnObjectQName: node.data.dmnObjectQName,
__readonly_dmnObjectId: node.data.dmnObject?.["@_id"],
__readonly_nodeNature: nodeNatures[node.type as NodeType],
mode: NodeDeletionMode.FROM_CURRENT_DRD_ONLY,
__readonly_mode: NodeDeletionMode.FROM_CURRENT_DRD_ONLY,
__readonly_externalModelsByNamespace: externalModelsByNamespace,
});

if (deletedShape) {
Expand Down
Loading

0 comments on commit e53f6b5

Please sign in to comment.