Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
89646b4
fix(cms): return reviewer-action refusals as values so production sho…
snowopsdev Nov 10, 2026
86bfeec
feat(cms): archived pieces leave the public site; publish and revisit…
snowopsdev Nov 10, 2026
80424fe
test(cms): cover narrowed article reads and brief concurrency against…
snowopsdev Nov 10, 2026
69606c4
fix(cms): log unexpected action failures and compare brief versions e…
snowopsdev Nov 10, 2026
1441692
fix(cms): cap positioning core claims at three in the schema
snowopsdev Nov 10, 2026
ef98d2e
fix(cms): setup editors surface save failures, refuse stale saves and…
snowopsdev Nov 10, 2026
d665ee8
test(cms): cover editor save failures, stale saves, step carry-over, …
snowopsdev Nov 10, 2026
4d31dde
fix(cms): keep the editor's version after a refused activation
snowopsdev Nov 10, 2026
481cf80
fix(cms): run bar follows the executing run, totals from SQL, banner …
snowopsdev Nov 10, 2026
17e2e98
fix(pipeline): report counts the evidence check and applies QA's qual…
snowopsdev Nov 10, 2026
432f4ce
fix(cms): reports show the evidence check and label checks and stages…
snowopsdev Nov 10, 2026
b4dbeba
test(cms): opsKpis guard follows the run bar to the SQL aggregate
snowopsdev Nov 10, 2026
4d04482
fix(cms): keep the running run on the bar when another queues behind it
snowopsdev Nov 10, 2026
fc13264
fix(cms): accept a banned-word suggestion only when the voice save lands
snowopsdev Nov 10, 2026
c34e6ec
fix: workspace saves check the loaded version; leave dialog waits for…
snowopsdev Nov 10, 2026
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
3 changes: 2 additions & 1 deletion cms/src/app/(frontend)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import React from 'react'

import config from '@/payload.config'
import { formatArticleDate } from '@/lib/articleReader'
import { PUBLIC } from '@/lib/findPublishedArticle'

export default async function HomePage() {
const headers = await getHeaders()
Expand All @@ -21,7 +22,7 @@ export default async function HomePage() {
metaDescription: true,
publishedAt: true,
},
where: { status: { equals: 'published' } },
where: PUBLIC,
limit: 12,
depth: 0,
sort: '-publishedAt',
Expand Down
67 changes: 38 additions & 29 deletions cms/src/components/ops/AssetStepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, { useState, useTransition } from 'react'

import { type AnyGuard, LeaveDialog, RestoreNotice, UnsavedBar } from './DirtyGuardUi'
import { assistAction, type AssistAsset } from './setupActions'
import { settle } from './settle'
import { SitePagesHint } from './SitePagesHint'
import './ops.css'

Expand Down Expand Up @@ -160,33 +161,35 @@ export function AssetStepper<Id extends string>({
setAssistError(null)
setWarnings([])
setAssistNote(null)
startTransition(async () => {
const result = await assistAction({
asset: stepAssist.asset,
section: stepAssist.section,
mode,
notes: notes[current.id] ?? '',
current: mode === 'refine' ? stepAssist.sectionValue(current.id) : null,
...(stepAssist.icpId != null ? { icpId: stepAssist.icpId } : {}),
})
if (!result.ok) {
setAssistError(result.error)
return
}
const value = asRecord(result.value)
if (!value) {
setAssistError('The assistant returned nothing usable for this step.')
return
}
stepAssist.onAssist(current.id, value)
setMock(result.mock)
setWarnings(result.warnings)
setAssistNote(
mode === 'draft'
? 'Drafted into the fields above. Nothing is saved until you press Save.'
: 'Revised the fields above. Nothing is saved until you press Save.',
)
})
startTransition(() =>
settle(async () => {
const result = await assistAction({
asset: stepAssist.asset,
section: stepAssist.section,
mode,
notes: notes[current.id] ?? '',
current: mode === 'refine' ? stepAssist.sectionValue(current.id) : null,
...(stepAssist.icpId != null ? { icpId: stepAssist.icpId } : {}),
})
if (!result.ok) {
setAssistError(result.error)
return
}
const value = asRecord(result.value)
if (!value) {
setAssistError('The assistant returned nothing usable for this step.')
return
}
stepAssist.onAssist(current.id, value)
setMock(result.mock)
setWarnings(result.warnings)
setAssistNote(
mode === 'draft'
? 'Drafted into the fields above. Nothing is saved until you press Save.'
: 'Revised the fields above. Nothing is saved until you press Save.',
)
}, setAssistError),
)
}

return (
Expand All @@ -208,7 +211,13 @@ export function AssetStepper<Id extends string>({
i === step ? ' is-current' : ''
}`}
>
<button type="button" onClick={() => onStep(i)} disabled={busy} title={s.title}>
<button
aria-current={i === step ? 'step' : undefined}
disabled={busy}
onClick={() => onStep(i)}
title={s.title}
type="button"
>
<span className="datum-ops__progress-num">{i + 1}</span>
<span className="datum-ops__progress-label">{s.title}</span>
</button>
Expand Down Expand Up @@ -321,7 +330,7 @@ export function AssetStepper<Id extends string>({
<UnsavedBar blocked={saveBlocked} guard={guard} onSave={onSave} pending={busy} />
) : null}
{/* A save the editor refuses would only close the dialog without leaving. */}
{guard ? <LeaveDialog canSave={!saveBlocked} guard={guard} /> : null}
{guard ? <LeaveDialog canSave={!saveBlocked} guard={guard} pending={busy} /> : null}
</div>
)
}
62 changes: 49 additions & 13 deletions cms/src/components/ops/BrandVoiceEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
brandVoiceActivationProblems,
emptyBrandVoiceContent,
} from '../../lib/brandVoice'
import { unwrap } from './actionResult'
import { AssetStepper } from './AssetStepper'
import { SaveButton } from './DirtyGuardUi'
import { AuditTimeline } from './AuditTimeline'
Expand Down Expand Up @@ -252,17 +253,49 @@ export function BrandVoiceEditor({
// safe choice is the one the keyboard lands on.
const [confirmArchive, setConfirmArchive] = useState(false)
const cancelArchiveRef = useRef<HTMLButtonElement>(null)
const keepDeleteRef = useRef<HTMLButtonElement>(null)
const archiveTriggerRef = useRef<HTMLButtonElement>(null)
const deleteTriggerRef = useRef<HTMLButtonElement>(null)
/** Which trigger should get focus back once its confirm has been backed out of. */
const refocus = useRef<'archive' | 'delete' | null>(null)

const cancelArchive = () => {
refocus.current = 'archive'
setConfirmArchive(false)
}
const cancelDelete = () => {
refocus.current = 'delete'
setConfirmDelete(false)
}

useEffect(() => {
if (!confirmArchive) return
cancelArchiveRef.current?.focus()
const onKey = (event: KeyboardEvent) => {
if (event.key === 'Escape') setConfirmArchive(false)
if (event.key === 'Escape') {
refocus.current = 'archive'
setConfirmArchive(false)
}
}
document.addEventListener('keydown', onKey)
return () => document.removeEventListener('keydown', onKey)
}, [confirmArchive])

// Arming swaps the trigger for its confirm buttons, so focus would fall to
// <body>: it goes to the safe choice (Cancel / Keep it), and back to the
// trigger when the confirm is backed out of.
useEffect(() => {
if (confirmDelete) keepDeleteRef.current?.focus()
}, [confirmDelete])

useEffect(() => {
if (confirmArchive || confirmDelete) return
const which = refocus.current
refocus.current = null
if (which === 'archive') archiveTriggerRef.current?.focus()
else if (which === 'delete') deleteTriggerRef.current?.focus()
}, [confirmArchive, confirmDelete])

// Reload the working copy when the server picks a different record than the
// one in hand. Saving a new voice also changes the selection — to the record
// we just created — and that must not pull the form out from under the
Expand Down Expand Up @@ -317,18 +350,18 @@ export function BrandVoiceEditor({
): Promise<{ id: number; version: string; saved: BrandVoiceContent }> => {
const onboardingStep = Math.max(record?.onboardingStep ?? 0, answeredThrough)
if (workingId == null) {
const { id, updatedAt, saved } = await createBrandVoiceDraftAction({
...content,
onboardingStep,
})
const { id, updatedAt, saved } = unwrap(
await createBrandVoiceDraftAction({
...content,
onboardingStep,
}),
)
setWorkingId(id)
router.replace(`${VIEW_PATH}?id=${id}&mode=${modeOf(step)}`)
return { id, version: updatedAt, saved }
}
const { updatedAt, saved } = await saveBrandVoiceDraftAction(
workingId,
{ ...content, onboardingStep },
suggestion?.id,
const { updatedAt, saved } = unwrap(
await saveBrandVoiceDraftAction(workingId, { ...content, onboardingStep }, suggestion?.id),
)
return { id: workingId, version: updatedAt, saved }
}
Expand Down Expand Up @@ -466,14 +499,14 @@ export function BrandVoiceEditor({
run(async () => {
if (workingId == null) return
setConfirmArchive(false)
await archiveBrandVoiceAction(workingId)
unwrap(await archiveBrandVoiceAction(workingId))
setMessage('Archived. Runs are blocked until you activate another voice.')
})

const remove = () =>
run(async () => {
if (workingId == null) return
await deleteDraftAction(workingId)
unwrap(await deleteDraftAction(workingId))
// Nothing of a deleted draft is worth keeping a copy of.
guard.markSaved(content)
setConfirmDelete(false)
Expand Down Expand Up @@ -629,7 +662,7 @@ export function BrandVoiceEditor({
ref={cancelArchiveRef}
type="button"
className="datum-ops__btn"
onClick={() => setConfirmArchive(false)}
onClick={cancelArchive}
disabled={pending}
>
Cancel
Expand All @@ -640,6 +673,7 @@ export function BrandVoiceEditor({
</>
) : (
<button
ref={archiveTriggerRef}
type="button"
className="datum-ops__btn"
onClick={() => setConfirmArchive(true)}
Expand All @@ -660,16 +694,18 @@ export function BrandVoiceEditor({
Confirm delete
</button>
<button
ref={keepDeleteRef}
type="button"
className="datum-ops__link-btn"
onClick={() => setConfirmDelete(false)}
onClick={cancelDelete}
disabled={pending}
>
Keep it
</button>
</>
) : (
<button
ref={deleteTriggerRef}
type="button"
className="datum-ops__link-btn"
onClick={() => setConfirmDelete(true)}
Expand Down
22 changes: 20 additions & 2 deletions cms/src/components/ops/BriefEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { toast } from '@payloadcms/ui'
import { useRouter } from 'next/navigation'
import React, { useState, useTransition } from 'react'
import React, { useEffect, useRef, useState, useTransition } from 'react'

import { approveBriefAction, type BriefEdits, saveBriefAction } from './briefActions'
import { LeaveDialog, RestoreNotice, SaveButton, UnsavedBar } from './DirtyGuardUi'
Expand Down Expand Up @@ -72,6 +72,13 @@ export function BriefEditor({
const [pending, startTransition] = useTransition()

const edits = (): BriefEdits => ({ angle, audience, sections, notes, icpId })
/**
* The `updatedAt` this form was built from, sent with a save so the server
* can refuse to overwrite a colleague's newer save. It follows the page
* while nothing here is unsaved, and the save's own answer; a dirty form
* keeps the version it was started from even if the page refreshes under it.
*/
const loadedAt = useRef(updatedAt)

// Sections are compared by what they say, not by the list keys the rows
// render under, so reordering or removing one cannot fool the comparison.
Expand Down Expand Up @@ -102,7 +109,7 @@ export function BriefEditor({
},
save: async () => {
setMessage(null)
const result = await saveBriefAction(articleId, edits())
const result = await saveBriefAction(articleId, edits(), loadedAt.current)
if (!result.ok) {
setMessage({ ok: false, text: result.error })
return null
Expand All @@ -116,11 +123,22 @@ export function BriefEditor({
setNotes(saved.notes)
setIcpId(saved.icpId)
toast.success(result.message)
if (result.updatedAt) loadedAt.current = result.updatedAt
router.refresh()
return { saved, version: result.updatedAt }
},
})

// Only ever forward: right after a save the page still carries the older
// version until its refresh lands.
useEffect(() => {
if (guard.dirty || !updatedAt) return
const held = loadedAt.current
if (!held || new Date(updatedAt).getTime() > new Date(held).getTime()) {
loadedAt.current = updatedAt
}
}, [guard.dirty, updatedAt])

const angleOptions = initial.angleOptions ?? []
/** The chosen card holds the single tab stop; a hand-typed angle leaves the first one. */
const focusableAngle = Math.max(
Expand Down
24 changes: 18 additions & 6 deletions cms/src/components/ops/DirtyGuardUi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,20 @@ const FOCUSABLE = 'button:not([disabled]), [href], input, select, textarea, [tab
* Escape is Stay. Without `save` there is no "Save and leave" — a guard that
* cannot save should not offer it.
*/
export function LeaveDialog({ guard, canSave = true }: { guard: AnyGuard; canSave?: boolean }) {
export function LeaveDialog({
guard,
canSave = true,
pending = false,
}: {
guard: AnyGuard
canSave?: boolean
/** The editor's own write in flight outside the guard (e.g. save-and-activate). */
pending?: boolean
}) {
const request = guard.leave
// A save started from the footer or the bar counts too: leaving mid-save would
// either lose it or submit it twice.
const busy = guard.leaveSaving || guard.saving || pending
const stayRef = useRef<HTMLButtonElement>(null)
const panelRef = useRef<HTMLDivElement>(null)

Expand All @@ -155,7 +167,7 @@ export function LeaveDialog({ guard, canSave = true }: { guard: AnyGuard; canSav
if (event.key === 'Escape') {
event.preventDefault()
event.stopPropagation()
if (!guard.leaveSaving) guard.stay()
if (!busy) guard.stay()
return
}
if (event.key !== 'Tab') return
Expand Down Expand Up @@ -191,24 +203,24 @@ export function LeaveDialog({ guard, canSave = true }: { guard: AnyGuard; canSav
{canSave ? (
<button
className="datum-ops__btn datum-ops__btn--primary"
disabled={guard.leaveSaving}
disabled={busy}
onClick={() => void guard.saveAndLeave()}
type="button"
>
{guard.leaveSaving ? 'Saving…' : 'Save and leave'}
{busy ? 'Saving…' : 'Save and leave'}
</button>
) : null}
<button
className="datum-ops__btn"
disabled={guard.leaveSaving}
disabled={busy}
onClick={guard.confirmLeave}
type="button"
>
Leave
</button>
<button
className="datum-ops__btn"
disabled={guard.leaveSaving}
disabled={busy}
onClick={guard.stay}
ref={stayRef}
type="button"
Expand Down
Loading
Loading