You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2022/02/01 22:39:45 UTC
[camel-karavan] branch main updated: Drag and Drop fix (#166)
This is an automated email from the ASF dual-hosted git repository.
marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
The following commit(s) were added to refs/heads/main by this push:
new 284214c Drag and Drop fix (#166)
284214c is described below
commit 284214c3f3bd9f3f80ce2ad58aa28e1b31a8863e
Author: Marat Gubaidullin <ma...@gmail.com>
AuthorDate: Tue Feb 1 17:38:37 2022 -0500
Drag and Drop fix (#166)
---
karavan-core/src/core/api/CamelDefinitionApiExt.ts | 51 +++++++-------
karavan-core/test/findStep.spec.ts | 28 +++++++-
karavan-designer/src/App.tsx | 82 +++++++++++-----------
karavan-designer/src/designer/KaravanDesigner.tsx | 2 +-
4 files changed, 93 insertions(+), 70 deletions(-)
diff --git a/karavan-core/src/core/api/CamelDefinitionApiExt.ts b/karavan-core/src/core/api/CamelDefinitionApiExt.ts
index 4802cb3..f13645e 100644
--- a/karavan-core/src/core/api/CamelDefinitionApiExt.ts
+++ b/karavan-core/src/core/api/CamelDefinitionApiExt.ts
@@ -86,34 +86,35 @@ export class CamelDefinitionApiExt {
return result;
}
- static findElement = (integration: Integration, uuid: string): CamelElement | undefined => {
- const step = CamelDefinitionApiExt.findStep(integration.spec.flows, uuid, undefined);
- return step.step;
+ static findElementInIntegration = (integration: Integration, uuid: string): CamelElement | undefined => {
+ const meta = CamelDefinitionApiExt.findElement(integration.spec.flows, uuid);
+ return meta.step;
}
- static findStep = (steps: CamelElement[] | undefined, uuid: string, parentUuid?: string, result?: CamelElementMeta): CamelElementMeta => {
+ static findElement = (steps: CamelElement[] | undefined, uuid: string, result: CamelElementMeta = new CamelElementMeta(undefined, undefined, undefined, []), parentUuid?: string): CamelElementMeta => {
if (result?.step !== undefined) return result;
- if (result === undefined) result = new CamelElementMeta(undefined, parentUuid, undefined, []);
if (steps !== undefined){
- for (let index = 0, step; step = steps[index]; index++) {
- if (step.uuid !== uuid) {
- if (step.dslName === 'ChoiceDefinition') {
- const o = (step as ChoiceDefinition).otherwise;
- const w = (step as ChoiceDefinition).when;
- const s: CamelElement[] = [];
- if (o) s.push(o);
- if (w) s.push(...w);
- result = CamelDefinitionApiExt.findStep(s, uuid, step.uuid, result);
- if (result?.pathUuids !== undefined && result?.pathUuids.length > 0) result.pathUuids.push(step.uuid);
- } else {
- result = CamelDefinitionApiExt.findStep((step as any).steps, uuid, step.uuid, result);
- if (result?.pathUuids !== undefined && result?.pathUuids.length > 0) result.pathUuids.push(step.uuid);
- }
- } else {
- const paths: string[] = result?.pathUuids ? result?.pathUuids : [];
- paths.push(step.uuid);
- result = new CamelElementMeta(step, parentUuid, index, paths);
+ for (let index = 0, step: CamelElement; step = steps[index]; index++) {
+ if (step.uuid === uuid) {
+ const p = [...result.pathUuids];
+ p.push(step.uuid);
+ result = new CamelElementMeta(step, parentUuid, index, p);
break;
+ } else {
+ const ce = CamelDefinitionApiExt.getElementChildrenDefinition(step.dslName);
+ ce.forEach(e => {
+ const cel = CamelDefinitionApiExt.getElementChildren(step, e);
+ if (e.multiple) {
+ result = CamelDefinitionApiExt.findElement(cel, uuid, result, step.uuid);
+ result.pathUuids.push(step.uuid);
+ } else {
+ const prop = (step as any)[e.name];
+ if (prop && prop.hasOwnProperty("uuid")) {
+ result = CamelDefinitionApiExt.findElement([prop], uuid, result, prop.uuid);
+ result.pathUuids.push(prop.uuid);
+ }
+ }
+ })
}
}
}
@@ -121,10 +122,10 @@ export class CamelDefinitionApiExt {
}
static moveElement = (integration: Integration, source: string, target: string): Integration => {
- const sourceFindStep = CamelDefinitionApiExt.findStep(integration.spec.flows, source, undefined);
+ const sourceFindStep = CamelDefinitionApiExt.findElement(integration.spec.flows, source);
const sourceStep = sourceFindStep.step;
const sourceUuid = sourceStep?.uuid;
- const targetFindStep = CamelDefinitionApiExt.findStep(integration.spec.flows, target, undefined);
+ const targetFindStep = CamelDefinitionApiExt.findElement(integration.spec.flows, target);
const parentUuid = targetFindStep.parentUuid;
if (sourceUuid && parentUuid && sourceStep && !targetFindStep.pathUuids.includes(source)) {
CamelDefinitionApiExt.deleteStepFromIntegration(integration, sourceUuid);
diff --git a/karavan-core/test/findStep.spec.ts b/karavan-core/test/findStep.spec.ts
index 3ea96d0..a5dfb79 100644
--- a/karavan-core/test/findStep.spec.ts
+++ b/karavan-core/test/findStep.spec.ts
@@ -24,7 +24,7 @@ import {
ChoiceDefinition,
ExpressionDefinition,
SimpleExpression,
- FilterDefinition
+ FilterDefinition, CatchDefinition, TryDefinition, FinallyDefinition, RouteDefinition
} from "../src/core/model/CamelDefinition";
import {CamelUtil} from "../src/core/api/CamelUtil";
import {CamelDefinitionApiExt} from "../src/core/api/CamelDefinitionApiExt";
@@ -48,7 +48,7 @@ describe('Find Step', () => {
if (when2 && when2.expression) {
when2.expression.simple = new SimpleExpression({expression: '$[body} == "hello world"'});
}
- const log: LogDefinition = <LogDefinition> CamelDefinitionApiExt.findElement(i, log2.uuid);
+ const log: LogDefinition = <LogDefinition> CamelDefinitionApiExt.findElementInIntegration(i, log2.uuid);
expect(log.logName).to.equal(log2.logName);
expect(log.message).to.equal(log2.message);
});
@@ -67,7 +67,29 @@ describe('Find Step', () => {
i.spec.flows?.push(flow1);
- const log: LogDefinition = <LogDefinition> CamelDefinitionApiExt.findElement(i, log2.uuid);
+ const log: LogDefinition = <LogDefinition> CamelDefinitionApiExt.findElementInIntegration(i, log2.uuid);
+ expect(log.logName).to.equal(log2.logName);
+ expect(log.message).to.equal(log2.message);
+ });
+
+ it('Find Step from Try-Catch-Finally clause', () => {
+ const log1 = new LogDefinition({message: "hello1"});
+ const log2 = new LogDefinition({message: "hello2"});
+ const log3 = new LogDefinition({message: "hello3"});
+ const catch1 = new CatchDefinition({exception:['IOException'], steps: [log1, log2, log3]})
+ const log4 = new LogDefinition({message: "hello4"});
+ const log5 = new LogDefinition({message: "hello5"});
+ const log6 = new LogDefinition({message: "hello6"});
+ const catch2 = new CatchDefinition({exception:['NullPointerException'], steps: [log4, log5, log6]})
+ const log7 = new LogDefinition({message: "hello7"});
+ const log8 = new LogDefinition({message: "hello8"});
+ const log9 = new LogDefinition({message: "hello9"});
+ const try1 = new TryDefinition({ doCatch:[catch1, catch2], steps: [log7, log8, log9]})
+ const from = new FromDefinition({uri: "direct1", steps:[try1]});
+ const i = Integration.createNew("test")
+ i.spec.flows?.push(new RouteDefinition({from: from}));
+
+ const log: LogDefinition = <LogDefinition> CamelDefinitionApiExt.findElementInIntegration(i, log2.uuid);
expect(log.logName).to.equal(log2.logName);
expect(log.message).to.equal(log2.message);
});
diff --git a/karavan-designer/src/App.tsx b/karavan-designer/src/App.tsx
index 3d4b477..bd74361 100644
--- a/karavan-designer/src/App.tsx
+++ b/karavan-designer/src/App.tsx
@@ -45,47 +45,47 @@ class App extends React.Component<Props, State> {
' from:\n' +
' uri: kamelet:http-secured-source\n' +
' steps:\n' +
- ' - saga: \n' +
- ' option:\n' +
- ' - option-name: o1\n' +
- ' expression:\n' +
- ' simple: "${body}" \n' +
- ' - option-name: o2\n' +
- ' expression:\n' +
- ' simple: "${body}" \n' +
- // ' - do-try:\n' +
- // ' steps:\n' +
- // ' - to: "direct:direct1"\n' +
- // ' - to: "direct:direct2"\n' +
- // ' - log: "log1"\n' +
- // ' do-catch:\n' +
- // ' - exception:\n' +
- // ' - "java.io.FileNotFoundException"\n' +
- // ' - "java.io.IOException"\n' +
- // ' steps:\n' +
- // ' - log: "log1"\n' +
- // ' - kamelet: \n' +
- // ' name: kafka-sink \n' +
- // ' - exception:\n' +
- // ' - "java.io.FileNotFoundException"\n' +
- // ' - "java.io.IOException"\n' +
- // ' steps:\n' +
- // ' - log: "log1"\n' +
- // ' - kamelet: \n' +
- // ' name: http-sink \n' +
- // ' - choice:\n' +
- // ' when:\n' +
- // ' - expression: {}\n' +
- // ' steps:\n' +
- // ' - log:\n' +
- // ' message: hello22s\n' +
- // ' logName: log22\n' +
- // ' otherwise: {}\n'+
- // ' - circuitBreaker: {}\n' +
- // ' - multicast:\n' +
- // ' steps:\n' +
- // ' - to: "http:localhost"\n' +
- // ' - to: "kafka:topic2"\n' +
+ // ' - saga: \n' +
+ // ' option:\n' +
+ // ' - option-name: o1\n' +
+ // ' expression:\n' +
+ // ' simple: "${body}" \n' +
+ // ' - option-name: o2\n' +
+ // ' expression:\n' +
+ // ' simple: "${body}" \n' +
+ ' - do-try:\n' +
+ ' steps:\n' +
+ ' - to: "direct:direct1"\n' +
+ ' - to: "direct:direct2"\n' +
+ ' - log: "log1"\n' +
+ ' do-catch:\n' +
+ ' - exception:\n' +
+ ' - "java.io.FileNotFoundException"\n' +
+ ' - "java.io.IOException"\n' +
+ ' steps:\n' +
+ ' - log: "log1"\n' +
+ ' - kamelet: \n' +
+ ' name: kafka-sink \n' +
+ ' - exception:\n' +
+ ' - "java.io.FileNotFoundException"\n' +
+ ' - "java.io.IOException"\n' +
+ ' steps:\n' +
+ ' - log: "log1"\n' +
+ ' - kamelet: \n' +
+ ' name: http-sink \n' +
+ ' - choice:\n' +
+ ' when:\n' +
+ ' - expression: {}\n' +
+ ' steps:\n' +
+ ' - log:\n' +
+ ' message: hello22s\n' +
+ ' logName: log22\n' +
+ ' otherwise: {}\n'+
+ ' - circuitBreaker: {}\n' +
+ ' - multicast:\n' +
+ ' steps:\n' +
+ ' - to: "http:localhost"\n' +
+ ' - to: "kafka:topic2"\n' +
'',
key: ''
};
diff --git a/karavan-designer/src/designer/KaravanDesigner.tsx b/karavan-designer/src/designer/KaravanDesigner.tsx
index 55bea0e..0cddf5d 100644
--- a/karavan-designer/src/designer/KaravanDesigner.tsx
+++ b/karavan-designer/src/designer/KaravanDesigner.tsx
@@ -181,7 +181,7 @@ export class KaravanDesigner extends React.Component<Props, State> {
moveElement = (source: string, target: string) => {
const i = CamelDefinitionApiExt.moveElement(this.state.integration, source, target);
const clone = CamelUtil.cloneIntegration(i);
- const selectedStep = CamelDefinitionApiExt.findElement(clone, source);
+ const selectedStep = CamelDefinitionApiExt.findElementInIntegration(clone, source);
this.setState({
integration: clone,
key: Math.random().toString(),