diff --git a/src/work.ts b/src/work.ts index 88c833b..bdf7f8b 100644 --- a/src/work.ts +++ b/src/work.ts @@ -555,7 +555,12 @@ export function readExternalIssues(root: string, config?: Pick[], label: string): string { +export function canonicalLabel(items: (Pick & Partial>)[], label: string): string { const k = labelKey(label) - for (const i of items) for (const l of i.labels) if (labelKey(l) === k) return l + // Live tickets set the spelling; an archived ticket's only counts when nothing live uses the label. + for (const live of [true, false]) + for (const i of items) if ((i.status !== 'archived') === live) for (const l of i.labels) if (labelKey(l) === k) return l return label.trim().replace(/\s+/g, ' ') } diff --git a/test/attachments.test.ts b/test/attachments.test.ts index e35529d..0405984 100644 --- a/test/attachments.test.ts +++ b/test/attachments.test.ts @@ -267,6 +267,11 @@ test('linear: open issues seed the table and the tracker; comments and state cha 'open issues only; started → in_progress', ) + // A project that has dropped its Linear source keeps the tables as history, but they no longer drive tickets. + const dropped = makeContextRepo({ 'context/work/linear/PRP.yaml': r.files!['context/work/linear/PRP.yaml'] }, { project: 'purposely', client: { name: 'Purposely', domains: [] }, sources: {} }) + mirrorExternal(dropped, { project: 'purposely', client: { name: 'Purposely', domains: [], contacts: [] }, sources: {} }) + assert.deepEqual(readWorkItems(dropped, 'PUR'), []) + // Next sync: PRP-1 moves to started — one state-change doc. state.issues[0] = lin('PRP-1', { state: { name: 'In Progress', type: 'started' }, updatedAt: '2026-09-03T10:00:00.000Z' }) state.comments = [] diff --git a/test/work-archive.test.ts b/test/work-archive.test.ts index 6b9b700..3296e05 100644 --- a/test/work-archive.test.ts +++ b/test/work-archive.test.ts @@ -1,6 +1,7 @@ import assert from 'node:assert/strict' import { test } from 'node:test' import { workAdd, workArchive, workList, workMove, workUnarchive } from '../src/commands/work.js' +import { canonicalLabel } from '../src/work.js' import { captureConsole, makeContextRepo } from './helpers.js' async function fixture() { @@ -48,3 +49,14 @@ test('work archive: keys archive exactly those tickets; a missing key or no sele assert.equal(statuses(root)['ACM-3'], 'review') }) }) + +test('labels: live tickets set the spelling of a label; an archived spelling only counts when nothing live uses it', () => { + const items = [ + { labels: ['Admin Panel'], status: 'archived' as const }, + { labels: ['admin panel', 'Old Theme'], status: 'todo' as const }, + { labels: ['Legacy Only'], status: 'archived' as const }, + ] + assert.equal(canonicalLabel(items, 'ADMIN panel'), 'admin panel') + assert.equal(canonicalLabel(items, 'legacy only'), 'Legacy Only') + assert.equal(canonicalLabel(items, ' brand new '), 'brand new') +}) diff --git a/web/src/BoardPage.tsx b/web/src/BoardPage.tsx index 30954e9..323a275 100644 --- a/web/src/BoardPage.tsx +++ b/web/src/BoardPage.tsx @@ -85,6 +85,19 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau ) const visible = useMemo(() => (board ? applyFilters(board.items, filters) : []), [board, filters]) + // Offer only labels on tickets this view can show: archived tickets keep their labels, + // but a label that lives only on them is noise until archived tickets are shown. + const labelOptions = useMemo(() => { + if (!board) return [] + const showArchived = route.view === 'kanban' ? filters.archived : filters.closed + const seen = new Map() + for (const live of [true, false]) { + if (!live && !showArchived) break + for (const i of board.items) if ((i.status !== 'archived') === live) for (const l of i.labels) if (!seen.has(l.toLowerCase())) seen.set(l.toLowerCase(), l) + } + for (const l of filters.labels) if (!seen.has(l.toLowerCase())) seen.set(l.toLowerCase(), l) + return [...seen.values()].sort((a, b) => a.localeCompare(b)) + }, [board, filters.archived, filters.closed, filters.labels, route.view]) const canEdit = board?.role === 'member' && !board.archived const open = (key?: string) => navigate({ ...route, item: key }) const openMenu: OpenTicketMenu = (item, e) => setMenu(menuPosition(item, e)) @@ -182,7 +195,7 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau - setFilters((f) => ({ ...f, labels }))} /> + setFilters((f) => ({ ...f, labels }))} /> setFilters((f) => ({ ...f, assignees }))} withNone /> {(filters.labels.length > 0 || filters.assignees.length > 0 || filters.q) && (