use correct keys for nested

This commit is contained in:
Alexander Wang 2023-05-04 20:13:55 -07:00
parent 47d2bf2095
commit b245aadd41
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
2 changed files with 23 additions and 4 deletions

View file

@ -82,7 +82,17 @@ func ReconnectEdge(g *d2graph.Graph, edgeKey string, srcKey, dstKey *string) (_
return nil, errors.New("edgeKey must refer to an existing edge")
}
edge, ok := g.Root.HasEdge(mk)
edgeTrimCommon(mk)
obj := g.Root
if mk.Key != nil {
var ok bool
obj, ok = g.Root.HasChild(d2graph.Key(mk.Key))
if !ok {
return nil, errors.New("edge not found")
}
}
edge, ok := obj.HasEdge(mk)
if !ok {
return nil, errors.New("edge not found")
}
@ -1856,7 +1866,16 @@ func ReconnectEdgeIDDeltas(g *d2graph.Graph, edgeKey string, srcKey, dstKey *str
return nil, errors.New("edgeKey must refer to an existing edge")
}
edge, ok := g.Root.HasEdge(mk)
edgeTrimCommon(mk)
obj := g.Root
if mk.Key != nil {
var ok bool
obj, ok = g.Root.HasChild(d2graph.Key(mk.Key))
if !ok {
return nil, errors.New("edge not found")
}
}
edge, ok := obj.HasEdge(mk)
if !ok {
return nil, errors.New("edge not found")
}

View file

@ -1557,7 +1557,7 @@ b -> a
name: "contained",
text: `a.x -> a.y
a.z`,
edgeKey: `(a.x -> a.y)[0]`,
edgeKey: `a.(x -> y)[0]`,
newDst: "a.z",
exp: `a.x -> a.z
a.y
@ -5667,7 +5667,7 @@ a -> b
text: `a.x -> a.y
a.z
`,
edge: "(a.x -> a.y)[0]",
edge: "a.(x -> y)[0]",
newDst: "a.z",
exp: `{