Skip to content

Commit

Permalink
Merge pull request #1830 from alixander/fix-nested-connection-delete
Browse files Browse the repository at this point in the history
fix nested connection implicit delete
  • Loading branch information
alixander committed Feb 9, 2024
2 parents defdde0 + 0d9328b commit 86f96fc
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 5 deletions.
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.

0 comments on commit 86f96fc

Please sign in to comment.