Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nested connection implicit delete #1830

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

#### Bugfixes ⛑️

- 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)
- Fixes edge case of bad import syntax crashing using d2 as a library [1829](https://github.com/terrastruct/d2/pull/1829)
11 changes: 11 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3239,6 +3239,17 @@ y: null
assert.Equal(t, 0, len(g.Edges))
},
},
{
name: "delete-nested-connection",
run: func(t *testing.T) {
g, _ := assertCompile(t, `
a -> b.c
b.c: null
`, "")
assert.Equal(t, 2, len(g.Objects))
assert.Equal(t, 0, len(g.Edges))
},
},
{
name: "delete-multiple-connections",
run: func(t *testing.T) {
Expand Down
17 changes: 12 additions & 5 deletions d2ir/d2ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -950,13 +950,20 @@ func (m *Map) DeleteField(ida ...string) *Field {
}
if len(rest) == 0 {
for _, fr := range f.References {
for _, e := range m.Edges {
for _, er := range e.References {
if er.Context_ == fr.Context_ {
m.DeleteEdge(e.ID)
break
currM := m
for currM != nil {
for _, e := range currM.Edges {
for _, er := range e.References {
if er.Context_ == fr.Context_ {
currM.DeleteEdge(e.ID)
break
}
}
}
if NodeBoardKind(currM) != "" {
break
}
currM = ParentMap(currM)
}
}
m.Fields = append(m.Fields[:i], m.Fields[i+1:]...)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.