Scrum4Me/components/ideas/idea-row-actions.tsx
Janpeter Visser d292e445d9
Sprint: Verbeteren debug mode (#179)
* feat(PBI-49): add debugProps helper + Vitest test

Adds lib/debug.ts with debugProps(id, component, file) that returns
data-debug-id and data-debug-label attrs in dev mode, empty object in
production. Adds __tests__/lib/debug.test.ts covering both modes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(PBI-49): add debug-id pattern doc + CLAUDE.md reference

Adds docs/patterns/debug-id.md documenting the named-component boundary
rule (6 punten), helper-voorbeeld, skip-criteria en motivatie voor
handmatige pad-argumenten. Voegt verwijzing toe aan CLAUDE.md
patterns-tabel.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(PBI-49): migrate 17 shared/ components to debugProps helper

Replace hardcoded data-debug-id + data-debug-label attribute pairs with
{...debugProps(id, component, file)} spread in all 17 components/shared/
files. Existing debug-ids preserved unchanged.

* feat(PBI-49): add debugProps to backlog/, sprint/, solo/ components

* feat(PBI-49): add debugProps to jobs/ + ideas/ components

* feat(PBI-49): add debugProps to products/ + settings/ + notifications/ components

* feat(PBI-49): add debugProps to admin/ + dashboard/ + dialogs/ + mobile/ + split-pane/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(PBI-49): use attr(data-debug-id) for debug tooltip in globals.css

* refactor(PBI-49): remove data-debug-label from debugProps helper + test

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* refactor(PBI-49): strip unused component/file args from debugProps in shared/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to StatusBar, NavBar, PanelNavBar

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/sprint/*

- new-sprint-dialog: __submit on submit button
- sprint-backlog: __list on SprintBacklogLeft + SprintBacklogRight scroll areas
- sprint-board-client: root wrapper div (display:contents) + __drag-overlay
- sprint-header: __title on goal button, __dates on dates button, __actions on action cluster
- sprint-run-controls: root on controls div, __start/__cancel on action buttons; __blockers-dialog on dialog content
- start-sprint-button: root on trigger button, __dialog on dialog content, __submit on submit button
- sync-active-sprint-cookie: no debug-id (returns null, side-effect only), comment added

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/backlog/*

* feat(PBI-49): add BEM sub-element data-debug-id to components/ideas/*

* feat(PBI-49): add BEM sub-element data-debug-id to components/dashboard/* + components/markdown.tsx

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to new-product-button

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/solo/*

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-elements to nav-status-indicators

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/jobs/*

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to components/products/*

* feat(PBI-49): add BEM sub-element data-debug-id to components/notifications/*

- answer-modal: __content (scroll area), __submit (footer)
- notifications-bridge: skip comment (bridge, non-rendering wrapper)
- notifications-realtime-mount: skip comment (returns null)
- notifications-sheet: __header, __items (questions list)
- push-toggle: __switch (button), __label (button text) on subscribed/unsubscribed states

* feat(PBI-49): add BEM sub-element data-debug-id to components/settings/*

- leave-product-button: root only (single-button component)
- min-quota-editor: __input (number input), __save (save button)
- profile-editor: __username (bio/short-description input), __save (submit)
- role-manager: __roles (checkbox list), __add (save button)
- token-manager: __tokens (active tokens list), __generate (create button)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* feat(PBI-49): add BEM sub-element data-debug-id to admin, auth, dialogs, entity-dialog, mobile, split-pane

* docs(PBI-49): add debug-labels BEM pattern doc + CLAUDE.md entry

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-09 22:46:29 +02:00

287 lines
8.4 KiB
TypeScript

'use client'
// IdeaRowActions — Grill Me / Make Plan / Materialiseer / Archive / Open.
// Disabled-rules per M12 T-508:
//
// Grill Me: niet in GRILLING|PLANNING; vereist product-met-repo +
// connectedWorkers > 0
// Make Plan: alleen in GRILLED|PLAN_FAILED|PLAN_READY (re-plan); idem
// voorwaarden
// Materialiseer: alleen in PLAN_READY (geen worker nodig — synchrone parser)
// PLANNED: alle drie disabled, "Bekijk PBI" link
// *_FAILED: "Probeer opnieuw" knop (= start-job opnieuw)
//
// Demo-tooltip om elke muteer-knop. connectedWorkers wordt gelezen uit
// useSoloStore (M12 grill-keuze 16 — geen lift voor v1).
import { useTransition } from 'react'
import { useRouter } from 'next/navigation'
import {
Archive,
ArrowRight,
ExternalLink,
Flame,
Layers,
RotateCw,
Sparkles,
} from 'lucide-react'
import { toast } from 'sonner'
import { Button } from '@/components/ui/button'
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '@/components/ui/tooltip'
import { DemoTooltip } from '@/components/shared/demo-tooltip'
import { useSoloStore } from '@/stores/solo-store'
import { debugProps } from '@/lib/debug'
import {
startGrillJobAction,
startMakePlanJobAction,
materializeIdeaPlanAction,
} from '@/actions/ideas'
import type { IdeaDto } from '@/lib/idea-dto'
interface IdeaRowActionsProps {
idea: IdeaDto
isDemo: boolean
onArchive: () => void
}
export function IdeaRowActions({ idea, isDemo, onArchive }: IdeaRowActionsProps) {
const router = useRouter()
const connectedWorkers = useSoloStore((s) => s.connectedWorkers)
const [pending, startTransition] = useTransition()
const hasProductWithRepo = idea.product != null && idea.product.repo_url !== null
const workerOk = connectedWorkers > 0
const status = idea.status
// ---- Grill Me ----
const grillBlockedReason = (() => {
if (status === 'grilling' || status === 'planning') return 'Job loopt al'
if (!hasProductWithRepo) return 'Idee heeft een product met repo nodig'
if (!workerOk) return 'Geen Claude-worker actief'
return null
})()
const grillEnabled = !grillBlockedReason && !isDemo && !pending
// ---- Make Plan ----
const makePlanAllowedStates = ['grilled', 'plan_failed', 'plan_ready']
const makePlanBlockedReason = (() => {
if (!makePlanAllowedStates.includes(status)) {
if (status === 'draft' || status === 'grill_failed') return 'Eerst grillen'
if (status === 'grilling' || status === 'planning') return 'Job loopt al'
if (status === 'planned') return 'Idee is gepland — open de PBI'
return null
}
if (!hasProductWithRepo) return 'Idee heeft een product met repo nodig'
if (!workerOk) return 'Geen Claude-worker actief'
return null
})()
const makePlanEnabled = !makePlanBlockedReason && !isDemo && !pending
// ---- Materialiseer ----
const materializeBlockedReason = (() => {
if (status !== 'plan_ready') return 'Plan is niet klaar'
return null
})()
const materializeEnabled = !materializeBlockedReason && !isDemo && !pending
// ---- Failed-states tonen "Probeer opnieuw" ----
const isFailedState = status === 'grill_failed' || status === 'plan_failed'
function runStart(action: typeof startGrillJobAction | typeof startMakePlanJobAction) {
startTransition(async () => {
const r = await action(idea.id)
if ('error' in r) {
toast.error(r.error)
return
}
toast.success('Job in de wachtrij — een worker pakt hem op.')
router.refresh()
})
}
function handleMaterialize() {
if (!confirm('Plan materialiseren? Dit maakt PBI + stories + taken aan.')) return
startTransition(async () => {
let r = await materializeIdeaPlanAction(idea.id)
if ('error' in r && r.code === 409 && r.error.startsWith('PBI_HAS_ACTIVE_TASKS:')) {
const pbiCode = r.error.split(':')[1]
const alongside = confirm(
`De bestaande PBI (${pbiCode}) heeft uitgevoerde taken.\n` +
`OK = nieuwe PBI naast bestaande aanmaken.\n` +
`Annuleren = stoppen.`
)
if (!alongside) return
r = await materializeIdeaPlanAction(idea.id, { allowAlongside: true })
}
if ('error' in r) {
toast.error(r.error)
return
}
toast.success(`Gematerialiseerd als ${r.data?.pbi_code}`)
if (idea.product_id) {
router.push(`/products/${idea.product_id}`)
} else {
router.refresh()
}
})
}
return (
<div className="flex items-center gap-1" {...debugProps('idea-row-actions', 'IdeaRowActions', 'components/ideas/idea-row-actions.tsx')}>
{/* Bekijk PBI — alleen zichtbaar in PLANNED */}
{status === 'planned' && idea.pbi && idea.product_id && (
<Button
variant="outline"
size="sm"
onClick={() => router.push(`/products/${idea.product_id!}`)}
>
Bekijk {idea.pbi.code}
<ExternalLink className="ml-1 size-3.5" />
</Button>
)}
{/* Grill Me */}
<span data-debug-id="idea-row-actions__grill">
<ActionButton
label="Grill"
icon={<Flame className="size-3.5" />}
enabled={grillEnabled}
blockedReason={grillBlockedReason}
isDemo={isDemo}
onClick={() => runStart(startGrillJobAction)}
/>
</span>
{/* Make Plan */}
<span data-debug-id="idea-row-actions__plan">
<ActionButton
label="Plan"
icon={<Sparkles className="size-3.5" />}
enabled={makePlanEnabled}
blockedReason={makePlanBlockedReason}
isDemo={isDemo}
onClick={() => runStart(startMakePlanJobAction)}
/>
</span>
{/* Materialiseer */}
<ActionButton
label="Maak PBI"
icon={<Layers className="size-3.5" />}
enabled={materializeEnabled}
blockedReason={materializeBlockedReason}
isDemo={isDemo}
onClick={handleMaterialize}
variant="default"
/>
{/* Failed-states: kleine retry-shortcut */}
{isFailedState && (
<DemoTooltip show={isDemo}>
<Button
size="sm"
variant="outline"
disabled={isDemo || pending || !workerOk || !hasProductWithRepo}
onClick={() =>
runStart(
status === 'grill_failed' ? startGrillJobAction : startMakePlanJobAction,
)
}
title="Probeer opnieuw"
>
<RotateCw className="size-3.5" />
</Button>
</DemoTooltip>
)}
{/* Open detail */}
<Button
size="sm"
variant="ghost"
onClick={() => router.push(`/ideas/${idea.id}`)}
aria-label="Open idee"
title="Open idee"
>
<ArrowRight className="size-4" />
</Button>
{/* Archive */}
<DemoTooltip show={isDemo}>
<Button
size="sm"
variant="ghost"
onClick={onArchive}
disabled={isDemo || pending}
aria-label="Archiveer idee"
title="Archiveer"
data-debug-id="idea-row-actions__delete"
>
<Archive className="size-4" />
</Button>
</DemoTooltip>
</div>
)
}
interface ActionButtonProps {
label: string
icon: React.ReactNode
enabled: boolean
blockedReason: string | null
isDemo: boolean
onClick: () => void
variant?: 'default' | 'outline'
}
function ActionButton({
label,
icon,
enabled,
blockedReason,
isDemo,
onClick,
variant = 'outline',
}: ActionButtonProps) {
// Bij demo: DemoTooltip toont reden. Bij niet-demo + reden: gewone tooltip.
if (isDemo) {
return (
<DemoTooltip show>
<Button size="sm" variant={variant} disabled>
{icon}
<span className="ml-1">{label}</span>
</Button>
</DemoTooltip>
)
}
if (!enabled && blockedReason) {
return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger render={<span className="inline-flex" />}>
<Button size="sm" variant={variant} disabled>
{icon}
<span className="ml-1">{label}</span>
</Button>
</TooltipTrigger>
<TooltipContent>{blockedReason}</TooltipContent>
</Tooltip>
</TooltipProvider>
)
}
return (
<Button size="sm" variant={variant} onClick={onClick}>
{icon}
<span className="ml-1">{label}</span>
</Button>
)
}