Skip to content

Commit 7317714

Browse files
committed
improved ocif import/export and dealing with deleting connections/relations
1 parent 31a0d2c commit 7317714

File tree

4 files changed

+72
-25
lines changed

4 files changed

+72
-25
lines changed

libs/app-canvas/src/app/exporters/export-ocwg.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
258258

259259
override exportConnection(
260260
_context: OCWGInfo,
261-
nodeInfo: BaseNodeInfo,
261+
_nodeInfo: BaseNodeInfo,
262262
node: IConnectionNodeComponent<BaseNodeInfo>
263263
): void {
264264
if (!node.startNode || !node.endNode) {
@@ -277,20 +277,20 @@ export class OCWGExporter extends BaseExporter<OCWGFile, OCWGInfo> {
277277
endMarker: 'arrowhead',
278278
relation: `${node.id}-edge`,
279279
},
280-
{
281-
...nodeInfo,
282-
type: connectionNodeInfoPropertyName,
283-
nodeType: nodeInfo.type,
284-
lineType: (nodeInfo as any).lineType ?? 'Straight',
285-
start: {
286-
connected_to: `${node.startNode.id}`,
287-
port_name: node.startNodeThumb?.thumbName ?? 'output',
288-
},
289-
end: {
290-
connected_to: `${node.endNode.id}`,
291-
port_name: node.endNodeThumb?.thumbName ?? 'input',
292-
},
293-
},
280+
// {
281+
// ...nodeInfo,
282+
// type: connectionNodeInfoPropertyName,
283+
// nodeType: nodeInfo.type,
284+
// lineType: (nodeInfo as any).lineType ?? 'Straight',
285+
// start: {
286+
// connected_to: `${node.startNode.id}`,
287+
// port_name: node.startNodeThumb?.thumbName ?? 'output',
288+
// },
289+
// end: {
290+
// connected_to: `${node.endNode.id}`,
291+
// port_name: node.endNodeThumb?.thumbName ?? 'input',
292+
// },
293+
// },
294294
],
295295
};
296296
if (this.file?.nodes) {

libs/app-canvas/src/app/flow-app.element.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ import {
130130
} from '@devhelpr/web-flow-executor';
131131
import { PasteNodeCommand } from './command-handlers/paste-node-command/paste-node-command';
132132
import { clearOCIF, getCurrentOCIF, setOCIF } from './importers/ocif-importer';
133+
import {
134+
OCIFRelation,
135+
OCIFNode,
136+
OCIFEdgeRelationExtension,
137+
} from './interfaces/ocif';
133138

134139
export type CreateRunCounterContext = (
135140
isRunViaRunButton: boolean,
@@ -2171,6 +2176,30 @@ export class FlowAppElement extends AppElement<NodeInfo> {
21712176
if (element.nodeInfo?.delete) {
21722177
element.nodeInfo.delete();
21732178
}
2179+
const ocif = getCurrentOCIF();
2180+
if (!ocif) {
2181+
return;
2182+
}
2183+
const node = element as INodeComponent<NodeInfo>;
2184+
if (node.nodeType === NodeType.Connection) {
2185+
const connection = node as IConnectionNodeComponent<NodeInfo>;
2186+
ocif.relations = ocif.relations.filter((relation: OCIFRelation) => {
2187+
let hasRelationToNode = false;
2188+
relation.data.forEach((extensionData) => {
2189+
if (
2190+
extensionData.type === '@ocwg/rel/edge' &&
2191+
(extensionData as unknown as OCIFEdgeRelationExtension).node ===
2192+
connection.id
2193+
) {
2194+
hasRelationToNode = true;
2195+
}
2196+
});
2197+
return !hasRelationToNode;
2198+
});
2199+
ocif.nodes = ocif.nodes.filter((ocifNode: OCIFNode) => {
2200+
return ocifNode.id !== connection.id;
2201+
});
2202+
}
21742203
};
21752204

21762205
onPreclearCanvas = () => {

libs/app-canvas/src/app/importers/ocif-importer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
nodeInfoPropertyName,
66
} from '../exporters/export-ocwg';
77
import { ocifArrow, ocifSchema, ocifToCodeFlowCanvas } from '../consts/ocif';
8-
import { OCIFEdgeRelation } from '../interfaces/ocif';
8+
import { OCIFEdgeRelationExtension } from '../interfaces/ocif';
99

1010
let rootOCIF: any = undefined;
1111

@@ -55,15 +55,14 @@ function isValidCodeFlowCanvasConnection(node: any): boolean {
5555
function getEdgeRelationById(
5656
ocif: any,
5757
relationId: string
58-
): OCIFEdgeRelation | undefined {
58+
): OCIFEdgeRelationExtension | undefined {
5959
if (!ocif.relations || !relationId) {
6060
return undefined;
6161
}
6262
const data = ocif.relations.find((r: any) => r.id === relationId);
6363
if (data) {
6464
const extension = getExtenstionData(data, '@ocwg/rel/edge');
6565
return {
66-
id: data.id,
6766
type: extension.type,
6867
start: extension.start,
6968
end: extension.end,

libs/app-canvas/src/app/interfaces/ocif.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,36 @@ export interface OCIFRelataionData {
22
type: string;
33
}
44

5+
export interface OCIFEdgeRelationExtension extends OCIFRelataionData {
6+
type: '@ocwg/rel/edge';
7+
node: string;
8+
start: string;
9+
end: string;
10+
rel: string;
11+
}
12+
513
export interface OCIFRelation {
614
id: string;
715
data: Array<OCIFRelataionData>;
816
}
917

10-
export interface OCIFEdgeRelation {
11-
id: string;
18+
// export interface OCIFEdgeRelation {
19+
// id: string;
1220

13-
type: '@ocwg/rel/edge';
14-
start: string;
15-
end: string;
16-
rel: string;
17-
node: string;
21+
// type: '@ocwg/rel/edge';
22+
// start: string;
23+
// end: string;
24+
// rel: string;
25+
// node: string;
26+
// }
27+
28+
export interface OCIFExtension {
29+
type: string;
30+
}
31+
32+
export interface OCIFNode {
33+
id: string;
34+
position?: number[];
35+
size?: number[];
36+
data?: OCIFExtension[];
1837
}

0 commit comments

Comments
 (0)