feat(ui): the log toggle works, and ⚠ n finally means something
UI-SPEC §3's layout has drawn both since the spec was written. The log toggle was plain text — a control that looks like one and does nothing — and `⚠ n` was never defined anywhere, in the spec or in the code. The toggle opens the console drawer, which is the only log surface that exists until M3's logging subsystem, and is disabled when there is no run to show rather than opening an empty drawer. `⚠ n` is **error rows currently on screen**, registered by `PdErrorRow` while it is mounted. A session tally was the obvious alternative and is the wrong one: it would read `⚠ 47` after a batch where 47 packages failed, stay there, and tell the user nothing they cannot already see. This returns to zero when the problems do, so the number and the screen agree. `PdSummarySheet`'s per-package rows opt out — one failed run is one problem, not forty-seven. The definition is an invention; UI-SPEC §3 says so. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fbc93e32fa
commit
545394619e
6 files changed
+69
-5
No files matched your search
@@ -21,12 +21,24 @@ import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { reportBugUrl, type BugReportLink, type PdError } from '@/ipc'
|
||||
import { useUiStore } from '@/stores'
|
||||
|
||||
export function PdErrorRow({ error }: { error: PdError }) {
|
||||
export function PdErrorRow({ error, counted = true }: { error: PdError; counted?: boolean }) {
|
||||
const { t } = useTranslation()
|
||||
const [open, setOpen] = useState(false)
|
||||
const [link, setLink] = useState<BugReportLink | null>(null)
|
||||
const [copied, setCopied] = useState(false)
|
||||
const addErrorRow = useUiStore((s) => s.addErrorRow)
|
||||
const removeErrorRow = useUiStore((s) => s.removeErrorRow)
|
||||
|
||||
// Registers while mounted, so `⚠ n` means "problems currently on screen" rather than a tally
|
||||
// that only grows. `counted={false}` is for a sheet that renders one row per failed package —
|
||||
// one failed run is one problem, not forty-seven.
|
||||
useEffect(() => {
|
||||
if (!counted) return undefined
|
||||
addErrorRow()
|
||||
return removeErrorRow
|
||||
}, [counted, addErrorRow, removeErrorRow])
|
||||
|
||||
// Asked for once per row rather than per click, so *Copy full log* can hide itself when there is
|
||||
// nothing to copy. A failure here costs the two buttons and nothing else — an error row that
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useTranslation } from 'react-i18next'
|
||||
|
||||
import { useEnvStore, useSettingsStore } from '@/stores'
|
||||
import { useEnvStore, usePlanStore, useSettingsStore, useUiStore } from '@/stores'
|
||||
|
||||
/**
|
||||
* The status line — UI-SPEC §3.
|
||||
@@ -14,6 +14,10 @@ export function PdStatusLine() {
|
||||
const rows = useEnvStore((s) => s.rows)
|
||||
const selected = useEnvStore((s) => s.selected)
|
||||
const scanning = useEnvStore((s) => s.scanning)
|
||||
const errorRows = useUiStore((s) => s.errorRows)
|
||||
const consoleOpen = usePlanStore((s) => s.consoleOpen)
|
||||
const setConsoleOpen = usePlanStore((s) => s.setConsoleOpen)
|
||||
const planPhase = usePlanStore((s) => s.phase)
|
||||
|
||||
const row = rows.find((r) => r.interpreter === selected)
|
||||
// The env's own directory name is what a user calls it (".venv", "sp5"), not the whole prefix.
|
||||
@@ -35,7 +39,31 @@ export function PdStatusLine() {
|
||||
<span className="text-accent">{engine}</span>
|
||||
<span aria-hidden="true">{'·'}</span>
|
||||
<span aria-live="polite">{scanning ? t('status.scanning') : t('status.idle')}</span>
|
||||
<span className="ml-auto">{t('status.log')}</span>
|
||||
|
||||
{/* §3 draws a log toggle here and it has been plain text since S1 — a control that looks
|
||||
like one and does nothing. It opens the console drawer, which is the only log surface
|
||||
that exists until M3's logging subsystem; disabled when there is no run to show. */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setConsoleOpen(!consoleOpen)
|
||||
}}
|
||||
disabled={planPhase === 'idle'}
|
||||
aria-expanded={consoleOpen}
|
||||
data-action="log"
|
||||
className="ml-auto underline underline-offset-2 disabled:no-underline disabled:opacity-40"
|
||||
>
|
||||
{t('status.log')}
|
||||
</button>
|
||||
|
||||
{/* §3's `⚠ n`, defined at last: error rows currently on screen. */}
|
||||
<span
|
||||
data-warnings={errorRows}
|
||||
title={t('status.warningsDetail')}
|
||||
className={errorRows > 0 ? 'text-warn' : undefined}
|
||||
>
|
||||
{`⚠ ${String(errorRows)}`}
|
||||
</span>
|
||||
</footer>
|
||||
)
|
||||
}
|
||||
@@ -53,6 +53,9 @@ function ResultRow({ result }: { result: StepResult }) {
|
||||
{failed && result.code != null ? (
|
||||
<div className="mt-2">
|
||||
<PdErrorRow
|
||||
// One failed run is one problem in the status line, not one per package: a batch
|
||||
// where 47 failed would otherwise read `⚠ 47`.
|
||||
counted={false}
|
||||
error={{
|
||||
code: result.code,
|
||||
message: result.pkg,
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
"noEnvironment": "no environment selected",
|
||||
"ready": "ready",
|
||||
"packages_one": "{{count}} package",
|
||||
"packages_other": "{{count}} packages"
|
||||
"packages_other": "{{count}} packages",
|
||||
"warningsDetail": "Problems currently shown on screen."
|
||||
},
|
||||
"actions": {
|
||||
"confirm": "Confirm",
|
||||
|
||||
@@ -21,7 +21,8 @@
|
||||
"log": "nhật ký",
|
||||
"noEnvironment": "chưa chọn môi trường",
|
||||
"ready": "sẵn sàng",
|
||||
"packages_other": "{{count}} gói"
|
||||
"packages_other": "{{count}} gói",
|
||||
"warningsDetail": "Số vấn đề đang hiển thị trên màn hình."
|
||||
},
|
||||
"actions": {
|
||||
"confirm": "Xác nhận",
|
||||
|
||||
@@ -506,11 +506,30 @@ export const useLegalStore = create<LegalState>((set) => ({
|
||||
interface UiState {
|
||||
nav: NavKey
|
||||
setNav: (nav: NavKey) => void
|
||||
/**
|
||||
* How many error rows are on screen — UI-SPEC §3's `⚠ n`, which the layout has shown since the
|
||||
* spec was written and nothing ever defined.
|
||||
*
|
||||
* **Live rows, not a session tally.** A counter that only went up would read `⚠ 47` after a
|
||||
* batch where 47 packages failed and stay there, which tells the user nothing they cannot
|
||||
* already see and never returns to zero. This is "how many problems are being shown right now",
|
||||
* so dismissing the panel that holds them clears it — the number and the screen agree.
|
||||
*
|
||||
* `PdSummarySheet`'s per-package rows opt out: one failed run is one problem, not 47.
|
||||
*/
|
||||
errorRows: number
|
||||
addErrorRow: () => void
|
||||
removeErrorRow: () => void
|
||||
}
|
||||
|
||||
export const useUiStore = create<UiState>((set) => ({
|
||||
nav: 'environments',
|
||||
setNav: (nav) => set({ nav }),
|
||||
errorRows: 0,
|
||||
addErrorRow: () => set((s) => ({ errorRows: s.errorRows + 1 })),
|
||||
// Clamped at zero: a double-unmount would otherwise drive it negative and the status line would
|
||||
// render a warning count that cannot happen.
|
||||
removeErrorRow: () => set((s) => ({ errorRows: Math.max(0, s.errorRows - 1) })),
|
||||
}))
|
||||
|
||||
// The plan store lives in its own file: it is the largest of them and the only one holding a live
|
||||
|
||||
Reference in new issue
Block a user