From e0697157fdf48395be5ae44f62999c99617ff2a9 Mon Sep 17 00:00:00 2001 From: Graza Date: Wed, 13 Nov 2024 15:46:54 +0700 Subject: [PATCH] wip: started parsing diffs --- internal/snapshot/snapshot_diff.go | 32 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/internal/snapshot/snapshot_diff.go b/internal/snapshot/snapshot_diff.go index d0439f9d..919e6b44 100644 --- a/internal/snapshot/snapshot_diff.go +++ b/internal/snapshot/snapshot_diff.go @@ -119,26 +119,32 @@ func updateDiffSnap(changeLog diff.Changelog, diffSnap *map[string]interface{}) var err error topLevel := change.Path[0] switch topLevel { - case "layout", "panels": + case "layout": switch change.Type { case "create": err = addKeyValueAtPath(*diffSnap, change.Path, "__diff", "inserted") - if topLevel == "panels" { - // PANEL SPECIFIC LOGIC - fmt.Println("a") - } case "delete": err = addKeyValueAtPath(*diffSnap, change.Path, "__diff", "deleted") - if topLevel == "panels" { - // PANEL SPECIFIC LOGIC - fmt.Println("a") - } + // TODO: #snapshot we need to extract the deleted layout item and inject into the diff case "update": err = addKeyValueAtPath(*diffSnap, change.Path, "__diff", "updated") - if topLevel == "panels" { - // PANEL SPECIFIC LOGIC - fmt.Println("a") - } + default: + continue + } + if err != nil { + return fmt.Errorf("failed to update diff snapshot: %w", err) + } + case "panels": + switch change.Type { + case "create": + err = addKeyValueAtPath(*diffSnap, change.Path, "__diff", "inserted") + case "delete": + fmt.Println("delete") + case "update": + updatePath := change.Path[:len(change.Path)-1] + updateKey := fmt.Sprintf("%s_diff", change.Path[len(change.Path)-1]) + err = addKeyValueAtPath(*diffSnap, updatePath, "__diff", "updated") + err = addKeyValueAtPath(*diffSnap, updatePath, updateKey, change.From) default: continue }