Sprint: Idee regril mogelijkheid (#144)
* feat(ST-cmovhveef): add PLANNED to GRILL_TRIGGERABLE_FROM and PLANNED→GRILLING transition - GRILL_TRIGGERABLE_FROM now includes 'PLANNED' in actions/ideas.ts - ALLOWED_TRANSITIONS PLANNED entry extended with 'GRILLING' in lib/idea-status.ts - Updated canTransition test to reflect the new re-grill-from-PLANNED behavior * test(ST-cmovhvef3): add exhaustive re-grill canTransition test covering PLANNED Adds a loop test that asserts canTransition(status, 'GRILLING') for all statuses in GRILL_TRIGGERABLE_FROM that support the transition, explicitly documenting PLANNED as a valid re-grill entry point. * feat(ST-cmovhvegf): add existingPbi pre-check in materializeIdeaPlanAction - Adds options.allowAlongside parameter to control behaviour when a PBI with executed tasks already exists. - Returns 409 PBI_HAS_ACTIVE_TASKS:<code> when tasks are DONE/IN_PROGRESS and allowAlongside is not set. - Auto-deletes the old PBI inside the transaction when no tasks have been executed (atomic replace). - Alongside mode (allowAlongside=true) skips deletion and creates a new PBI. * test(ST-cmovhveh3): add pre-check integration tests for materializeIdeaPlanAction Three new scenarios in ideas-crud.test.ts: - auto-vervang: old PBI deleted in transaction when no executed tasks - conflict-409: returns PBI_HAS_ACTIVE_TASKS:<code> with active tasks - alongside: skips delete and creates new PBI when allowAlongside=true Also adds task.count, pbi.findUnique, pbi.delete to prisma mock. * feat(ST-cmovhveih): remove PLANNED-blokkering in idea-row-actions, add inline Bekijk-PBI button - Removed grillBlockedReason guard for status==='planned', enabling re-grill from PLANNED - Removed the early return for PLANNED that hid all standard buttons - Added conditional 'Bekijk <code>' button at the start of the standard button set, visible only when status==='planned' and PBI + product_id are present * feat(ST-cmovhvej7): add PBI_HAS_ACTIVE_TASKS alongside-dialoog in materialize handler When materializeIdeaPlanAction returns code 409 with PBI_HAS_ACTIVE_TASKS:<code>, a confirm dialog offers the user a choice: create new PBI alongside the existing one or cancel. Alongside=true retries the action; cancel leaves the idea in PLAN_READY.
This commit is contained in:
parent
2d27c41d38
commit
5cb3abbd3d
5 changed files with 130 additions and 34 deletions
|
|
@ -338,7 +338,7 @@ export async function downloadIdeaMdAction(
|
|||
// ---------------------------------------------------------------------------
|
||||
// Job-triggers (Grill Me / Make Plan / Cancel)
|
||||
|
||||
const GRILL_TRIGGERABLE_FROM: IdeaStatus[] = ['DRAFT', 'GRILLED', 'GRILL_FAILED', 'PLAN_READY']
|
||||
const GRILL_TRIGGERABLE_FROM: IdeaStatus[] = ['DRAFT', 'GRILLED', 'GRILL_FAILED', 'PLAN_READY', 'PLANNED']
|
||||
const MAKE_PLAN_TRIGGERABLE_FROM: IdeaStatus[] = ['GRILLED', 'PLAN_FAILED', 'PLAN_READY']
|
||||
|
||||
export async function startGrillJobAction(id: string): Promise<ActionResult<{ job_id: string }>> {
|
||||
|
|
@ -540,6 +540,7 @@ function nextNumber(existing: (string | null)[], re: RegExp): number {
|
|||
|
||||
export async function materializeIdeaPlanAction(
|
||||
id: string,
|
||||
options?: { allowAlongside?: boolean },
|
||||
): Promise<ActionResult<{ pbi_id: string; pbi_code: string; story_ids: string[]; task_ids: string[] }>> {
|
||||
const session = await getSession()
|
||||
if (!session.userId) return { error: 'Niet ingelogd', code: 401 }
|
||||
|
|
@ -550,7 +551,7 @@ export async function materializeIdeaPlanAction(
|
|||
|
||||
const idea = await prisma.idea.findFirst({
|
||||
where: { id, user_id: session.userId },
|
||||
select: { id: true, status: true, product_id: true, plan_md: true },
|
||||
select: { id: true, status: true, product_id: true, plan_md: true, pbi_id: true },
|
||||
})
|
||||
if (!idea) return { error: 'Idee niet gevonden', code: 404 }
|
||||
if (idea.status !== 'PLAN_READY') {
|
||||
|
|
@ -574,8 +575,36 @@ export async function materializeIdeaPlanAction(
|
|||
const productId = idea.product_id
|
||||
const plan = parsed.plan
|
||||
|
||||
let oldPbiId: string | null = null
|
||||
if (idea.pbi_id) {
|
||||
const executedCount = await prisma.task.count({
|
||||
where: {
|
||||
story: { pbi_id: idea.pbi_id },
|
||||
status: { in: ['DONE', 'IN_PROGRESS'] },
|
||||
},
|
||||
})
|
||||
if (executedCount > 0 && !options?.allowAlongside) {
|
||||
const existingPbi = await prisma.pbi.findUnique({
|
||||
where: { id: idea.pbi_id },
|
||||
select: { code: true },
|
||||
})
|
||||
return {
|
||||
error: `PBI_HAS_ACTIVE_TASKS:${existingPbi?.code ?? idea.pbi_id}`,
|
||||
code: 409,
|
||||
}
|
||||
}
|
||||
if (executedCount === 0) {
|
||||
oldPbiId = idea.pbi_id
|
||||
}
|
||||
// executedCount > 0 && allowAlongside: doorgaan zonder delete
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await prisma.$transaction(async (tx) => {
|
||||
if (oldPbiId) {
|
||||
await tx.pbi.delete({ where: { id: oldPbiId } })
|
||||
}
|
||||
|
||||
// Codes: één keer SELECT max per type binnen de transactie. Bij P2002
|
||||
// (race met andere materialize) abort de transactie en gooien we 409.
|
||||
const [existingPbis, existingStories, existingTasks] = await Promise.all([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue