Skip to content

Commit 0d9328b

Browse files
committed
fix nested connection implicit delete
1 parent defdde0 commit 0d9328b

File tree

4 files changed

+289
-5
lines changed

4 files changed

+289
-5
lines changed

ci/release/changelogs/next.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44

55
#### Bugfixes ⛑️
66

7+
- Fixes `null` being set on a nested shape not working in certain cases when connections also pointed to that shape [1830](https://github.com/terrastruct/d2/pull/1830)
78
- Fixes edge case of bad import syntax crashing using d2 as a library [1829](https://github.com/terrastruct/d2/pull/1829)

d2compiler/compile_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -3239,6 +3239,17 @@ y: null
32393239
assert.Equal(t, 0, len(g.Edges))
32403240
},
32413241
},
3242+
{
3243+
name: "delete-nested-connection",
3244+
run: func(t *testing.T) {
3245+
g, _ := assertCompile(t, `
3246+
a -> b.c
3247+
b.c: null
3248+
`, "")
3249+
assert.Equal(t, 2, len(g.Objects))
3250+
assert.Equal(t, 0, len(g.Edges))
3251+
},
3252+
},
32423253
{
32433254
name: "delete-multiple-connections",
32443255
run: func(t *testing.T) {

d2ir/d2ir.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,20 @@ func (m *Map) DeleteField(ida ...string) *Field {
950950
}
951951
if len(rest) == 0 {
952952
for _, fr := range f.References {
953-
for _, e := range m.Edges {
954-
for _, er := range e.References {
955-
if er.Context_ == fr.Context_ {
956-
m.DeleteEdge(e.ID)
957-
break
953+
currM := m
954+
for currM != nil {
955+
for _, e := range currM.Edges {
956+
for _, er := range e.References {
957+
if er.Context_ == fr.Context_ {
958+
currM.DeleteEdge(e.ID)
959+
break
960+
}
958961
}
959962
}
963+
if NodeBoardKind(currM) != "" {
964+
break
965+
}
966+
currM = ParentMap(currM)
960967
}
961968
}
962969
m.Fields = append(m.Fields[:i], m.Fields[i+1:]...)

testdata/d2compiler/TestCompile2/nulls/implicit/delete-nested-connection.exp.json

+265
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)