Files
probo/pkg/coredata/task_order_field.go
Sacha Al Himdani 324f4ce793 Add task priority enum and rename priority to rank
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>
2026-04-02 13:35:39 +02:00

61 lines
1.7 KiB
Go

// Copyright (c) 2025-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 "fmt"
type (
TaskOrderField string
)
const (
TaskOrderFieldPriorityRank TaskOrderField = "PRIORITY_RANK" // ordering only
TaskOrderFieldCreatedAt TaskOrderField = "CREATED_AT"
)
func (p TaskOrderField) Column() string {
switch p {
case TaskOrderFieldPriorityRank:
return "priority_rank"
case TaskOrderFieldCreatedAt:
return "created_at"
}
panic(fmt.Sprintf("unsupported order by: %s", p))
}
func (p TaskOrderField) IsValid() bool {
switch p {
case TaskOrderFieldPriorityRank, TaskOrderFieldCreatedAt:
return true
}
return false
}
func (p TaskOrderField) String() string {
return string(p)
}
func (p TaskOrderField) MarshalText() ([]byte, error) {
return []byte(p.String()), nil
}
func (p *TaskOrderField) UnmarshalText(text []byte) error {
*p = TaskOrderField(text)
if !p.IsValid() {
return fmt.Errorf("%s is not a valid TaskOrderField", string(text))
}
return nil
}