The window (U21). It may now be maximized and snapped; the 1600x1100 cap is gone, and the content column stops at max-w-content (87.5rem) instead, centred in what is left. The window is created hidden and src-tauri/src/window.rs fits it to the monitor's work area before showing it: 1180x760 is taller than the work area of a 1920x1080 panel at 150% and of a 1366x768 laptop, so the status line and the plan panel's Confirm opened under the taskbar. Never below 900x560; pinned to the corner rather than centred off-screen when even that does not fit. UI-SPEC §5 says so. The webview's grants (U1, U32). core:default granted some sixty core commands nothing called and not core:window:allow-close, so Decline on the legal gate did nothing in the installed app while its component test - which mocks close() - passed. default.json now holds exactly the five the frontend calls, and a test in lib.rs pins the union of every capability file, plus the opener's four hosts. CSP (U56): object-src, base-uri and form-action 'none'. A release build's style-src drops 'unsafe-inline' - React sets styles through CSSOM, which CSP does not govern. index.html keeps it for `npm run dev`, where Vite injects <style> elements; both policies are enforced, so the stricter decides. To be confirmed on the installed build. Language (U3): the choice is stored and applied at start. save() sent locale: null every time, so choosing Vietnamese lasted until the window closed. Settings now load before the legal gate, so the gate is in the chosen language too, and <html lang> follows the UI. Keys: a screen's data-autofocus wins over the heading (U12) - Search's field lost focus to the shell's effect, which runs after its children's - and `/` works from Search itself. Ctrl+1..9 by e.code (U49): on AZERTY Ctrl+3 reports `"`. A release build swallows F5, Ctrl+R, Ctrl+P, Ctrl+F, F3 and Alt+arrows (U20), which reloaded, printed and found in a single-page app. Also: Security scrolls (U2); the legal gate shows a consent that cannot be recorded (U29); Report bug asks for the link again with the environment, so the issue carries the Python and engine versions, at one subprocess per click rather than per row (U31); the package table's header and rows share one set of widths and one gutter, and narrow tables drop Size so names stay visible at 900px (U22, U23); the grid is focusable (Sonar S6852); --color-danger is #F26A63 and danger badges use a 15% tint, with tokens.test.ts now compositing every badge tint over every surface (U46 - 3.92:1 before); test seeds typecheck instead of `as never`, the IPC mock uses the real isPdError and has the audit cache entry (U10). U14 and U26 were already fixed by earlier commits in this release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
144 lines
5.9 KiB
TypeScript
144 lines
5.9 KiB
TypeScript
/**
|
|
* The inline error row — ERROR-CATALOG §3.
|
|
*
|
|
* Shape is fixed: `code · localized one-liner · [Details ⌄ stderr tail] · [Copy full log] ·
|
|
* [Report bug]`. The **code is never localized** (I18N §2) and the one-liner is looked up *from*
|
|
* the code, so an unknown code degrades to a generic sentence rather than to a blank row or a raw
|
|
* key. Every `Code::ALL` variant has copy in both locales as of S7, asserted by `i18n.test.ts`.
|
|
*
|
|
* *Copy full log* and *Report bug* both read `report_bug_url`, which is one call returning both
|
|
* halves — the truncated excerpt inside the URL and the complete buffer for the clipboard (§4.3).
|
|
* Neither sends anything: the URL opens in the user's browser with the issue form prefilled, and
|
|
* they submit it or do not. That is the whole of PipDock's telemetry story.
|
|
*
|
|
* The two buttons are rendered only when there is a log to offer. A *Copy full log* that copies
|
|
* nothing is worse than no button — it reports success over an empty clipboard.
|
|
*/
|
|
|
|
import { writeText } from '@tauri-apps/plugin-clipboard-manager'
|
|
import { useEffect, useState } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
|
|
import { useOpenExternal } from '@/components/useOpenExternal'
|
|
import { reportBugUrl, type BugReportLink, type PdError } from '@/ipc'
|
|
import { useEnvStore, useUiStore } from '@/stores'
|
|
|
|
export function PdErrorRow({ error, counted = true }: { error: PdError; counted?: boolean }) {
|
|
const { t } = useTranslation()
|
|
const { open: openExternal, failed: openFailed } = useOpenExternal()
|
|
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)
|
|
// The selected environment, for the Python and engine versions in the issue (U31).
|
|
const env = useEnvStore((s) => s.rows.find((r) => r.interpreter === s.selected)?.env)
|
|
|
|
// 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
|
|
// errored while offering to report an error is not worth a second error row.
|
|
useEffect(() => {
|
|
let alive = true
|
|
void reportBugUrl(undefined, error.code)
|
|
.then((l) => {
|
|
if (alive) setLink(l)
|
|
})
|
|
.catch(() => undefined)
|
|
return () => {
|
|
alive = false
|
|
}
|
|
}, [error.code])
|
|
|
|
// `errors.<code>` when the catalog has it, otherwise the generic line. Falling back to the raw
|
|
// developer message would leak English into a VI build.
|
|
const key = `errors.${error.code}`
|
|
const message = t(key)
|
|
const oneLiner = message === key ? t('errors.unknown') : message
|
|
|
|
return (
|
|
<div role="alert" className="rounded-pd border border-danger/40 bg-surface-2 p-3">
|
|
<p className="flex flex-wrap items-baseline gap-2">
|
|
<code className="font-mono text-data text-danger">{error.code}</code>
|
|
<span>{oneLiner}</span>
|
|
</p>
|
|
|
|
{error.stderrTail !== undefined && error.stderrTail !== '' ? (
|
|
<>
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
setOpen((v) => !v)
|
|
}}
|
|
aria-expanded={open}
|
|
className="mt-2 text-data text-text-dim underline underline-offset-2"
|
|
>
|
|
{t('actions.details')}
|
|
</button>
|
|
{open ? (
|
|
<pre className="mt-2 max-h-48 overflow-auto rounded-pd bg-bg p-2 font-mono text-data text-text-dim">
|
|
{error.stderrTail}
|
|
</pre>
|
|
) : null}
|
|
</>
|
|
) : null}
|
|
|
|
{link === null ? null : (
|
|
<div className="mt-2 flex flex-wrap items-center gap-3">
|
|
{link.log === '' ? null : (
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
void writeText(link.log).then(() => {
|
|
setCopied(true)
|
|
})
|
|
}}
|
|
data-action="copy-log"
|
|
className="text-data text-text-dim underline underline-offset-2"
|
|
>
|
|
{copied ? t('errors.logCopied') : t('actions.copyLog')}
|
|
</button>
|
|
)}
|
|
<button
|
|
type="button"
|
|
onClick={() => {
|
|
// Asked again, with the environment, only when the user reports: the versions are
|
|
// what makes an issue answerable, and finding pip's costs a subprocess — one per
|
|
// click rather than one per row mounted, and a summary can mount dozens (U31). The
|
|
// link already in hand is the fallback, not a reason to send nothing.
|
|
void reportBugUrl(env ?? undefined, error.code).then(
|
|
(fresh) => {
|
|
openExternal(fresh.url)
|
|
},
|
|
() => {
|
|
openExternal(link.url)
|
|
},
|
|
)
|
|
}}
|
|
data-action="report-bug"
|
|
className="text-data text-text-dim underline underline-offset-2"
|
|
>
|
|
{t('actions.reportBug')}
|
|
</button>
|
|
{/* §4.4: nothing is sent automatically, and the row says so rather than leaving the
|
|
user to guess what "Report bug" does. */}
|
|
<span className="text-data text-text-dim">{t('errors.logPrivacy')}</span>
|
|
{openFailed ? (
|
|
<span className="text-data text-warn" role="alert">
|
|
{t('actions.openFailed')}
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|