From 7cddc332f861d8e1c12f536fd46a973d9ccef27a Mon Sep 17 00:00:00 2001 From: weeihan Date: Sun, 16 Aug 2026 15:37:45 +0800 Subject: [PATCH] fix(bulk-import): type safety and unused imports Remove unused db import, fix type casting for database query result, correct requireAdmin() usage in API routes. --- app/api/admin/bulk-import/create/route.ts | 9 +- app/api/admin/bulk-import/route.ts | 4 +- ...026-08-16-capa-board-scrollable-columns.md | 207 +++++++++++++++ lib/incidents/bulk-import.ts | 3 +- package-lock.json | 236 +++++++++++++++++- package.json | 1 + 6 files changed, 450 insertions(+), 10 deletions(-) create mode 100644 docs/superpowers/plans/2026-08-16-capa-board-scrollable-columns.md diff --git a/app/api/admin/bulk-import/create/route.ts b/app/api/admin/bulk-import/create/route.ts index d806bbf..944956d 100644 --- a/app/api/admin/bulk-import/create/route.ts +++ b/app/api/admin/bulk-import/create/route.ts @@ -3,8 +3,9 @@ import { createBulkIncidents, type ExtractedIncidentMetadata } from '@/lib/incid import { NextRequest, NextResponse } from 'next/server' export async function POST(request: NextRequest) { - const user = await requireAdmin() - if (!user?.id) return new NextResponse('Unauthorized', { status: 401 }) + const { session } = await requireAdmin() + if (!session?.id) return new NextResponse('Unauthorized', { status: 401 }) + const userId = session.id try { const body = await request.json() @@ -28,8 +29,8 @@ export async function POST(request: NextRequest) { priority: f.priority as any })) - // Create incidents (files attached in frontend during upload) - const created = await createBulkIncidents(metadata, user.id, []) + // Create incidents with user ID + const created = await createBulkIncidents(metadata, userId, []) return NextResponse.json({ status: 'success', diff --git a/app/api/admin/bulk-import/route.ts b/app/api/admin/bulk-import/route.ts index 814db92..8cb9af1 100644 --- a/app/api/admin/bulk-import/route.ts +++ b/app/api/admin/bulk-import/route.ts @@ -11,8 +11,8 @@ import pdf from 'pdf-parse' const execAsync = promisify(exec) export async function POST(request: NextRequest) { - const user = await requireAdmin() - if (!user) return new NextResponse('Unauthorized', { status: 401 }) + const { session } = await requireAdmin() + if (!session) return new NextResponse('Unauthorized', { status: 401 }) let tempDir: string | null = null diff --git a/docs/superpowers/plans/2026-08-16-capa-board-scrollable-columns.md b/docs/superpowers/plans/2026-08-16-capa-board-scrollable-columns.md new file mode 100644 index 0000000..e0cebf4 --- /dev/null +++ b/docs/superpowers/plans/2026-08-16-capa-board-scrollable-columns.md @@ -0,0 +1,207 @@ +# CAPA Board Scrollable Columns Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Add vertical scrolling to CAPA board status columns so large numbers of closed/completed cases don't overflow the viewport; apply uniformly to all statuses. + +**Architecture:** Set a max-height on each status column container with `overflow-y-auto` to create independent scrollable areas. This preserves the board layout while accommodating growth. No database or API changes needed—pure UI improvement. + +**Tech Stack:** React, TailwindCSS, Next.js (no new dependencies) + +## Global Constraints + +- Version bump: 1.2.0 → 1.2.1 +- Apply scrolling to all status columns uniformly (open, in_progress, overdue, pending_verification, verified, closed) +- Preserve existing board and table view toggle +- Mobile-responsive: scrollable on desktop, adapt on smaller screens if needed +- No breaking changes to component props or API + +--- + +## File Structure + +**Modified files:** +- `components/capa/capa-board.tsx` — Add max-height + overflow-y-auto to status column container +- `package.json` — Bump version to 1.2.1 + +--- + +## Task 1: Add scrollable container to status columns + +**Files:** +- Modify: `components/capa/capa-board.tsx:108-132` + +**Interfaces:** +- Consumes: Existing `STATUS_COLORS`, `STATUS_LABELS`, `byStatus` grouping +- Produces: Unchanged `CapaBoard` component signature; internal styling only + +- [ ] **Step 1: Read current board view structure** + +Current code (lines 108-132): +```jsx +
+ {STATUS_ORDER.filter(s => s !== 'reopened').map(status => ( +
+

+ {STATUS_LABELS[status]} ({byStatus[status].length}) +

+
+ {/* items */} +
+
+ ))} +
+``` + +Problem: When `byStatus[status]` has 50+ items, the column grows vertically unbounded. + +- [ ] **Step 2: Modify status column to add scroll container** + +Wrap the items container (`
`) with max-height and overflow. Replace lines 114-129: + +```jsx +
+ {byStatus[status].map(c => ( + +

{c.description}

+
+ {(c.owner as { name: string } | null)?.name ?? '—'} + {c.priority} +
+

Due {c.due_date}

+ + ))} + {byStatus[status].length === 0 && ( +

Empty

+ )} +
+``` + +Key changes: +- `max-h-96` — Limit column height to 24rem (384px), tunable per design +- `overflow-y-auto` — Vertical scroll when content exceeds max-height +- `pr-2` — Add right padding for scrollbar gutter visibility + +- [ ] **Step 3: Test in browser** + +Build and start dev server: +```bash +npm run build +npm run dev +``` + +Navigate to `/hse/capa`. Create test scenario: +- Manually add 30+ CAPAs to "closed" status in DB (or use existing data) +- Verify closed column scrolls independently without affecting other columns +- Verify other status columns (open, in_progress, etc.) also scroll when content is heavy +- Test on mobile (sm breakpoint) — scrolling should still work within narrower columns + +Expected: Each status column scrolls vertically; header and grid layout remain fixed. + +- [ ] **Step 4: Verify mobile responsiveness** + +Check at breakpoints: +- **Mobile (< 640px):** Single column, should scroll if many items +- **Tablet (640px–1024px):** Two columns, both scrollable +- **Desktop (> 1024px):** Three columns, all scrollable + +All scrollable behavior should work; no layout shifts. + +- [ ] **Step 5: Commit** + +```bash +git add components/capa/capa-board.tsx +git commit -m "feat(capa-board): add scrollable columns for large case lists + +Wrap status column items in max-h-96 overflow-y-auto container so that +columns with 30+ items scroll independently. Apply to all statuses +uniformly. Preserves board layout and header visibility." +``` + +--- + +## Task 2: Bump version to 1.2.1 + +**Files:** +- Modify: `package.json:3` + +**Interfaces:** +- Consumes: Current version string (1.2.0) +- Produces: Updated version string (1.2.1) + +- [ ] **Step 1: Update package.json version** + +Replace line 3: +```json + "version": "1.2.1", +``` + +- [ ] **Step 2: Commit** + +```bash +git add package.json +git commit -m "bump: version 1.2.0 to 1.2.1" +``` + +--- + +## Task 3: Rebuild and deploy + +**Files:** +- Generate: `.next/` build directory + +**Interfaces:** +- Consumes: Updated source files +- Produces: Production-ready bundle + +- [ ] **Step 1: Build** + +```bash +npm run build +``` + +Expected output: Build completes, no errors. + +- [ ] **Step 2: Sync to server** + +```bash +rsync -avz -e "ssh -p 9321" /Users/yapweeihan/Projects/IMS.nosync/.next/ \ + setia@175.136.239.121:/var/www/ims/.next/ +``` + +- [ ] **Step 3: Restart service** + +```bash +ssh -p 9321 setia@175.136.239.121 "sudo systemctl restart ims && sleep 1 && sudo systemctl is-active ims" +``` + +Expected: Service restarts, returns "active". + +- [ ] **Step 4: Verify in production** + +Navigate to `http://64.176.82.100/ims/hse/capa` in browser. Confirm: +- Board view displays with scrollable columns +- Sidebar shows version v1.2.1 +- All status columns scroll when content is abundant + +--- + +## Spec Coverage + +✓ CAPA board closed status is scrollable +✓ All status columns apply same principle +✓ Version incremented by 0.0.1 (1.2.0 → 1.2.1) +✓ No breaking changes + +--- + +Plan complete and saved. Ready for execution. + +**Two execution options:** + +**1. Subagent-Driven (recommended)** — Fresh subagent per task, review between tasks, fast iteration + +**2. Inline Execution** — Execute tasks in this session via executing-plans, batch execution with checkpoints + +Which approach? diff --git a/lib/incidents/bulk-import.ts b/lib/incidents/bulk-import.ts index 35eaf8f..e6d2951 100644 --- a/lib/incidents/bulk-import.ts +++ b/lib/incidents/bulk-import.ts @@ -1,6 +1,5 @@ import { createDeepSeekClient } from '@/lib/claude/client' import { withUser } from '@/lib/db/with-user' -import { db } from '@/lib/db' import { incidents, evidenceFiles, sites, zones } from '@/lib/db/schema' import { uploadEvidenceFile } from '@/lib/storage/evidence' import { writeAuditLog } from '@/lib/db/audit' @@ -133,7 +132,7 @@ export async function createBulkIncidents( const existing = await txDb.execute( sql`SELECT COUNT(*) as cnt FROM ${incidents} WHERE ${incidents.reference_no} LIKE ${prefix + '-%'}` ) - const count = (existing as any).rows?.[0]?.cnt || 0 + const count = (existing as { rows: Array<{ cnt: number }> }).rows?.[0]?.cnt || 0 const nextNum = parseInt(String(count)) + 1 const reference_no = `${prefix}-${String(nextNum).padStart(4, '0')}` diff --git a/package-lock.json b/package-lock.json index 95ef2ff..3ffa9cb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "ims-app", - "version": "0.1.0", + "version": "1.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "ims-app", - "version": "0.1.0", + "version": "1.2.1", "dependencies": { "@anthropic-ai/sdk": "^0.111.0", "@supabase/ssr": "^0.12.0", @@ -19,6 +19,7 @@ "next": "^15.5.20", "openai": "^6.46.0", "pdf-lib": "^1.17.1", + "pdf-parse": "^2.4.5", "pg": "^8.22.0", "react": "^19.2.7", "react-dom": "^19.2.7" @@ -2259,6 +2260,205 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@napi-rs/canvas": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas/-/canvas-0.1.80.tgz", + "integrity": "sha512-DxuT1ClnIPts1kQx8FBmkk4BQDTfI5kIzywAaMjQSXfNnra5UFU9PwurXrl+Je3bJ6BGsp/zmshVVFbCmyI+ww==", + "license": "MIT", + "workspaces": [ + "e2e/*" + ], + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "@napi-rs/canvas-android-arm64": "0.1.80", + "@napi-rs/canvas-darwin-arm64": "0.1.80", + "@napi-rs/canvas-darwin-x64": "0.1.80", + "@napi-rs/canvas-linux-arm-gnueabihf": "0.1.80", + "@napi-rs/canvas-linux-arm64-gnu": "0.1.80", + "@napi-rs/canvas-linux-arm64-musl": "0.1.80", + "@napi-rs/canvas-linux-riscv64-gnu": "0.1.80", + "@napi-rs/canvas-linux-x64-gnu": "0.1.80", + "@napi-rs/canvas-linux-x64-musl": "0.1.80", + "@napi-rs/canvas-win32-x64-msvc": "0.1.80" + } + }, + "node_modules/@napi-rs/canvas-android-arm64": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-0.1.80.tgz", + "integrity": "sha512-sk7xhN/MoXeuExlggf91pNziBxLPVUqF2CAVnB57KLG/pz7+U5TKG8eXdc3pm0d7Od0WreB6ZKLj37sX9muGOQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-darwin-arm64": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-0.1.80.tgz", + "integrity": "sha512-O64APRTXRUiAz0P8gErkfEr3lipLJgM6pjATwavZ22ebhjYl/SUbpgM0xcWPQBNMP1n29afAC/Us5PX1vg+JNQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-darwin-x64": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-0.1.80.tgz", + "integrity": "sha512-FqqSU7qFce0Cp3pwnTjVkKjjOtxMqRe6lmINxpIZYaZNnVI0H5FtsaraZJ36SiTHNjZlUB69/HhxNDT1Aaa9vA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-arm-gnueabihf": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-0.1.80.tgz", + "integrity": "sha512-eyWz0ddBDQc7/JbAtY4OtZ5SpK8tR4JsCYEZjCE3dI8pqoWUC8oMwYSBGCYfsx2w47cQgQCgMVRVTFiiO38hHQ==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-arm64-gnu": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-0.1.80.tgz", + "integrity": "sha512-qwA63t8A86bnxhuA/GwOkK3jvb+XTQaTiVML0vAWoHyoZYTjNs7BzoOONDgTnNtr8/yHrq64XXzUoLqDzU+Uuw==", + "cpu": [ + "arm64" + ], + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-arm64-musl": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-0.1.80.tgz", + "integrity": "sha512-1XbCOz/ymhj24lFaIXtWnwv/6eFHXDrjP0jYkc6iHQ9q8oXKzUX1Lc6bu+wuGiLhGh2GS/2JlfORC5ZcXimRcg==", + "cpu": [ + "arm64" + ], + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-riscv64-gnu": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-riscv64-gnu/-/canvas-linux-riscv64-gnu-0.1.80.tgz", + "integrity": "sha512-XTzR125w5ZMs0lJcxRlS1K3P5RaZ9RmUsPtd1uGt+EfDyYMu4c6SEROYsxyatbbu/2+lPe7MPHOO/0a0x7L/gw==", + "cpu": [ + "riscv64" + ], + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-x64-gnu": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-0.1.80.tgz", + "integrity": "sha512-BeXAmhKg1kX3UCrJsYbdQd3hIMDH/K6HnP/pG2LuITaXhXBiNdh//TVVVVCBbJzVQaV5gK/4ZOCMrQW9mvuTqA==", + "cpu": [ + "x64" + ], + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-linux-x64-musl": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-0.1.80.tgz", + "integrity": "sha512-x0XvZWdHbkgdgucJsRxprX/4o4sEed7qo9rCQA9ugiS9qE2QvP0RIiEugtZhfLH3cyI+jIRFJHV4Fuz+1BHHMg==", + "cpu": [ + "x64" + ], + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@napi-rs/canvas-win32-x64-msvc": { + "version": "0.1.80", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-0.1.80.tgz", + "integrity": "sha512-Z8jPsM6df5V8B1HrCHB05+bDiCxjE9QA//3YrkKIdVDEwn5RKaqOxCJDRJkl48cJbylcrJbW4HxZbTte8juuPg==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/@napi-rs/wasm-runtime": { "version": "1.1.6", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.1.6.tgz", @@ -8668,6 +8868,38 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "license": "0BSD" }, + "node_modules/pdf-parse": { + "version": "2.4.5", + "resolved": "https://registry.npmjs.org/pdf-parse/-/pdf-parse-2.4.5.tgz", + "integrity": "sha512-mHU89HGh7v+4u2ubfnevJ03lmPgQ5WU4CxAVmTSh/sxVTEDYd1er/dKS/A6vg77NX47KTEoihq8jZBLr8Cxuwg==", + "license": "Apache-2.0", + "dependencies": { + "@napi-rs/canvas": "0.1.80", + "pdfjs-dist": "5.4.296" + }, + "bin": { + "pdf-parse": "bin/cli.mjs" + }, + "engines": { + "node": ">=20.16.0 <21 || >=22.3.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/mehmet-kozan" + } + }, + "node_modules/pdfjs-dist": { + "version": "5.4.296", + "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-5.4.296.tgz", + "integrity": "sha512-DlOzet0HO7OEnmUmB6wWGJrrdvbyJKftI1bhMitK7O2N8W2gc757yyYBbINy9IDafXAV9wmKr9t7xsTaNKRG5Q==", + "license": "Apache-2.0", + "engines": { + "node": ">=20.16.0 || >=22.3.0" + }, + "optionalDependencies": { + "@napi-rs/canvas": "^0.1.80" + } + }, "node_modules/pg": { "version": "8.22.0", "resolved": "https://registry.npmjs.org/pg/-/pg-8.22.0.tgz", diff --git a/package.json b/package.json index e319daa..af678a5 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "next": "^15.5.20", "openai": "^6.46.0", "pdf-lib": "^1.17.1", + "pdf-parse": "^2.4.5", "pg": "^8.22.0", "react": "^19.2.7", "react-dom": "^19.2.7"