pelican/internal/board/shuffle.go
Dan Anglin e99c8cd877
All checks were successful
/ test (pull_request) Successful in 36s
/ lint (pull_request) Successful in 38s
feat: add backend support for status repositioning
Add backend support for repositioning statuses on the Kanban board.
Part of apollo/pelican#27
2024-01-25 01:36:22 +00:00

26 lines
679 B
Go

package board
// shuffle takes a list of Statuses and swaps its position with the Status closer to its desired
// position until it reaches it.
//
// This is currently used to move specified columns forwards or backwards on the Kanban board.
// When a column changes position the other columns shuffle forward or backwards as required.
func shuffle(list []Status, oldIndex, newIndex int) []Status {
if newIndex == oldIndex {
return list
}
if newIndex < oldIndex {
for i := oldIndex; i > newIndex; i-- {
list[i], list[i-1] = list[i-1], list[i]
}
return list
}
for i := oldIndex; i < newIndex; i++ {
list[i], list[i+1] = list[i+1], list[i]
}
return list
}