Skip to content

Commit

Permalink
Fix #2589. Maintain cardProperty order on patch (#2625)
Browse files Browse the repository at this point in the history
Thanks. Merging as the CI failure is not related to this change.
  • Loading branch information
chenilim authored Mar 24, 2022
1 parent 62672cb commit e82305d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions server/model/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ func (p *BoardPatch) Patch(board *Board) *Board {
}

if len(p.UpdatedCardProperties) != 0 || len(p.DeletedCardProperties) != 0 {
// first we accumulate all properties indexed by ID
// first we accumulate all properties indexed by, and maintain their order
keyOrder := []string{}
cardPropertyMap := map[string]map[string]interface{}{}
for _, prop := range board.CardProperties {
id, ok := prop["id"].(string)
Expand All @@ -233,6 +234,7 @@ func (p *BoardPatch) Patch(board *Board) *Board {
}

cardPropertyMap[id] = prop
keyOrder = append(keyOrder, id)
}

// if there are properties marked for removal, we delete them
Expand All @@ -249,13 +251,20 @@ func (p *BoardPatch) Patch(board *Board) *Board {
continue
}

_, exists := cardPropertyMap[id]
if !exists {
keyOrder = append(keyOrder, id)
}
cardPropertyMap[id] = newprop
}

// and finally we flatten and save the updated properties
newCardProperties := []map[string]interface{}{}
for _, p := range cardPropertyMap {
newCardProperties = append(newCardProperties, p)
for _, key := range keyOrder {
p, exists := cardPropertyMap[key]
if exists {
newCardProperties = append(newCardProperties, p)
}
}

board.CardProperties = newCardProperties
Expand Down

0 comments on commit e82305d

Please sign in to comment.