Skip to content
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

feature: support autolayout in seata-statemachine-designer #6415

Merged
merged 23 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
53536f0
issue: Resolve issue related to autolayout in seata-statemachine-desi…
Mar 12, 2024
5c26eb1
Delete all/.factorypath
Code-breaker1998 Mar 12, 2024
ca99cad
Delete console/.factorypath
Code-breaker1998 Mar 12, 2024
aad7783
Delete integration/motan/.factorypath
Code-breaker1998 Mar 12, 2024
4e8f56e
Delete saga/seata-saga-statemachine-designer/package-lock.json
Code-breaker1998 Mar 12, 2024
2fd4a3e
Delete seata-spring-autoconfigure/seata-spring-autoconfigure-client/.…
Code-breaker1998 Mar 12, 2024
b52d4e2
Delete seata-spring-autoconfigure/seata-spring-autoconfigure-core/.fa…
Code-breaker1998 Mar 12, 2024
e7bbb29
Delete seata-spring-autoconfigure/seata-spring-autoconfigure-server/.…
Code-breaker1998 Mar 12, 2024
0d506ce
Delete seata-spring-boot-starter/.factorypath
Code-breaker1998 Mar 12, 2024
c267e30
Delete saga/seata-saga-statemachine-designer/src/modeling/SagaExporte…
Code-breaker1998 Mar 12, 2024
357fa7f
Update Edge.js
Code-breaker1998 Mar 13, 2024
d247cf4
Update SagaImporter.js
Code-breaker1998 Mar 13, 2024
6c6c69c
Update Node.js
Code-breaker1998 Mar 13, 2024
c113d2e
removed debugger and console.log from SagaImporter.js
Code-breaker1998 Mar 13, 2024
9169582
Added SagaExporter.js file
Code-breaker1998 Mar 13, 2024
f791fb7
Revert "Delete saga/seata-saga-statemachine-designer/package-lock.json"
ptyin Mar 13, 2024
460fbc4
fix eslint problems and revert package-lock.json
ptyin Mar 13, 2024
62a724a
remove extra space lines
ptyin Mar 13, 2024
4bf8db3
Added literal constant and optimize the code
Code-breaker1998 Mar 15, 2024
5cf0642
fix eslint problems
ptyin Mar 16, 2024
45e4868
use 'is' to substitute conditions
ptyin Mar 16, 2024
ccfaf86
register 2.x.md
ptyin Mar 16, 2024
1bc9fbb
register 2.x.md
ptyin Mar 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion saga/seata-saga-statemachine-designer/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"react/no-deprecated": 0,
"react/react-in-jsx-scope": 0,
"react/jsx-no-bind": 0,
"no-underscore-dangle": 0
"no-underscore-dangle": 0,
"no-restricted-syntax": 0
}
}
115 changes: 101 additions & 14 deletions saga/seata-saga-statemachine-designer/src/modeling/SagaImporter.js
ptyin marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,49 @@ function collectWaypoints(edge) {
return null;
}

function addArrayList(definitions) {
const adjList = new Map();
forEach(definitions.States, (semantic) => {
// Initialize an array to store values for the key
adjList.set(semantic, []);

if (semantic.Next || semantic.CompensateState || semantic.Choices) {
const options = [];

if (semantic.Next) {
options.push(semantic.Next);
}

if (semantic.CompensateState) {
options.push(semantic.CompensateState);
}

if (semantic.Choices) {
semantic.Choices.forEach((option) => options.push(option.Next));
}

const existingValues = adjList.get(semantic);
options.forEach((next) => {
existingValues.push(definitions.States[next]);
});
adjList.set(semantic, existingValues);
}
});
return adjList;
}

function addCatchList(definitions, nodes) {
const adjList = new Map();
adjList.set(nodes, []);
nodes.Catch.forEach((option) => {
const { Next } = option;
const existingValues = adjList.get(nodes);
existingValues.push(definitions.States[Next]);
adjList.set(nodes, existingValues);
});
return adjList;
}

export default function SagaImporter(
sagaFactory,
eventBus,
Expand Down Expand Up @@ -76,38 +119,77 @@ SagaImporter.prototype.import = function (definitions) {
const root = this.sagaFactory.create('StateMachine');
root.importJson(definitions);
this.root(root);

// Add start state
let start = this.sagaFactory.create('StartState');
let stateArrayList = new Map();
start.importJson(definitions);
let begin = start;
start = this.add(start);

const edges = [];
const catches = [];
forEach(definitions.States, (semantic) => {
const state = this.sagaFactory.create(semantic.Type);
state.importJson(semantic);

if (semantic.style === undefined) {
stateArrayList = addArrayList(definitions);
state.importStates(definitions, semantic, begin, stateArrayList);
} else {
state.importJson(semantic);
begin = state;
}
const host = this.add(state);
if (semantic.edge) {

if (semantic.edge === undefined) {
state.importEdges(definitions, semantic);
if (semantic.edge) {
edges.push(...Object.values(semantic.edge));
}
} else {
edges.push(...Object.values(semantic.edge));
}
if (semantic.catch) {
const node = this.sagaFactory.create('Catch');
node.importJson(semantic.catch);
const source = this.add(node);

if (semantic.Catch) {
let source;
if (semantic.catch === undefined) {
const node = this.sagaFactory.create('Catch');
const catchList = addCatchList(definitions, semantic);
node.addCatch(definitions, semantic, catchList, stateArrayList);
source = this.add(node);
} else {
const node = this.sagaFactory.create('Catch');
node.importJson(semantic.catch);
source = this.add(node);
}

if (semantic.catch.edge === undefined) {
state.importCatchesEdges(definitions, semantic);
}
if (semantic.catch.edge) {
semantic.Catch.forEach((exceptionMatch) => {
if (semantic.catch.edge[exceptionMatch.Next]) {
semantic.catch.edge[exceptionMatch.Next].Exceptions = exceptionMatch.Exceptions;
}
});

this.modeling.updateAttachment(source, host);
catches.push({
source,
edges: Object.values(semantic.catch.edge),
});
}
this.modeling.updateAttachment(source, host);
catches.push({ source, edges: Object.values(semantic.catch.edge) });
}
});

// Add start edge
if ((definitions.edge === undefined) && (definitions.States)) {
start = this.sagaFactory.create('StartState');
definitions.edge = {};
start.importJsonEdges(definitions);
if (definitions.edge) {
const startEdge = this.sagaFactory.create('Transition');
startEdge.importJson(definitions.edge);
this.add(startEdge, { source: start });
}
}
if (definitions.edge) {
const startEdge = this.sagaFactory.create('Transition');
startEdge.importJson(definitions.edge);
Expand All @@ -121,7 +203,10 @@ SagaImporter.prototype.import = function (definitions) {
});

forEach(catches, (oneCatch) => {
const { source, edges: exceptionMatches } = oneCatch;
const {
source,
edges: exceptionMatches,
} = oneCatch;
forEach(exceptionMatches, (semantic) => {
const exceptionMatch = this.sagaFactory.create(semantic.Type);
exceptionMatch.importJson(semantic);
Expand All @@ -133,7 +218,10 @@ SagaImporter.prototype.import = function (definitions) {
console.error(error);
}

this.eventBus.fire('import.done', { error, warnings });
this.eventBus.fire('import.done', {
error,
warnings,
});
};

SagaImporter.prototype.root = function (semantic) {
Expand Down Expand Up @@ -181,7 +269,6 @@ SagaImporter.prototype.add = function (semantic, attrs = {}) {
target,
waypoints,
});
// console.log(elementDefinition);

element = elementFactory.createConnection(elementDefinition);

Expand Down
Loading
Loading