Skip to content

Commit

Permalink
Merge pull request #1073 from alixander/fix-generated-containers-delete
Browse files Browse the repository at this point in the history
Fix generated containers delete
  • Loading branch information
alixander authored Mar 21, 2023
2 parents a44958a + b0faa8a commit 1cc0416
Show file tree
Hide file tree
Showing 3 changed files with 511 additions and 1 deletion.
11 changes: 10 additions & 1 deletion d2oracle/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,15 @@ func DeleteIDDeltas(g *d2graph.Graph, key string) (deltas map[string]string, err
if !ok {
return nil, nil
}

ignored := obj
for _, ch := range obj.ChildrenArray {
if ch.ID == obj.ID {
ignored = nil
break
}
}

for _, ch := range obj.ChildrenArray {
// Record siblings as the unique key generated should not conflict with any siblings either
var siblingsToBeHoisted []string
Expand Down Expand Up @@ -2094,7 +2103,7 @@ func DeleteIDDeltas(g *d2graph.Graph, key string) (deltas map[string]string, err
}

if conflictingObj, ok := g.Root.HasChild(d2graph.Key(hoistedMK.Key)); (ok && conflictingObj != obj) || conflictsWithNewID {
newKey, _, err := generateUniqueKey(g, hoistedAbsID, obj, append(newIDs, siblingsToBeHoisted...))
newKey, _, err := generateUniqueKey(g, hoistedAbsID, ignored, append(newIDs, siblingsToBeHoisted...))
if err != nil {
return nil, err
}
Expand Down
41 changes: 41 additions & 0 deletions d2oracle/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3526,6 +3526,29 @@ func TestDelete(t *testing.T) {
key: `x`,

exp: `x.y.z -> y.b
`,
},
{
name: "duplicate_generated",

text: `x
x 2
x 3: {
x 3
x 4
}
x 4
y
`,
key: `x 3`,
exp: `x
x 2
x 3
x 5
x 4
y
`,
},
{
Expand Down Expand Up @@ -5503,6 +5526,24 @@ x.y.z.w.e.p.l -> x.y.z.1.2.3.4

exp: `{
"x.x": "x"
}`,
},
{
name: "duplicate_generated",

text: `x
x 2
x 3: {
x 3
x 4
}
x 4
y
`,
key: `x 3`,
exp: `{
"x 3.x 3": "x 3",
"x 3.x 4": "x 5"
}`,
},
{
Expand Down
Loading

0 comments on commit 1cc0416

Please sign in to comment.