feat(PBI-76): migrate localStorage prefs to user-settings store (Phase 1) (#188)
* feat(PBI-76): one-shot localStorage→user-settings migration helper Reads all legacy keys (sprint_pb_*, pbi_*, story_sort, debug-mode, and dynamic *_filter_kind/*_filter_status for jobs columns) and returns a typed UserSettings patch plus the keys to clear. Idempotent via scrum4me:settings_migrated=v1 marker. Skips invalid values silently so existing corrupt entries do not block migration. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): bridge runs one-shot localStorage migration After hydrate, scans legacy localStorage keys via buildMigrationPatch and, if any data is found, pushes one bulk patch to the server, applies it locally, then removes the legacy keys. Demo accounts skip the migration entirely. Cancellable on unmount to avoid setState on unmounted component. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): migrate sprint-backlog to user-settings store Replaces six useState+useEffect+localStorage flows with selectors from useUserSettingsStore. Defaults are applied at the selector level (filterStatus 'OPEN', sort 'code', etc) so the component matches its previous behaviour. The collapsed Set is derived from the persisted array, falling back to auto-collapse-DONE when no preference exists yet. setPref calls are fire-and-forget — the optimistic flow handles the local state update. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): migrate pbi-list to user-settings store Same pattern as sprint-backlog: replaces local useState + localStorage hydration/persist with selectors from useUserSettingsStore. filterPopoverOpen blijft lokaal — die was nooit gepersisteerd in pbi-list. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): migrate story-panel sort to user-settings store Single pref (sortMode) — replaces sync localStorage useState initializer with a selector. Default 'priority' applied at the read site. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): migrate jobs-column to user-settings store Per-instance filter state (kinds + statuses) now lives under views.jobsColumns[storageKeyPrefix] in user-settings. Removes the local CSV-encoding helpers — store keeps arrays natively. A single persist() call writes both fields together so the two arrays cannot drift in optimistic mid-flight updates. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(PBI-76): migrate debug-mode to user-settings store DebugToggle reads debugMode from user-settings.devTools and toggles via setPref. Removes the standalone stores/debug-store.ts (no consumers left). Body classlist update only fires after the store is hydrated to avoid a flash on initial paint. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore(PBI-76): remove unused readLocalStoragePref helper No consumers left after migrating sprint-backlog, pbi-list, story-panel, jobs-column, and debug-store to user-settings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * test(PBI-76): mock user-settings action in backlog integration test PbiList now imports the user-settings store, which transitively loads actions/user-settings.ts → lib/prisma. The vitest jsdom environment has no DATABASE_URL, so we add a mock alongside the existing action mocks. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(docs): allow balanced parens in markdown link URLs Previously the link-checker regex stopped at the first ')', breaking on Next.js route-group paths like `app/(app)/...`. The new regex matches one level of balanced parens inside the URL. Caught by CI on PR #188 — pre-existing breakage from PBI-78 plan doc that was already merged on main. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
a1e6ec35e5
commit
852945efa3
12 changed files with 475 additions and 220 deletions
|
|
@ -1,11 +1,13 @@
|
|||
'use client'
|
||||
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useMemo } from 'react'
|
||||
import { useShallow } from 'zustand/react/shallow'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Popover, PopoverTrigger, PopoverContent } from '@/components/ui/popover'
|
||||
import JobCard from './job-card'
|
||||
import { JOB_STATUS_LABELS } from '@/components/shared/job-status'
|
||||
import { jobStatusToApi, type ClaudeJobStatusApi } from '@/lib/job-status'
|
||||
import { useUserSettingsStore } from '@/stores/user-settings/store'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { debugProps } from '@/lib/debug'
|
||||
import type { JobWithRelations } from '@/actions/jobs-page'
|
||||
|
|
@ -82,20 +84,6 @@ function MultiFilterPills<T extends string>({
|
|||
)
|
||||
}
|
||||
|
||||
function parseCsv<T extends string>(raw: string | null, allowed: Set<T>): Set<T> {
|
||||
if (!raw) return new Set()
|
||||
const out = new Set<T>()
|
||||
for (const part of raw.split(',')) {
|
||||
const v = part.trim()
|
||||
if (v && allowed.has(v as T)) out.add(v as T)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
function setToCsv<T extends string>(s: Set<T>): string {
|
||||
return Array.from(s).join(',')
|
||||
}
|
||||
|
||||
interface JobsColumnProps {
|
||||
title: string
|
||||
jobs: JobWithRelations[]
|
||||
|
|
@ -115,45 +103,50 @@ export default function JobsColumn({
|
|||
statusOptions,
|
||||
emptyText,
|
||||
}: JobsColumnProps) {
|
||||
const kindKey = `${storageKeyPrefix}_filter_kind`
|
||||
const statusKey = `${storageKeyPrefix}_filter_status`
|
||||
|
||||
const statusValues = useMemo(
|
||||
const allowedStatuses = useMemo(
|
||||
() => new Set<ClaudeJobStatusApi>(statusOptions.map((o) => o.value)),
|
||||
[statusOptions]
|
||||
[statusOptions],
|
||||
)
|
||||
const colPrefs = useUserSettingsStore(
|
||||
useShallow((s) => s.entities.settings.views?.jobsColumns?.[storageKeyPrefix]),
|
||||
)
|
||||
const setPref = useUserSettingsStore((s) => s.setPref)
|
||||
|
||||
const [filterKinds, setFilterKinds] = useState<Set<ClaudeJobKind>>(() => new Set())
|
||||
const [filterStatuses, setFilterStatuses] = useState<Set<ClaudeJobStatusApi>>(() => new Set())
|
||||
const [prefsLoaded, setPrefsLoaded] = useState(false)
|
||||
const filterKinds = useMemo<Set<ClaudeJobKind>>(() => {
|
||||
const out = new Set<ClaudeJobKind>()
|
||||
for (const v of colPrefs?.kinds ?? []) {
|
||||
if (KIND_VALUES.has(v as ClaudeJobKind)) out.add(v as ClaudeJobKind)
|
||||
}
|
||||
return out
|
||||
}, [colPrefs?.kinds])
|
||||
|
||||
useEffect(() => {
|
||||
/* eslint-disable react-hooks/set-state-in-effect */
|
||||
setFilterKinds(parseCsv<ClaudeJobKind>(localStorage.getItem(kindKey), KIND_VALUES))
|
||||
setFilterStatuses(parseCsv<ClaudeJobStatusApi>(localStorage.getItem(statusKey), statusValues))
|
||||
setPrefsLoaded(true)
|
||||
/* eslint-enable react-hooks/set-state-in-effect */
|
||||
}, [kindKey, statusKey, statusValues])
|
||||
const filterStatuses = useMemo<Set<ClaudeJobStatusApi>>(() => {
|
||||
const out = new Set<ClaudeJobStatusApi>()
|
||||
for (const v of colPrefs?.statuses ?? []) {
|
||||
if (allowedStatuses.has(v as ClaudeJobStatusApi)) out.add(v as ClaudeJobStatusApi)
|
||||
}
|
||||
return out
|
||||
}, [colPrefs?.statuses, allowedStatuses])
|
||||
|
||||
useEffect(() => { if (prefsLoaded) localStorage.setItem(kindKey, setToCsv(filterKinds)) }, [filterKinds, prefsLoaded, kindKey])
|
||||
useEffect(() => { if (prefsLoaded) localStorage.setItem(statusKey, setToCsv(filterStatuses)) }, [filterStatuses, prefsLoaded, statusKey])
|
||||
|
||||
function toggleKind(v: ClaudeJobKind) {
|
||||
setFilterKinds((prev) => {
|
||||
const next = new Set(prev)
|
||||
if (next.has(v)) next.delete(v)
|
||||
else next.add(v)
|
||||
return next
|
||||
function persist(kinds: Set<ClaudeJobKind>, statuses: Set<ClaudeJobStatusApi>) {
|
||||
void setPref(['views', 'jobsColumns', storageKeyPrefix], {
|
||||
kinds: Array.from(kinds),
|
||||
statuses: Array.from(statuses),
|
||||
})
|
||||
}
|
||||
|
||||
function toggleKind(v: ClaudeJobKind) {
|
||||
const next = new Set(filterKinds)
|
||||
if (next.has(v)) next.delete(v)
|
||||
else next.add(v)
|
||||
persist(next, filterStatuses)
|
||||
}
|
||||
|
||||
function toggleStatus(v: ClaudeJobStatusApi) {
|
||||
setFilterStatuses((prev) => {
|
||||
const next = new Set(prev)
|
||||
if (next.has(v)) next.delete(v)
|
||||
else next.add(v)
|
||||
return next
|
||||
})
|
||||
const next = new Set(filterStatuses)
|
||||
if (next.has(v)) next.delete(v)
|
||||
else next.add(v)
|
||||
persist(filterKinds, next)
|
||||
}
|
||||
|
||||
const filtered = jobs.filter((j) => {
|
||||
|
|
@ -207,14 +200,14 @@ export default function JobsColumn({
|
|||
options={KIND_OPTIONS}
|
||||
selected={filterKinds}
|
||||
onToggle={toggleKind}
|
||||
onClear={() => setFilterKinds(new Set())}
|
||||
onClear={() => persist(new Set(), filterStatuses)}
|
||||
/>
|
||||
<MultiFilterPills
|
||||
label="Status"
|
||||
options={statusOptions}
|
||||
selected={filterStatuses}
|
||||
onToggle={toggleStatus}
|
||||
onClear={() => setFilterStatuses(new Set())}
|
||||
onClear={() => persist(filterKinds, new Set())}
|
||||
/>
|
||||
<div className="flex justify-end pt-1 border-t border-border">
|
||||
<Button
|
||||
|
|
@ -223,10 +216,7 @@ export default function JobsColumn({
|
|||
size="sm"
|
||||
className="h-7 text-xs"
|
||||
disabled={activeFilterCount === 0}
|
||||
onClick={() => {
|
||||
setFilterKinds(new Set())
|
||||
setFilterStatuses(new Set())
|
||||
}}
|
||||
onClick={() => persist(new Set(), new Set())}
|
||||
>
|
||||
Wis filters
|
||||
</Button>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue