Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat([issue-1606]): make editorial health-panel category/check rows clickable triage filters
[._.]/ Adam Eivy3837ae9cb7e6
diff --git a/client/src/components/pipeline/editorial/EditorialFindingsTriage.jsx b/client/src/components/pipeline/editorial/EditorialFindingsTriage.jsxindex b5ed1a1504..ed14aaa97b 100644--- a/client/src/components/pipeline/editorial/EditorialFindingsTriage.jsx+++ b/client/src/components/pipeline/editorial/EditorialFindingsTriage.jsx@@ -27,6 +27,9 @@ import {applyFindingsView,normalizeFindingSort,FINDING_SORT_OPTIONS,+ FINDING_FILTER_PARAMS as FILTER_PARAMS,+ ALL_FINDING_FILTER_PARAMS as ALL_FILTER_PARAMS,+ FINDINGS_TRIAGE_ANCHOR_ID,} from '../../../lib/editorialChecks';import { fixEditsOf, selectedEditsFor } from '../manuscript/ManuscriptCommentCard';import InlineDiff from '../../ui/InlineDiff';@@ -49,10 +52,8 @@ const STATUS_LABELS = { open: 'Open', accepted: 'Accepted', dismissed: 'Dismisseconst SEVERITY_FILTER_ORDER = ['high', 'medium', 'low'];const STATUS_FILTER_ORDER = ['open', 'accepted', 'dismissed'];-// URL params that persist the triage filters/sort (#1600). `f`-prefixed so they-// never collide with the page's own `series` / `custom` params.-const FILTER_PARAMS = { severity: 'fsev', status: 'fstatus', scope: 'fscope', check: 'fcheck', issue: 'fissue', query: 'fq', sort: 'fsort' };-const ALL_FILTER_PARAMS = Object.values(FILTER_PARAMS);+// FILTER_PARAMS / ALL_FILTER_PARAMS are imported from the lib so the health+// panel can deep-link the triage to a category/check using the same keys (#1606).const parseSet = (raw) => new Set((raw || '').split(',').map((s) => s.trim()).filter(Boolean));const serializeSet = (set) => [...set].join(',');@@ -534,7 +535,7 @@ function FindingsToolbar({ facets, filters, sort, setParam, toggleInParam, onCle) : null}{facets.scopes.length > 1 ? (<span className="flex items-center gap-1">- <label htmlFor="ec-find-scope" className="text-[10px] uppercase tracking-wide text-gray-600">Category</label>+ <label htmlFor="ec-find-scope" className="text-[10px] uppercase tracking-wide text-gray-600">Scope</label><selectid="ec-find-scope"value={[...filters.scopes][0] || ''}@@ -546,6 +547,20 @@ function FindingsToolbar({ facets, filters, sort, setParam, toggleInParam, onCle</select></span>) : null}+ {facets.categories.length > 1 ? (+ <span className="flex items-center gap-1">+ <label htmlFor="ec-find-category" className="text-[10px] uppercase tracking-wide text-gray-600">Category</label>+ <select+ id="ec-find-category"+ value={[...filters.categories][0] || ''}+ onChange={(e) => setParam('category', e.target.value)}+ className="max-w-[9rem] rounded border border-port-border bg-port-bg px-1.5 py-1 text-xs text-gray-200 focus:border-port-accent focus:outline-none"+ >+ <option value="">All</option>+ {facets.categories.map((c) => <option key={c.category} value={c.category}>{c.label}</option>)}+ </select>+ </span>+ ) : null}{facets.checks.length > 1 ? (<span className="flex items-center gap-1"><label htmlFor="ec-find-check" className="text-[10px] uppercase tracking-wide text-gray-600">Check</label>@@ -642,11 +657,12 @@ export default function EditorialFindingsTriage({ seriesId, comments = [], checkscopes: parseSet(searchParams.get(FILTER_PARAMS.scope)),checkIds: parseSet(searchParams.get(FILTER_PARAMS.check)),issues: parseSet(searchParams.get(FILTER_PARAMS.issue)),+ categories: parseSet(searchParams.get(FILTER_PARAMS.category)),query: searchParams.get(FILTER_PARAMS.query) || '',}), [searchParams]);const activeFilterCount = filters.severities.size + filters.statuses.size+ filters.scopes.size + filters.checkIds.size + filters.issues.size- + (filters.query ? 1 : 0);+ + filters.categories.size + (filters.query ? 1 : 0);// Write a single facet param (empty value clears it), preserving every other// param the page owns. `replace` so filtering doesn't pile up history entries.@@ -724,7 +740,7 @@ export default function EditorialFindingsTriage({ seriesId, comments = [], checkconst totalOpen = openFindingsTotal(groups);const shownOpen = openFindingsTotal(visibleView);return (- <div className="space-y-2">+ <div id={FINDINGS_TRIAGE_ANCHOR_ID} className="scroll-mt-4 space-y-2"><FindingsToolbarfacets={facets}filters={filters}diff --git a/client/src/components/pipeline/editorial/EditorialFindingsTriage.test.jsx b/client/src/components/pipeline/editorial/EditorialFindingsTriage.test.jsxindex 42476f9694..83c3e2581a 100644--- a/client/src/components/pipeline/editorial/EditorialFindingsTriage.test.jsx+++ b/client/src/components/pipeline/editorial/EditorialFindingsTriage.test.jsx@@ -273,6 +273,30 @@ describe('EditorialFindingsTriage', () => {expect(screen.queryByText('Sagging middle')).toBeNull();});+ // ---- Category filter (#1606) — a comment-level facet distinct from scope. ----+ const categoryComments = () => [+ { id: 'n1', checkId: 'naming.dissimilar-names', category: 'naming', status: 'open', severity: 'high', issueNumber: 1, problem: 'Confusable names' },+ { id: 'p1', checkId: 'pacing.scene-drag', category: 'pacing', status: 'open', severity: 'low', issueNumber: 2, problem: 'Sagging middle' },+ ];+ const renderCategory = (initialEntries = ['/']) => render(+ <MemoryRouter initialEntries={initialEntries}>+ <EditorialFindingsTriage seriesId="ser-1" checksById={twoCheckChecks} comments={categoryComments()} />+ </MemoryRouter>,+ );++ it('filters by finding category via the Category select (#1606)', () => {+ renderCategory();+ fireEvent.change(screen.getByLabelText('Category'), { target: { value: 'pacing' } });+ expect(screen.getByText('Sagging middle')).toBeTruthy();+ expect(screen.queryByText('Confusable names')).toBeNull();+ });++ it('honors a category filter supplied via the URL query (#1606)', () => {+ renderCategory(['/?fcat=naming']);+ expect(screen.getByText('Confusable names')).toBeTruthy();+ expect(screen.queryByText('Sagging middle')).toBeNull();+ });+it('honors filters supplied via the URL query so a view is deep-linkable (#1600)', () => {renderTwoCheck(['/?fsev=low']);expect(screen.getByText('Sagging middle')).toBeTruthy();diff --git a/client/src/components/pipeline/editorial/EditorialHealthPanel.jsx b/client/src/components/pipeline/editorial/EditorialHealthPanel.jsxindex 49cf0a2729..083f9d7a70 100644--- a/client/src/components/pipeline/editorial/EditorialHealthPanel.jsx+++ b/client/src/components/pipeline/editorial/EditorialHealthPanel.jsx@@ -15,9 +15,11 @@* completes), so the score reflects the freshest review.*/import { useCallback, useEffect, useRef, useState } from 'react';+import { useSearchParams } from 'react-router-dom';import { Activity, Loader2, TrendingUp, TrendingDown } from 'lucide-react';import toast from '../../ui/Toast';import { getEditorialHealth, setEditorialReadinessGate } from '../../../services/api';+import { FINDING_FILTER_PARAMS, FINDINGS_TRIAGE_ANCHOR_ID } from '../../../lib/editorialChecks';import {scoreBand,deltaDisplay,@@ -81,12 +83,55 @@ function CheckSparkline({ counts }) {// remainder is surfaced as a "+N more" note rather than silently dropped.const MAX_CHECK_ROWS = 8;+// A clickable breakdown row (#1606) — toggles a triage filter, with the active+// highlight kept in one place so the category and check lists can't drift. The+// row's inner content differs per breakdown, so it's passed as children; layout+// tweaks (width/gap) come through `className`.+function FilterRowButton({ active, title, onClick, className = '', children }) {+ return (+ <button+ type="button"+ onClick={onClick}+ aria-pressed={active}+ title={title}+ className={`flex items-center rounded px-1 py-0.5 text-[11px] transition-colors hover:bg-port-border/50 ${active ? 'bg-port-accent/15 ring-1 ring-port-accent/40' : ''} ${className}`}+ >+ {children}+ </button>+ );+}+export default function EditorialHealthPanel({ seriesId, refreshKey = 0, checksById = {} }) {const [health, setHealth] = useState(null);const [loading, setLoading] = useState(false);const [savingGate, setSavingGate] = useState(false);const [showIssues, setShowIssues] = useState(false);+ // Make the breakdown rows navigable (#1606): clicking a category/check deep-links+ // the triage filter (shared `f`-prefixed URL params) and scrolls the findings+ // list into view. Reading the active filter lets a row toggle itself off and show+ // an active state. Other filters the user set in the toolbar are preserved.+ const [searchParams, setSearchParams] = useSearchParams();+ const activeCategory = searchParams.get(FINDING_FILTER_PARAMS.category) || '';+ const activeCheck = searchParams.get(FINDING_FILTER_PARAMS.check) || '';+ const toggleFilter = (paramKey, value, isActive) => {+ setSearchParams((prev) => {+ const next = new URLSearchParams(prev);+ if (isActive) next.delete(paramKey); else next.set(paramKey, value);+ return next;+ }, { replace: true });+ // The triage container is always mounted, so its anchor exists before the+ // filtered re-render — scroll right away (no deferral needed).+ if (!isActive && typeof document !== 'undefined') {+ document.getElementById(FINDINGS_TRIAGE_ANCHOR_ID)+ ?.scrollIntoView({ behavior: 'smooth', block: 'start' });+ }+ };+ const filterByCategory = (category) =>+ toggleFilter(FINDING_FILTER_PARAMS.category, category, activeCategory === category);+ const filterByCheck = (checkId) =>+ toggleFilter(FINDING_FILTER_PARAMS.check, checkId, activeCheck === checkId);+// Guard against a stale response: switching series (or a fast refresh) can let// an older fetch resolve last and render the wrong series' health. Only the// latest requested series is allowed to write state.@@ -215,19 +260,27 @@ export default function EditorialHealthPanel({ seriesId, refreshKey = 0, checksB{categories.length ? (<div className="border-t border-port-border/60 pt-2.5"><span className="block text-[10px] uppercase tracking-wide text-gray-600">Open by category</span>- <ul className="mt-1 flex flex-wrap gap-x-3 gap-y-1">+ <ul className="mt-1 flex flex-wrap gap-x-2 gap-y-1">{categories.map(({ category, count }) => {const regressed = regressions.find((r) => r.category === category);+ const active = activeCategory === category;return (- <li key={category} className="flex items-center gap-1 text-[11px] text-gray-400">- <span className="text-gray-300">{category}</span>- <span className="text-gray-500">{count}</span>- {regressed ? (- <span className="flex items-center gap-0.5 text-port-error" title={`Regressed: ${regressed.from} → ${regressed.to} since the previous revision`}>- <TrendingUp size={11} />- {regressed.from}→{regressed.to}- </span>- ) : null}+ <li key={category}>+ <FilterRowButton+ active={active}+ onClick={() => filterByCategory(category)}+ title={active ? `Clear the ${category} filter` : `Filter findings to ${category}`}+ className="gap-1"+ >+ <span className={active ? 'text-gray-100' : 'text-gray-300'}>{category}</span>+ <span className="text-gray-500">{count}</span>+ {regressed ? (+ <span className="flex items-center gap-0.5 text-port-error" title={`Regressed: ${regressed.from} → ${regressed.to} since the previous revision`}>+ <TrendingUp size={11} />+ {regressed.from}→{regressed.to}+ </span>+ ) : null}+ </FilterRowButton></li>);})}@@ -240,20 +293,30 @@ export default function EditorialHealthPanel({ seriesId, refreshKey = 0, checksB{checkRows.length ? (<div className="border-t border-port-border/60 pt-2.5"><span className="block text-[10px] uppercase tracking-wide text-gray-600">Open by check</span>- <ul className="mt-1 space-y-1">- {checkRows.map(({ checkId, label, count, counts, regressed }) => (- <li key={checkId} className="flex items-center gap-2 text-[11px] text-gray-400">- <span className="min-w-0 flex-1 truncate text-gray-300" title={label}>{label}</span>- {regressed ? (- <span className="flex shrink-0 items-center gap-0.5 text-port-error" title={`Regressed: ${regressed.from} → ${regressed.to} since the previous revision`}>- <TrendingUp size={11} />- {regressed.from}→{regressed.to}- </span>- ) : null}- <span className="w-5 shrink-0 text-right text-gray-500">{count}</span>- <CheckSparkline counts={counts} />- </li>- ))}+ <ul className="mt-1 space-y-0.5">+ {checkRows.map(({ checkId, label, count, counts, regressed }) => {+ const active = activeCheck === checkId;+ return (+ <li key={checkId}>+ <FilterRowButton+ active={active}+ onClick={() => filterByCheck(checkId)}+ title={active ? `Clear the ${label} filter` : `Filter findings to ${label}`}+ className="w-full gap-2 text-gray-400"+ >+ <span className={`min-w-0 flex-1 truncate text-left ${active ? 'text-gray-100' : 'text-gray-300'}`} title={label}>{label}</span>+ {regressed ? (+ <span className="flex shrink-0 items-center gap-0.5 text-port-error" title={`Regressed: ${regressed.from} → ${regressed.to} since the previous revision`}>+ <TrendingUp size={11} />+ {regressed.from}→{regressed.to}+ </span>+ ) : null}+ <span className="w-5 shrink-0 text-right text-gray-500">{count}</span>+ <CheckSparkline counts={counts} />+ </FilterRowButton>+ </li>+ );+ })}</ul>{hiddenCheckCount ? (<p className="mt-1 text-[10px] text-gray-600">+{hiddenCheckCount} more check{hiddenCheckCount === 1 ? '' : 's'} with open findings</p>diff --git a/client/src/components/pipeline/editorial/EditorialHealthPanel.test.jsx b/client/src/components/pipeline/editorial/EditorialHealthPanel.test.jsxindex 533c631a5e..2009d651a6 100644--- a/client/src/components/pipeline/editorial/EditorialHealthPanel.test.jsx+++ b/client/src/components/pipeline/editorial/EditorialHealthPanel.test.jsx@@ -1,5 +1,6 @@import { describe, it, expect, vi, beforeEach } from 'vitest';import { render, screen, waitFor, fireEvent } from '@testing-library/react';+import { MemoryRouter, useSearchParams } from 'react-router-dom';import EditorialHealthPanel from './EditorialHealthPanel';const getEditorialHealth = vi.fn();@@ -10,6 +11,21 @@ vi.mock('../../../services/api', () => ({}));vi.mock('../../ui/Toast', () => ({ default: { error: vi.fn(), success: vi.fn() } }));+// Surfaces the live URL query string so a click that deep-links a triage filter+// (#1606) is assertable.+function Probe() {+ const [sp] = useSearchParams();+ return <div data-testid="search-params">{sp.toString()}</div>;+}+const wrap = (props, route = '/') => (+ <MemoryRouter initialEntries={[route]}>+ <EditorialHealthPanel {...props} />+ <Probe />+ </MemoryRouter>+);+const renderPanel = (props = {}, route) => render(wrap(props, route));+const params = () => screen.getByTestId('search-params').textContent;+const health = (over = {}) => ({seriesId: 'ser-1',score: 83,@@ -31,18 +47,22 @@ const health = (over = {}) => ({beforeEach(() => {getEditorialHealth.mockReset();setEditorialReadinessGate.mockReset();+ // jsdom doesn't implement scrollIntoView; stub it so the deep-link scroll is a no-op.+ window.HTMLElement.prototype.scrollIntoView = vi.fn();});describe('EditorialHealthPanel', () => {it('renders nothing without a series', () => {- const { container } = render(<EditorialHealthPanel seriesId="" />);- expect(container.firstChild).toBeNull();+ const { container } = renderPanel({ seriesId: '' });+ // The router + probe still render; the panel itself renders null.+ expect(screen.queryByText('Editorial Health')).toBeNull();expect(getEditorialHealth).not.toHaveBeenCalled();+ expect(container).toBeTruthy();});it('shows the score, readiness, severity breakdown and trend delta', async () => {getEditorialHealth.mockResolvedValue(health());- render(<EditorialHealthPanel seriesId="ser-1" />);+ renderPanel({ seriesId: 'ser-1' });expect(await screen.findByText('83')).toBeTruthy();expect(screen.getByText('Not ready')).toBeTruthy();expect(screen.getByText('+13')).toBeTruthy();@@ -53,13 +73,13 @@ describe('EditorialHealthPanel', () => {getEditorialHealth.mockResolvedValue(health({trend: { points: [{ score: 90 }, { score: 70 }], regressions: [{ category: 'continuity', from: 1, to: 2 }], delta: -20 },}));- render(<EditorialHealthPanel seriesId="ser-1" />);+ renderPanel({ seriesId: 'ser-1' });expect(await screen.findByText('1→2')).toBeTruthy();});it('marks ready when the gate is satisfied', async () => {getEditorialHealth.mockResolvedValue(health({ ready: true, score: 100, openBySeverity: { high: 0, medium: 0, low: 0 }, open: 0 }));- render(<EditorialHealthPanel seriesId="ser-1" />);+ renderPanel({ seriesId: 'ser-1' });expect(await screen.findByText('Ready')).toBeTruthy();expect(screen.getByText('No open findings')).toBeTruthy();});@@ -67,7 +87,7 @@ describe('EditorialHealthPanel', () => {it('persists a readiness-gate change and refetches', async () => {getEditorialHealth.mockResolvedValue(health());setEditorialReadinessGate.mockResolvedValue({ readinessGate: 'noOpenHighOrMedium' });- render(<EditorialHealthPanel seriesId="ser-1" />);+ renderPanel({ seriesId: 'ser-1' });await screen.findByText('83');fireEvent.change(screen.getByLabelText('Ready when:'), { target: { value: 'noOpenHighOrMedium' } });await waitFor(() => expect(setEditorialReadinessGate).toHaveBeenCalledWith('noOpenHighOrMedium', { silent: true }));@@ -77,9 +97,9 @@ describe('EditorialHealthPanel', () => {it('refetches when refreshKey changes', async () => {getEditorialHealth.mockResolvedValue(health());- const { rerender } = render(<EditorialHealthPanel seriesId="ser-1" refreshKey={0} />);+ const { rerender } = renderPanel({ seriesId: 'ser-1', refreshKey: 0 });await screen.findByText('83');- rerender(<EditorialHealthPanel seriesId="ser-1" refreshKey={1} />);+ rerender(wrap({ seriesId: 'ser-1', refreshKey: 1 }));await waitFor(() => expect(getEditorialHealth).toHaveBeenCalledTimes(2));});@@ -87,7 +107,7 @@ describe('EditorialHealthPanel', () => {getEditorialHealth.mockResolvedValue(health({trend: { points: [{ score: 83 }], regressions: [], delta: 0 },}));- render(<EditorialHealthPanel seriesId="ser-1" />);+ renderPanel({ seriesId: 'ser-1' });await screen.findByText('83');// The "+0/0" delta chip should not render for a single revision.expect(screen.queryByTitle('Change since the previous revision')).toBeNull();@@ -110,7 +130,7 @@ describe('EditorialHealthPanel', () => {'naming.dissimilar-names': { label: 'Name dissimilarity' },'roster.economy': { label: 'Cast economy' },};- render(<EditorialHealthPanel seriesId="ser-1" checksById={checksById} />);+ renderPanel({ seriesId: 'ser-1', checksById });await screen.findByText('83');expect(screen.getByText('Open by check')).toBeTruthy();// Labels resolved from the catalog, sorted by count desc.@@ -125,7 +145,7 @@ describe('EditorialHealthPanel', () => {openByCheck: { 'custom.orphan': 1 },trend: { points: [{ score: 83, openByCheck: { 'custom.orphan': 1 } }], regressions: [], checkRegressions: [], delta: 0 },}));- render(<EditorialHealthPanel seriesId="ser-1" />);+ renderPanel({ seriesId: 'ser-1' });await screen.findByText('83');expect(screen.getByText('custom.orphan')).toBeTruthy();});@@ -138,7 +158,7 @@ describe('EditorialHealthPanel', () => {{ issueNumber: 3, score: 100, open: 0, openBySeverity: { high: 0, medium: 0, low: 0 } },],}));- render(<EditorialHealthPanel seriesId="ser-1" />);+ renderPanel({ seriesId: 'ser-1' });await screen.findByText('83');// Two issues carry open findings (issue 3 is clean → excluded); expand.const toggle = screen.getByText(/By issue \(2\)/);@@ -147,4 +167,34 @@ describe('EditorialHealthPanel', () => {expect(screen.getByText('Issue 1')).toBeTruthy();expect(screen.queryByText('Issue 3')).toBeNull();});++ it('deep-links the triage category filter when a category row is clicked (#1606)', async () => {+ getEditorialHealth.mockResolvedValue(health());+ renderPanel({ seriesId: 'ser-1' }, '/?series=ser-1');+ await screen.findByText('83');+ fireEvent.click(screen.getByTitle('Filter findings to continuity'));+ await waitFor(() => expect(params()).toContain('fcat=continuity'));+ // The page's own params are preserved (filter is additive, not a replace).+ expect(params()).toContain('series=ser-1');+ });++ it('toggles the category filter off when its active row is clicked again (#1606)', async () => {+ getEditorialHealth.mockResolvedValue(health());+ renderPanel({ seriesId: 'ser-1' }, '/?fcat=continuity');+ await screen.findByText('83');+ // The active row offers a clear affordance.+ fireEvent.click(screen.getByTitle('Clear the continuity filter'));+ await waitFor(() => expect(params()).not.toContain('fcat=continuity'));+ });++ it('deep-links the triage check filter when a check row is clicked (#1606)', async () => {+ getEditorialHealth.mockResolvedValue(health({+ openByCheck: { 'roster.economy': 1 },+ trend: { points: [{ score: 83, openByCheck: { 'roster.economy': 1 } }], regressions: [], checkRegressions: [], delta: 0 },+ }));+ renderPanel({ seriesId: 'ser-1', checksById: { 'roster.economy': { label: 'Cast economy' } } });+ await screen.findByText('83');+ fireEvent.click(screen.getByTitle('Filter findings to Cast economy'));+ await waitFor(() => expect(params()).toContain('fcheck=roster.economy'));+ });});diff --git a/client/src/lib/editorialChecks.js b/client/src/lib/editorialChecks.jsindex bd0a071948..0f5b742c2c 100644--- a/client/src/lib/editorialChecks.js+++ b/client/src/lib/editorialChecks.js@@ -15,6 +15,37 @@ export const CHECK_SCOPE_LABELS = Object.freeze({export const scopeLabel = (scope) =>CHECK_SCOPE_LABELS[scope] || (scope ? scope[0].toUpperCase() + scope.slice(1) : 'Other');+// A finding's editorial category (continuity / pacing / style / …) — distinct+// from its check scope. Mirrors the server's normalization in editorialScore.js+// so the triage facet and the health panel's "open by category" agree.+export const normCategory = (comment) =>+ (typeof comment?.category === 'string' && comment.category) ? comment.category : 'other';++// Title-case a raw category token for display in the toolbar select.+export const categoryLabel = (category) =>+ category ? category[0].toUpperCase() + category.slice(1) : 'Other';++// URL params that persist the triage filters/sort (#1600). `f`-prefixed so they+// never collide with the page's own `series` / `custom` params. Exported (rather+// than living in the triage component) so the health panel can deep-link the+// triage to a category/check from its clickable breakdown rows (#1606).+export const FINDING_FILTER_PARAMS = Object.freeze({+ severity: 'fsev',+ status: 'fstatus',+ scope: 'fscope',+ check: 'fcheck',+ issue: 'fissue',+ category: 'fcat',+ query: 'fq',+ sort: 'fsort',+});+export const ALL_FINDING_FILTER_PARAMS = Object.freeze(Object.values(FINDING_FILTER_PARAMS));++// DOM id on the triage container so the health panel can scroll the findings+// list into view after deep-linking a filter (#1606) — single source of truth+// shared by the panel (scroll target) and the triage (anchor).+export const FINDINGS_TRIAGE_ANCHOR_ID = 'editorial-findings-triage';+const SEVERITY_ORDER = Object.freeze(['high', 'medium', 'low']);/**@@ -174,12 +205,15 @@ export function deriveFindingFacets(groups = []) {const scopes = new Map();const checks = [];const issues = new Map();+ const categories = new Map();for (const g of groups) {if (!scopes.has(g.scope)) scopes.set(g.scope, scopeLabel(g.scope));checks.push({ id: g.checkId, label: g.label });for (const c of g.comments) {severities.add(normSeverity(c));statuses.add(normStatus(c));+ const cat = normCategory(c);+ if (!categories.has(cat)) categories.set(cat, categoryLabel(cat));const key = findingIssueKey(c);if (!issues.has(key)) issues.set(key, key === 'none' ? 'Series-wide' : `Issue ${c.issueNumber}`);}@@ -197,15 +231,19 @@ export function deriveFindingFacets(groups = []) {scopes: [...scopes.entries()].map(([scope, label]) => ({ scope, label })),checks,issues: issueList,+ categories: [...categories.entries()]+ .map(([category, label]) => ({ category, label }))+ .sort((a, b) => a.label.localeCompare(b.label)),};}// A single comment passes the comment-level filters (severity/status/issue/query).// Scope + check are group-level and filtered separately.function commentPassesFilters(c, filters) {- const { severities, statuses, issues, query } = filters;+ const { severities, statuses, issues, categories, query } = filters;if (severities?.size && !severities.has(normSeverity(c))) return false;if (statuses?.size && !statuses.has(normStatus(c))) return false;+ if (categories?.size && !categories.has(normCategory(c))) return false;if (issues?.size && !issues.has(findingIssueKey(c))) return false;if (query) {const hay = `${c.problem || ''} ${c.location || ''}`.toLowerCase();@@ -290,7 +328,8 @@ function sortGroups(groups, sort) {* scope/check is filtered out or that have no comment matching the comment-level* filters, recomputes each surviving group's counts, sorts findings within each* group, then orders the groups. `filters` carries Sets for severities, statuses,- * scopes, checkIds, issues plus a `query` string; any empty/absent facet is "all".+ * scopes, checkIds, issues, categories plus a `query` string; any empty/absent+ * facet is "all".*/export function applyFindingsView(groups = [], filters = {}, sort = 'scope') {const view = normalizeFindingSort(sort);diff --git a/client/src/lib/editorialChecks.test.js b/client/src/lib/editorialChecks.test.jsindex 0018327ff7..701dea8e6a 100644--- a/client/src/lib/editorialChecks.test.js+++ b/client/src/lib/editorialChecks.test.js@@ -6,6 +6,8 @@ import {openFindingsTotal,findingManuscriptLink,scopeLabel,+ categoryLabel,+ normCategory,deriveFindingFacets,applyFindingsView,normalizeFindingSort,@@ -154,9 +156,9 @@ describe('scopeLabel', () => {});const findingsFixture = () => [- { id: 'a1', checkId: 'pacing', status: 'open', severity: 'high', issueNumber: 2, problem: 'Slow open', location: 'p1' },- { id: 'a2', checkId: 'pacing', status: 'dismissed', severity: 'low', issueNumber: 2, problem: 'Old note' },- { id: 'b1', checkId: 'naming', status: 'open', severity: 'medium', issueNumber: 1, problem: 'Confusable names' },+ { id: 'a1', checkId: 'pacing', category: 'pacing', status: 'open', severity: 'high', issueNumber: 2, problem: 'Slow open', location: 'p1' },+ { id: 'a2', checkId: 'pacing', category: 'pacing', status: 'dismissed', severity: 'low', issueNumber: 2, problem: 'Old note' },+ { id: 'b1', checkId: 'naming', category: 'naming', status: 'open', severity: 'medium', issueNumber: 1, problem: 'Confusable names' },{ id: 'b2', checkId: 'naming', status: 'open', severity: 'low', issueNumber: null, problem: 'Series-wide naming' },];const fixtureRows = {@@ -192,6 +194,24 @@ describe('deriveFindingFacets', () => {expect(f.scopes.map((s) => s.scope)).toEqual(['scene', 'series']);expect(f.issues.map((i) => i.key)).toEqual(['1', '2', 'none']);expect(f.issues.find((i) => i.key === 'none').label).toBe('Series-wide');+ // Categories come from the finding's `category` field; a finding without one+ // buckets under 'other'. Sorted by display label.+ expect(f.categories.map((c) => c.category)).toEqual(['naming', 'other', 'pacing']);+ expect(f.categories.map((c) => c.label)).toEqual(['Naming', 'Other', 'Pacing']);+ });+});++describe('normCategory / categoryLabel', () => {+ it('normalizes a finding category, bucketing missing/blank under "other"', () => {+ expect(normCategory({ category: 'continuity' })).toBe('continuity');+ expect(normCategory({ category: '' })).toBe('other');+ expect(normCategory({})).toBe('other');+ expect(normCategory(null)).toBe('other');+ });++ it('title-cases a category token for display', () => {+ expect(categoryLabel('continuity')).toBe('Continuity');+ expect(categoryLabel('')).toBe('Other');});});@@ -218,13 +238,24 @@ describe('applyFindingsView', () => {expect(ids).toEqual(['a1', 'b1', 'b2']);});- it('filters by scope (category) and by check id', () => {+ it('filters by scope and by check id', () => {const byScope = applyFindingsView(groupsFixture(), { scopes: new Set(['series']) }, 'scope');expect(byScope.map((g) => g.checkId)).toEqual(['naming']);const byCheck = applyFindingsView(groupsFixture(), { checkIds: new Set(['pacing']) }, 'scope');expect(byCheck.map((g) => g.checkId)).toEqual(['pacing']);});+ it('filters by finding category (comment-level), bucketing un-categorized under "other"', () => {+ const byPacing = applyFindingsView(groupsFixture(), { categories: new Set(['pacing']) }, 'scope');+ expect(byPacing.flatMap((g) => g.comments.map((c) => c.id))).toEqual(['a1', 'a2']);+ // 'naming' category only matches b1 (b2 has no category → 'other'), so the+ // naming group keeps just b1.+ const byNaming = applyFindingsView(groupsFixture(), { categories: new Set(['naming']) }, 'scope');+ expect(byNaming.flatMap((g) => g.comments.map((c) => c.id))).toEqual(['b1']);+ const byOther = applyFindingsView(groupsFixture(), { categories: new Set(['other']) }, 'scope');+ expect(byOther.flatMap((g) => g.comments.map((c) => c.id))).toEqual(['b2']);+ });+it('filters by issue, including the series-wide "none" bucket', () => {const issue2 = applyFindingsView(groupsFixture(), { issues: new Set(['2']) }, 'scope');expect(issue2.flatMap((g) => g.comments.map((c) => c.id))).toEqual(['a1', 'a2']);