From b690ebb234c7acc7dcfbe8aa797df430fad2aae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jos=C3=A9=20dos=20Santos?= Date: Wed, 31 Jul 2024 17:28:16 -0300 Subject: [PATCH 01/32] kie-issues#1298: Decision Services & multiple DRDs: make it possible to add external Decisions to a Decision Service. --- packages/dmn-editor/src/diagram/Diagram.tsx | 6 ++-- .../mutations/addDecisionToDecisionService.ts | 36 +++++++++++++------ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/packages/dmn-editor/src/diagram/Diagram.tsx b/packages/dmn-editor/src/diagram/Diagram.tsx index 5a132532d71..9627f532080 100644 --- a/packages/dmn-editor/src/diagram/Diagram.tsx +++ b/packages/dmn-editor/src/diagram/Diagram.tsx @@ -57,7 +57,7 @@ import { } from "../externalNodes/ExternalNodesPanel"; import { nodeNatures } from "../mutations/NodeNature"; import { addConnectedNode } from "../mutations/addConnectedNode"; -import { addDecisionToDecisionService } from "../mutations/addDecisionToDecisionService"; +import { addDecisionToDecisionService, DrgElement } from "../mutations/addDecisionToDecisionService"; import { addEdge } from "../mutations/addEdge"; import { addShape } from "../mutations/addShape"; import { addStandaloneNode } from "../mutations/addStandaloneNode"; @@ -1009,12 +1009,14 @@ export const Diagram = React.forwardRef + | Normalized<{ __$$element: "businessKnowledgeModel" } & DMN15__tBusinessKnowledgeModel> + | Normalized<{ __$$element: "decisionService" } & DMN15__tDecisionService> + | Normalized<{ __$$element: "inputData" } & DMN15__tInputData> + | Normalized<{ __$$element: "knowledgeSource" } & DMN15__tKnowledgeSource>; export function addDecisionToDecisionService({ definitions, - decisionId, + drgElement, decisionServiceId, drdIndex, snapGrid, + decisionShape, + elementId, }: { definitions: Normalized; - decisionId: string; + drgElement: DrgElement; decisionServiceId: string; drdIndex: number; snapGrid: SnapGrid; + decisionShape: Normalized; + elementId: string; }) { - console.debug(`DMN MUTATION: Adding Decision '${decisionId}' to Decision Service '${decisionServiceId}'`); + console.debug(`DMN MUTATION: Adding Decision '${elementId}' to Decision Service '${decisionServiceId}'`); - const decision = definitions.drgElement?.find((s) => s["@_id"] === decisionId); - if (decision?.__$$element !== "decision") { - throw new Error(`DMN MUTATION: DRG Element with id '${decisionId}' is either not a Decision or doesn't exist.`); + if (drgElement?.__$$element !== "decision") { + throw new Error(`DMN MUTATION: DRG Element with id '${elementId}' is either not a Decision or doesn't exist.`); } const decisionService = definitions.drgElement?.find((s) => s["@_id"] === decisionServiceId); @@ -54,9 +71,6 @@ export function addDecisionToDecisionService({ } const diagram = addOrGetDrd({ definitions, drdIndex }); - const decisionShape = diagram.diagramElements.find( - (s) => s["@_dmnElementRef"] === decisionId && s.__$$element === "dmndi:DMNShape" - ) as Normalized; const decisionServiceShape = diagram.diagramElements.find( (s) => s["@_dmnElementRef"] === decisionServiceId && s.__$$element === "dmndi:DMNShape" @@ -65,10 +79,10 @@ export function addDecisionToDecisionService({ const section = getSectionForDecisionInsideDecisionService({ decisionShape, decisionServiceShape, snapGrid }); if (section === "encapsulated") { decisionService.encapsulatedDecision ??= []; - decisionService.encapsulatedDecision.push({ "@_href": `#${decisionId}` }); + decisionService.encapsulatedDecision.push({ "@_href": `${elementId}` }); } else if (section === "output") { decisionService.outputDecision ??= []; - decisionService.outputDecision.push({ "@_href": `#${decisionId}` }); + decisionService.outputDecision.push({ "@_href": `${elementId}` }); } else { throw new Error(`DMN MUTATION: Invalid section to add decision to: '${section}' `); } From 33de8ea424d1b18f03e58ffe855cf1a8ea740a01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Jos=C3=A9=20dos=20Santos?= Date: Fri, 2 Aug 2024 18:33:56 -0300 Subject: [PATCH 02/32] Tests e2e --- packages/dmn-editor/src/DmnEditor.tsx | 4 +- packages/dmn-editor/src/diagram/Palette.tsx | 6 +- .../src/externalNodes/ExternalNodesPanel.tsx | 1 + .../src/includedModels/IncludedModels.tsx | 6 +- .../stories/dev/DevWebApp.stories.tsx | 7 +- .../EmptyWithAvailableExternalModels.mdx | 10 + ...ptyWithAvailableExternalModels.stories.tsx | 134 +++++++++++ .../availableModelsToInclude.ts | 76 ++++++ .../externalModels.ts | 217 ++++++++++++++++++ .../dmn-editor/tests-e2e/__fixtures__/base.ts | 10 + .../tests-e2e/__fixtures__/includedModels.ts | 54 +++++ .../tests-e2e/__fixtures__/nodes.ts | 16 +- .../tests-e2e/__fixtures__/palette.ts | 15 ++ .../tests-e2e/__fixtures__/stories.ts | 38 +++ ...-included-node-inside-decision-service.png | Bin 0 -> 45507 bytes ...-included-node-inside-decision-service.png | Bin 0 -> 45507 bytes .../drgElements/addIncludedNodes.spec.ts | 76 ++++++ 17 files changed, 660 insertions(+), 10 deletions(-) create mode 100644 packages/dmn-editor/stories/misc/emptyWithAvailableExternalModels/EmptyWithAvailableExternalModels.mdx create mode 100644 packages/dmn-editor/stories/misc/emptyWithAvailableExternalModels/EmptyWithAvailableExternalModels.stories.tsx create mode 100644 packages/dmn-editor/stories/misc/emptyWithAvailableExternalModels/availableModelsToInclude.ts create mode 100644 packages/dmn-editor/stories/misc/emptyWithAvailableExternalModels/externalModels.ts create mode 100644 packages/dmn-editor/tests-e2e/__fixtures__/includedModels.ts create mode 100644 packages/dmn-editor/tests-e2e/__fixtures__/stories.ts create mode 100644 packages/dmn-editor/tests-e2e/__screenshots__/Google-Chrome/drgElements/add-included-node-inside-decision-service.png create mode 100644 packages/dmn-editor/tests-e2e/__screenshots__/chromium/drgElements/add-included-node-inside-decision-service.png create mode 100644 packages/dmn-editor/tests-e2e/drgElements/addIncludedNodes.spec.ts diff --git a/packages/dmn-editor/src/DmnEditor.tsx b/packages/dmn-editor/src/DmnEditor.tsx index 39871faa1af..030d9a97576 100644 --- a/packages/dmn-editor/src/DmnEditor.tsx +++ b/packages/dmn-editor/src/DmnEditor.tsx @@ -392,7 +392,9 @@ export const DmnEditorInternal = ({ - {navigationTab === DmnEditorTab.INCLUDED_MODELS && } +
+ {navigationTab === DmnEditorTab.INCLUDED_MODELS && } +
diff --git a/packages/dmn-editor/src/diagram/Palette.tsx b/packages/dmn-editor/src/diagram/Palette.tsx index 77a7f980b2a..c03dffe7faa 100644 --- a/packages/dmn-editor/src/diagram/Palette.tsx +++ b/packages/dmn-editor/src/diagram/Palette.tsx @@ -245,7 +245,11 @@ export function Palette({ pulse }: { pulse: boolean }) {