feat(PBI-74): sprint-workspace-store (Story 9) (#181)
* feat(PBI-74): sprint-workspace-store skelet (Story 9 / T-879)
- stores/sprint-workspace/{types,store,selectors,restore}.ts conform
product-workspace blueprint
- ContextSlice: activeProduct, activeSprintId, activeStoryId, activeTaskId
- EntitiesSlice: sprintsById, storiesById, tasksById
- RelationsSlice: sprintIdsByProduct, storyIdsBySprint, taskIdsByStory
- LoadingSlice met activeRequestId voor race-safe ensure*Loaded
- SyncSlice: realtimeStatus, lastResyncAt, resyncReason
- Realtime applyRealtimeEvent voor sprint/story/task entities + unknown-event
fallback, parent-move handling, child-cleanup bij D op sprint/story
- Optimistic mutations: sprint-story-order, sprint-task-order, entity-patch
- LocalStorage hints (storage key sprint-workspace-hints) per product/sprint
- 45 unit-tests groen — verplicht 13 cases uit workspace-store.md §Tests
* feat(PBI-74): sprint hydratie + realtime SSE (Story 9 / T-880)
- app/api/realtime/sprint/route.ts: SSE-stream LISTEN/NOTIFY op
scrum4me_changes, filter entity ∈ {sprint, story, task} per product_id;
ready-event, heartbeat 25s, hard-close 240s
- lib/realtime/use-sprint-realtime.ts: client-hook met backoff-reconnect;
ready-cycle telt; geen close op hidden; setRealtimeStatus
- lib/realtime/use-sprint-workspace-resync.ts: visibility + online triggers
resyncActiveScopes('visible' | 'reconnect')
- components/sprint/sprint-hydration-wrapper.tsx: hydrateSnapshot via
useEffect met fingerprint-check; mount realtime + resync
- app/(app)/products/[id]/sprint/[sprintId]/page.tsx: wrap SprintBoardClient
in SprintHydrationWrapper; bouw SprintWorkspaceTask-shape voor
tasksByStoryWorkspace en SprintHydrationData voor de wrapper
Schaduw-fase: useSprintStore blijft parallel werken in board components
totdat T-881 die migreert en T-883 de oude store opruimt.
* feat(PBI-74): migreer sprint-board componenten naar workspace-store (Story 9 / T-881)
- TaskList: leest tasks via selectTasksForStory met useShallow; DnD via
applyOptimisticMutation('sprint-task-order') + settle/rollback
- SprintBacklogLeft: leest stories via selectStoriesForActiveSprint met
useShallow; props 'stories' verwijderd
- SprintBoardClient: leest sprintStories uit selector i.p.v. lokale state;
add/remove via direct setState met manuele snapshot-rollback;
reorder via applyOptimisticMutation('sprint-story-order'); assignee-
change via store entity-mutation; tasksByStory en sprintStoryIdList
props weg
- app/(app)/.../sprint/[sprintId]/page.tsx: bouwt SprintHydrationData voor
wrapper; geeft alleen non-store props door aan SprintBoardClient
useSprintStore wordt nergens meer geïmporteerd — alleen comment-referentie
in SprintHydrationWrapper. Cleanup van het bestand zelf in T-883.
Verify groen (671 tests, typecheck, lint clean).
* feat(PBI-74): read-routes voor sprint-workspace + cache-headers (Story 9 / T-882)
- GET /api/products/[id]/sprints — lijst sprints per product
(ensureProductSprintsLoaded). force-dynamic, productAccessFilter,
start_date/end_date naar ISO-date string.
- GET /api/sprints/[id]/workspace — sprint snapshot met sprint-meta,
stories (incl. taskCount/doneCount/assignee), tasks gegroepeerd per
story (ensureSprintLoaded). force-dynamic, productAccessFilter via
product, status-vertaling via taskStatusToApi/storyStatusToApi.
Race-safe loaders (activeRequestId-guard), restore-flow (cascade-restore
via writeProductHint/writeSprintHint/writeStoryHint/writeTaskHint),
resync-laag (useSprintWorkspaceResync visibility + online), unknown-event
filter (isUnknownEntityEvent → resyncActiveScopes('unknown-event')) zijn
allemaal in T-879/T-880 al ingebouwd; T-882 sluit het loop met de
ontbrekende API-endpoints + cache-headers (cache: 'no-store' op fetches,
force-dynamic op routes).
* feat(PBI-74): cleanup oude sprint-store (Story 9 / T-883)
- rm stores/sprint-store.ts — alle componenten lezen nu via
useSprintWorkspaceStore (T-881 voltooide imports-migratie)
- update SprintHydrationWrapper-comment: schaduw-fase referenties
verwijderd
Verify: 671 tests groen, typecheck clean, build groen.
Grep useSprintStore = 0.
* docs(PBI-74): update Story 9 status in implementatieplan (T-884)
- Frontmatter: ready-to-execute → in-progress; revision 1 → 2;
last_updated 2026-05-09 → 2026-05-10
- Stories-tabel: kolom Status toegevoegd (Stories 1-8 DONE via PR #180,
Story 9 met T-884 op review)
- §Story 9: per-taak status + acceptatie-checklist voor T-884 manuele
staging-checks
- Aanbeveling-blokje: noteert dat Story 9 vroeger gestart is dan het
ontwerpdoc adviseerde
This commit is contained in:
parent
5df04feb11
commit
98ee05d458
19 changed files with 3115 additions and 219 deletions
96
lib/realtime/use-sprint-realtime.ts
Normal file
96
lib/realtime/use-sprint-realtime.ts
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
'use client'
|
||||
|
||||
// PBI-74 / Story 9 / T-880: Client hook for the sprint workspace SSE stream.
|
||||
// Mounts in SprintHydrationWrapper so it survives Server Action refreshes.
|
||||
// Dispatches sprint/story/task change events into useSprintWorkspaceStore.
|
||||
//
|
||||
// Mirrors use-backlog-realtime.ts:
|
||||
// - Stream blijft open op tab hidden — gemiste events worden opgehaald via
|
||||
// resyncActiveScopes('visible') uit useSprintWorkspaceResync.
|
||||
// - Latere 'ready'-events (post-reconnect) triggeren
|
||||
// resyncActiveScopes('reconnect') zodat events tijdens disconnect alsnog
|
||||
// binnenkomen.
|
||||
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { useSprintWorkspaceStore } from '@/stores/sprint-workspace/store'
|
||||
|
||||
const BACKOFF_START_MS = 1_000
|
||||
const BACKOFF_MAX_MS = 30_000
|
||||
|
||||
export function useSprintRealtime(productId: string | null) {
|
||||
const sourceRef = useRef<EventSource | null>(null)
|
||||
const backoffRef = useRef<number>(BACKOFF_START_MS)
|
||||
const reconnectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)
|
||||
const readyCountRef = useRef<number>(0)
|
||||
|
||||
useEffect(() => {
|
||||
if (!productId) return
|
||||
|
||||
const close = () => {
|
||||
if (sourceRef.current) {
|
||||
sourceRef.current.close()
|
||||
sourceRef.current = null
|
||||
}
|
||||
if (reconnectTimerRef.current) {
|
||||
clearTimeout(reconnectTimerRef.current)
|
||||
reconnectTimerRef.current = null
|
||||
}
|
||||
}
|
||||
|
||||
const connect = () => {
|
||||
close()
|
||||
const source = new EventSource(
|
||||
`/api/realtime/sprint?product_id=${encodeURIComponent(productId)}`,
|
||||
)
|
||||
sourceRef.current = source
|
||||
useSprintWorkspaceStore.getState().setRealtimeStatus('connecting')
|
||||
|
||||
source.addEventListener('ready', () => {
|
||||
backoffRef.current = BACKOFF_START_MS
|
||||
readyCountRef.current += 1
|
||||
useSprintWorkspaceStore.getState().setRealtimeStatus('open')
|
||||
if (readyCountRef.current > 1) {
|
||||
void useSprintWorkspaceStore.getState().resyncActiveScopes('reconnect')
|
||||
}
|
||||
})
|
||||
|
||||
source.onmessage = (e) => {
|
||||
if (!e.data) return
|
||||
try {
|
||||
const payload = JSON.parse(e.data) as Record<string, unknown>
|
||||
useSprintWorkspaceStore.getState().applyRealtimeEvent(payload)
|
||||
} catch (err) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
console.error('[realtime/sprint] failed to parse event', err, e.data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
source.onerror = () => {
|
||||
if (sourceRef.current !== source) return
|
||||
close()
|
||||
useSprintWorkspaceStore.getState().setRealtimeStatus('disconnected')
|
||||
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return
|
||||
const delay = backoffRef.current
|
||||
backoffRef.current = Math.min(backoffRef.current * 2, BACKOFF_MAX_MS)
|
||||
reconnectTimerRef.current = setTimeout(connect, delay)
|
||||
}
|
||||
}
|
||||
|
||||
const onVisibility = () => {
|
||||
if (document.visibilityState === 'visible' && sourceRef.current === null) {
|
||||
backoffRef.current = BACKOFF_START_MS
|
||||
connect()
|
||||
}
|
||||
}
|
||||
|
||||
connect()
|
||||
document.addEventListener('visibilitychange', onVisibility)
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('visibilitychange', onVisibility)
|
||||
close()
|
||||
readyCountRef.current = 0
|
||||
}
|
||||
}, [productId])
|
||||
}
|
||||
36
lib/realtime/use-sprint-workspace-resync.ts
Normal file
36
lib/realtime/use-sprint-workspace-resync.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
'use client'
|
||||
|
||||
// PBI-74 / Story 9 / T-880: useSprintWorkspaceResync.
|
||||
//
|
||||
// Trigger resyncActiveScopes bij:
|
||||
// - hidden→visible (browser-throttled events kunnen gemist zijn)
|
||||
// - online (netwerk hersteld na disconnect)
|
||||
//
|
||||
// Hoort gemount te worden naast useSprintRealtime in SprintHydrationWrapper.
|
||||
|
||||
import { useEffect } from 'react'
|
||||
import { useSprintWorkspaceStore } from '@/stores/sprint-workspace/store'
|
||||
|
||||
export function useSprintWorkspaceResync(): void {
|
||||
useEffect(() => {
|
||||
if (typeof document === 'undefined') return
|
||||
|
||||
const onVisibility = () => {
|
||||
if (document.visibilityState === 'visible') {
|
||||
void useSprintWorkspaceStore.getState().resyncActiveScopes('visible')
|
||||
}
|
||||
}
|
||||
|
||||
const onOnline = () => {
|
||||
void useSprintWorkspaceStore.getState().resyncActiveScopes('reconnect')
|
||||
}
|
||||
|
||||
document.addEventListener('visibilitychange', onVisibility)
|
||||
window.addEventListener('online', onOnline)
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('visibilitychange', onVisibility)
|
||||
window.removeEventListener('online', onOnline)
|
||||
}
|
||||
}, [])
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue