fix move id delta

This commit is contained in:
Alexander Wang 2023-03-19 20:50:53 -07:00
parent 282167781c
commit 1cef4177fb
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
3 changed files with 37 additions and 2 deletions

View file

@ -1886,7 +1886,7 @@ func MoveIDDeltas(g *d2graph.Graph, key, newKey string) (deltas map[string]strin
}
if _, ok := g.Root.HasChild(d2graph.Key(hoistedMK.Key)); ok || conflictsWithNewID {
newKey, _, err := generateUniqueKey(g, hoistedAbsID, nil, newIDs)
newKey, _, err := generateUniqueKey(g, hoistedAbsID, obj, newIDs)
if err != nil {
return nil, err
}

View file

@ -3372,6 +3372,24 @@ b: {
exp: `b: {
a
}
`,
},
{
name: "container_conflicts_generated",
text: `Square 2: "" {
Square: ""
}
Square: ""
Square 3
`,
key: `Square 2`,
newKey: `Square 3.Square 2`,
exp: `Square 4: ""
Square: ""
Square 3: {
Square 2: ""
}
`,
},
}
@ -4939,6 +4957,7 @@ Text
Text 2
`,
},
{
name: "drop_value",
text: `a.b.c: "c label"
@ -5278,6 +5297,22 @@ x.a -> x.b
"x.(a -> b)[0]": "(a 2 -> b)[0]",
"x.a": "a 2",
"x.b": "b"
}`,
},
{
name: "container_conflicts_generated",
text: `Square 2: "" {
Square: ""
}
Square: ""
Square 3
`,
key: `Square 2`,
newKey: `Square 3.Square 2`,
exp: `{
"Square 2": "Square 3.Square 2",
"Square 2.Square": "Square 2"
}`,
},
}

View file

@ -14,7 +14,7 @@ func GetParentID(g *d2graph.Graph, absID string) (string, error) {
}
obj, ok := g.Root.HasChild(d2graph.Key(mk.Key))
if !ok {
return "", fmt.Errorf("%v parent not found", absID)
return "", fmt.Errorf("%v not found", absID)
}
return obj.Parent.AbsID(), nil