Skip to content

Commit 8c9773d

Browse files
committed
improved group export and import to OCIF but still WiP
1 parent 9fe7a50 commit 8c9773d

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

libs/app-canvas/src/app/exporters/BaseExporter.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,16 @@ export abstract class BaseExporter<T extends ExportFile, X> {
9999
isRectThumb,
100100
parentId
101101
);
102-
if (!isRectThumb) {
103-
node.thumbConnectors?.forEach((thumb) => {
104-
this.exportThumb(contextInfo, thumb);
105-
});
106-
}
102+
if (id) {
103+
if (!isRectThumb) {
104+
node.thumbConnectors?.forEach((thumb) => {
105+
this.exportThumb(contextInfo, thumb);
106+
});
107+
}
107108

108-
if (node.nodeInfo?.canvasAppInstance) {
109-
this.exportNodes(id, node.nodeInfo.canvasAppInstance.elements);
109+
if (node.nodeInfo?.canvasAppInstance) {
110+
this.exportNodes(id, node.nodeInfo.canvasAppInstance.elements);
111+
}
110112
}
111113
});
112114

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,26 @@ export class OCIFExporter extends BaseExporter<OCIFFile, OCIFInfo> {
219219
data: [...portsNode],
220220
resource: `${node.id}-resource`,
221221
};
222-
222+
if (nodeInfo.type === 'group') {
223+
// only export group as a relation
224+
if (
225+
node.nodeInfo?.isGroup &&
226+
this.file &&
227+
node.nodeInfo?.groupedNodeIds
228+
) {
229+
const relation = {
230+
id: `${ocifNode.id}`,
231+
data: [
232+
{
233+
type: '@ocif/rel/group' as const,
234+
members: [...node.nodeInfo.groupedNodeIds],
235+
},
236+
],
237+
};
238+
this.file.relations.push(relation);
239+
}
240+
return '';
241+
}
223242
if (
224243
ocifNode.data &&
225244
nodeInfo.type !== 'rect-node' &&
@@ -259,18 +278,7 @@ export class OCIFExporter extends BaseExporter<OCIFFile, OCIFInfo> {
259278
id: `${ocifNode.id}-resource`,
260279
representations: [{ 'mime-type': 'text/plain', content: nodeInfo.type }],
261280
});
262-
if (node.nodeInfo?.isGroup && this.file && node.nodeInfo?.groupedNodeIds) {
263-
const relation = {
264-
id: `${ocifNode.id}-group}`,
265-
data: [
266-
{
267-
type: '@ocif/rel/group' as const,
268-
members: [...node.nodeInfo.groupedNodeIds],
269-
},
270-
],
271-
};
272-
this.file.relations.push(relation);
273-
}
281+
274282
return ocifNode.id;
275283
}
276284
override exportThumb(

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,28 @@ export const importOCIF = (ocif: any) => {
253253
}
254254
});
255255
}
256+
257+
if (ocif.relations) {
258+
ocif.relations.forEach((relation: any) => {
259+
if (relation && relation.data) {
260+
const group = getExtenstionData(relation, '@ocif/rel/group');
261+
if (group) {
262+
flow.flows['flow'].nodes.push({
263+
id: relation.id,
264+
x: 0,
265+
y: 0,
266+
width: 0,
267+
height: 0,
268+
nodeType: 'Shape',
269+
nodeInfo: {
270+
type: 'group',
271+
groupedNodeIds: group.members,
272+
} as any,
273+
});
274+
}
275+
}
276+
});
277+
}
256278
return flow;
257279
};
258280

0 commit comments

Comments
 (0)