Sprint: Stories en taken krijgen één voorspelbare volgorde gekoppeld aan hun code; drag-and-drop herordening voor stories/taken verdwijnt, priority wordt puur label. (#201)
* feat(code): add parseCodeNumber helper to lib/code.ts
Pure helper that extracts the trailing numeric sequence from a code string
(ST-007 → 7, T-42 → 42). Non-conforming codes fall back to Number.MAX_SAFE_INTEGER
so they sort to the end. Includes 5 unit tests.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(tasks): add code field to BacklogTask type and all task selects
Adds `code: string | null` to BacklogTask interface and includes it in
all Prisma task.findMany selects (backlog API, stories tasks API, page
hydration routes). Updates coerceTaskPayload and test fixtures to match.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* feat(sort-order): derive story/task sort_order from parseCodeNumber(code)
All create paths (createStoryAction, saveTask, createTaskAction,
materializeIdeaPlanAction) and code-edit paths (updateStoryAction, saveTask
update) now set sort_order = parseCodeNumber(code) instead of last+1.
Removes stale last-record queries from create paths.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix(sort-order): decouple sprint membership actions from sort_order
createSprintAction and addStoryToSprintAction no longer write sort_order
when adding stories to a sprint. sort_order is derived from code via
parseCodeNumber, so membership should only set sprint_id + status.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(ordering): remove priority from all story/task orderBy
Story- en taak-ordering is nu puur sort_order asc (created_at als
tiebreaker). PBI-ordering (priority + sort_order) blijft ongewijzigd.
Gewijzigd: backlog/route, pbis/stories/route, claude-context/route,
next-story/route, workspace/route, tasks/route, sprint-runs (query +
in-memory sort), solo-workspace-server, page.tsx (app + mobile + sprint),
store compareStory, actions/sprints story-query, next-story test.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* refactor(dnd): remove drag-and-drop reorder for stories and tasks
- Remove reorderStoriesAction, reorderTasksAction, reorderSprintStoriesAction
- Delete REST route app/api/stories/[id]/tasks/reorder/route.ts
- Remove DnD from backlog story-panel and task-panel (flat list)
- Remove reorder-within-sprint branch from sprint-board-client handleDragEnd
- Switch SortableSprintRow to plain SprintRow using useDraggable (membership drag kept)
- Remove all DnD from task-list (status toggle + edit kept)
- Remove story-order/task-order/sprint-story-order/sprint-task-order mutation types and store handlers
- Remove related tests for deleted reorder route; fix sprint store tests
* feat(backlog): toon code-badge op backlog-taakkaarten
Geeft code={task.code} door aan <BacklogCard> in TaskCard (task-panel.tsx).
BacklogCard rendert de CodeBadge al conditionally — alleen de prop ontbrak.
* feat(migration): backfill story/task sort_order from code numeric suffix
One-time Prisma migration that sets sort_order = trailing numeric part
of code for all existing stories and tasks, consistent with
parseCodeNumber (fallback = Number.MAX_SAFE_INTEGER for non-conforming
codes). PBIs are intentionally excluded.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* docs+tests(sort-order): update for code-binding order on stories/tasks
- Rewrite docs/patterns/sort-order.md: float-insertion PBI only; story/task
sort_order = parseCodeNumber(code), never drag/membership mutated
- Update plan-to-pbi-flow.md: sort_order auto, sprint_id param, priority=label
- Update make-plan.md: priority=label, array order = execution order
- Update rest-contract.md: fix sprint-tasks ordering, remove reorder endpoint
- Add ADR-0011: code is bindende volgordesleutel voor stories/taken
- Regenerate docs/INDEX.md via npm run docs
- Remove reorderStoriesAction/reorderTasksAction mocks from backlog tests
- Remove dnd-kit mocks from task-panel test (panel no longer uses dnd)
- Extend materializeIdeaPlanAction test: assert sort_order=parseCodeNumber(code)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
b6249a41c0
commit
ff22196714
43 changed files with 296 additions and 951 deletions
|
|
@ -21,6 +21,7 @@ import { canTransition, isGrillMdEditable, isIdeaEditable, isPlanMdEditable } fr
|
|||
import { nextIdeaCode } from '@/lib/idea-code-server'
|
||||
import { parsePlanMd } from '@/lib/idea-plan-parser'
|
||||
import { ACTIVE_JOB_STATUSES } from '@/lib/job-status'
|
||||
import { parseCodeNumber } from '@/lib/code'
|
||||
|
||||
import type { ClaudeJobKind, Idea, IdeaStatus } from '@prisma/client'
|
||||
|
||||
|
|
@ -720,16 +721,17 @@ export async function materializeIdeaPlanAction(
|
|||
|
||||
for (let si = 0; si < plan.stories.length; si++) {
|
||||
const s = plan.stories[si]
|
||||
const storyCode = `ST-${String(nextStoryN++).padStart(3, '0')}`
|
||||
const story = await tx.story.create({
|
||||
data: {
|
||||
pbi_id: pbi.id,
|
||||
product_id: productId,
|
||||
code: `ST-${String(nextStoryN++).padStart(3, '0')}`,
|
||||
code: storyCode,
|
||||
title: s.title,
|
||||
description: s.description ?? null,
|
||||
acceptance_criteria: s.acceptance_criteria ?? null,
|
||||
priority: s.priority,
|
||||
sort_order: si + 1, // sequential within PBI
|
||||
sort_order: parseCodeNumber(storyCode),
|
||||
status: 'OPEN',
|
||||
},
|
||||
select: { id: true },
|
||||
|
|
@ -738,11 +740,12 @@ export async function materializeIdeaPlanAction(
|
|||
|
||||
for (let ti = 0; ti < s.tasks.length; ti++) {
|
||||
const t = s.tasks[ti]
|
||||
const taskCode = `T-${nextTaskN++}`
|
||||
const task = await tx.task.create({
|
||||
data: {
|
||||
story_id: story.id,
|
||||
product_id: productId,
|
||||
code: `T-${nextTaskN++}`,
|
||||
code: taskCode,
|
||||
title: t.title,
|
||||
description: t.description ?? null,
|
||||
implementation_plan: t.implementation_plan ?? null,
|
||||
|
|
@ -751,7 +754,7 @@ export async function materializeIdeaPlanAction(
|
|||
// gemixte task-priorities binnen één story zouden anders de
|
||||
// YAML-volgorde verstoren (zie plan-fix task-volgorde-na-upload).
|
||||
priority: s.priority,
|
||||
sort_order: ti + 1,
|
||||
sort_order: parseCodeNumber(taskCode),
|
||||
status: 'TO_DO',
|
||||
verify_required: t.verify_required ?? 'ALIGNED_OR_PARTIAL',
|
||||
verify_only: t.verify_only ?? false,
|
||||
|
|
|
|||
|
|
@ -85,10 +85,10 @@ async function startSprintRunCore(
|
|||
// TO_DO, dus EXCLUDED/IN_PROGRESS/REVIEW/DONE/FAILED tasks komen niet
|
||||
// terecht in pre-flight blockers, jobs of SprintTaskExecution-rijen.
|
||||
where: { status: 'TO_DO' },
|
||||
orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }],
|
||||
orderBy: [{ sort_order: 'asc' }],
|
||||
},
|
||||
},
|
||||
orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }],
|
||||
orderBy: [{ sort_order: 'asc' }],
|
||||
})
|
||||
|
||||
const blockers: PreFlightBlocker[] = []
|
||||
|
|
@ -167,7 +167,6 @@ async function startSprintRunCore(
|
|||
(a, b) =>
|
||||
a.pbi.priority - b.pbi.priority ||
|
||||
a.pbi.sort_order - b.pbi.sort_order ||
|
||||
a.priority - b.priority ||
|
||||
a.sort_order - b.sort_order,
|
||||
)
|
||||
.flatMap((s) => s.tasks)
|
||||
|
|
|
|||
|
|
@ -431,7 +431,7 @@ export async function createSprintAction(_prevState: unknown, formData: FormData
|
|||
if (pbi) {
|
||||
const stories = await prisma.story.findMany({
|
||||
where: { pbi_id: pbi.id, sprint_id: null },
|
||||
orderBy: [{ priority: 'asc' }, { sort_order: 'asc' }],
|
||||
orderBy: [{ sort_order: 'asc' }],
|
||||
select: { id: true },
|
||||
})
|
||||
if (stories.length > 0) {
|
||||
|
|
@ -440,7 +440,7 @@ export async function createSprintAction(_prevState: unknown, formData: FormData
|
|||
...stories.map((s, i) =>
|
||||
prisma.story.update({
|
||||
where: { id: s.id },
|
||||
data: { sprint_id: sprint.id, status: 'IN_SPRINT', sort_order: i + 1 },
|
||||
data: { sprint_id: sprint.id, status: 'IN_SPRINT' },
|
||||
}),
|
||||
),
|
||||
prisma.task.updateMany({
|
||||
|
|
@ -531,14 +531,9 @@ export async function addStoryToSprintAction(sprintId: string, storyId: string)
|
|||
if (!story) return { error: 'Story niet gevonden' }
|
||||
if (story.product_id !== sprint.product_id) return { error: 'Story hoort niet bij deze Sprint' }
|
||||
|
||||
const last = await prisma.story.findFirst({
|
||||
where: { sprint_id: sprintId },
|
||||
orderBy: { sort_order: 'desc' },
|
||||
})
|
||||
|
||||
await prisma.story.update({
|
||||
where: { id: storyId },
|
||||
data: { sprint_id: sprintId, status: 'IN_SPRINT', sort_order: (last?.sort_order ?? 0) + 1.0 },
|
||||
data: { sprint_id: sprintId, status: 'IN_SPRINT' },
|
||||
})
|
||||
|
||||
revalidatePath(`/products/${sprint.product_id}/sprint`)
|
||||
|
|
@ -567,32 +562,6 @@ export async function removeStoryFromSprintAction(storyId: string) {
|
|||
return { success: true }
|
||||
}
|
||||
|
||||
export async function reorderSprintStoriesAction(sprintId: string, orderedIds: string[]) {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { error: 'Niet ingelogd' }
|
||||
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
||||
if (hasDuplicateIds(orderedIds)) return { error: 'Ongeldige Sprint Backlog-volgorde' }
|
||||
|
||||
const sprint = await prisma.sprint.findFirst({
|
||||
where: { id: sprintId, product: productAccessFilter(session.userId) },
|
||||
})
|
||||
if (!sprint) return { error: 'Sprint niet gevonden' }
|
||||
|
||||
const stories = await prisma.story.findMany({
|
||||
where: { id: { in: orderedIds }, sprint_id: sprintId, product_id: sprint.product_id },
|
||||
select: { id: true },
|
||||
})
|
||||
if (stories.length !== orderedIds.length) return { error: 'Ongeldige Sprint Backlog-volgorde' }
|
||||
|
||||
await prisma.$transaction(
|
||||
orderedIds.map((id, i) =>
|
||||
prisma.story.update({ where: { id }, data: { sort_order: i + 1.0 } })
|
||||
)
|
||||
)
|
||||
|
||||
revalidatePath(`/products/${sprint.product_id}/sprint`)
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
export async function completeSprintAction(
|
||||
sprintId: string,
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { prisma } from '@/lib/prisma'
|
|||
import { SessionData, sessionOptions } from '@/lib/session'
|
||||
import { getAccessibleProduct, productAccessFilter } from '@/lib/product-access'
|
||||
import { requireProductWriter } from '@/lib/auth'
|
||||
import { isValidCode, normalizeCode } from '@/lib/code'
|
||||
import { isValidCode, normalizeCode, parseCodeNumber } from '@/lib/code'
|
||||
import { createWithCodeRetry, generateNextStoryCode } from '@/lib/code-server'
|
||||
import { createStorySchema, updateStorySchema } from '@/lib/schemas/story'
|
||||
import { enforceUserRateLimit } from '@/lib/rate-limit'
|
||||
|
|
@ -78,12 +78,6 @@ export async function createStoryAction(_prevState: unknown, formData: FormData)
|
|||
}
|
||||
}
|
||||
|
||||
const last = await prisma.story.findFirst({
|
||||
where: { pbi_id: parsed.data.pbiId, priority: parsed.data.priority },
|
||||
orderBy: { sort_order: 'desc' },
|
||||
})
|
||||
const sort_order = (last?.sort_order ?? 0) + 1.0
|
||||
|
||||
const insert = (code: string) =>
|
||||
prisma.story.create({
|
||||
data: {
|
||||
|
|
@ -94,7 +88,7 @@ export async function createStoryAction(_prevState: unknown, formData: FormData)
|
|||
description: parsed.data.description ?? null,
|
||||
acceptance_criteria: parsed.data.acceptance_criteria ?? null,
|
||||
priority: parsed.data.priority,
|
||||
sort_order,
|
||||
sort_order: parseCodeNumber(code),
|
||||
status: 'OPEN',
|
||||
},
|
||||
})
|
||||
|
|
@ -167,7 +161,7 @@ export async function updateStoryAction(_prevState: unknown, formData: FormData)
|
|||
await prisma.story.update({
|
||||
where: { id: parsed.data.id },
|
||||
data: {
|
||||
...(code ? { code } : {}),
|
||||
...(code ? { code, sort_order: parseCodeNumber(code) } : {}),
|
||||
title: parsed.data.title,
|
||||
description: parsed.data.description ?? null,
|
||||
acceptance_criteria: parsed.data.acceptance_criteria ?? null,
|
||||
|
|
@ -363,43 +357,3 @@ export async function claimAllUnassignedInActiveSprintAction(productId: string)
|
|||
return { success: true, count: result.count }
|
||||
}
|
||||
|
||||
export async function reorderStoriesAction(
|
||||
pbiId: string,
|
||||
productId: string,
|
||||
orderedIds: string[],
|
||||
newPriority?: number
|
||||
) {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { error: 'Niet ingelogd' }
|
||||
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
||||
if (hasDuplicateIds(orderedIds)) return { error: 'Ongeldige story-volgorde' }
|
||||
if (newPriority !== undefined && (!Number.isInteger(newPriority) || newPriority < 1 || newPriority > 4)) {
|
||||
return { error: 'Ongeldige prioriteit' }
|
||||
}
|
||||
|
||||
const pbi = await prisma.pbi.findFirst({
|
||||
where: { id: pbiId, product: productAccessFilter(session.userId) },
|
||||
})
|
||||
if (!pbi) return { error: 'PBI niet gevonden' }
|
||||
|
||||
const stories = await prisma.story.findMany({
|
||||
where: { id: { in: orderedIds }, pbi_id: pbiId, product_id: pbi.product_id },
|
||||
select: { id: true },
|
||||
})
|
||||
if (stories.length !== orderedIds.length) return { error: 'Ongeldige story-volgorde' }
|
||||
|
||||
await prisma.$transaction(
|
||||
orderedIds.map((id, i) =>
|
||||
prisma.story.update({
|
||||
where: { id },
|
||||
data: {
|
||||
sort_order: i + 1.0,
|
||||
...(newPriority !== undefined ? { priority: newPriority } : {}),
|
||||
},
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
revalidatePath(`/products/${pbi.product_id}`)
|
||||
return { success: true }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { productAccessFilter } from '@/lib/product-access'
|
|||
import { requireProductWriter } from '@/lib/auth'
|
||||
import { taskSchema as sharedTaskSchema, type TaskInput } from '@/lib/schemas/task'
|
||||
import { propagateStatusUpwards } from '@/lib/tasks-status-update'
|
||||
import { normalizeCode } from '@/lib/code'
|
||||
import { normalizeCode, parseCodeNumber } from '@/lib/code'
|
||||
import { createWithCodeRetry, generateNextTaskCode, isCodeUniqueConflict } from '@/lib/code-server'
|
||||
import { enforceUserRateLimit } from '@/lib/rate-limit'
|
||||
|
||||
|
|
@ -80,6 +80,7 @@ export async function saveTask(
|
|||
description: description ?? null,
|
||||
implementation_plan: implementation_plan ?? null,
|
||||
priority,
|
||||
...(inputCode ? { code: inputCode, sort_order: parseCodeNumber(inputCode) } : {}),
|
||||
},
|
||||
select: { id: true, title: true, status: true },
|
||||
})
|
||||
|
|
@ -106,15 +107,8 @@ export async function saveTask(
|
|||
})
|
||||
if (!story) return { ok: false, code: 403, error: 'forbidden' }
|
||||
|
||||
const last = await prisma.task.findFirst({
|
||||
where: { story_id: context.storyId },
|
||||
orderBy: { sort_order: 'desc' },
|
||||
select: { sort_order: true },
|
||||
})
|
||||
|
||||
const productId = story.product_id
|
||||
const sprintId = story.sprint_id ?? null
|
||||
const sortOrder = (last?.sort_order ?? 0) + 1.0
|
||||
const storyId = context.storyId
|
||||
|
||||
const task = await createWithCodeRetry(
|
||||
|
|
@ -130,7 +124,7 @@ export async function saveTask(
|
|||
description: description ?? null,
|
||||
implementation_plan: implementation_plan ?? null,
|
||||
priority,
|
||||
sort_order: sortOrder,
|
||||
sort_order: parseCodeNumber(code),
|
||||
status: 'TO_DO',
|
||||
},
|
||||
select: { id: true, title: true, status: true },
|
||||
|
|
@ -207,11 +201,6 @@ export async function createTaskAction(_prevState: unknown, formData: FormData)
|
|||
})
|
||||
if (!story) return { error: 'Story niet gevonden' }
|
||||
|
||||
const last = await prisma.task.findFirst({
|
||||
where: { story_id: storyId },
|
||||
orderBy: { sort_order: 'desc' },
|
||||
})
|
||||
|
||||
const productId = story.product_id
|
||||
const task = await createWithCodeRetry(
|
||||
() => generateNextTaskCode(productId),
|
||||
|
|
@ -225,7 +214,7 @@ export async function createTaskAction(_prevState: unknown, formData: FormData)
|
|||
title: parsed.data.title,
|
||||
description: parsed.data.description ?? null,
|
||||
priority: parsed.data.priority,
|
||||
sort_order: (last?.sort_order ?? 0) + 1.0,
|
||||
sort_order: parseCodeNumber(code),
|
||||
status: 'TO_DO',
|
||||
},
|
||||
}),
|
||||
|
|
@ -333,22 +322,3 @@ export async function updateTaskPlanAction(taskId: string, productId: string, im
|
|||
return { success: true }
|
||||
}
|
||||
|
||||
export async function reorderTasksAction(storyId: string, orderedIds: string[]) {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { error: 'Niet ingelogd' }
|
||||
if (session.isDemo) return { error: 'Niet beschikbaar in demo-modus' }
|
||||
|
||||
const story = await prisma.story.findFirst({
|
||||
where: { id: storyId, product: productAccessFilter(session.userId) },
|
||||
})
|
||||
if (!story) return { error: 'Story niet gevonden' }
|
||||
|
||||
await prisma.$transaction(
|
||||
orderedIds.map((id, i) =>
|
||||
prisma.task.update({ where: { id }, data: { sort_order: i + 1.0 } })
|
||||
)
|
||||
)
|
||||
|
||||
revalidatePath(`/products/${story.product_id}/sprint/planning`)
|
||||
return { success: true }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue