delete iddelta
This commit is contained in:
parent
aa321c2066
commit
e072296717
2 changed files with 71 additions and 12 deletions
|
|
@ -2117,7 +2117,7 @@ func updateNear(prevG, g *d2graph.Graph, from, to *string, includeDescendants bo
|
||||||
tmpG, _ := recompile(prevG.AST)
|
tmpG, _ := recompile(prevG.AST)
|
||||||
appendMapKey(tmpG.AST, valueMK)
|
appendMapKey(tmpG.AST, valueMK)
|
||||||
if to == nil {
|
if to == nil {
|
||||||
deltas, err := DeleteIDDeltas(tmpG, *from)
|
deltas, err := DeleteIDDeltas(tmpG, nil, *from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -2162,7 +2162,7 @@ func updateNear(prevG, g *d2graph.Graph, from, to *string, includeDescendants bo
|
||||||
tmpG, _ := recompile(prevG.AST)
|
tmpG, _ := recompile(prevG.AST)
|
||||||
appendMapKey(tmpG.AST, valueMK)
|
appendMapKey(tmpG.AST, valueMK)
|
||||||
if to == nil {
|
if to == nil {
|
||||||
deltas, err := DeleteIDDeltas(tmpG, *from)
|
deltas, err := DeleteIDDeltas(tmpG, nil, *from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -2693,7 +2693,7 @@ func MoveIDDeltas(g *d2graph.Graph, key, newKey string, includeDescendants bool)
|
||||||
return deltas, nil
|
return deltas, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func DeleteIDDeltas(g *d2graph.Graph, key string) (deltas map[string]string, err error) {
|
func DeleteIDDeltas(g *d2graph.Graph, boardPath []string, key string) (deltas map[string]string, err error) {
|
||||||
defer xdefer.Errorf(&err, "failed to get deltas for deletion of %#v", key)
|
defer xdefer.Errorf(&err, "failed to get deltas for deletion of %#v", key)
|
||||||
deltas = make(map[string]string)
|
deltas = make(map[string]string)
|
||||||
|
|
||||||
|
|
@ -2703,7 +2703,16 @@ func DeleteIDDeltas(g *d2graph.Graph, key string) (deltas map[string]string, err
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeTrimCommon(mk)
|
edgeTrimCommon(mk)
|
||||||
obj := g.Root
|
|
||||||
|
boardG := g
|
||||||
|
if len(boardPath) > 0 {
|
||||||
|
boardG = GetBoardGraph(g, boardPath)
|
||||||
|
if boardG == nil {
|
||||||
|
return nil, fmt.Errorf("board %v not found", boardPath)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
obj := boardG.Root
|
||||||
conflictNewIDs := make(map[*d2graph.Object]string)
|
conflictNewIDs := make(map[*d2graph.Object]string)
|
||||||
conflictOldIDs := make(map[*d2graph.Object]string)
|
conflictOldIDs := make(map[*d2graph.Object]string)
|
||||||
var newIDs []string
|
var newIDs []string
|
||||||
|
|
@ -2715,7 +2724,7 @@ func DeleteIDDeltas(g *d2graph.Graph, key string) (deltas map[string]string, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var ok bool
|
var ok bool
|
||||||
obj, ok = g.Root.HasChild(d2graph.Key(mk.Key))
|
obj, ok = boardG.Root.HasChild(d2graph.Key(mk.Key))
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
@ -2742,7 +2751,7 @@ func DeleteIDDeltas(g *d2graph.Graph, key string) (deltas map[string]string, err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
hoistedAbsID := ch2.ID
|
hoistedAbsID := ch2.ID
|
||||||
if obj.Parent != g.Root {
|
if obj.Parent != boardG.Root {
|
||||||
hoistedAbsID = obj.Parent.AbsID() + "." + ch2.ID
|
hoistedAbsID = obj.Parent.AbsID() + "." + ch2.ID
|
||||||
}
|
}
|
||||||
siblingsToBeHoisted = append(siblingsToBeHoisted, hoistedAbsID)
|
siblingsToBeHoisted = append(siblingsToBeHoisted, hoistedAbsID)
|
||||||
|
|
@ -2757,7 +2766,7 @@ func DeleteIDDeltas(g *d2graph.Graph, key string) (deltas map[string]string, err
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
hoistedAbsID := ch.ID
|
hoistedAbsID := ch.ID
|
||||||
if obj.Parent != g.Root {
|
if obj.Parent != boardG.Root {
|
||||||
hoistedAbsID = obj.Parent.AbsID() + "." + ch.ID
|
hoistedAbsID = obj.Parent.AbsID() + "." + ch.ID
|
||||||
}
|
}
|
||||||
hoistedMK, err := d2parser.ParseMapKey(hoistedAbsID)
|
hoistedMK, err := d2parser.ParseMapKey(hoistedAbsID)
|
||||||
|
|
@ -2773,8 +2782,8 @@ 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 {
|
if conflictingObj, ok := boardG.Root.HasChild(d2graph.Key(hoistedMK.Key)); (ok && conflictingObj != obj) || conflictsWithNewID {
|
||||||
newKey, _, err := generateUniqueKey(g, hoistedAbsID, ignored, append(newIDs, siblingsToBeHoisted...))
|
newKey, _, err := generateUniqueKey(boardG, hoistedAbsID, ignored, append(newIDs, siblingsToBeHoisted...))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7730,8 +7730,9 @@ func TestDeleteIDDeltas(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
|
||||||
text string
|
boardPath []string
|
||||||
key string
|
text string
|
||||||
|
key string
|
||||||
|
|
||||||
exp string
|
exp string
|
||||||
expErr string
|
expErr string
|
||||||
|
|
@ -7998,6 +7999,55 @@ Square
|
||||||
exp: `{
|
exp: `{
|
||||||
"x.Square 2": "Square 4",
|
"x.Square 2": "Square 4",
|
||||||
"x.Square 3": "Square 3"
|
"x.Square 3": "Square 3"
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "scenarios-basic",
|
||||||
|
text: `x
|
||||||
|
|
||||||
|
scenarios: {
|
||||||
|
y: {
|
||||||
|
a
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
boardPath: []string{"y"},
|
||||||
|
key: `a`,
|
||||||
|
|
||||||
|
exp: `{}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "scenarios-parent",
|
||||||
|
text: `x
|
||||||
|
|
||||||
|
scenarios: {
|
||||||
|
y: {
|
||||||
|
a.x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
boardPath: []string{"y"},
|
||||||
|
key: `a`,
|
||||||
|
|
||||||
|
exp: `{
|
||||||
|
"a.x": "x 2"
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "layers-parent",
|
||||||
|
text: `x
|
||||||
|
|
||||||
|
layers: {
|
||||||
|
y: {
|
||||||
|
a.x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
boardPath: []string{"y"},
|
||||||
|
key: `a`,
|
||||||
|
|
||||||
|
exp: `{
|
||||||
|
"a.x": "x"
|
||||||
}`,
|
}`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -8013,7 +8063,7 @@ Square
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
deltas, err := d2oracle.DeleteIDDeltas(g, tc.key)
|
deltas, err := d2oracle.DeleteIDDeltas(g, tc.boardPath, tc.key)
|
||||||
if tc.expErr != "" {
|
if tc.expErr != "" {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("expected error with: %q", tc.expErr)
|
t.Fatalf("expected error with: %q", tc.expErr)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue