@pega/cosmos-react-build 3.0.0-dev.2.1 → 3.0.0-dev.20.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/AppHeader/AppHeader.d.ts +4 -2
- package/lib/components/AppHeader/AppHeader.d.ts.map +1 -1
- package/lib/components/AppHeader/AppHeader.js +10 -9
- package/lib/components/AppHeader/AppHeader.js.map +1 -1
- package/lib/components/AppHeader/AppHeader.styles.d.ts +1 -1
- package/lib/components/AppHeader/AppHeader.styles.d.ts.map +1 -1
- package/lib/components/AppHeader/AppHeader.styles.js +5 -19
- package/lib/components/AppHeader/AppHeader.styles.js.map +1 -1
- package/lib/components/AppHeader/BranchButton.d.ts.map +1 -1
- package/lib/components/AppHeader/BranchButton.js +1 -1
- package/lib/components/AppHeader/BranchButton.js.map +1 -1
- package/lib/components/AppShell/AppShell.d.ts +1 -0
- package/lib/components/AppShell/AppShell.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.js +15 -20
- package/lib/components/AppShell/AppShell.js.map +1 -1
- package/lib/components/AppShell/AppShell.styles.d.ts +1 -0
- package/lib/components/AppShell/AppShell.styles.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.styles.js +17 -2
- package/lib/components/AppShell/AppShell.styles.js.map +1 -1
- package/lib/components/AppShell/AppShell.types.d.ts +6 -9
- package/lib/components/AppShell/AppShell.types.d.ts.map +1 -1
- package/lib/components/AppShell/AppShell.types.js.map +1 -1
- package/lib/components/AppShell/AppShellContext.d.ts +1 -0
- package/lib/components/AppShell/AppShellContext.d.ts.map +1 -1
- package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts +9 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.d.ts.map +1 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.js +238 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.js.map +1 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts +23 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.d.ts.map +1 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js +2 -0
- package/lib/components/DynamicContentEditor/DynamicContentEditor.types.js.map +1 -0
- package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts +308 -0
- package/lib/components/DynamicContentEditor/PegaCustomElement.d.ts.map +1 -0
- package/lib/components/DynamicContentEditor/PegaCustomElement.js +23 -0
- package/lib/components/DynamicContentEditor/PegaCustomElement.js.map +1 -0
- package/lib/components/DynamicContentEditor/index.d.ts +3 -0
- package/lib/components/DynamicContentEditor/index.d.ts.map +1 -0
- package/lib/components/DynamicContentEditor/index.js +2 -0
- package/lib/components/DynamicContentEditor/index.js.map +1 -0
- package/lib/components/FlowModeller/AddNode.d.ts +11 -9
- package/lib/components/FlowModeller/AddNode.d.ts.map +1 -1
- package/lib/components/FlowModeller/AddNode.js +9 -3
- package/lib/components/FlowModeller/AddNode.js.map +1 -1
- package/lib/components/FlowModeller/Connector.d.ts +7 -0
- package/lib/components/FlowModeller/Connector.d.ts.map +1 -0
- package/lib/components/FlowModeller/Connector.js +71 -0
- package/lib/components/FlowModeller/Connector.js.map +1 -0
- package/lib/components/FlowModeller/DeletePopover.d.ts +19 -0
- package/lib/components/FlowModeller/DeletePopover.d.ts.map +1 -0
- package/lib/components/FlowModeller/DeletePopover.js +136 -0
- package/lib/components/FlowModeller/DeletePopover.js.map +1 -0
- package/lib/components/FlowModeller/FlowModeller.d.ts +3 -19
- package/lib/components/FlowModeller/FlowModeller.d.ts.map +1 -1
- package/lib/components/FlowModeller/FlowModeller.js +185 -61
- package/lib/components/FlowModeller/FlowModeller.js.map +1 -1
- package/lib/components/FlowModeller/FlowModeller.types.d.ts +25 -0
- package/lib/components/FlowModeller/FlowModeller.types.d.ts.map +1 -0
- package/lib/components/FlowModeller/FlowModeller.types.js +2 -0
- package/lib/components/FlowModeller/FlowModeller.types.js.map +1 -0
- package/lib/components/FlowModeller/FlowModellerContext.d.ts +6 -0
- package/lib/components/FlowModeller/FlowModellerContext.d.ts.map +1 -0
- package/lib/components/FlowModeller/FlowModellerContext.js +7 -0
- package/lib/components/FlowModeller/FlowModellerContext.js.map +1 -0
- package/lib/components/FlowModeller/Node/Node.types.d.ts +22 -9
- package/lib/components/FlowModeller/Node/Node.types.d.ts.map +1 -1
- package/lib/components/FlowModeller/Node/Node.types.js +2 -3
- package/lib/components/FlowModeller/Node/Node.types.js.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.d.ts +7 -4
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.d.ts.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.js +21 -11
- package/lib/components/FlowModeller/Node/NodeTemplate.styles.js.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplates.d.ts +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplates.d.ts.map +1 -1
- package/lib/components/FlowModeller/Node/NodeTemplates.js +42 -18
- package/lib/components/FlowModeller/Node/NodeTemplates.js.map +1 -1
- package/lib/components/FlowModeller/Node.d.ts +5 -0
- package/lib/components/FlowModeller/Node.d.ts.map +1 -0
- package/lib/components/FlowModeller/Node.js +22 -0
- package/lib/components/FlowModeller/Node.js.map +1 -0
- package/lib/components/FlowModeller/Renderer/Renderer.d.ts.map +1 -1
- package/lib/components/FlowModeller/Renderer/Renderer.js +37 -6
- package/lib/components/FlowModeller/Renderer/Renderer.js.map +1 -1
- package/lib/components/FlowModeller/Renderer/Renderer.types.d.ts +9 -9
- package/lib/components/FlowModeller/Renderer/Renderer.types.d.ts.map +1 -1
- package/lib/components/FlowModeller/Renderer/Renderer.types.js.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/Graph.d.ts +8 -3
- package/lib/components/FlowModeller/Renderer/Utils/Graph.d.ts.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/Graph.js +7 -1
- package/lib/components/FlowModeller/Renderer/Utils/Graph.js.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.d.ts +2 -1
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.d.ts.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.js +19 -6
- package/lib/components/FlowModeller/Renderer/Utils/GraphLayout.js.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/GraphTraversal.d.ts +9 -6
- package/lib/components/FlowModeller/Renderer/Utils/GraphTraversal.d.ts.map +1 -1
- package/lib/components/FlowModeller/Renderer/Utils/GraphTraversal.js +23 -3
- package/lib/components/FlowModeller/Renderer/Utils/GraphTraversal.js.map +1 -1
- package/lib/components/FlowModeller/Utils/addNodeUtils.d.ts +17 -0
- package/lib/components/FlowModeller/Utils/addNodeUtils.d.ts.map +1 -0
- package/lib/components/FlowModeller/Utils/{AddNodeUtils.js → addNodeUtils.js} +58 -35
- package/lib/components/FlowModeller/Utils/addNodeUtils.js.map +1 -0
- package/lib/components/FlowModeller/Utils/deleteNodeUtils.d.ts +30 -0
- package/lib/components/FlowModeller/Utils/deleteNodeUtils.d.ts.map +1 -0
- package/lib/components/FlowModeller/Utils/deleteNodeUtils.js +81 -0
- package/lib/components/FlowModeller/Utils/deleteNodeUtils.js.map +1 -0
- package/lib/components/FlowModeller/helper.d.ts +18 -8
- package/lib/components/FlowModeller/helper.d.ts.map +1 -1
- package/lib/components/FlowModeller/helper.js +114 -55
- package/lib/components/FlowModeller/helper.js.map +1 -1
- package/lib/components/FlowModeller/index.d.ts +8 -3
- package/lib/components/FlowModeller/index.d.ts.map +1 -1
- package/lib/components/FlowModeller/index.js +5 -1
- package/lib/components/FlowModeller/index.js.map +1 -1
- package/lib/components/ItemLibrary/ItemLibrary.d.ts +8 -6
- package/lib/components/ItemLibrary/ItemLibrary.d.ts.map +1 -1
- package/lib/components/ItemLibrary/ItemLibrary.js +6 -8
- package/lib/components/ItemLibrary/ItemLibrary.js.map +1 -1
- package/lib/components/LifeCycle/Category.d.ts.map +1 -1
- package/lib/components/LifeCycle/Category.js +17 -13
- package/lib/components/LifeCycle/Category.js.map +1 -1
- package/lib/components/LifeCycle/LifeCycle.d.ts.map +1 -1
- package/lib/components/LifeCycle/LifeCycle.js +2 -3
- package/lib/components/LifeCycle/LifeCycle.js.map +1 -1
- package/lib/components/LifeCycle/LifeCycle.types.d.ts +2 -4
- package/lib/components/LifeCycle/LifeCycle.types.d.ts.map +1 -1
- package/lib/components/LifeCycle/LifeCycle.types.js.map +1 -1
- package/lib/components/LifeCycle/LifeCycleList.d.ts +1 -1
- package/lib/components/LifeCycle/LifeCycleList.d.ts.map +1 -1
- package/lib/components/LifeCycle/LifeCycleList.js +3 -2
- package/lib/components/LifeCycle/LifeCycleList.js.map +1 -1
- package/lib/components/LifeCycle/Stage.d.ts.map +1 -1
- package/lib/components/LifeCycle/Stage.js +8 -17
- package/lib/components/LifeCycle/Stage.js.map +1 -1
- package/lib/components/LifeCycle/Step.d.ts +3 -6
- package/lib/components/LifeCycle/Step.d.ts.map +1 -1
- package/lib/components/LifeCycle/Step.js +20 -42
- package/lib/components/LifeCycle/Step.js.map +1 -1
- package/lib/components/LifeCycle/Task.d.ts +4 -1
- package/lib/components/LifeCycle/Task.d.ts.map +1 -1
- package/lib/components/LifeCycle/Task.js +17 -10
- package/lib/components/LifeCycle/Task.js.map +1 -1
- package/lib/components/LifeCycle/index.d.ts +1 -2
- package/lib/components/LifeCycle/index.d.ts.map +1 -1
- package/lib/components/LifeCycle/index.js.map +1 -1
- package/lib/components/ObjectPreview/ObjectPreview.d.ts +16 -0
- package/lib/components/ObjectPreview/ObjectPreview.d.ts.map +1 -0
- package/lib/components/ObjectPreview/ObjectPreview.js +25 -0
- package/lib/components/ObjectPreview/ObjectPreview.js.map +1 -0
- package/lib/components/ObjectPreview/index.d.ts +3 -0
- package/lib/components/ObjectPreview/index.d.ts.map +1 -0
- package/lib/components/ObjectPreview/index.js +3 -0
- package/lib/components/ObjectPreview/index.js.map +1 -0
- package/lib/components/ObjectSelect/ObjectPicker.d.ts +15 -0
- package/lib/components/ObjectSelect/ObjectPicker.d.ts.map +1 -0
- package/lib/components/ObjectSelect/ObjectPicker.js +36 -0
- package/lib/components/ObjectSelect/ObjectPicker.js.map +1 -0
- package/lib/components/ObjectSelect/ObjectSelect.d.ts +32 -0
- package/lib/components/ObjectSelect/ObjectSelect.d.ts.map +1 -0
- package/lib/components/ObjectSelect/ObjectSelect.js +41 -0
- package/lib/components/ObjectSelect/ObjectSelect.js.map +1 -0
- package/lib/components/ObjectSelect/ObjectSummary.d.ts +24 -0
- package/lib/components/ObjectSelect/ObjectSummary.d.ts.map +1 -0
- package/lib/components/ObjectSelect/ObjectSummary.js +45 -0
- package/lib/components/ObjectSelect/ObjectSummary.js.map +1 -0
- package/lib/components/ObjectSelect/index.d.ts +3 -0
- package/lib/components/ObjectSelect/index.d.ts.map +1 -0
- package/lib/components/ObjectSelect/index.js +2 -0
- package/lib/components/ObjectSelect/index.js.map +1 -0
- package/lib/components/ObjectSelect/useCreateModal.d.ts +34 -0
- package/lib/components/ObjectSelect/useCreateModal.d.ts.map +1 -0
- package/lib/components/ObjectSelect/useCreateModal.js +61 -0
- package/lib/components/ObjectSelect/useCreateModal.js.map +1 -0
- package/lib/components/PageTemplates/GalleryPage.js +4 -4
- package/lib/components/PageTemplates/GalleryPage.js.map +1 -1
- package/lib/components/PageTemplates/PageTemplates.d.ts +3 -3
- package/lib/components/PageTemplates/PageTemplates.d.ts.map +1 -1
- package/lib/components/PageTemplates/PageTemplates.js +45 -37
- package/lib/components/PageTemplates/PageTemplates.js.map +1 -1
- package/lib/components/SummaryCard/SummaryCard.d.ts +2 -3
- package/lib/components/SummaryCard/SummaryCard.d.ts.map +1 -1
- package/lib/components/SummaryCard/SummaryCard.js +3 -4
- package/lib/components/SummaryCard/SummaryCard.js.map +1 -1
- package/lib/components/Workbench/ConfigurationPanel.d.ts.map +1 -1
- package/lib/components/Workbench/ConfigurationPanel.js +2 -3
- package/lib/components/Workbench/ConfigurationPanel.js.map +1 -1
- package/lib/components/Workbench/Toolbar.d.ts +1 -5
- package/lib/components/Workbench/Toolbar.d.ts.map +1 -1
- package/lib/components/Workbench/Toolbar.js +8 -8
- package/lib/components/Workbench/Toolbar.js.map +1 -1
- package/lib/components/Workbench/UtilityPanel.js +1 -1
- package/lib/components/Workbench/UtilityPanel.js.map +1 -1
- package/lib/components/Workbench/Workbench.d.ts.map +1 -1
- package/lib/components/Workbench/Workbench.js +3 -4
- package/lib/components/Workbench/Workbench.js.map +1 -1
- package/lib/components/Workbench/Workbench.styles.d.ts +1 -1
- package/lib/components/Workbench/Workbench.styles.d.ts.map +1 -1
- package/lib/components/Workbench/Workbench.styles.js +12 -17
- package/lib/components/Workbench/Workbench.styles.js.map +1 -1
- package/lib/components/Workbench/Workbench.types.d.ts +0 -2
- package/lib/components/Workbench/Workbench.types.d.ts.map +1 -1
- package/lib/components/Workbench/Workbench.types.js.map +1 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -1
- package/lib/index.js.map +1 -1
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/utils.d.ts +14 -0
- package/lib/utils/utils.d.ts.map +1 -0
- package/lib/utils/utils.js +13 -0
- package/lib/utils/utils.js.map +1 -0
- package/package.json +21 -14
- package/lib/components/FlowModeller/Renderer/Connectors.d.ts +0 -13
- package/lib/components/FlowModeller/Renderer/Connectors.d.ts.map +0 -1
- package/lib/components/FlowModeller/Renderer/Connectors.js +0 -47
- package/lib/components/FlowModeller/Renderer/Connectors.js.map +0 -1
- package/lib/components/FlowModeller/Renderer/Nodes.d.ts +0 -9
- package/lib/components/FlowModeller/Renderer/Nodes.d.ts.map +0 -1
- package/lib/components/FlowModeller/Renderer/Nodes.js +0 -25
- package/lib/components/FlowModeller/Renderer/Nodes.js.map +0 -1
- package/lib/components/FlowModeller/Utils/AddNodeUtils.d.ts +0 -16
- package/lib/components/FlowModeller/Utils/AddNodeUtils.d.ts.map +0 -1
- package/lib/components/FlowModeller/Utils/AddNodeUtils.js.map +0 -1
- package/lib/components/Visual/Visual.d.ts +0 -17
- package/lib/components/Visual/Visual.d.ts.map +0 -1
- package/lib/components/Visual/Visual.js +0 -28
- package/lib/components/Visual/Visual.js.map +0 -1
- package/lib/components/Visual/index.d.ts +0 -3
- package/lib/components/Visual/index.d.ts.map +0 -1
- package/lib/components/Visual/index.js +0 -3
- package/lib/components/Visual/index.js.map +0 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect, forwardRef } from 'react';
|
|
3
|
+
import styled from 'styled-components';
|
|
4
|
+
import { Button, Select, Option, Text, Flex, useI18n, Icon, Popover } from '@pega/cosmos-react-core';
|
|
5
|
+
import { DirectedGraph } from './Renderer/Utils/Graph';
|
|
6
|
+
import deleteNodeUtils from './Utils/deleteNodeUtils';
|
|
7
|
+
export const StyledDeletePopover = styled(Popover) `
|
|
8
|
+
max-width: 25rem;
|
|
9
|
+
`;
|
|
10
|
+
const DeletePopover = forwardRef(({ show, target, flowGraphData, rendererGraphData, nodeId, onChange, onSubmit, onCancel }, ref) => {
|
|
11
|
+
const [currentSelection, setCurrentSelection] = useState(0);
|
|
12
|
+
const t = useI18n();
|
|
13
|
+
const graph = new DirectedGraph(rendererGraphData);
|
|
14
|
+
const deleteOptionsResult = deleteNodeUtils.getDeleteNodeOptions(graph, nodeId);
|
|
15
|
+
const deleteOptions = deleteOptionsResult.options;
|
|
16
|
+
const nodeType = graph.getNode(nodeId).type.name;
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (deleteOptionsResult) {
|
|
19
|
+
const itemsToDelete = nodeType !== 'Decision'
|
|
20
|
+
? deleteOptionsResult.allItems
|
|
21
|
+
: deleteOptions[currentSelection].restItems;
|
|
22
|
+
// add the actual node to be deleted also, to the list
|
|
23
|
+
itemsToDelete.nodes[nodeId] = graph.getNode(nodeId);
|
|
24
|
+
onChange?.(itemsToDelete, deleteOptions[currentSelection].pathItems);
|
|
25
|
+
}
|
|
26
|
+
}, [rendererGraphData]);
|
|
27
|
+
const onChangeHandler = (ev) => {
|
|
28
|
+
const newSelection = ev.target.selectedIndex >= deleteOptions.length ? -1 : ev.target.selectedIndex;
|
|
29
|
+
setCurrentSelection(newSelection);
|
|
30
|
+
let itemsToDelete;
|
|
31
|
+
if (deleteOptionsResult)
|
|
32
|
+
itemsToDelete = deleteOptionsResult.allItems;
|
|
33
|
+
let itemsToRetain;
|
|
34
|
+
if (newSelection !== -1) {
|
|
35
|
+
itemsToDelete = deleteOptions[newSelection].restItems;
|
|
36
|
+
itemsToRetain = deleteOptions[newSelection].pathItems;
|
|
37
|
+
}
|
|
38
|
+
// add the actual node to be deleted also, to the list
|
|
39
|
+
if (itemsToDelete)
|
|
40
|
+
itemsToDelete.nodes[nodeId] = graph.getNode(nodeId);
|
|
41
|
+
if (itemsToDelete)
|
|
42
|
+
onChange?.(itemsToDelete, itemsToRetain, ev);
|
|
43
|
+
};
|
|
44
|
+
const submitHandler = (ev) => {
|
|
45
|
+
let error = true;
|
|
46
|
+
const finalGraph = new DirectedGraph(flowGraphData);
|
|
47
|
+
const finalDeleteOptionsResult = deleteNodeUtils.getDeleteNodeOptions(finalGraph, nodeId);
|
|
48
|
+
let newTargetNode = finalDeleteOptionsResult?.destinationNodeId
|
|
49
|
+
? finalGraph.getNode(finalDeleteOptionsResult.destinationNodeId)
|
|
50
|
+
: undefined;
|
|
51
|
+
let itemsToDelete = finalDeleteOptionsResult.allItems;
|
|
52
|
+
const selectedOption = currentSelection === -1 || nodeType !== 'Decision'
|
|
53
|
+
? undefined
|
|
54
|
+
: finalDeleteOptionsResult?.options[currentSelection];
|
|
55
|
+
let finalMetaData = selectedOption;
|
|
56
|
+
if (selectedOption) {
|
|
57
|
+
const pathConnectors = selectedOption.pathItems.connectors;
|
|
58
|
+
const connectors = Object.keys(pathConnectors);
|
|
59
|
+
for (let i = 0; i < connectors.length; i += 1) {
|
|
60
|
+
const connectorData = pathConnectors[connectors[i]];
|
|
61
|
+
if (connectorData &&
|
|
62
|
+
finalGraph.getNode(connectorData.fromNodeId).type?.minConnectors !== 0 &&
|
|
63
|
+
connectorData.toNodeId === finalDeleteOptionsResult.destinationNodeId) {
|
|
64
|
+
error = false;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (error) {
|
|
69
|
+
onSubmit?.({
|
|
70
|
+
graphData: {
|
|
71
|
+
nodes: [],
|
|
72
|
+
connectors: []
|
|
73
|
+
},
|
|
74
|
+
updates: {
|
|
75
|
+
connectors: []
|
|
76
|
+
},
|
|
77
|
+
deletes: { nodes: {}, connectors: {} },
|
|
78
|
+
error: true
|
|
79
|
+
}, ev);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
finalMetaData = finalDeleteOptionsResult.options.find(current => selectedOption.connector.id === current.connector.id);
|
|
83
|
+
if (finalMetaData) {
|
|
84
|
+
// get the ref of the first node of the retaining path
|
|
85
|
+
newTargetNode = finalGraph.getNode(finalMetaData.connector.toNodeId);
|
|
86
|
+
itemsToDelete = finalMetaData.restItems;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// get the in-connectors of the selected node
|
|
90
|
+
const nodeInConnectors = finalGraph.getInConnectors(nodeId);
|
|
91
|
+
// iterate and set the targetNode to the above first node instead of the selected node.
|
|
92
|
+
nodeInConnectors.forEach(con => {
|
|
93
|
+
finalGraph.setConnector(con.id, {
|
|
94
|
+
toNodeId: newTargetNode ? newTargetNode.id : undefined
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
const resultGraphData = finalGraph.getGraphData();
|
|
98
|
+
itemsToDelete.nodes[nodeId] = finalGraph.getNode(nodeId);
|
|
99
|
+
// filter the highlighted nodes, including the selected node
|
|
100
|
+
const nodes = resultGraphData.nodes.filter(item => {
|
|
101
|
+
return itemsToDelete.nodes[item.id] === undefined;
|
|
102
|
+
});
|
|
103
|
+
if (finalMetaData) {
|
|
104
|
+
itemsToDelete.connectors[finalMetaData.connector.id] = finalMetaData.connector;
|
|
105
|
+
}
|
|
106
|
+
// filter the highlighted connectors
|
|
107
|
+
const connectors = resultGraphData.connectors.filter(item => {
|
|
108
|
+
return itemsToDelete.connectors[item.id] === undefined;
|
|
109
|
+
});
|
|
110
|
+
const outcome = {
|
|
111
|
+
graphData: {
|
|
112
|
+
nodes: nodes,
|
|
113
|
+
connectors
|
|
114
|
+
},
|
|
115
|
+
updates: {
|
|
116
|
+
connectors: nodeInConnectors
|
|
117
|
+
},
|
|
118
|
+
deletes: itemsToDelete,
|
|
119
|
+
error: false
|
|
120
|
+
};
|
|
121
|
+
onSubmit?.(outcome, ev);
|
|
122
|
+
};
|
|
123
|
+
const onCancelHandler = () => {
|
|
124
|
+
onCancel?.();
|
|
125
|
+
};
|
|
126
|
+
return (_jsx(StyledDeletePopover, { show: show, target: target, placement: 'right-end', ref: ref, modifiers: [
|
|
127
|
+
{
|
|
128
|
+
name: 'offset',
|
|
129
|
+
options: { offset: [0, 8] }
|
|
130
|
+
}
|
|
131
|
+
], children: _jsxs(Flex, { container: { gap: 2, pad: 2, direction: 'column' }, children: [_jsxs(Flex, { container: { alignItems: 'center', justify: 'between' }, children: [_jsx(Text, { variant: 'h4', children: t('delete_step_title') }), _jsx(Button, { variant: 'simple', icon: true, label: t('close'), onClick: onCancelHandler, children: _jsx(Icon, { name: 'times' }) })] }), nodeType === 'Decision' ? (_jsxs(_Fragment, { children: [_jsx(Text, { children: t('delete_decision_step') }), _jsxs(Select, { id: 'select-demo', label: t('delete_step_outcome'), required: true, onChange: onChangeHandler, children: [deleteOptions.map((item, index) => {
|
|
132
|
+
return (_jsx(Option, { selected: currentSelection === index, children: item.connector.label ? item.connector.label : item.connector.id }, item.connector.id));
|
|
133
|
+
}), _jsx(Option, { selected: currentSelection === -1, children: t('delete_all_outcomes') }, 'none')] })] })) : (_jsx(Text, { children: t('delete_step') })), _jsxs(Flex, { container: { direction: 'row', justify: 'between' }, children: [_jsx(Button, { onClick: onCancelHandler, children: t('cancel') }), _jsx(Button, { variant: 'primary', onClick: submitHandler, children: t('delete') })] })] }) }));
|
|
134
|
+
});
|
|
135
|
+
export default DeletePopover;
|
|
136
|
+
//# sourceMappingURL=DeletePopover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeletePopover.js","sourceRoot":"","sources":["../../../src/components/FlowModeller/DeletePopover.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAmC,SAAS,EAAE,UAAU,EAAO,MAAM,OAAO,CAAC;AAC9F,OAAO,MAAM,MAAM,mBAAmB,CAAC;AAEvC,OAAO,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,OAAO,EAER,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,aAAa,EAAa,MAAM,wBAAwB,CAAC;AAClE,OAAO,eAIN,MAAM,yBAAyB,CAAC;AAmBjC,MAAM,CAAC,MAAM,mBAAmB,GAAG,MAAM,CAAC,OAAO,CAAC,CAAA;;CAEjD,CAAC;AAEF,MAAM,aAAa,GAAG,UAAU,CAC9B,CACE,EACE,IAAI,EACJ,MAAM,EACN,aAAa,EACb,iBAAiB,EACjB,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,QAAQ,EACe,EACzB,GAAkC,EAClC,EAAE;IACF,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAAS,CAAC,CAAC,CAAC;IAEpE,MAAM,CAAC,GAAG,OAAO,EAAE,CAAC;IAEpB,MAAM,KAAK,GAAG,IAAI,aAAa,CAAC,iBAAiB,CAAC,CAAC;IAEnD,MAAM,mBAAmB,GAAG,eAAe,CAAC,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC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MAAM,IAAC,OAAO,EAAE,eAAe,YAAG,CAAC,CAAC,QAAQ,CAAC,GAAU,EACxD,KAAC,MAAM,IAAC,OAAO,EAAC,SAAS,EAAC,OAAO,EAAE,aAAa,YAC7C,CAAC,CAAC,QAAQ,CAAC,GACL,IACJ,IACF,GACa,CACvB,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC","sourcesContent":["import { useState, ChangeEventHandler, ChangeEvent, useEffect, forwardRef, Ref } from 'react';\nimport styled from 'styled-components';\n\nimport {\n Button,\n Select,\n Option,\n Text,\n Flex,\n useI18n,\n Icon,\n Popover,\n PopoverProps\n} from '@pega/cosmos-react-core';\n\nimport { DirectedGraph, GraphData } from './Renderer/Utils/Graph';\nimport deleteNodeUtils, {\n GraphDataAsMap,\n DeleteNodeOutcome,\n DeleteNodeModalOption\n} from './Utils/deleteNodeUtils';\nimport { NodeProps } from './Node/Node.types';\n\nexport interface DeleteNodePopoverProps {\n show: boolean;\n target: PopoverProps['target'];\n flowGraphData: GraphData;\n rendererGraphData: GraphData;\n nodeId: string;\n onChange?: (\n itemsToDelete: GraphDataAsMap,\n itemsToRetain: GraphDataAsMap | undefined,\n ev?: ChangeEvent\n ) => void;\n ref?: Ref<HTMLDivElement>;\n onSubmit?: (outcome: DeleteNodeOutcome, ev: Event) => void;\n onCancel?: () => void;\n}\n\nexport const StyledDeletePopover = styled(Popover)`\n max-width: 25rem;\n`;\n\nconst DeletePopover = forwardRef(\n (\n {\n show,\n target,\n flowGraphData,\n rendererGraphData,\n nodeId,\n onChange,\n onSubmit,\n onCancel\n }: DeleteNodePopoverProps,\n ref: DeleteNodePopoverProps['ref']\n ) => {\n const [currentSelection, setCurrentSelection] = useState<number>(0);\n\n const t = useI18n();\n\n const graph = new DirectedGraph(rendererGraphData);\n\n const deleteOptionsResult = deleteNodeUtils.getDeleteNodeOptions(graph, nodeId);\n\n const deleteOptions: DeleteNodeModalOption[] = deleteOptionsResult.options;\n const nodeType = (graph.getNode(nodeId) as NodeProps).type.name;\n\n useEffect(() => {\n if (deleteOptionsResult) {\n const itemsToDelete: GraphDataAsMap =\n nodeType !== 'Decision'\n ? deleteOptionsResult.allItems\n : deleteOptions[currentSelection].restItems;\n\n // add the actual node to be deleted also, to the list\n itemsToDelete.nodes[nodeId] = graph.getNode(nodeId);\n\n onChange?.(itemsToDelete, deleteOptions[currentSelection].pathItems);\n }\n }, [rendererGraphData]);\n\n const onChangeHandler: ChangeEventHandler = (ev: ChangeEvent<HTMLSelectElement>) => {\n const newSelection =\n ev.target.selectedIndex >= deleteOptions.length ? -1 : ev.target.selectedIndex;\n\n setCurrentSelection(newSelection);\n\n let itemsToDelete;\n if (deleteOptionsResult) itemsToDelete = deleteOptionsResult.allItems;\n\n let itemsToRetain;\n\n if (newSelection !== -1) {\n itemsToDelete = deleteOptions[newSelection].restItems;\n itemsToRetain = deleteOptions[newSelection].pathItems;\n }\n\n // add the actual node to be deleted also, to the list\n if (itemsToDelete) itemsToDelete.nodes[nodeId] = graph.getNode(nodeId);\n\n if (itemsToDelete) onChange?.(itemsToDelete, itemsToRetain, ev);\n };\n\n const submitHandler = (ev: Event) => {\n let error = true;\n const finalGraph = new DirectedGraph(flowGraphData);\n const finalDeleteOptionsResult = deleteNodeUtils.getDeleteNodeOptions(finalGraph, nodeId);\n\n let newTargetNode = finalDeleteOptionsResult?.destinationNodeId\n ? finalGraph.getNode(finalDeleteOptionsResult.destinationNodeId)\n : undefined;\n let itemsToDelete = finalDeleteOptionsResult.allItems;\n\n const selectedOption =\n currentSelection === -1 || nodeType !== 'Decision'\n ? undefined\n : finalDeleteOptionsResult?.options[currentSelection];\n let finalMetaData = selectedOption;\n\n if (selectedOption) {\n const pathConnectors = selectedOption.pathItems.connectors;\n const connectors = Object.keys(pathConnectors);\n for (let i = 0; i < connectors.length; i += 1) {\n const connectorData = pathConnectors[connectors[i]];\n if (\n connectorData &&\n finalGraph.getNode(connectorData.fromNodeId).type?.minConnectors !== 0 &&\n connectorData.toNodeId === finalDeleteOptionsResult.destinationNodeId\n ) {\n error = false;\n break;\n }\n }\n if (error) {\n onSubmit?.(\n {\n graphData: {\n nodes: [],\n connectors: []\n },\n updates: {\n connectors: []\n },\n deletes: { nodes: {}, connectors: {} },\n error: true\n },\n ev\n );\n return;\n }\n\n finalMetaData = finalDeleteOptionsResult.options.find(\n current => selectedOption.connector.id === current.connector.id\n );\n\n if (finalMetaData) {\n // get the ref of the first node of the retaining path\n newTargetNode = finalGraph.getNode(finalMetaData.connector.toNodeId);\n itemsToDelete = finalMetaData.restItems;\n }\n }\n\n // get the in-connectors of the selected node\n const nodeInConnectors = finalGraph.getInConnectors(nodeId);\n\n // iterate and set the targetNode to the above first node instead of the selected node.\n\n nodeInConnectors.forEach(con => {\n finalGraph.setConnector(con.id, {\n toNodeId: newTargetNode ? newTargetNode.id : undefined\n });\n });\n\n const resultGraphData = finalGraph.getGraphData();\n\n itemsToDelete.nodes[nodeId] = finalGraph.getNode(nodeId);\n\n // filter the highlighted nodes, including the selected node\n const nodes = resultGraphData.nodes.filter(item => {\n return itemsToDelete.nodes[item.id] === undefined;\n });\n\n if (finalMetaData) {\n itemsToDelete.connectors[finalMetaData.connector.id] = finalMetaData.connector;\n }\n\n // filter the highlighted connectors\n const connectors = resultGraphData.connectors.filter(item => {\n return itemsToDelete.connectors[item.id] === undefined;\n });\n\n const outcome: DeleteNodeOutcome = {\n graphData: {\n nodes: nodes as NodeProps[],\n connectors\n },\n updates: {\n connectors: nodeInConnectors\n },\n deletes: itemsToDelete,\n error: false\n };\n onSubmit?.(outcome, ev);\n };\n\n const onCancelHandler = () => {\n onCancel?.();\n };\n\n return (\n <StyledDeletePopover\n show={show}\n target={target}\n placement='right-end'\n ref={ref}\n modifiers={[\n {\n name: 'offset',\n options: { offset: [0, 8] }\n }\n ]}\n >\n <Flex container={{ gap: 2, pad: 2, direction: 'column' }}>\n <Flex container={{ alignItems: 'center', justify: 'between' }}>\n <Text variant='h4'>{t('delete_step_title')}</Text>\n <Button variant='simple' icon label={t('close')} onClick={onCancelHandler}>\n <Icon name='times' />\n </Button>\n </Flex>\n {nodeType === 'Decision' ? (\n <>\n <Text>{t('delete_decision_step')}</Text>\n <Select\n id='select-demo'\n label={t('delete_step_outcome')}\n required\n onChange={onChangeHandler}\n >\n {deleteOptions.map((item, index) => {\n return (\n <Option key={item.connector.id} selected={currentSelection === index}>\n {item.connector.label ? item.connector.label : item.connector.id}\n </Option>\n );\n })}\n\n <Option key='none' selected={currentSelection === -1}>\n {t('delete_all_outcomes')}\n </Option>\n </Select>\n </>\n ) : (\n <Text>{t('delete_step')}</Text>\n )}\n\n <Flex container={{ direction: 'row', justify: 'between' }}>\n <Button onClick={onCancelHandler}>{t('cancel')}</Button>\n <Button variant='primary' onClick={submitHandler}>\n {t('delete')}\n </Button>\n </Flex>\n </Flex>\n </StyledDeletePopover>\n );\n }\n);\n\nexport default DeletePopover;\n"]}
|
|
@@ -1,21 +1,5 @@
|
|
|
1
|
-
import { PropsWithoutRef
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { AddNodeHandlerParams } from './Renderer/Renderer.types';
|
|
5
|
-
import { ActionParams, NodeProps, NodeLibraryItem, NodeType } from './Node/Node.types';
|
|
6
|
-
export interface FlowModellerProps {
|
|
7
|
-
graphData: GraphData<NodeProps, ConnectorProps>;
|
|
8
|
-
/** Node actions */
|
|
9
|
-
actions?: Action[];
|
|
10
|
-
/** Callback to add node from connector */
|
|
11
|
-
onNodeAdd: (nodeType: NodeType, params: AddNodeHandlerParams) => void;
|
|
12
|
-
/** Callback for handling the click on the node */
|
|
13
|
-
onNodeClick?: (nodeId: string) => void;
|
|
14
|
-
/** Callback for actions on Node */
|
|
15
|
-
onNodeActionClick?: (param: ActionParams, e: MouseEvent) => void;
|
|
16
|
-
/** Types of nodes */
|
|
17
|
-
nodeLibrary: NodeLibraryItem[];
|
|
18
|
-
}
|
|
19
|
-
declare const FlowModeller: ({ graphData, onNodeActionClick, onNodeClick, onNodeAdd, nodeLibrary, actions }: PropsWithoutRef<FlowModellerProps>) => JSX.Element;
|
|
1
|
+
import { PropsWithoutRef } from 'react';
|
|
2
|
+
import { FlowModellerProps } from './FlowModeller.types';
|
|
3
|
+
declare const FlowModeller: ({ graphData, highlightData, onNodeActionClick, onNodeAdd, nodeLibrary, onNodeClick, onDelete, actions, readOnly }: PropsWithoutRef<FlowModellerProps>) => JSX.Element;
|
|
20
4
|
export default FlowModeller;
|
|
21
5
|
//# sourceMappingURL=FlowModeller.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FlowModeller.d.ts","sourceRoot":"","sources":["../../../src/components/FlowModeller/FlowModeller.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,
|
|
1
|
+
{"version":3,"file":"FlowModeller.d.ts","sourceRoot":"","sources":["../../../src/components/FlowModeller/FlowModeller.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EAQhB,MAAM,OAAO,CAAC;AA+Bf,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAsFzD,QAAA,MAAM,YAAY,sHAUf,gBAAgB,iBAAiB,CAAC,gBA8SpC,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useEffect, useReducer, useCallback } from 'react';
|
|
3
|
-
import
|
|
4
|
-
import { createUID, useElement, useOuterEvent, Flex, Text, defaultThemeProp, useI18n } from '@pega/cosmos-react-core';
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useReducer, useCallback, useRef, useMemo } from 'react';
|
|
3
|
+
import { createUID, useElement, useOuterEvent, useI18n } from '@pega/cosmos-react-core';
|
|
5
4
|
import ItemLibrary from '../ItemLibrary/ItemLibrary';
|
|
5
|
+
import { DirectedGraph } from './Renderer/Utils/Graph';
|
|
6
6
|
import FlowRenderer from './Renderer/Renderer';
|
|
7
|
-
import { StartNode, EndNode, DefaultNode } from './Node/NodeTemplates';
|
|
8
7
|
import { START_NODETYPE, STOP_NODETYPE } from './Node/Node.types';
|
|
9
|
-
import PlaceHolderHelper
|
|
8
|
+
import PlaceHolderHelper from './Utils/addNodeUtils';
|
|
10
9
|
import { AddButton } from './AddNode';
|
|
10
|
+
import FlowModellerHelper from './helper';
|
|
11
|
+
import DeletePopover from './DeletePopover';
|
|
12
|
+
import Connector from './Connector';
|
|
13
|
+
import Node from './Node';
|
|
14
|
+
import FlowModellerContext from './FlowModellerContext';
|
|
11
15
|
const initState = {
|
|
12
16
|
showLib: false,
|
|
17
|
+
activeItem: null,
|
|
18
|
+
allowNonBranchNode: false,
|
|
13
19
|
activeAddBtnMeta: {
|
|
14
20
|
target: null,
|
|
15
21
|
meta: {
|
|
@@ -18,8 +24,9 @@ const initState = {
|
|
|
18
24
|
}
|
|
19
25
|
},
|
|
20
26
|
graphData: { nodes: [], connectors: [] },
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
highlightItems: undefined,
|
|
28
|
+
showDeletePopover: false,
|
|
29
|
+
deleteProps: undefined
|
|
23
30
|
};
|
|
24
31
|
const reducer = (state, action) => {
|
|
25
32
|
switch (action.type) {
|
|
@@ -27,50 +34,109 @@ const reducer = (state, action) => {
|
|
|
27
34
|
// minor optimization, not to update state.. if no change in the value
|
|
28
35
|
return action.payload.show === state.showLib
|
|
29
36
|
? state
|
|
30
|
-
: { ...state, showLib: action.payload.show };
|
|
37
|
+
: { ...state, showLib: action.payload.show, allowNonBranchNode: false };
|
|
38
|
+
case 'setActiveItem':
|
|
39
|
+
return {
|
|
40
|
+
...state,
|
|
41
|
+
activeItem: action.payload.target
|
|
42
|
+
};
|
|
31
43
|
case 'setActiveAddButton':
|
|
32
44
|
state.activeAddBtnMeta = {
|
|
33
45
|
...action.payload
|
|
34
46
|
};
|
|
35
47
|
return {
|
|
36
48
|
...state,
|
|
37
|
-
showLib: true
|
|
49
|
+
showLib: true,
|
|
50
|
+
allowNonBranchNode: action.payload.allowNonBranchNode
|
|
38
51
|
};
|
|
39
52
|
case 'setGraphData':
|
|
40
53
|
return {
|
|
41
54
|
...state,
|
|
42
55
|
graphData: action.payload.graphData,
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
highlightItems: action.payload.highlightItems
|
|
57
|
+
};
|
|
58
|
+
case 'highlight':
|
|
59
|
+
// minor optimization to avoid unnecessary re-render
|
|
60
|
+
if (action.payload.hideDeletePopover === !state.showDeletePopover) {
|
|
61
|
+
return state;
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
...state,
|
|
65
|
+
highlightItems: action.payload.highlightItems,
|
|
66
|
+
showDeletePopover: action.payload.hideDeletePopover !== true && state.showDeletePopover
|
|
67
|
+
};
|
|
68
|
+
case 'showDeletePopover':
|
|
69
|
+
return {
|
|
70
|
+
...state,
|
|
71
|
+
showDeletePopover: action.payload.showDeletePopover,
|
|
72
|
+
deleteProps: action.payload.deleteProps
|
|
45
73
|
};
|
|
46
74
|
default:
|
|
47
75
|
return state;
|
|
48
76
|
}
|
|
49
77
|
};
|
|
50
|
-
const
|
|
51
|
-
return css `
|
|
52
|
-
border-radius: ${theme.base['border-radius']};
|
|
53
|
-
background: ${theme.base.colors.slate.dark};
|
|
54
|
-
color: ${theme.base.colors.white};
|
|
55
|
-
text-align: center;
|
|
56
|
-
padding: calc(0.5 * ${theme.base.spacing});
|
|
57
|
-
overflow: hidden;
|
|
58
|
-
text-overflow: ellipsis;
|
|
59
|
-
max-width: 32ch;
|
|
60
|
-
white-space: nowrap;
|
|
61
|
-
`;
|
|
62
|
-
});
|
|
63
|
-
StyledLabel.defaultProps = defaultThemeProp;
|
|
64
|
-
const FlowModeller = ({ graphData, onNodeActionClick, onNodeClick, onNodeAdd, nodeLibrary, actions }) => {
|
|
78
|
+
const FlowModeller = ({ graphData, highlightData, onNodeActionClick, onNodeAdd, nodeLibrary, onNodeClick, onDelete, actions, readOnly }) => {
|
|
65
79
|
const [state, dispatch] = useReducer(reducer, initState);
|
|
66
80
|
const [popoverEl, setPopoverEl] = useElement(null);
|
|
81
|
+
const [deletePopoverEl, setDeletePopoverEl] = useElement(null);
|
|
82
|
+
const stateRef = useRef(initState);
|
|
83
|
+
// stateRef always refers to the same state obj
|
|
84
|
+
// "fixed" callbacks can refer to this object whenever
|
|
85
|
+
// it need the current value. Note: the callbacks will not
|
|
86
|
+
// be reactive - they will not re-run the instant state changes,
|
|
87
|
+
// but they *will* see the current value whenever they do run
|
|
88
|
+
stateRef.current = state;
|
|
67
89
|
const t = useI18n();
|
|
68
90
|
const onNodeCreate = (el, meta) => {
|
|
91
|
+
const graph = new DirectedGraph(graphData);
|
|
92
|
+
let isAllowNonBranchNode = false;
|
|
93
|
+
if (meta.refType === 'connector') {
|
|
94
|
+
if (!Array.isArray(meta.refId))
|
|
95
|
+
meta.refId = [meta.refId];
|
|
96
|
+
const connectorData = graph.getConnector(meta.refId[0]);
|
|
97
|
+
const toNode = graph.getNode(connectorData.toNodeId);
|
|
98
|
+
const inConnectors = graph.getInConnectors(toNode.id);
|
|
99
|
+
let hiddenConnectorsCount = 0;
|
|
100
|
+
inConnectors.forEach(connector => {
|
|
101
|
+
const node = graph.getNode(connector.fromNodeId);
|
|
102
|
+
if (node.type.minConnectors === 0)
|
|
103
|
+
hiddenConnectorsCount += 1;
|
|
104
|
+
});
|
|
105
|
+
const isPlaceholderConnector = meta.refId.length > 1;
|
|
106
|
+
/** if node is being added on a placeholder connector then reduce number of in connectors of destination node
|
|
107
|
+
* by total number of connectors converging/joining to form placeholder connector and add one to the in connector count
|
|
108
|
+
*/
|
|
109
|
+
const inConnectorsCount = isPlaceholderConnector
|
|
110
|
+
? inConnectors.length - meta.refId.length + 1
|
|
111
|
+
: inConnectors.length;
|
|
112
|
+
/** if node is being added on a placeholder connector then reduce number of hidden connectors of destination node
|
|
113
|
+
* by total number of connectors converging/joining to from placeholder connector and are originating from go to nodes
|
|
114
|
+
*/
|
|
115
|
+
if (isPlaceholderConnector) {
|
|
116
|
+
meta.refId.forEach(connector => {
|
|
117
|
+
if (graph.getNode(graph.getConnector(connector).fromNodeId).type.minConnectors === 0)
|
|
118
|
+
hiddenConnectorsCount -= 1;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/** check destination/target node in connectors count is more than one
|
|
122
|
+
* check non-hidden/visible connectors among in connectors of destination/target node are more than 1
|
|
123
|
+
* check connectors converging/joining to form a placeholder connector are not equal to total number of in connectors
|
|
124
|
+
*/
|
|
125
|
+
if (inConnectorsCount > 1 &&
|
|
126
|
+
inConnectorsCount - hiddenConnectorsCount > 1 &&
|
|
127
|
+
inConnectors.length !== meta.refId.length) {
|
|
128
|
+
isAllowNonBranchNode = true;
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
isAllowNonBranchNode = false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
69
134
|
dispatch({
|
|
70
135
|
type: 'setActiveAddButton',
|
|
71
136
|
payload: {
|
|
72
137
|
target: el,
|
|
73
|
-
meta
|
|
138
|
+
meta,
|
|
139
|
+
allowNonBranchNode: isAllowNonBranchNode
|
|
74
140
|
}
|
|
75
141
|
});
|
|
76
142
|
};
|
|
@@ -82,13 +148,73 @@ const FlowModeller = ({ graphData, onNodeActionClick, onNodeClick, onNodeAdd, no
|
|
|
82
148
|
}
|
|
83
149
|
});
|
|
84
150
|
};
|
|
151
|
+
const closeDeleteModel = () => {
|
|
152
|
+
// un-highlight the nodes and connectors
|
|
153
|
+
dispatch({
|
|
154
|
+
type: 'highlight',
|
|
155
|
+
payload: {
|
|
156
|
+
highlightItems: undefined,
|
|
157
|
+
hideDeletePopover: true
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
const onDeleteWrapper = (params, e) => {
|
|
162
|
+
const result = FlowModellerHelper.deleteNode(graphData, params.nodeId);
|
|
163
|
+
if (result) {
|
|
164
|
+
if (!result.updates && result.error) {
|
|
165
|
+
onDelete?.({ ...params, additionalData: result }, t('delete_referenced_step_error'), e);
|
|
166
|
+
}
|
|
167
|
+
else if (result.error) {
|
|
168
|
+
onDelete?.({ ...params, additionalData: result }, t('delete_step_error'), e);
|
|
169
|
+
}
|
|
170
|
+
onDelete?.({ ...params, additionalData: result }, '', e);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
dispatch({
|
|
174
|
+
type: 'showDeletePopover',
|
|
175
|
+
payload: {
|
|
176
|
+
showDeletePopover: true,
|
|
177
|
+
deleteProps: {
|
|
178
|
+
flowGraphData: graphData,
|
|
179
|
+
rendererGraphData: stateRef.current.graphData,
|
|
180
|
+
nodeId: params.nodeId,
|
|
181
|
+
target: {
|
|
182
|
+
getBoundingClientRect: () => document
|
|
183
|
+
.getElementById(`modeller-node-${stateRef.current.deleteProps?.nodeId}`)
|
|
184
|
+
?.getBoundingClientRect()
|
|
185
|
+
},
|
|
186
|
+
onChange: highlights => {
|
|
187
|
+
dispatch({
|
|
188
|
+
type: 'highlight',
|
|
189
|
+
payload: {
|
|
190
|
+
highlightItems: highlights
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
},
|
|
194
|
+
onSubmit: outcome => {
|
|
195
|
+
// un-highlight the nodes and connectors
|
|
196
|
+
closeDeleteModel();
|
|
197
|
+
if (outcome.error) {
|
|
198
|
+
onDelete?.({ ...params, additionalData: outcome }, t('delete_step_error'), e);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
onDelete?.({ ...params, additionalData: outcome }, '', e);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
onCancel: closeDeleteModel
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
};
|
|
85
210
|
useEffect(() => {
|
|
211
|
+
const graph = new DirectedGraph(graphData);
|
|
86
212
|
const onGetNewPHNode = metaData => {
|
|
87
213
|
return {
|
|
88
214
|
id: createUID(),
|
|
89
215
|
children: (_jsx(AddButton, { addNodeHandler: (e) => {
|
|
90
216
|
onNodeCreate(e.currentTarget, metaData);
|
|
91
|
-
} }
|
|
217
|
+
} })),
|
|
92
218
|
position: { x: 0, y: 0 },
|
|
93
219
|
dimensions: { width: 1, height: 0 }
|
|
94
220
|
};
|
|
@@ -98,33 +224,12 @@ const FlowModeller = ({ graphData, onNodeActionClick, onNodeClick, onNodeAdd, no
|
|
|
98
224
|
id: createUID(),
|
|
99
225
|
fromNodeId,
|
|
100
226
|
toNodeId,
|
|
101
|
-
points: []
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const refId = isPlaceHolderConnector(props)
|
|
107
|
-
? props.realConnectors
|
|
108
|
-
: id.toString();
|
|
109
|
-
const metaData = {
|
|
110
|
-
refType: 'connector',
|
|
111
|
-
refId
|
|
227
|
+
points: [],
|
|
228
|
+
data: {
|
|
229
|
+
onNodeCreate,
|
|
230
|
+
type: 'default'
|
|
231
|
+
}
|
|
112
232
|
};
|
|
113
|
-
return (_jsxs(_Fragment, { children: [labelLayout?.value && (_jsx(Flex, { container: { justify: 'center' }, children: _jsx(StyledLabel, { children: labelLayout.value }, void 0) }, void 0)), _jsx(AddButton, { addNodeHandler: (e) => {
|
|
114
|
-
onNodeCreate(e.currentTarget, metaData);
|
|
115
|
-
} }, void 0)] }, void 0));
|
|
116
|
-
};
|
|
117
|
-
const Node = ({ id, type, label, description, additionalData }) => {
|
|
118
|
-
if (!type) {
|
|
119
|
-
return _jsx("div", {}, void 0);
|
|
120
|
-
}
|
|
121
|
-
if (type?.id === START_NODETYPE.id) {
|
|
122
|
-
return _jsx(StartNode, { id: id, type: type, label: label.toUpperCase() }, void 0);
|
|
123
|
-
}
|
|
124
|
-
if (type?.id === STOP_NODETYPE.id) {
|
|
125
|
-
return _jsx(EndNode, { id: id, type: type, label: label.toUpperCase() }, void 0);
|
|
126
|
-
}
|
|
127
|
-
return (_jsx(DefaultNode, { id: id, label: label, type: type, description: description, onActionClick: onNodeActionClick, onClick: onNodeClick, actions: actions, additionalData: additionalData }, void 0));
|
|
128
233
|
};
|
|
129
234
|
const flowNodes = graphData.nodes.map(node => {
|
|
130
235
|
const flowNode = {
|
|
@@ -136,6 +241,13 @@ const FlowModeller = ({ graphData, onNodeActionClick, onNodeClick, onNodeAdd, no
|
|
|
136
241
|
position: {
|
|
137
242
|
x: 0,
|
|
138
243
|
y: 0
|
|
244
|
+
},
|
|
245
|
+
data: {
|
|
246
|
+
isActive: state.activeItem?.id === node.id,
|
|
247
|
+
actions,
|
|
248
|
+
onDelete: onDeleteWrapper,
|
|
249
|
+
onActionClick: onNodeActionClick,
|
|
250
|
+
onClick: onNodeClick
|
|
139
251
|
}
|
|
140
252
|
};
|
|
141
253
|
if (node.type.id === START_NODETYPE.id || node.type.id === STOP_NODETYPE.id) {
|
|
@@ -145,11 +257,15 @@ const FlowModeller = ({ graphData, onNodeActionClick, onNodeClick, onNodeAdd, no
|
|
|
145
257
|
return flowNode;
|
|
146
258
|
});
|
|
147
259
|
const connectors = graphData.connectors.map(connector => {
|
|
260
|
+
const nodeData = graph.getNode(connector.fromNodeId);
|
|
261
|
+
const isBranchNode = nodeData.type.minConnectors === 0;
|
|
148
262
|
return {
|
|
149
263
|
...connector,
|
|
150
264
|
points: [],
|
|
151
265
|
data: {
|
|
152
|
-
label: connector.label
|
|
266
|
+
label: connector.label,
|
|
267
|
+
onNodeCreate,
|
|
268
|
+
type: !isBranchNode ? 'default' : 'hidden'
|
|
153
269
|
}
|
|
154
270
|
};
|
|
155
271
|
});
|
|
@@ -158,9 +274,7 @@ const FlowModeller = ({ graphData, onNodeActionClick, onNodeClick, onNodeAdd, no
|
|
|
158
274
|
dispatch({
|
|
159
275
|
type: 'setGraphData',
|
|
160
276
|
payload: {
|
|
161
|
-
graphData: newGraphData
|
|
162
|
-
connectorComponent: Connector,
|
|
163
|
-
nodeComponent: Node
|
|
277
|
+
graphData: newGraphData
|
|
164
278
|
}
|
|
165
279
|
});
|
|
166
280
|
}, [graphData]);
|
|
@@ -178,14 +292,24 @@ const FlowModeller = ({ graphData, onNodeActionClick, onNodeClick, onNodeAdd, no
|
|
|
178
292
|
}
|
|
179
293
|
}, [closeMenu]);
|
|
180
294
|
useOuterEvent('mousedown', [popoverEl], closeMenu);
|
|
295
|
+
useOuterEvent('mousedown', [deletePopoverEl], closeDeleteModel);
|
|
181
296
|
useEffect(() => {
|
|
182
297
|
document.addEventListener('keydown', onKeydown);
|
|
183
298
|
return () => {
|
|
184
299
|
document.removeEventListener('keydown', onKeydown);
|
|
185
300
|
};
|
|
186
301
|
}, []);
|
|
187
|
-
|
|
188
|
-
|
|
302
|
+
let items = nodeLibrary !== undefined ? nodeLibrary : [];
|
|
303
|
+
if (!state.allowNonBranchNode) {
|
|
304
|
+
items = items.filter(shapeTypes => {
|
|
305
|
+
if (shapeTypes.type) {
|
|
306
|
+
return shapeTypes.type.minConnectors !== 0;
|
|
307
|
+
}
|
|
308
|
+
return true;
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
const ctxValue = useMemo(() => ({ readOnly, highlights: highlightData ?? state.highlightItems }), [readOnly, state.highlightItems, highlightData]);
|
|
312
|
+
return (_jsxs("div", { children: [_jsx(FlowModellerContext.Provider, { value: ctxValue, children: _jsx(FlowRenderer, { graphData: state.graphData, connector: Connector, node: Node }) }), state.showDeletePopover && state.deleteProps && (_jsx(DeletePopover, { show: state.showDeletePopover, ref: setDeletePopoverEl, ...state.deleteProps })), _jsx(ItemLibrary, { show: state.showLib, target: state.activeAddBtnMeta.target, placeholder: t('search_nodes'), items: items, onClick: onLibraryItemSelect, ref: setPopoverEl, position: 'bottom' })] }));
|
|
189
313
|
};
|
|
190
314
|
export default FlowModeller;
|
|
191
315
|
//# sourceMappingURL=FlowModeller.js.map
|