The existing integer priority field represents positional ordering within a state, not semantic importance. Rename it to rank and introduce a new priority field with enum values URGENT, HIGH, MEDIUM and LOW across the entire stack. Rank is now scoped to (state, priority) so tasks are ordered within each priority group. A generated priority_rank column combines both fields into a single sortable integer for cursor pagination. Dragging a task across priority groups updates its priority automatically based on the drop position neighbors. The backend first moves the task to the new group then repositions it at the target rank. The migration defaults existing rows to MEDIUM priority and backfills ranks per (state, priority) group. Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
// Copyright (c) 2026 Probo Inc <hello@getprobo.com>.
|
|
//
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
// copyright notice and this permission notice appear in all copies.
|
|
//
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
// PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
package coredata
|
|
|
|
import (
|
|
"database/sql/driver"
|
|
"fmt"
|
|
)
|
|
|
|
type TaskPriority string
|
|
|
|
const (
|
|
TaskPriorityUrgent TaskPriority = "URGENT"
|
|
TaskPriorityHigh TaskPriority = "HIGH"
|
|
TaskPriorityMedium TaskPriority = "MEDIUM"
|
|
TaskPriorityLow TaskPriority = "LOW"
|
|
)
|
|
|
|
func TaskPriorities() []TaskPriority {
|
|
return []TaskPriority{
|
|
TaskPriorityUrgent,
|
|
TaskPriorityHigh,
|
|
TaskPriorityMedium,
|
|
TaskPriorityLow,
|
|
}
|
|
}
|
|
|
|
func (tp TaskPriority) String() string {
|
|
return string(tp)
|
|
}
|
|
|
|
func (tp *TaskPriority) Scan(value any) error {
|
|
var s string
|
|
switch v := value.(type) {
|
|
case string:
|
|
s = v
|
|
case []byte:
|
|
s = string(v)
|
|
default:
|
|
return fmt.Errorf("unsupported type for TaskPriority: %T", value)
|
|
}
|
|
|
|
switch s {
|
|
case "URGENT":
|
|
*tp = TaskPriorityUrgent
|
|
case "HIGH":
|
|
*tp = TaskPriorityHigh
|
|
case "MEDIUM":
|
|
*tp = TaskPriorityMedium
|
|
case "LOW":
|
|
*tp = TaskPriorityLow
|
|
default:
|
|
return fmt.Errorf("invalid TaskPriority value: %q", s)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (tp TaskPriority) Value() (driver.Value, error) {
|
|
return tp.String(), nil
|
|
}
|