Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,12 @@ export function readExternalIssues(root: string, config?: Pick<LoreConfig, 'sour
}
}
const linearDir = join(root, 'context/work/linear')
if (existsSync(linearDir)) {
// A Linear source that was removed or disabled leaves its tables behind as
// history; they must stop driving tickets, or stale labels and statuses
// would be written back over every later change.
const linear = config?.sources.linear as { disabled?: boolean } | undefined
const linearLive = !config || (linear !== undefined && !linear.disabled)
if (linearLive && existsSync(linearDir)) {
for (const entry of readdirSync(linearDir).sort()) {
if (!/\.ya?ml$/.test(entry)) continue
for (const i of readLinearTable(readFileSync(join(linearDir, entry), 'utf8')) as LinearWorkItem[]) {
Expand Down Expand Up @@ -681,9 +686,11 @@ export function hasLabel(labels: string[], label: string): boolean {
}

/** A label as the project already spells it, or cleaned up if it is new. */
export function canonicalLabel(items: Pick<LoreWorkItem, 'labels'>[], label: string): string {
export function canonicalLabel(items: (Pick<LoreWorkItem, 'labels'> & Partial<Pick<LoreWorkItem, 'status'>>)[], 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, ' ')
}

Expand Down
5 changes: 5 additions & 0 deletions test/attachments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
12 changes: 12 additions & 0 deletions test/work-archive.test.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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')
})
15 changes: 14 additions & 1 deletion web/src/BoardPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>()
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))
Expand Down Expand Up @@ -182,7 +195,7 @@ export function BoardPage({ route, onUnauthorized }: { route: BoardRoute; onUnau
<SearchField.ClearButton />
</SearchField.Group>
</SearchField>
<FilterSelect label="Label" value={filters.labels} options={board.labels} onChange={(labels) => setFilters((f) => ({ ...f, labels }))} />
<FilterSelect label="Label" value={filters.labels} options={labelOptions} onChange={(labels) => setFilters((f) => ({ ...f, labels }))} />
<FilterSelect label="Assignee" value={filters.assignees} options={board.assignees} onChange={(assignees) => setFilters((f) => ({ ...f, assignees }))} withNone />
{(filters.labels.length > 0 || filters.assignees.length > 0 || filters.q) && (
<Button size="sm" variant="ghost" onPress={() => setFilters((f) => ({ ...f, q: '', labels: [], assignees: [] }))}>
Expand Down
Loading