* 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.
85 lines
2.7 KiB
TypeScript
85 lines
2.7 KiB
TypeScript
// Bidirectionele case-mapper voor IdeaStatus + transitie-guard helper.
|
|
// DB houdt UPPER_SNAKE; API exposeert lowercase.
|
|
// Patroon volgt lib/task-status.ts.
|
|
|
|
import type { IdeaStatus } from '@prisma/client'
|
|
|
|
const IDEA_DB_TO_API = {
|
|
DRAFT: 'draft',
|
|
GRILLING: 'grilling',
|
|
GRILL_FAILED: 'grill_failed',
|
|
GRILLED: 'grilled',
|
|
PLANNING: 'planning',
|
|
PLAN_FAILED: 'plan_failed',
|
|
PLAN_READY: 'plan_ready',
|
|
PLANNED: 'planned',
|
|
} as const satisfies Record<IdeaStatus, string>
|
|
|
|
const IDEA_API_TO_DB: Record<string, IdeaStatus> = {
|
|
draft: 'DRAFT',
|
|
grilling: 'GRILLING',
|
|
grill_failed: 'GRILL_FAILED',
|
|
grilled: 'GRILLED',
|
|
planning: 'PLANNING',
|
|
plan_failed: 'PLAN_FAILED',
|
|
plan_ready: 'PLAN_READY',
|
|
planned: 'PLANNED',
|
|
}
|
|
|
|
export type IdeaStatusApi = (typeof IDEA_DB_TO_API)[IdeaStatus]
|
|
|
|
export function ideaStatusToApi(s: IdeaStatus): IdeaStatusApi {
|
|
return IDEA_DB_TO_API[s]
|
|
}
|
|
|
|
export function ideaStatusFromApi(s: string): IdeaStatus | null {
|
|
return IDEA_API_TO_DB[s.toLowerCase()] ?? null
|
|
}
|
|
|
|
export const IDEA_STATUS_API_VALUES = Object.values(IDEA_DB_TO_API)
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// State-machine transition table (zie docs/plans/M12-ideas.md state-machine).
|
|
// Server-actions gebruiken canTransition(from, to) als guard vóór mutatie.
|
|
//
|
|
// Asymmetrisch: trek vanuit DRAFT alleen naar GRILLING; vanuit GRILLED kan
|
|
// re-grill (→ GRILLING) of make-plan (→ PLANNING) gebeuren. PLANNED is een
|
|
// terminal state; verlaat alleen via expliciete relink (PBI verwijderd → PLAN_READY).
|
|
|
|
const ALLOWED_TRANSITIONS: Record<IdeaStatus, ReadonlyArray<IdeaStatus>> = {
|
|
DRAFT: ['GRILLING'],
|
|
GRILLING: ['GRILLED', 'GRILL_FAILED'],
|
|
GRILL_FAILED: ['GRILLING', 'DRAFT'],
|
|
GRILLED: ['GRILLING', 'PLANNING'],
|
|
PLANNING: ['PLAN_READY', 'PLAN_FAILED'],
|
|
PLAN_FAILED: ['PLANNING', 'GRILLED'],
|
|
PLAN_READY: ['PLANNING', 'PLANNED'],
|
|
PLANNED: ['PLAN_READY', 'GRILLING'], // PLAN_READY via relinkIdeaPlanAction; GRILLING via startGrillJobAction
|
|
}
|
|
|
|
export function canTransition(from: IdeaStatus, to: IdeaStatus): boolean {
|
|
return ALLOWED_TRANSITIONS[from].includes(to)
|
|
}
|
|
|
|
// Statussen waarin een idee bewerkbaar is (form-input, niet md-velden).
|
|
const EDITABLE_STATUSES: ReadonlyArray<IdeaStatus> = [
|
|
'DRAFT',
|
|
'GRILL_FAILED',
|
|
'GRILLED',
|
|
'PLAN_FAILED',
|
|
'PLAN_READY',
|
|
]
|
|
|
|
export function isIdeaEditable(s: IdeaStatus): boolean {
|
|
return EDITABLE_STATUSES.includes(s)
|
|
}
|
|
|
|
// Statussen waarin grill_md bewerkbaar is (handmatige finetuning).
|
|
export function isGrillMdEditable(s: IdeaStatus): boolean {
|
|
return s === 'GRILLED' || s === 'PLAN_READY'
|
|
}
|
|
|
|
// Statussen waarin plan_md bewerkbaar is.
|
|
export function isPlanMdEditable(s: IdeaStatus): boolean {
|
|
return s === 'PLAN_READY'
|
|
}
|