Skip to content

Commit 00a1c00

Browse files
committed
Merge branch 'feature/638-fix-add-forward-on-self-closing-tag'
2 parents 2e3367b + dadb0d4 commit 00a1c00

File tree

3 files changed

+73
-11
lines changed

3 files changed

+73
-11
lines changed

frank-flow/src/frontend/src/app/shared/models/flow-structure-node.model.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class FlowStructureNode {
1616
public nestedElements: FlowNodeNestedElements = {};
1717
public senders: FlowStructureNode[];
1818
public path: string;
19+
public isSelfClosing: boolean;
1920

2021
constructor(
2122
line: number,
@@ -25,13 +26,15 @@ export class FlowStructureNode {
2526
type: string,
2627
path: string,
2728
attributes: FlowNodeAttributes,
29+
isSelfClosing: boolean,
2830
forwards?: any[]
2931
) {
3032
this.line = line;
3133
this.endLine = endLine;
3234
this.startColumn = startColumn;
3335
this.column = column;
3436
this.type = type;
37+
this.isSelfClosing = isSelfClosing;
3538
this.forwards = forwards;
3639
this.attributes = attributes ?? [];
3740
this.path = path;

frank-flow/src/frontend/src/app/shared/services/flow-structure.service.ts

Lines changed: 68 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ export class FlowStructureService {
139139
}
140140

141141
addConnection(sourceId: string, targetId: string): void {
142-
const endLine = this.getEndLineOfSourceElement(sourceId);
142+
const sourceNode = this.getSourceNode(sourceId);
143143
const target = this.flowStructure.nodes.find(
144144
(node) => node.uid == targetId
145145
);
146146

147+
const endLine =
148+
(sourceNode?.endLine ?? 0) + (sourceNode?.isSelfClosing ? 1 : 0);
147149
const text = `\t\t\t\t<Forward name="success" path="${target?.name}" />\n`;
148150
const range = {
149151
startLineNumber: endLine,
@@ -152,15 +154,61 @@ export class FlowStructureService {
152154
endLineNumber: endLine,
153155
};
154156

155-
this.monacoEditorComponent?.applyEdits([{ range, text }]);
157+
if (sourceNode?.isSelfClosing) {
158+
this.monacoEditorComponent?.applyEdits([
159+
this.getClosingBracketEditOperation(sourceNode),
160+
{ range, text },
161+
this.getClosingTagEditOperation(sourceNode),
162+
]);
163+
} else {
164+
this.monacoEditorComponent?.applyEdits([{ range, text }]);
165+
}
156166
}
157167

158-
getEndLineOfSourceElement(sourceId: string): number {
159-
const currentPipe = this.flowStructure.pipes.find(
168+
getSourceNode(sourceId: string): FlowStructureNode | undefined {
169+
return this.flowStructure.pipes.find(
160170
(pipe: FlowStructureNode) => pipe.uid === sourceId
161171
);
172+
}
173+
174+
getClosingBracketEditOperation(
175+
sourceNode: FlowStructureNode
176+
): monaco.editor.ISingleEditOperation {
177+
const text = `>`;
178+
let column = sourceNode.column - 2;
179+
if (this.hasSpaceBeforeClosingBracket(sourceNode)) {
180+
column -= 1;
181+
}
182+
const range = {
183+
startLineNumber: sourceNode.endLine,
184+
startColumn: column,
185+
endColumn: sourceNode.column,
186+
endLineNumber: sourceNode.endLine,
187+
};
188+
189+
return { range, text };
190+
}
191+
192+
hasSpaceBeforeClosingBracket(sourceNode: FlowStructureNode): boolean {
193+
const lastAttribute = this.findLastAttribute(sourceNode.attributes);
194+
return (
195+
sourceNode.column - (lastAttribute?.endColumn ?? 0) >= 3 &&
196+
lastAttribute?.line === sourceNode.endLine
197+
);
198+
}
162199

163-
return currentPipe!.endLine;
200+
getClosingTagEditOperation(
201+
sourceNode: FlowStructureNode
202+
): monaco.editor.ISingleEditOperation {
203+
const text = `\t\t\t</${sourceNode.type}>\n`;
204+
const range = {
205+
startLineNumber: sourceNode.endLine + 1,
206+
startColumn: 0,
207+
endColumn: 0,
208+
endLineNumber: sourceNode.endLine + 1,
209+
};
210+
211+
return { range, text };
164212
}
165213

166214
deleteConnection(
@@ -306,7 +354,7 @@ export class FlowStructureService {
306354
(pipes[pipes.length - 1] ? lastPipe.endLine : lastPipe.line) + 1;
307355
const pipeName = this.getUniquePipeName(pipeData.getName());
308356

309-
const text = `\t\t\t<${pipeData.getType()} name="${pipeName}">\n\t\t\t</${pipeData.getType()}>\n`;
357+
const text = `\t\t\t<${pipeData.getType()} name="${pipeName}" />\n`;
310358
const range = {
311359
startLineNumber: line,
312360
startColumn: 0,
@@ -744,7 +792,9 @@ export class FlowStructureService {
744792
parent: FlowStructureNode
745793
): void {
746794
const lastNestedElement = this.findLastNestedElement(parent);
747-
let text = `\t\t\t\t<${parameter.type} name="${parameter.name}">\n\t\t\t\t</${parameter.type}>\n`;
795+
let text = `\t\t\t\t<${parameter.type} name="${parameter.name}" />\n`;
796+
797+
const endLine = parent.endLine + (parent.isSelfClosing ? 1 : 0);
748798

749799
const range = lastNestedElement
750800
? {
@@ -754,13 +804,21 @@ export class FlowStructureService {
754804
endColumn: 0,
755805
}
756806
: {
757-
startLineNumber: parent.line + 1,
758-
endLineNumber: parent.line + 1,
807+
startLineNumber: endLine,
808+
endLineNumber: endLine,
759809
startColumn: 0,
760810
endColumn: 0,
761811
};
762812

763-
this.monacoEditorComponent?.applyEdits([{ text, range }], true);
813+
if (parent.isSelfClosing) {
814+
this.monacoEditorComponent?.applyEdits([
815+
this.getClosingBracketEditOperation(parent),
816+
{ range, text },
817+
this.getClosingTagEditOperation(parent),
818+
]);
819+
} else {
820+
this.monacoEditorComponent?.applyEdits([{ range, text }]);
821+
}
764822
}
765823

766824
findLastNestedElement(

frank-flow/src/frontend/src/app/shared/workers/xml-to-flow-structure.worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ parser.on('opentag', (tag: TagForOptions<{}>) => {
9999
parser.column + MONACO_COLUMN_OFFSET,
100100
tag.name,
101101
path,
102-
bufferAttributes
102+
bufferAttributes,
103+
tag.isSelfClosing
103104
);
104105

105106
bufferAttributes = {};

0 commit comments

Comments
 (0)