Skip to content

Commit

Permalink
fix order by to not remove keys
Browse files Browse the repository at this point in the history
  • Loading branch information
iignatevich committed Nov 6, 2024
1 parent d3b9111 commit 2e0e6d8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/sync/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,22 @@ func (m *OrderedMap[T]) Keys() []string {
// OrderBy updates the order of keys in the [OrderedMap] based on the orderList.
func (m *OrderedMap[T]) OrderBy(orderList []string) {
var newKeys []string
var remainingKeys []string

keysLoop:
for _, key := range m.keys {
isInOrderList := false
for _, orderKey := range orderList {
if key == orderKey {
isInOrderList = true
continue keysLoop
}
}

if !isInOrderList {
remainingKeys = append(remainingKeys, key)
}
}

for _, item := range orderList {
_, ok := m.Get(item)
Expand All @@ -279,6 +295,7 @@ func (m *OrderedMap[T]) OrderBy(orderList []string) {
}
}

newKeys = append(newKeys, remainingKeys...)
m.keys = newKeys
}

Expand Down

0 comments on commit 2e0e6d8

Please sign in to comment.