From a55e17012c65268564e8b919fb674f9e316eb676 Mon Sep 17 00:00:00 2001 From: Zakk Date: Fri, 2 Oct 2026 02:30:40 +1000 Subject: [PATCH] feat(config): show diagnostics above the source editor The diagnostics list sat below the editor (beside it on wide screens) and was easy to miss. A summary bar now sits under the editor toolbar with the error and warning counts and whether they belong to the accepted config, the file or the current draft; with nothing to report it is one quiet line. It opens on errors and stays shut for warnings; a collapse holds per source until a new error appears. Rows read line: message, keep the backend's words under a disclosure, and their action jumps the editor to the line or opens the other source. The editor gains lint gutter markers, and the Config files tab shows the error count. The level filter, the side panel and their strings and styles are gone. --- e2e/config.spec.ts | 51 ++++--- e2e/editor.spec.ts | 2 +- e2e/mobile.spec.ts | 15 +- src/features/config/SourceCard.tsx | 165 ++++++++++++---------- src/features/config/useConfigPage.test.ts | 41 +++++- src/features/config/useConfigPage.ts | 87 ++++++++++-- src/features/config/view.test.ts | 53 ++++++- src/features/config/view.ts | 59 ++++++-- src/i18n/locales/en.json | 8 +- src/i18n/locales/zh-CN.json | 8 +- src/i18n/locales/zh-TW.json | 8 +- src/ui/code/CodeEditor.tsx | 122 +++++++++------- src/ui/styles/feature-details.css | 6 + src/ui/styles/page-layout.css | 58 +++++--- 14 files changed, 471 insertions(+), 212 deletions(-) diff --git a/e2e/config.spec.ts b/e2e/config.spec.ts index d30d1b22..a47fe427 100644 --- a/e2e/config.spec.ts +++ b/e2e/config.spec.ts @@ -83,6 +83,9 @@ test('editing validates, shows diagnostics on errors, and saves through a reload await expect(diagnostics.getByRole('listitem')).toHaveCount(1); await expect(diagnostics).toContainText('Unknown section "unknown_section"'); await expect(page.locator('.rp-toast.negative')).toContainText('Validation found 1 error'); + await page.keyboard.press('ControlOrMeta+Home'); + await diagnostics.getByRole('button', {name: /^Go to line/}).click(); + await expect(page.locator('.cm-activeLine')).toContainText('unknown_section'); await editor.click(); await page.keyboard.press('ControlOrMeta+End'); await page.keyboard.press('ArrowUp'); @@ -182,18 +185,21 @@ test('paste into a read-only source is refused with the read-only notice', async test.describe(() => { test.use({storage: faults}); - test('the diagnostics panel lists accepted diagnostics and opens the source at the line', async ({page}) => { + test('the diagnostics summary lists accepted diagnostics and opens the source at the line', async ({page}) => { await page.goto('/#/config?tab=validate'); - await expect(page.getByRole('region', {name: 'Diagnostics', exact: true})).toBeFocused(); + const panel = page.getByRole('region', {name: 'Diagnostics', exact: true}); + await expect(panel).toBeFocused(); + await expect(panel).toContainText('Diagnostics kept for the accepted configuration'); const rows = page.getByRole('list', {name: 'Diagnostics'}).getByRole('listitem'); + // Without errors the summary stays shut until opened. + await expect(rows).toHaveCount(0); + await panel.getByRole('button', {name: /Errors 0/}).click(); await expect(rows).toHaveCount(3); - await page.getByRole('radio', {name: 'Info 1', exact: true}).click(); - await expect(rows).toHaveCount(1); - await page.getByRole('radio', {name: 'All 3', exact: true}).click(); await page.getByRole('button', {name: 'Validate', exact: true}).click(); - await expect(page.getByRole('region', {name: 'Diagnostics', exact: true})).toContainText('Current config file diagnostics'); + await expect(panel).toContainText('No diagnostics'); await expect(rows).toHaveCount(0); await page.reload(); + await panel.getByRole('button', {name: /Errors 0/}).click(); await page.getByRole('button', {name: 'Open config file: rules.dae:3', exact: true}).click(); await expect(page).toHaveURL(/tab=source&source=src-rules&line=3$/); @@ -219,14 +225,17 @@ test('identical diagnostics share one row with their count, and a known code kee await page.route('**/api/v1/config', route => route.fulfill({json: config})); await page.goto('/#/config?tab=validate'); - await expect(page.getByRole('radio', {name: 'All 3', exact: true})).toBeVisible(); + await page + .getByRole('region', {name: 'Diagnostics', exact: true}) + .getByRole('button', {name: /Warnings 3/}) + .click(); const rows = page.getByRole('list', {name: 'Diagnostics'}).getByRole('listitem'); await expect(rows).toHaveCount(1); await expect(rows).toContainText('Duplicate node in the subscription; the first usable entry is kept (3 times)'); - - await expect(page.locator('.rp-config-diagnostics')).toContainText( - 'kept (3 times). Backend message: duplicate endpoint identity; retaining the first usable entry' - ); + const backend = rows.getByText('duplicate endpoint identity; retaining the first usable entry', {exact: true}); + await expect(backend).toBeHidden(); + await rows.getByRole('button', {name: 'Backend message', exact: true}).click(); + await expect(backend).toBeVisible(); await page.goto('/#/config?tab=source&source=src-main'); await expect(page.getByRole('list', {name: 'Diagnostics'}).getByRole('listitem')).toHaveCount(1); }); @@ -583,7 +592,11 @@ test('configuration diagnostics wrap on phones', async ({page}) => { config.diagnostics = [{level: 'warning', source_id: main.id, line: null, column: null, span: null, code: 'duplicate', message}]; await page.route('**/api/v1/config', route => route.fulfill({json: config})); await page.goto('/#/config?tab=source'); - const diagnostic = page.getByRole('list', {name: 'Diagnostics'}).getByText(`Backend message: ${message}`, {exact: true}); + await page + .getByRole('region', {name: 'Diagnostics', exact: true}) + .getByRole('button', {name: /Warnings 1/}) + .click(); + const diagnostic = page.getByRole('list', {name: 'Diagnostics'}).getByText(`Backend message: ${message}`); await expect(diagnostic).toBeVisible(); expect(await diagnostic.evaluate(element => element.scrollWidth <= element.clientWidth)).toBe(true); }); @@ -599,6 +612,12 @@ test('a validation run gives way to the accepted diagnostics after a reload', as await generation; await route.fulfill({contentType: 'text/event-stream', body: 'event: generation.changed\ndata: {}\n\n'}); }); + // A validation that finds something, so the summary names what it checked. + await page.route('**/api/v1/config/validate', async route => { + const result = await api.validateConfig(route.request().postDataJSON()); + const warning = {level: 'warning', source_id: 'src-main', line: null, column: null, span: null, code: 'duplicate', message: 'Checked'} as const; + await route.fulfill({json: {...result, diagnostics: [warning]}}); + }); await page.goto('/#/config?tab=validate'); const panel = page.getByRole('region', {name: 'Diagnostics', exact: true}); await page.getByRole('button', {name: 'Validate', exact: true}).click(); @@ -609,7 +628,7 @@ test('a validation run gives way to the accepted diagnostics after a reload', as await api.replaceConfigSource(source.id, source.content + '\n# elsewhere\n', `"${source.content_sha256}"`); await expect.poll(async () => (await api.config()).generation_id).not.toBe(before.generation_id); changed(); - await expect(panel).toContainText('Diagnostics kept for the accepted configuration'); + await expect(panel).toContainText('No diagnostics'); await expect(panel).not.toContainText('Current config file diagnostics'); }); @@ -650,7 +669,7 @@ httpTest('a restart-only change is refused with the setting named, and the next await expect(page.getByRole('list', {name: 'Diagnostics'})).toContainText('global.log_level'); await expect(editor).toContainText('# restart draft'); await editor.fill((await editor.innerText()) + '\n# revised draft\n'); - await expect(page.getByRole('list', {name: 'Diagnostics'})).not.toContainText('global.log_level'); + await expect(page.getByRole('list', {name: 'Diagnostics'})).toHaveCount(0); await page.getByRole('button', {name: 'Apply', exact: true}).click(); await expect(page.locator('.rp-toast.positive', {hasText: 'written'})).toContainText('configuration reloaded'); }); @@ -929,7 +948,7 @@ test('source editing writes form-owned values in full', async ({page}) => { expect((await api.config()).sources[0].content).toContain('tproxy_port: 23456'); }); -test('legacy validation links focus diagnostics beside the source at its line', async ({page}) => { +test('legacy validation links focus diagnostics above the source at its line', async ({page}) => { const {api} = await mockBackend(page); const file = (await api.config()).sources.find(source => source.kind === 'main')!; const line = file.content.slice(0, file.content.indexOf('tproxy_port:')).split('\n').length; @@ -939,7 +958,7 @@ test('legacy validation links focus diagnostics beside the source at its line', await expect(page.getByRole('region', {name: 'Diagnostics', exact: true})).toBeFocused(); await expect(page.getByRole('region', {name: 'Diagnostics', exact: true})).toBeInViewport(); await expect(page.locator('.cm-activeLine')).toContainText('tproxy_port:'); - await expect(page.getByRole('list', {name: 'Diagnostics'})).toHaveCount(1); + await expect(page.getByRole('region', {name: 'Diagnostics', exact: true})).toHaveCount(1); }); test('located routing and DNS rules open their exact edit dialogs', async ({page}) => { diff --git a/e2e/editor.spec.ts b/e2e/editor.spec.ts index 85705cda..22f2d8af 100644 --- a/e2e/editor.spec.ts +++ b/e2e/editor.spec.ts @@ -18,7 +18,7 @@ test('the editor toolbar opens find and replace and goes to a line', async ({pag await line.fill('3'); await page.keyboard.press('Enter'); await expect(page.locator('.cm-goto-line')).toHaveCount(0); - await expect(page.locator('.cm-activeLineGutter')).toHaveText('3'); + await expect(page.locator('.cm-lineNumbers .cm-activeLineGutter')).toHaveText('3'); }); test('a read-only source keeps Find and Go to line, and its editing commands are disabled', async ({page}) => { diff --git a/e2e/mobile.spec.ts b/e2e/mobile.spec.ts index b6e87454..2a62360f 100644 --- a/e2e/mobile.spec.ts +++ b/e2e/mobile.spec.ts @@ -368,12 +368,17 @@ for (const [scheme, palette] of [ const cache = await backend.api.dnsCache(); backend.handlers['GET dns/cache'] = async () => ({...cache, total: 0, entries: []}); await page.goto('/#/config?tab=source'); - const light = page.locator('.rp-light', {hasText: message}).first(); - await expect(light).toBeVisible(); - const prose = await light.evaluate(el => { - const text = el.querySelector('span')!; + await page + .getByRole('region', {name: 'Diagnostics', exact: true}) + .getByRole('button', {name: /Warnings 1/}) + .click(); + const list = page.getByRole('list', {name: 'Diagnostics'}); + await list.getByRole('button', {name: 'Backend message', exact: true}).click(); + const backendText = list.getByText(message, {exact: true}); + await expect(backendText).toBeVisible(); + const prose = await backendText.evaluate(el => { const range = document.createRange(); - range.selectNodeContents(text); + range.selectNodeContents(el); const box = el.closest('.rp-card')!.getBoundingClientRect(); return {lines: range.getClientRects().length, contained: [...range.getClientRects()].every(rect => rect.left >= box.left && rect.right <= box.right)}; }); diff --git a/src/features/config/SourceCard.tsx b/src/features/config/SourceCard.tsx index 678e2daf..ef313584 100644 --- a/src/features/config/SourceCard.tsx +++ b/src/features/config/SourceCard.tsx @@ -1,6 +1,6 @@ -import {useEffect, useRef, useState} from 'react'; +import {useEffect, useRef} from 'react'; import {useT} from '../../i18n'; -import {Badge, Button, Card, Disclosure, Light, Link, Segmented, type Action} from '../../ui/ui'; +import {Badge, Button, Card, Disclosure, Light, Link, VisuallyHidden, type Action} from '../../ui/ui'; import {CodeEditor} from '../../ui/code/CodeEditor'; import {ChangedOnDisk} from './ChangedOnDisk'; import {useSourceCard, type SourceCardProps} from './useConfigPage'; @@ -11,14 +11,14 @@ export function SourceCard(props: SourceCardProps) { const { writable, links, - checkedDraft, + diagnostics: d, note, refused, - shown, marks, text, outbounds, focus, + focusKey, dirty, conflict, keep, @@ -34,8 +34,7 @@ export function SourceCard(props: SourceCardProps) { validateDisabled, reason } = useSourceCard(props); - const panel = useRef(null); - const [level, setLevel] = useState('all'); + const panel = useRef(null); useEffect(() => { if (props.focusDiagnostics) { panel.current?.focus(); @@ -53,7 +52,58 @@ export function SourceCard(props: SourceCardProps) { ))} ); - const filtered = shown.filter(item => level === 'all' || item.level === level); + // Pinned under the editor's toolbar: the counts, opened into the list on errors. + const banner = ( +
+ {d.quiet ? ( + {d.quiet} + ) : ( + + + {t('config.levelErrors', {n: d.errors})} + + + {t('config.levelWarnings', {n: d.warnings})} + + + } + aside={{d.scope}} + > +
+ {d.rows.map(item => ( +
+
+ + {`${item.levelText} `} + {item.text} + + {item.backend && ( + + {item.backend} + + )} +
+ {item.action && ( + + )} +
+ ))} +
+
+ )} +
+ ); const actions: Action[] = [ ...(canValidate ? [ @@ -83,73 +133,40 @@ export function SourceCard(props: SourceCardProps) { : []) ]; return ( -
- -
- - {dirty ? ( - <> - {t('config.unsaved')} - {t('config.unsavedHint')} - - ) : ( - {note} - )} - -
- {conflict && } - {located.length ? formLinks : links.length > 0 && {formLinks}} - void save() : undefined} - /> -
- - - {dirty - ? t(checkedDraft ? 'config.draftDiagnostics' : 'config.draftPending') - : checkedDraft - ? t('config.fileDiagnostics') - : t('config.acceptedDiagnostics', {generation: props.generation})} + +
+ + {dirty ? ( + <> + {t('config.unsaved')} + {t('config.unsavedHint')} + + ) : ( + {note} + )} - sum + item.count, 0)})], - ['error', t('config.levelErrors', {n: shown.filter(item => item.level === 'error').reduce((sum, item) => sum + item.count, 0)})], - ['warning', t('config.levelWarnings', {n: shown.filter(item => item.level === 'warning').reduce((sum, item) => sum + item.count, 0)})], - ['info', t('config.levelInfo', {n: shown.filter(item => item.level === 'info').reduce((sum, item) => sum + item.count, 0)})] - ]} - /> -
- {filtered.map(item => ( -
- - {item.detail} - - -
- ))} -
- {!filtered.length &&

{dirty && !checkedDraft ? t('config.draftPending') : t('config.noDiagnostics')}

} - -
+
+ {conflict && } + {located.length ? formLinks : links.length > 0 && {formLinks}} + void save() : undefined} + /> + ); } diff --git a/src/features/config/useConfigPage.test.ts b/src/features/config/useConfigPage.test.ts index fa7d0593..51c415b9 100644 --- a/src/features/config/useConfigPage.test.ts +++ b/src/features/config/useConfigPage.test.ts @@ -58,7 +58,10 @@ beforeEach(async () => { editor, focusLine: null, generation: config.generation_id, - focusDiagnostics: false + focusDiagnostics: false, + diagnosticsChoice: null, + chooseDiagnostics: vi.fn(), + reportErrors: vi.fn() }; }); @@ -84,7 +87,7 @@ it('keeps cross-source rejection rows without marking or jumping the edited file const other = {...config.diagnostics[0], level: 'error' as const, source_id: config.sources[1].id, line: 2}; editor.errorSource = props.source.id; editor.diagnostics = [other]; - expect(read().shown[0]).toMatchObject({sourceId: other.source_id, where: 'rules.dae:2'}); + expect(read().diagnostics.rows[0]).toMatchObject({sourceId: other.source_id, where: 'rules.dae:2'}); expect(read().marks).toEqual([]); vi.mocked(editor.validate).mockResolvedValue({...validation, valid: false, diagnostics: [other]}); await read().validate(); @@ -100,20 +103,20 @@ it('retains accepted diagnostics and a legacy focus request before redacted text hookHarness.reset(); props = page.sourceProps!; expect(read().checkedDraft).toBe(false); - expect(read().shown).toHaveLength(config.diagnostics.length); + expect(read().diagnostics.rows).toHaveLength(config.diagnostics.length); }); it('restores accepted provenance after cancel and after a generation change', async () => { const draftError = {...config.diagnostics[0], level: 'error' as const}; read().change(props.source.content + '\n# draft'); - expect(read().shown).toEqual([]); + expect(read().diagnostics.rows).toEqual([]); vi.mocked(editor.validate).mockResolvedValue({...validation, valid: false, diagnostics: [draftError]}); await read().validate(); expect(read().checkedDraft).toBe(true); read().cancel(); expect(read().dirty).toBe(false); expect(read().checkedDraft).toBe(false); - expect(read().shown).toHaveLength(config.diagnostics.length); + expect(read().diagnostics.rows).toHaveLength(config.diagnostics.length); await read().validate(); props.generation = 'next'; read(); @@ -142,3 +145,31 @@ it.each([true, false])('validates and saves a raw edit of a form-owned value (ac expect(read().dirty).toBe(!accepted); expect(read().checkedDraft).toBe(!accepted); }); + +it('summarises the shown diagnostics, opens on errors and jumps within the source', async () => { + expect(read().diagnostics).toMatchObject({errors: 0, quiet: 'No diagnostics', open: false}); + read().change(props.source.content + '\n# draft'); + expect(read().diagnostics.quiet).toBe('Current draft has not been validated.'); + const error = {level: 'error' as const, source_id: props.source.id, line: 3, column: 1, span: null, code: 'invalid', message: 'Bad'}; + const other = {...error, source_id: config.sources[1].id, line: 2}; + vi.mocked(editor.validate).mockResolvedValue({...validation, valid: false, diagnostics: [error, other, {...error, level: 'warning', line: 4}]}); + await read().validate(); + const d = read().diagnostics; + expect(d).toMatchObject({errors: 2, warnings: 1, open: true, scope: 'Current draft diagnostics'}); + d.setOpen(false); + expect(props.chooseDiagnostics).toHaveBeenCalledWith({open: false, errorKeys: expect.any(Array)}); + props.diagnosticsChoice = vi.mocked(props.chooseDiagnostics).mock.calls[0][0]; + expect(read().diagnostics.open).toBe(false); + const before = read().focusKey; + read().diagnostics.go(read().diagnostics.rows.find(row => row.action === 'jump')!); + expect(read()).toMatchObject({focus: 3}); + expect(read().focusKey).not.toBe(before); + read().diagnostics.go(read().diagnostics.rows.find(row => row.action === 'open')!); + expect(props.open).toHaveBeenCalledWith(other.source_id, 2); +}); + +it('counts the accepted errors on the source tab', () => { + config.diagnostics = [{level: 'error', source_id: 'src-main', line: 1, column: 1, span: null, code: 'invalid', message: 'Bad'}]; + const page = hookHarness.render(() => useConfigPage({query: 'tab=modules', go: vi.fn()})); + expect(page.tabs.find(item => item.id === 'source')?.label).toBe('Config files (1)'); +}); diff --git a/src/features/config/useConfigPage.ts b/src/features/config/useConfigPage.ts index c1c02b16..7ff67948 100644 --- a/src/features/config/useConfigPage.ts +++ b/src/features/config/useConfigPage.ts @@ -1,6 +1,6 @@ import {sourceForms} from './sourceForms'; import {useEffect, useMemo, useRef, useState} from 'react'; -import {useT, useLang, LOCALE} from '../../i18n'; +import {useT, useLang, LOCALE, formatNumber} from '../../i18n'; import {useCapabilities, useConfig, useConfigEditor, useVersion, useRules, useDnsRules, useGroups} from '../../store'; import {readGroupEntries} from '../../dae/groups'; import {groupQuery} from '../shared/link'; @@ -10,7 +10,20 @@ import {downloadFile, isMac, toast, toastFailure, useLinked} from '../../ui/ui'; import {allGroupNames, fileName, restartRequired} from '../../dae/sources'; import type {PageProps} from '../../shell/routes'; import {buildHash, href, pickTab, tabQuery, within} from '../../shell/route'; -import {configMetadata, saveReason, saveView, validateReason, sourceView, diagnosticRows, sourceMarks, readOnlyBadge} from './view'; +import { + configMetadata, + saveReason, + saveView, + validateReason, + sourceView, + diagnosticRows, + diagnosticSummary, + diagnosticsOpen, + sourceMarks, + readOnlyBadge, + type DiagnosticRow, + type DiagnosticsChoice +} from './view'; import {configTabs} from './nav'; import {useDraftGuard} from '../../shell/draft'; import {useValidationSources} from './useValidationSources'; @@ -78,6 +91,11 @@ export function useConfigPage({go, query}: PageProps) { const tabs = configTabs(!!engine.globalSettings); const readOnly = source ? readOnlyBadge(source, configWritable, isComplete(source), engine, t) : null; const canWrite = !!source && !readOnly; + // Each source keeps the person's last open or collapse of its diagnostics, and the card reports the errors it shows + // for the tab, a draft's included; away from the card the tab counts the accepted configuration's. + const [choices, setChoices] = useState>({}); + const [shownErrors, setShownErrors] = useState(null); + const tabErrors = shownErrors ?? counts.error; const fallback = params.has('source') || mainSource?.content === undefined ? 'source' : 'modules'; const tab = pickTab( params.get('tab') === 'validate' ? within(query, {tab: 'source'}) : query, @@ -97,7 +115,10 @@ export function useConfigPage({go, query}: PageProps) { editor, focusLine, generation: config.data?.generation_id ?? '', - focusDiagnostics: params.get('tab') === 'validate' + focusDiagnostics: params.get('tab') === 'validate', + diagnosticsChoice: choices[source.id] ?? null, + chooseDiagnostics: choice => setChoices(previous => ({...previous, [source.id]: choice})), + reportErrors: setShownErrors } : null; const newSourceProps: NewSourceProps | null = @@ -109,7 +130,10 @@ export function useConfigPage({go, query}: PageProps) { ready: !!config.data, metadata: config.data ? configMetadata(config.data.revision, t) : [], redacted: !!config.data?.secrets_redacted, - tabs: tabs.map(item => ({id: item.id, label: t(item.titleKey)})), + tabs: tabs.map(item => ({ + id: item.id, + label: item.id === 'source' && tabErrors ? t('ui.aside', {text: t(item.titleKey), note: formatNumber(tabErrors, locale)}) : t(item.titleKey) + })), tab, setTab: (tab: string) => go('config', within(tabQuery(query, tab, null), {field: null})), selectedId: selectedId ?? '', @@ -142,9 +166,27 @@ export type SourceCardProps = { focusLine: number | null; generation: string; focusDiagnostics: boolean; + diagnosticsChoice: DiagnosticsChoice | null; + chooseDiagnostics: (choice: DiagnosticsChoice) => void; + reportErrors: (errors: number | null) => void; }; -export function useSourceCard({source, sources, diagnostics, canValidate, canWrite, readOnly, isComplete, editor, focusLine, generation}: SourceCardProps) { +export function useSourceCard({ + source, + sources, + diagnostics, + canValidate, + canWrite, + readOnly, + isComplete, + editor, + focusLine, + generation, + open, + diagnosticsChoice, + chooseDiagnostics, + reportErrors +}: SourceCardProps) { const t = useT(); const locale = LOCALE[useLang()]; const engine = engineOf(useVersion().data); @@ -173,8 +215,11 @@ export function useSourceCard({source, sources, diagnostics, canValidate, canWri const text = draft?.text ?? source.content ?? ''; // Names to complete after "->": the groups of every source, this one as edited. const outbounds = () => allGroupNames(sources, {id: source.id, content: text}); - const [jump, setJump] = useState(null); - // A line asked for through the address (a diagnostic's "open source") wins over the last validation's first error. + // A line the card moves the editor to; the key makes a second request for the same line move it again. + const [jump, setJump] = useState<{line: number; key: number} | null>(null); + const jumps = useRef(0); + const jumpTo = (line: number | null) => setJump(line === null ? null : {line, key: ++jumps.current}); + // A line asked for through the address (a diagnostic in another source) wins over the last validation's first error. useLinked(focusLine, () => setJump(null)); const dirty = draft !== null && draft.text !== source.content; // The file changed on disk under the draft, whether a refetch or a refused save showed it. Saving waits until the @@ -192,7 +237,7 @@ export function useSourceCard({source, sources, diagnostics, canValidate, canWri setFound(result.diagnostics); // Put the cursor on the first error so the problem is on screen, not below a long file. const first = result.diagnostics.find(d => d.source_id === source.id && d.level === 'error' && d.line !== null); - setJump(first ? first.line : null); + jumpTo(first ? first.line : null); if (!result.valid) toast('negative', t('config.invalid', {n: result.diagnostics.filter(d => d.level === 'error').length})); else if (announce) toast('positive', t('config.valid')); return result.valid; @@ -237,6 +282,12 @@ export function useSourceCard({source, sources, diagnostics, canValidate, canWri } : undefined; const view = sourceView(source, locale, t); + const checkedDraft = found !== null || saveErrors !== null; + const rows = useMemo(() => diagnosticRows(shown, sources, locale, t, source.id), [shown, sources, locale, t, source.id]); + const summary = diagnosticSummary(rows); + const pending = dirty && !checkedDraft; + useEffect(() => reportErrors(pending ? null : summary.errors), [reportErrors, pending, summary.errors]); + useEffect(() => () => reportErrors(null), [reportErrors]); return { writable, links: groupLink @@ -259,12 +310,26 @@ export function useSourceCard({source, sources, diagnostics, canValidate, canWri : sourceForms(text, source.id, engine, source.kind), note: readOnly?.note ?? t(canValidate ? 'config.editNoteValidate' : 'config.editNote'), refused, - shown: diagnosticRows(shown, sources, locale, t), - checkedDraft: found !== null || saveErrors !== null, + diagnostics: { + rows, + errors: summary.errors, + warnings: summary.warnings, + scope: dirty ? t('config.draftDiagnostics') : checkedDraft ? t('config.fileDiagnostics') : t('config.acceptedDiagnostics', {generation}), + // One quiet line instead of the bar: a draft not checked yet, or nothing to report. + quiet: pending ? t('config.draftPending') : rows.length ? null : t('config.clean'), + open: diagnosticsOpen(summary.errorKeys, diagnosticsChoice), + setOpen: (open: boolean) => chooseDiagnostics({open, errorKeys: summary.errorKeys}), + go: (row: DiagnosticRow) => { + if (row.action === 'jump') jumpTo(row.line); + else if (row.action === 'open') open(row.sourceId, row.line); + } + }, + checkedDraft, marks, text, outbounds, - focus: jump ?? focusLine, + focus: jump?.line ?? focusLine, + focusKey: jump?.key ?? 0, dirty, conflict: conflict ? t('config.changedOnDisk') : null, keep: () => setDraft(current => current && {...current, origin: source}), diff --git a/src/features/config/view.test.ts b/src/features/config/view.test.ts index 03e89af2..6381152c 100644 --- a/src/features/config/view.test.ts +++ b/src/features/config/view.test.ts @@ -3,7 +3,19 @@ import {configNotes, version} from '../../api/mock/fixtures'; import {createMockApi} from '../../api/mock'; import {engineOf} from '../../api/engines'; import {translate, type Translator} from '../../i18n'; -import {configMetadata, saveReason, saveView, validateReason, sourceView, readOnlyBadge, diagnosticRows, sectionSummaries, sourceMarks} from './view'; +import { + configMetadata, + saveReason, + saveView, + validateReason, + sourceView, + readOnlyBadge, + diagnosticRows, + diagnosticSummary, + diagnosticsOpen, + sectionSummaries, + sourceMarks +} from './view'; import type {ConfigSource} from '../../api/model'; import {validationSources} from '../../dae/sources'; import {diagnose} from '../../api/mock/config'; @@ -98,14 +110,41 @@ it('projects source locations without inventing a line for source-wide diagnosti expect(rows[0].where).toBe('config.dae:5'); expect(rows[0].tone).toBe('warn'); expect(rows[1].where).toBe('missing'); - expect(rows[1].detail).toBe(t('ui.backendMessage', {message: configNotes[0].message})); + expect(rows[1].text).toBe(t('ui.valuePair', {label: 'missing', value: t('ui.backendMessage', {message: configNotes[0].message})})); + expect(rows[1].backend).toBeNull(); }); it('shows the backend words of a reused code once, in the detail', async () => { const configSources = (await createMockApi().config()).sources; const [row] = diagnosticRows([{...configNotes[0], code: 'unsupported_value', line: null}], configSources, 'en-US', t); expect(row.message).toBe(t('ui.backend.unsupportedValue')); - expect(row.detail).toBe(t('config.backendDetail', {text: t('ui.backend.unsupportedValue'), message: configNotes[0].message})); - expect(row.detail.split(configNotes[0].message)).toHaveLength(2); + expect(row.backend).toBe(configNotes[0].message); + expect(row.text).not.toContain(configNotes[0].message); +}); +it.each([ + ['a line in the source on show', 'main', 5, 'Line 5: No group named "alpha"', 'jump'], + ['the source on show as a whole', 'main', null, 'No group named "alpha"', null], + ['a line in another source', 'include', 8, 'rules.dae line 8: No group named "alpha"', 'open'], + ['another source as a whole', 'include', null, 'rules.dae: No group named "alpha"', 'open'] +] as const)('lists %s with its place and action', (_, sourceId, line, text, action) => { + const item = {...configNotes[0], source_id: sourceId, line, code: 'unknown_outbound', message: '', params: {name: 'alpha'}}; + expect(diagnosticRows([item], [source(''), source('', 'include')], 'en-US', t, 'main')[0]).toMatchObject({text, action}); +}); +it('counts repeated diagnostics and keys errors by what they say, not where', () => { + const error = {...configNotes[0], level: 'error' as const, code: 'other', message: 'Bad'}; + const rows = diagnosticRows([error, error, {...error, line: 9}, configNotes[0]], [], 'en-US', t); + const summary = diagnosticSummary(rows); + expect(summary).toMatchObject({errors: 3, warnings: 1}); + expect(summary.errorKeys).toHaveLength(1); + expect(diagnosticSummary(diagnosticRows([{...error, message: 'Other'}], [], 'en-US', t)).errorKeys).not.toEqual(summary.errorKeys); +}); +it.each([ + ['errors open the list', ['a'], null, true], + ['warnings alone leave it shut', [], null, false], + ['a collapse holds while the errors are the same', ['a'], {open: false, errorKeys: ['a', 'b']}, false], + ['a new error opens it again', ['a', 'c'], {open: false, errorKeys: ['a']}, true], + ['an open holds without errors', [], {open: true, errorKeys: []}, true] +] as const)('%s', (_, errorKeys, choice, open) => { + expect(diagnosticsOpen([...errorKeys], choice && {...choice, errorKeys: [...choice.errorKeys]})).toBe(open); }); it('keeps a diagnostic row id when the diagnostics before it go away', async () => { const configSources = (await createMockApi().config()).sources; @@ -172,7 +211,7 @@ it('shows the same localized diagnostic in rows and both editor marks', () => { const described = translateTW('config.backendDetail', {text: summary, message: 'No group named "nowhere"'}); const rows = diagnosticRows([item], [source(text)], 'zh-TW', translateTW); expect(rows[0].message).toBe(summary); - expect(rows[0].detail).toContain(described); + expect(rows[0].backend).toBe('No group named "nowhere"'); expect(sourceMarks([item], 'main', translateTW)[0].message).toBe(described); // The page's own words already are the backend's in English. expect(sourceMarks([item], 'main', t)[0].message).toBe('No group named "nowhere"'); @@ -184,7 +223,7 @@ it('keeps backend detail separate in rows and editor marks', () => { const row = diagnosticRows([item], [], 'zh-TW', translateTW)[0]; const mark = sourceMarks([item], item.source_id, translateTW)[0]; expect(row.message).toBe(translateTW('ui.backend.duplicateSubscriptionEntry')); - expect(row.detail).toContain('Original backend detail'); + expect(row.backend).toBe('Original backend detail'); expect(mark.message).toContain(row.message); expect(mark.message).toContain('Original backend detail'); }); @@ -194,7 +233,7 @@ it('shows a backend diagnostic that lacks the demo parameters in its own words', const summary = t('ui.backendMessage', {message: 'No include-resolution base'}); const row = diagnosticRows([item], [], 'en-US', t)[0]; expect(row.message).toBe(summary); - expect(row.detail).not.toContain('{path}'); + expect(row.text).not.toContain('{path}'); expect(sourceMarks([item], item.source_id, t)[0].message).toBe(summary); }); diff --git a/src/features/config/view.ts b/src/features/config/view.ts index 046a3948..5e5625e3 100644 --- a/src/features/config/view.ts +++ b/src/features/config/view.ts @@ -37,10 +37,10 @@ export function sourceMarks(diagnostics: ConfigDiagnostic[], sourceId: string, t .map(d => ({line: d.line!, column: d.column, level: d.level, message: diagnosticText(diagnosticMessage(d, t), t)})); } -// A diagnostic's words, the same in its row and its editor mark. A translated code keeps the backend's own words, which -// name the entry the code cannot. -function diagnosticText({summary, detail}: BackendMessage, t: Translator, text = summary): string { - return detail ? t('config.backendDetail', {text, message: detail}) : text; +// A diagnostic's words in its editor mark, where the row's backend disclosure has no room. A translated code keeps the +// backend's own words, which name the entry the code cannot. +function diagnosticText({summary, detail}: BackendMessage, t: Translator): string { + return detail ? t('config.backendDetail', {text: summary, message: detail}) : summary; } function ruleCount(text: string, block: TextBlock, tokens: TextToken[]): number { @@ -224,7 +224,7 @@ export function readOnlyBadge( const label = t(text.label); return {reason, label, note: t(text.note), ...(text.help && {help: {title: label, text: t(text.help)}})}; } -type DiagnosticRow = { +export type DiagnosticRow = { id: string; level: ConfigDiagnostic['level']; tone: 'err' | 'warn' | 'info'; @@ -234,13 +234,26 @@ type DiagnosticRow = { where: string; message: string; code: string; - detail: string; + // What the diagnostic says, without where: the same error moved by an edit above it keeps it. + identity: string; + // The row as listed: its line (with the file when it is another source) and its message. + text: string; + // The backend's own words when the message is a translation that leaves something out. + backend: string | null; + // A line in the source on show moves its editor; another source opens there. + action: 'jump' | 'open' | null; count: number; }; const tones = {error: 'err', warning: 'warn', info: 'info'} as const; const levels: Record = {error: 'config.level.error', warning: 'config.level.warning', info: 'config.level.info'}; // Identical diagnostics, such as one warning per duplicate entry at the same place, share one row with their count. -export function diagnosticRows(diagnostics: ConfigDiagnostic[], sources: ConfigSource[], locale: string, t: Translator): DiagnosticRow[] { +export function diagnosticRows( + diagnostics: ConfigDiagnostic[], + sources: ConfigSource[], + locale: string, + t: Translator, + current: string | null = null +): DiagnosticRow[] { const paths = new Map(sources.map(source => [source.id, fileName(source)])); // The key is also the row id, so a selection follows its diagnostic when the polled list changes around it. const groups = new Map(); @@ -255,7 +268,8 @@ export function diagnosticRows(diagnostics: ConfigDiagnostic[], sources: ConfigS const presented = diagnosticMessage(item, t); const text = presented.summary; const message = count > 1 ? t('config.repeated', {text, n: formatNumber(count, locale)}) : text; - const described = diagnosticText(presented, t, message); + const own = item.source_id === current; + const line = item.line === null ? null : formatNumber(item.line, locale); return { id: key, level: item.level, @@ -266,11 +280,38 @@ export function diagnosticRows(diagnostics: ConfigDiagnostic[], sources: ConfigS where: item.line === null ? path : `${path}:${item.line}`, message, code: item.code, - detail: item.line === null ? described : t('config.atFile', {file: path, line: formatNumber(item.line, locale), message: described}), + identity: JSON.stringify([item.source_id, item.code, item.message, item.params]), + text: + line === null + ? own + ? message + : t('ui.valuePair', {label: path, value: message}) + : own + ? t('config.atLine', {line, message}) + : t('config.atFile', {file: path, line, message}), + backend: presented.detail ?? null, + action: !own ? 'open' : item.line === null ? null : 'jump', count }; }); } + +// The diagnostics bar's counts, and its errors by what they say, so editing above one does not make it new. +export function diagnosticSummary(rows: DiagnosticRow[]) { + const total = (level: ConfigDiagnostic['level']) => rows.filter(row => row.level === level).reduce((sum, row) => sum + row.count, 0); + const errorKeys = [...new Set(rows.filter(row => row.level === 'error').map(row => row.identity))]; + return {errors: total('error'), warnings: total('warning'), errorKeys}; +} + +// The person's last open or collapse of the diagnostics bar, with the errors it listed then. +export type DiagnosticsChoice = {open: boolean; errorKeys: string[]}; +// Errors open the list and anything less leaves it shut. A collapse holds until an error appears that it did not list; +// an open holds until the person collapses it. +export function diagnosticsOpen(errorKeys: string[], choice: DiagnosticsChoice | null): boolean { + if (choice && (choice.open || errorKeys.every(key => choice.errorKeys.includes(key)))) return choice.open; + return errorKeys.length > 0; +} + // The save button, shown only with unsaved changes. A refetch can make the source read-only while a draft is open; // then Save is refused and its tip gives the reason. While a validation runs the disabled button says so; otherwise, // saving included, it names the shortcut. diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 8d89fd12..9016b243 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -110,7 +110,9 @@ "cm.undo": "Undo", "config.acceptedDiagnostics": "Diagnostics kept for the accepted configuration (generation {generation})", "config.atFile": "{file} line {line}: {message}", + "config.atLine": "Line {line}: {message}", "config.backendDetail": "{text}. Backend message: {message}", + "config.backendText": "Backend message", "config.changedMeanwhile": "The configuration changed or another write was still in progress, so nothing was written. Refresh and try again", "config.changedOnDisk": "The file changed on disk while you were editing; applying would replace that change.", "config.clean": "No diagnostics", @@ -198,18 +200,16 @@ "one": "Validation found {n} error", "other": "Validation found {n} errors" }, + "config.jumpToLine": "Go to line {line}", "config.keepChanges": "Keep changes", "config.kind.generated": "Generated", "config.kind.include": "Include", "config.kind.main": "Main", "config.kind.subscription": "Subscription", - "config.level": "Level", "config.level.error": "Error", "config.level.info": "Info", "config.level.warning": "Warning", - "config.levelAll": "All {n}", "config.levelErrors": "Errors {n}", - "config.levelInfo": "Info {n}", "config.levelWarnings": "Warnings {n}", "config.loadedAt": "Loaded: {time}", "config.moduleAbsent": "Section not configured; add it to {file}.", @@ -264,7 +264,7 @@ "config.newSourceSegments": "Path segments cannot be empty, . or ..", "config.newSourceTitle": "New config file", "config.newSourceUnmatched": "No include pattern of the loaded files matches this path, so the backend will refuse it.", - "config.noDiagnostics": "No items at this level", + "config.openSource": "Open", "config.openSourceAt": "Open config file: {where}", "config.readOnly": "Read-only", "config.readOnlyAttempt": "This file is read-only", diff --git a/src/i18n/locales/zh-CN.json b/src/i18n/locales/zh-CN.json index 25fe9a33..b31e63e6 100644 --- a/src/i18n/locales/zh-CN.json +++ b/src/i18n/locales/zh-CN.json @@ -104,7 +104,9 @@ "cm.undo": "撤销", "config.acceptedDiagnostics": "生效配置(generation {generation})保留的诊断", "config.atFile": "{file} 第 {line} 行:{message}", + "config.atLine": "第 {line} 行:{message}", "config.backendDetail": "{text}。后端消息:{message}", + "config.backendText": "后端消息", "config.changedMeanwhile": "配置已被更改或另一次写入尚未完成,因此未写入。请刷新后重试", "config.changedOnDisk": "编辑期间磁盘上的文件已更改,应用会覆盖该更改。", "config.clean": "没有诊断", @@ -186,18 +188,16 @@ "config.globalUnset": "未设置", "config.incomplete": "内容不完整或已脱敏,不能在此编辑", "config.invalid": "校验发现 {n} 个错误", + "config.jumpToLine": "跳转到第 {line} 行", "config.keepChanges": "保留修改", "config.kind.generated": "引擎生成", "config.kind.include": "引入文件", "config.kind.main": "主配置", "config.kind.subscription": "订阅", - "config.level": "级别", "config.level.error": "错误", "config.level.info": "提示", "config.level.warning": "警告", - "config.levelAll": "全部 {n}", "config.levelErrors": "错误 {n}", - "config.levelInfo": "提示 {n}", "config.levelWarnings": "警告 {n}", "config.loadedAt": "加载时间:{time}", "config.moduleAbsent": "未设置此区段;可加入 {file}。", @@ -228,7 +228,7 @@ "config.newSourceSegments": "路径不能包含空段、. 或 ..", "config.newSourceTitle": "新建配置文件", "config.newSourceUnmatched": "已加载文件的 include 区段中没有匹配此路径的模式,因此后端会拒绝创建。", - "config.noDiagnostics": "没有此级别的项目", + "config.openSource": "打开", "config.openSourceAt": "打开配置文件:{where}", "config.readOnly": "只读", "config.readOnlyAttempt": "此文件只读", diff --git a/src/i18n/locales/zh-TW.json b/src/i18n/locales/zh-TW.json index cff60232..1b335bd9 100644 --- a/src/i18n/locales/zh-TW.json +++ b/src/i18n/locales/zh-TW.json @@ -104,7 +104,9 @@ "cm.undo": "復原", "config.acceptedDiagnostics": "生效組態(generation {generation})保留的診斷", "config.atFile": "{file} 第 {line} 行:{message}", + "config.atLine": "第 {line} 行:{message}", "config.backendDetail": "{text}。後端訊息:{message}", + "config.backendText": "後端訊息", "config.changedMeanwhile": "組態已被變更或另一次寫入尚未完成,因此未寫入。請重新整理後重試", "config.changedOnDisk": "編輯期間磁碟上的檔案已變更,套用會覆蓋該變更。", "config.clean": "沒有診斷", @@ -186,18 +188,16 @@ "config.globalUnset": "未設定", "config.incomplete": "內容不完整或已遮蔽,不能在此編輯", "config.invalid": "驗證發現 {n} 個錯誤", + "config.jumpToLine": "前往第 {line} 行", "config.keepChanges": "保留修改", "config.kind.generated": "引擎產生", "config.kind.include": "引入檔", "config.kind.main": "主組態", "config.kind.subscription": "訂閱", - "config.level": "等級", "config.level.error": "錯誤", "config.level.info": "提示", "config.level.warning": "警告", - "config.levelAll": "全部 {n}", "config.levelErrors": "錯誤 {n}", - "config.levelInfo": "提示 {n}", "config.levelWarnings": "警告 {n}", "config.loadedAt": "載入時間:{time}", "config.moduleAbsent": "未設定此區段;可加入 {file}。", @@ -228,7 +228,7 @@ "config.newSourceSegments": "路徑不可包含空段、. 或 ..", "config.newSourceTitle": "新增設定檔", "config.newSourceUnmatched": "已載入檔案的 include 區段中沒有符合此路徑的樣式,因此後端會拒絕建立。", - "config.noDiagnostics": "沒有此等級的項目", + "config.openSource": "開啟", "config.openSourceAt": "開啟設定檔:{where}", "config.readOnly": "唯讀", "config.readOnlyAttempt": "此檔案唯讀", diff --git a/src/ui/code/CodeEditor.tsx b/src/ui/code/CodeEditor.tsx index 1be06561..9068ad93 100644 --- a/src/ui/code/CodeEditor.tsx +++ b/src/ui/code/CodeEditor.tsx @@ -1,4 +1,4 @@ -import {useEffect, useLayoutEffect, useRef} from 'react'; +import {useEffect, useLayoutEffect, useRef, type ReactNode} from 'react'; import {Menu, MenuItem} from 'react-aria-components'; import {useT, type Translator} from '../../i18n'; import type {Key} from '../../i18n'; @@ -18,7 +18,7 @@ import { } from '@codemirror/view'; import {defaultKeymap, history, historyKeymap, indentWithTab, redo, toggleComment, undo} from '@codemirror/commands'; import {bracketMatching, syntaxHighlighting, HighlightStyle, indentUnit, indentOnInput, indentService} from '@codemirror/language'; -import {setDiagnostics} from '@codemirror/lint'; +import {lintGutter, setDiagnostics} from '@codemirror/lint'; import {highlightSelectionMatches, searchKeymap, gotoLine, openSearchPanel} from '@codemirror/search'; import {tags} from '@lezer/highlight'; import {dae} from './dae'; @@ -88,7 +88,13 @@ const theme = EditorView.theme({ '.cm-cursor': {borderLeftColor: 'var(--rp-text)'}, '.cm-matchingBracket': {backgroundColor: 'color-mix(in srgb, var(--rp-accent) 20%, transparent)', outline: 'none'}, '.cm-selectionMatch': {backgroundColor: 'color-mix(in srgb, var(--rp-notice) 25%, transparent)'}, - // Diagnostics show as underlines and the list above the editor, not gutter icons; the hover tooltip is the kit's. + // Diagnostics show as gutter markers, underlines and the list above the editor; the hover tooltip is the kit's. + '.cm-gutter-lint': {width: '12px'}, + '.cm-gutter-lint .cm-gutterElement': {padding: '0'}, + '.cm-lint-marker': {width: '8px', height: '8px', margin: '6px 2px', borderRadius: '50%'}, + '.cm-lint-marker-error': {content: 'none', backgroundColor: 'var(--rp-negative)'}, + '.cm-lint-marker-warning': {content: 'none', backgroundColor: 'var(--rp-notice)'}, + '.cm-lint-marker-info': {content: 'none', backgroundColor: 'var(--rp-foam)'}, '.cm-tooltip.cm-tooltip-lint': { backgroundColor: 'var(--rp-text)', color: 'var(--rp-on-text)', @@ -225,7 +231,9 @@ export function CodeEditor({ onSave, onReadOnlyAttempt, compact, - actions = [] + actions = [], + focusKey, + banner }: { value: string; onChange?: (value: string) => void; @@ -241,6 +249,10 @@ export function CodeEditor({ onReadOnlyAttempt?: () => void; compact?: boolean; actions?: Action[]; + // Changes to move to focusLine again when it is the line already asked for. + focusKey?: number; + // What shows under the toolbar, above the text, such as a diagnostics summary. + banner?: ReactNode; }) { const toolbar = useRef(null); const collapsed = useOverflow(toolbar, actions.map(action => action.label).join('\n') + readOnly + label); @@ -274,6 +286,7 @@ export function CodeEditor({ doc: value, extensions: [ lineNumbers(), + lintGutter(), highlightSpecialChars(), undoable.current.of(history()), rectangularSelection(), @@ -360,7 +373,7 @@ export function CodeEditor({ const line = instance.state.doc.line(focusLine); instance.dispatch({selection: {anchor: line.from}, effects: [setFocusLine.of(focusLine), EditorView.scrollIntoView(line.from, {y: 'center'})]}); instance.focus(); - }, [focusLine]); + }, [focusLine, focusKey]); // The toolbar runs the keymap's own commands. Find and Go to line only move and select, so they stay in a read-only // source; the editing menu is disabled there, and a preview without onChange, which never becomes editable, has none. // A compact preview keeps its reduced height and has no toolbar. @@ -370,57 +383,60 @@ export function CodeEditor({ return ( <> {!compact && ( -
- -
-
- - - - {onChange && ( - { - const command = editCommands.find(command => command.id === key); - if (command) run(command.run); - }} - > - {editCommands.map(command => ( - - {t(command.label)} - - ))} - - } - > - {t('cm.commands')} - +
+
+ +
+
+ + + + {onChange && ( + { + const command = editCommands.find(command => command.id === key); + if (command) run(command.run); + }} + > + {editCommands.map(command => ( + + {t(command.label)} + + ))} + + } + > + {t('cm.commands')} + + )} +
+ {collapsed && ( +
+ requestAnimationFrame(() => run(openSearchPanel))}, + {id: 'line', label: t('cm.gotoLine'), onAction: () => requestAnimationFrame(() => run(gotoLine))}, + ...(onChange + ? editCommands.map(command => ({ + id: command.id, + label: t(command.label), + isDisabled: readOnly, + onAction: () => requestAnimationFrame(() => run(command.run)) + })) + : []) + ]} + /> +
)}
- {collapsed && ( -
- requestAnimationFrame(() => run(openSearchPanel))}, - {id: 'line', label: t('cm.gotoLine'), onAction: () => requestAnimationFrame(() => run(gotoLine))}, - ...(onChange - ? editCommands.map(command => ({ - id: command.id, - label: t(command.label), - isDisabled: readOnly, - onAction: () => requestAnimationFrame(() => run(command.run)) - })) - : []) - ]} - /> -
- )}
+ {banner}
)}
diff --git a/src/ui/styles/feature-details.css b/src/ui/styles/feature-details.css index 52a17152..8185faf3 100644 --- a/src/ui/styles/feature-details.css +++ b/src/ui/styles/feature-details.css @@ -29,6 +29,12 @@ min-width: 0; max-width: 100%; } +/* The toolbar and any banner under it. */ +.rp-editor-head { + display: flex; + flex-direction: column; + gap: var(--rp-space-2); +} .rp-editor-toolbar, .rp-editor-actions > .rp-toolbar { flex-wrap: nowrap; diff --git a/src/ui/styles/page-layout.css b/src/ui/styles/page-layout.css index 13f955b1..a90e508a 100644 --- a/src/ui/styles/page-layout.css +++ b/src/ui/styles/page-layout.css @@ -320,12 +320,47 @@ } } -/* Configuration page: diagnostics wrap instead of overflowing the card. */ -.rp-config-diagnostics .rp-light { +/* Configuration page: the diagnostics bar under the editor's toolbar. Its list scrolls inside a bounded height so the + pinned bar never fills the screen, and each row's action lines up in one column at its end. */ +.rp-config-diagnostics { + outline: none; +} +/* The counts keep their line; what they were counted on wraps under them on a phone. */ +.rp-config-diagnostics .rp-disclosure-head { + flex-wrap: wrap; + column-gap: var(--rp-space-3); +} +.rp-config-diagnostics .rp-disclosure-head > .rp-disclosure-trigger { + flex: none; +} +.rp-config-diagnostics .rp-disclosure-head > .rp-label { + flex: 0 1 auto; min-width: 0; - max-width: 100%; +} +.rp-config-diagnostic-list { + display: grid; + grid-template-columns: minmax(0, 1fr) max-content; + gap: var(--rp-space-2) var(--rp-space-3); + max-height: min(16rem, 35vh); + overflow: auto; + overscroll-behavior: contain; +} +.rp-config-diagnostic { + display: grid; + grid-column: 1 / -1; + grid-template-columns: subgrid; + align-items: start; +} +.rp-config-diagnostic > :only-child { + grid-column: 1 / -1; +} +.rp-config-diagnostic .rp-light { white-space: normal; - overflow-wrap: anywhere; +} +/* The backend's words open in the row's small type, under its message. */ +.rp-config-diagnostic .rp-disclosure-trigger { + font-size: var(--rp-text-xs); + line-height: 16px; } /* The group's basis decides whether the action buttons share its line. Inside it, the picker keeps the basename and chevron together while the badge and facts wrap on phones when they no longer fit. */ @@ -351,18 +386,3 @@ .rp-source-note { min-height: 0; } - -.rp-config-workspace { - display: grid; - grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); - gap: 24px; - align-items: start; -} -.rp-config-workspace > * { - min-width: 0; -} -@media (max-width: 959.98px) { - .rp-config-workspace { - grid-template-columns: minmax(0, 1fr); - } -}