1
0
mirror of https://github.com/mattermost/focalboard.git synced 2024-11-27 08:31:20 +02:00

Fix #2589. Maintain cardProperty order on patch (#2625)

Thanks. Merging as the CI failure is not related to this change.
This commit is contained in:
Chen-I Lim 2022-03-24 10:04:14 -07:00 committed by GitHub
parent 62672cb231
commit e82305de56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
@ -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
@ -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