Repository navigation
fix(vscode): keep fields the canvas does not edit - #3566
markscott-ms wants to merge 1 commit into
Conversation
rocketstack-matt
left a comment
There was a problem hiding this comment.
Two more cases where opening the canvas still changes the document.
| const relId = (existingRel?.['unique-id'] as string) ?? `containment-${parentId}`; | ||
| calmRelationships.push({ | ||
| const originalInner = originalVariant(existingRel, variant); | ||
| calmRelationships.push(applyCanvasFields(existingRel, { |
There was a problem hiding this comment.
#3518 expects the document not to change on open, other than _layout. This loop writes one relationship for each container, from the first match only. In all six examples/fluxnova architectures, the platform has one composed-of relationship for each node: after open, the first has all the nodes and keeps its description ("contains the BPM engine"), and the others are removed. Also, a node that is in two containers (composed-of a system and deployed-in a cluster) is drawn in one only, so the other relationship loses it.
Please write each original containment relationship back with its own nodes. Remove only a node that was drawn in that container and is not now, and add new children to the first relationship of the container.
| ): Record<string, unknown> | undefined { | ||
| const lineStyle = (data.lineStyle as string) ?? 'solid'; | ||
| const routing = (data.routing as string) ?? 'bezier'; | ||
| const meta: Record<string, unknown> = { ...((data.edgeMetadata as Record<string, unknown>) ?? {}) }; | ||
| if (lineStyle && lineStyle !== 'solid') meta['line-style'] = lineStyle; | ||
| if (routing && routing !== 'bezier') meta['routing'] = routing; | ||
| if (Object.keys(meta).length === 0) return undefined; |
There was a problem hiding this comment.
CALM allows metadata to be an array. The parser copies an array into an object, so on open "metadata": [{ "owner": "a" }] on a connects or interacts relationship becomes { "0": { "owner": "a" } }. The docify C4 fixtures in shared/test_fixtures have this form. #3552 covers only the architecture metadata. If the canvas did not change it, write the array back:
| ): Record<string, unknown> | undefined { | |
| const lineStyle = (data.lineStyle as string) ?? 'solid'; | |
| const routing = (data.routing as string) ?? 'bezier'; | |
| const meta: Record<string, unknown> = { ...((data.edgeMetadata as Record<string, unknown>) ?? {}) }; | |
| if (lineStyle && lineStyle !== 'solid') meta['line-style'] = lineStyle; | |
| if (routing && routing !== 'bezier') meta['routing'] = routing; | |
| if (Object.keys(meta).length === 0) return undefined; | |
| ): Record<string, unknown> | unknown[] | undefined { | |
| const lineStyle = (data.lineStyle as string) ?? 'solid'; | |
| const routing = (data.routing as string) ?? 'bezier'; | |
| const meta: Record<string, unknown> = { ...((data.edgeMetadata as Record<string, unknown>) ?? {}) }; | |
| if (lineStyle && lineStyle !== 'solid') meta['line-style'] = lineStyle; | |
| if (routing && routing !== 'bezier') meta['routing'] = routing; | |
| const originalMeta = original?.metadata; | |
| if (Array.isArray(originalMeta) && JSON.stringify(meta) === JSON.stringify({ ...originalMeta })) return originalMeta; | |
| if (Object.keys(meta).length === 0) return undefined; |
Please also add an array metadata to the round-trip fixture.
CALM Canvas wrote each node and relationship again from the fields it edits, so opening the canvas removed all other fields. Start from the original element instead, keep relationships the canvas does not draw, and keep the document order. Closes #3518
9689eee to
701242b
Compare
Description
Closes #3518.
CALM Canvas wrote each node and relationship again from only the fields that it edits. Thus, to open the canvas removed all other fields from the document (for example
development-language, theinterfacesofconnectsends, and containment descriptions).flowToCalmnow starts from the original element and changes only the fields that the canvas edits. If the user clears one of those fields, it is removed.Decisions and gotchas:
connects(or custom) relationship moves to a different nodeinterfaces, because they belong to the old nodeconnectswith nodestination.node)interactsedgesprotocolandcontrols. Both are valid on all relationship typesmetadatakeys keep their order, so an unchanged document gives the same text, exceptmetadata._layoutThe canvas still emits a change when it opens, so the buffer becomes dirty because of
_layout(#3552). The reverse relationship of anA→B/B→Apair now keeps its owncontrolsand unedited fields, but it still gets theprotocol,descriptionandmetadataof its pair (#3519).Type of Change
Affected Components
cli/)calm/)calm-ai/)calm-hub/)calm-hub-ui/)calm-lab/)calm-models/)calm-server/)calm-studio/)calm-widgets/)calm-guard/)docs/)shared/)calm-plugins/vscode/)Commit Message Format ✅
Testing
A new round-trip test uses a document with each optional field and checks that parse, then
flowToCalm, gives the same text. Other new tests cover edits, reconnected ends, relationships that are not drawn, containment and bidirectional pairs.calm/architecture/calm-3.jsonalso gives the same text, except_layout.Checklist