review: the scan the first two commits needed

Five findings, all valid.  The substantive one: the video page's Download /
Delete / Refresh / AddToPlaylist strip was still four bare buttons in a `<p>` --
the direct analogue of the archive row this PR started with -- and the scan that
was supposed to catch exactly that reported the app clean.

It only ever saw `{fooButton}` interpolations, and most of the app writes its
buttons out in place.  Scanning for adjacent button ELEMENTS finds twelve more
rows in the same state: reorder icons in the playlist and field-schema tables,
both service tables on the controller page, its hotspot Save/QR pair and its
Restart/Shutdown pair, the downloads footer, the one-time pad's Generate/Cheat
Sheet, and the ration calculator's CSV/Print.  All rowed.

Two holes had to be closed before that scan could be trusted, because a scan
that reports noise is worse than one with a stated limit:

  - `tagsIn` never captured the tag NAME, so `ROW_COMPONENTS.has(undefined)` was
    false for every tag and the list of components that lay out their own
    children -- Group, ButtonGroup, Modal.Actions -- silently accepted none of
    them.  56 false positives, every modal footer in the app among them.
  - A row whose style is a const (`style={seasonRowStyle}`) says nothing in its
    own attributes.  Resolved now; the dates selector's seasons row is a
    four-column grid with a gap and was reported three times.

Also from review: the row body is found by walking to the MATCHING close rather
than the first `</div>`, which one nested div would have truncated -- and the
collection form now nests one, so this was about to matter.  Cancel and Save
travel together in a row of their own pushed to the end; `margin-left: auto` on
Save alone was right for a row that could not wrap, and would now drop Save onto
a second line by itself with Cancel left among the action buttons.  The doc
page's comment no longer implies the picker's 1em separation was not a change.

One more found on the way: the file browser's filter row is flex with no gap, and
its collapse-all button carried `margin-left: 0.5em` for it.  The gap is the
container's.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Roland 2026-08-05 17:06:56 -06:00
parent 076e982b69
commit 4a51662714
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
12 changed files with 200 additions and 61 deletions

View file

@ -586,6 +586,9 @@ tr.drag-deselecting td {
.file-browser-filter-container {
display: flex;
justify-content: flex-end;
/* The gap is the container's. The collapse-all button carried `margin-left: 0.5em` for it,
which is the same thing one element to the right of where it belongs. */
gap: 0.5em;
/* No `margin-bottom`: this is a top-level block of the Files page, and the page's stack
spaces it (see `.wrolpi-stack`). Its own 0.5em was added to that. */
}

View file

@ -805,11 +805,37 @@ describe('a row of buttons', () => {
const tagsIn = (text) => [...scannable(text).matchAll(TAG)].map(match => ({
start: match.index,
end: match.index + match[0].length,
// The name was not captured until a test needed to accept `Group` and `Modal.Actions` as
// rows: `ROW_COMPONENTS.has(undefined)` is false for every tag, so the list of components
// that lay out their own children silently accepted none of them.
name: match[2],
attributes: match[3],
closing: match[1] === '/',
selfClosing: match[4] === '/',
}));
/**
* The text inside the element opened by `open`, found by walking forward to its MATCHING close.
*
* Written as "slice to the first `</div>`" first, which is true of every row in the app today
* and is a false negative waiting to happen: one nested div -- an error-trigger wrapper, a
* format-picker span, the Cancel/Save pair the collection form now groups -- truncates the body,
* and every button after it goes unscanned.
*/
const bodyOfElement = (text, tags, open) => {
let depth = 0;
for (const tag of tags) {
if (tag.start <= open.start || tag.selfClosing) continue;
if (tag.closing) {
if (depth === 0) return text.slice(open.end, tag.start);
depth -= 1;
} else {
depth += 1;
}
}
return text.slice(open.end); // Unclosed; scan what is left rather than nothing.
};
/**
* The tag that encloses `index`: walk the tags before it backwards, letting a close push the
* depth up and an open bring it back down, and stop at the first open that is still unclosed.
@ -863,8 +889,40 @@ describe('a row of buttons', () => {
*/
const ROW_CLASSES = [
'wrolpi-button-row', 'wrolpi-modal-actions', 'wrolpi-confirm-actions', 'preview-toolbar-group',
// Two that predate `.wrolpi-button-row` and are already correct: the file browser's sticky
// footer, and its filter row. Both are checked against the stylesheet below like the rest.
'sticky-footer', 'file-browser-filter-container',
];
const isRow = (tag) => !!tag && ROW_CLASSES.some(name => tag.attributes.includes(name));
/*
* Components that lay their own children out in a row. A `Group` or a `ButtonGroup` is a row by
* construction, so a caller putting buttons in one has already answered the question.
*/
const ROW_COMPONENTS = new Set(['Group', 'ButtonGroup', 'Row', 'Stack', 'Modal.Actions']);
/*
* An inline flex or grid with a gap of its own -- an anonymous row. Several call sites write one
* rather than reach for a class, and they are not wrong; a scan that only knew about class names
* would report every one of them.
*/
const INLINE_ROW = /display:\s*['"]?(?:flex|grid)/;
const isInlineRow = (attributes, text) => {
if (INLINE_ROW.test(attributes) && attributes.includes('gap')) return true;
/*
* `style={someStyle}` -- the style is a const somewhere above, so the attribute itself says
* nothing. Resolving it matters: the seasons row on the dates selector is a four-column
* grid with a gap, declared exactly that way, and it would otherwise be reported forever.
*/
const named = /style=\{(\w+)\}/.exec(attributes);
if (!named) return false;
const declared = new RegExp(`\\b${named[1]}\\s*=\\s*(\\{[^;]*?\\});`).exec(text);
return !!declared && INLINE_ROW.test(declared[1]) && declared[1].includes('gap');
};
const isRow = (tag, text = '') => !!tag && (
ROW_COMPONENTS.has(tag.name)
|| ROW_CLASSES.some(name => tag.attributes.includes(name))
|| isInlineRow(tag.attributes, text));
it('lays every row out as a flex row with a gap', () => {
// Otherwise the list above is just a list of names the scans below happen to accept.
@ -895,11 +953,10 @@ describe('a row of buttons', () => {
const where = path.relative(SRC, file);
const blocks = actionFragments(text);
for (const tag of tagsIn(text)) {
const tags = tagsIn(text);
for (const tag of tags) {
if (!tag.closing && tag.attributes.includes('wrolpi-button-row')) {
// A row holds buttons, not more divs, so its first `</div>` is its own.
const closes = text.indexOf('</div>', tag.end);
blocks.push(closes === -1 ? '' : text.slice(tag.end, closes));
blocks.push(bodyOfElement(text, tags, tag));
}
}
rows += blocks.length;
@ -963,7 +1020,7 @@ describe('a row of buttons', () => {
expect(offenders).toEqual([]);
});
it('never lists buttons as bare siblings', () => {
it('never lists interpolated buttons as bare siblings', () => {
/*
* The touching itself, and the reported defect: the archive page interpolated six buttons
* one after another straight into its Panel, so every pair shared an edge.
@ -972,6 +1029,8 @@ describe('a row of buttons', () => {
* `actionButtons` fragment are blanked first -- a fragment is spread into its parent's row
* and has no business being one itself, which the previous test is what checks. Blanked
* rather than skipped so every index still points where it did.
*
* The sibling test below covers the other way a row is written; this one only sees `{foo}`.
*/
const offenders = [];
let runs = 0;
@ -1003,6 +1062,55 @@ describe('a row of buttons', () => {
expect(offenders).toEqual([]);
});
it('never lists written-out buttons as bare siblings either', () => {
/*
* The same claim for the other way a row is written. The interpolation scan above sees
* `{fooButton}` and nothing else, and most of the app writes its buttons out in place --
* which is how the video page's Download/Delete/Refresh/AddToPlaylist strip, the direct
* analogue of the archive row this PR started with, went on touching after that scan
* reported the app clean. Twelve more rows were in the same state, in table cells, on the
* controller page, and under the one-time-pad and ration calculators.
*
* A "row" is deliberately broad here: the class, a Group or ButtonGroup, or an inline
* flex/grid with a gap, including one whose style is a const declared above. The point is
* whether the buttons are spaced by something, not whether they use this PR's class.
*/
const offenders = [];
let runs = 0;
for (const file of sourceFiles()) {
let text = fs.readFileSync(file, 'utf8');
// A fragment is spread into its parent's row; the earlier test checks that parent.
for (const fragment of actionFragments(text)) {
text = text.replace(fragment, ' '.repeat(fragment.length));
}
const tags = tagsIn(text);
// A button element ending, then whitespace, then another button beginning.
const runPattern = /(?:<\/\w*Button>|<\w*Button\b[^>]*?\/>)\s*<\w*Button\b/g;
for (const match of scannable(text).matchAll(runPattern)) {
// Anchor on the SECOND button's `<`: at the first one's closing tag the pair is
// still open, and the walk would report the first button as its own parent.
const at = match.index + match[0].lastIndexOf('<');
runs += 1;
if (!isRow(enclosingTag(tags, at), text)) {
offenders.push(`${path.relative(SRC, file)}:${
text.slice(0, at).split('\n').length}`);
}
}
}
/*
* Around eighty, which is why this is a scan and not a list. Asserted loosely at both ends
* -- tight enough that a pattern matching nothing shows up, loose enough that adding a
* button to an existing row is not a test failure.
*/
expect(runs).toBeGreaterThan(60);
expect(runs).toBeLessThan(200);
expect(offenders).toEqual([]);
});
it('puts every Back button in a row, so the page stack cannot stretch it', () => {
/*
* A page's blocks are stacked by `.wrolpi-stack`, which is a flex column at

View file

@ -408,9 +408,16 @@ function DocPage() {
</div>
</Media>
<Media greaterThanOrEqual='tablet'>
{/* The row's own `margin-top` separates it from what is above; the gap
inside it separates the format picker from the actions, so the span
that used to hold them apart with `margin-right` is gone. */}
{/*
* The format picker and the actions are one row, separated by its gap.
*
* This IS a change: the picker used to sit 1em from the actions, held
* there by a span with `margin-right`, and it now sits at the row's
* 0.625rem like everything else in a row. The two groups read as slightly
* closer than before. Deliberate -- one spacing rule for buttons in a row
* beats a second one for buttons in a row that happen to be a picker --
* but it is a visual change and not a pure refactor.
*/}
<div className='wrolpi-button-row' style={{marginTop: '1em'}}>
{formatButtons}
{actionButtons}

View file

@ -571,7 +571,6 @@ export function FileBrowser() {
onClick={onCollapseAll}
disabled={!openFolders || openFolders.length === 0}
label='Close all folders'
style={{marginLeft: '0.5em'}}
/>
</div>
<FileBrowserContent

View file

@ -313,13 +313,15 @@ function PlaylistItemsTable({items, editable, onMove, onRemove}) {
<Table.Cell>
<ItemTitle item={item} label={label}/>
</Table.Cell>
{editable && <Table.Cell style={{textAlign: 'right', whiteSpace: 'nowrap'}}>
<Button icon='arrow up' size='xs' disabled={index === 0}
onClick={() => onMove(index, -1)}/>
<Button icon='arrow down' size='xs' disabled={index === items.length - 1}
onClick={() => onMove(index, 1)}/>
<Button role='danger' icon='trash' size='xs'
onClick={() => onRemove(item.id)}/>
{editable && <Table.Cell>
<div className='wrolpi-button-row' style={{justifyContent: 'flex-end'}}>
<Button icon='arrow up' size='xs' disabled={index === 0}
onClick={() => onMove(index, -1)}/>
<Button icon='arrow down' size='xs' disabled={index === items.length - 1}
onClick={() => onMove(index, 1)}/>
<Button role='danger' icon='trash' size='xs'
onClick={() => onRemove(item.id)}/>
</div>
</Table.Cell>}
</Table.Row>;
})}

View file

@ -485,7 +485,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
</Link>}
</h3>
<p>
<div className='wrolpi-button-row'>
<Button component='a' href={downloadUrl} icon='download'>
Download
</Button>
@ -503,7 +503,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
disabled={!videoFile.url}
>Refresh</APIButton>
<AddToPlaylistButton fileGroupId={videoFile.id}/>
</p>
</div>
</Panel>
<Panel>

View file

@ -286,6 +286,7 @@ function MobileServiceRow({service, onAction}) {
<div style={{fontSize: '0.9em', color: 'var(--muted)'}}>{service.description}</div>}
</Table.Cell>
<Table.Cell numeric>
<div className='wrolpi-button-row' style={{justifyContent: 'flex-end'}}>
{isRunning ? (
<IconButton
icon='stop'
@ -319,6 +320,7 @@ function MobileServiceRow({service, onAction}) {
role='primary'
onClick={handleViewLogs}
/>
</div>
<ServiceLogsModal
service={service}
logsOpen={logsOpen}
@ -366,6 +368,7 @@ function DesktopServiceRow({service, onAction, dockerized}) {
</Table.Cell>
<Table.Cell>{service.port || '-'}</Table.Cell>
<Table.Cell>
<div className='wrolpi-button-row'>
{isRunning ? (
<IconButton
icon='stop'
@ -399,6 +402,7 @@ function DesktopServiceRow({service, onAction, dockerized}) {
role='primary'
onClick={handleViewLogs}
/>
</div>
<ServiceLogsModal
service={service}
logsOpen={logsOpen}
@ -1575,7 +1579,7 @@ function HotspotSettingsForm() {
onChange={(value) => setForm({...form, protocol: value})}
/>
</Group>
<div style={{marginTop: '0.8em'}}>
<div className='wrolpi-button-row' style={{marginTop: '0.8em'}}>
<Button
color='violet'
disabled={dockerized}
@ -1586,7 +1590,6 @@ function HotspotSettingsForm() {
icon='qrcode'
label='Scan this code to join the hotspot'
color='violet'
style={{marginLeft: '0.5em'}}
onClick={() => setQrOpen(true)}
/>
<Modal size='small' open={qrOpen} onClose={() => setQrOpen(false)} closeIcon>
@ -1620,7 +1623,7 @@ function AdminControlsSection() {
<HotspotSettingsForm/>
{!dockerized && (
<div style={{marginTop: '1em'}}>
<div className='wrolpi-button-row' style={{marginTop: '1em'}}>
<RestartButton/>
<ShutdownButton/>
</div>

View file

@ -612,6 +612,7 @@ export function OnceDownloadsTable({downloads, fetchDownloads}) {
const footer = <Table.Footer>
<Table.Row>
<Table.HeaderCell colSpan={4}>
<div className='wrolpi-button-row'>
<ClearDownloadsButton
callback={fetchDownloads}
selectedIds={selectedIds}
@ -627,6 +628,7 @@ export function OnceDownloadsTable({downloads, fetchDownloads}) {
selectedIds={selectedIds}
clearSelection={clearSelection}
/>
</div>
</Table.HeaderCell>
</Table.Row>
</Table.Footer>;

View file

@ -155,10 +155,12 @@ export function OneTimePadCalculator() {
<Header as='h4'>One-Time Pads can be used to encrypt your communications. This can be done by hand
(yes, really) or in this app.</Header>
<p>These messages are never stored and cannot be retrieved.</p>
<Button color='violet' disabled={!activeChars} onClick={handleGenerateNewPad}>
Generate New Pad
</Button>
<Button role='cancel' component='a' href={cheatSheetURL}>Cheat Sheet PDF</Button>
<div className='wrolpi-button-row'>
<Button color='violet' disabled={!activeChars} onClick={handleGenerateNewPad}>
Generate New Pad
</Button>
<Button role='cancel' component='a' href={cheatSheetURL}>Cheat Sheet PDF</Button>
</div>
<SimpleAccordion title='Advanced'>
<Header as='h4'>Pad characters</Header>

View file

@ -283,15 +283,17 @@ function SupplyPlan({name, items, fields, caloriesKey, countKey, currentDays, to
{projectedDays ? <> to reach about <strong>{formatDuration(projectedDays)}</strong> of food.</> : '.'}
</p>
<Button role='primary' icon='download'
onClick={() => downloadCSV(
inventoryExportFilename(`${name || 'inventory'} shopping list`, 'csv'),
shoppingListCSV(sortedRows))}>
Download CSV
</Button>
<Button icon='print' onClick={printShoppingList}>
Print / Save as PDF
</Button>
<div className='wrolpi-button-row'>
<Button role='primary' icon='download'
onClick={() => downloadCSV(
inventoryExportFilename(`${name || 'inventory'} shopping list`, 'csv'),
shoppingListCSV(sortedRows))}>
Download CSV
</Button>
<Button icon='print' onClick={printShoppingList}>
Print / Save as PDF
</Button>
</div>
{/* Hidden printable block — `printShoppingList` makes this the only thing printed. */}
<ShoppingListPrint name={name} rows={sortedRows}

View file

@ -70,23 +70,30 @@ export function CollectionEditForm({
*/}
<div className='wrolpi-button-row'>
{actionButtons}
{onCancel && <Button
type='button'
role='cancel'
onClick={onCancel}
disabled={form.disabled}
>
Cancel
</Button>}
<Button
type='submit'
role='save'
size='lg'
style={{marginLeft: 'auto'}}
disabled={form.disabled}
>
Save
</Button>
{/*
* Cancel and Save travel together, in a row of their own pushed to the end.
* `margin-left: auto` was on Save alone, which was right for a row that could
* not wrap: now that it can, Save would drop onto a second line by itself,
* flush right, with Cancel left behind among the action buttons.
*/}
<div className='wrolpi-button-row' style={{marginInlineStart: 'auto'}}>
{onCancel && <Button
type='button'
role='cancel'
onClick={onCancel}
disabled={form.disabled}
>
Cancel
</Button>}
<Button
type='submit'
role='save'
size='lg'
disabled={form.disabled}
>
Save
</Button>
</div>
</div>
</div>
</form>

View file

@ -81,10 +81,12 @@ export function FieldSchemaEditor({fields, open, onClose, onSave}) {
<Table.Body>
{draft.map((f, index) => <Table.Row key={index}>
<Table.Cell>
<IconButton size='xs' icon='arrow up' onClick={() => move(index, -1)}
disabled={index === 0} label='Move up'/>
<IconButton size='xs' icon='arrow down' onClick={() => move(index, 1)}
disabled={index === draft.length - 1} label='Move down'/>
<div className='wrolpi-button-row'>
<IconButton size='xs' icon='arrow up' onClick={() => move(index, -1)}
disabled={index === 0} label='Move up'/>
<IconButton size='xs' icon='arrow down' onClick={() => move(index, 1)}
disabled={index === draft.length - 1} label='Move down'/>
</div>
</Table.Cell>
<Table.Cell>
<TextInput value={f.label || ''} placeholder='Label'
@ -121,11 +123,13 @@ export function FieldSchemaEditor({fields, open, onClose, onSave}) {
</Table.Row>)}
</Table.Body>
</Table>
<Button icon='plus' onClick={add}>Add Field</Button>
<Button icon='balance scale' onClick={addCountByWeight}
title='Add Unit Weight, Total Weight, and an auto-counted Count'>
Count by Weight
</Button>
<div className='wrolpi-button-row'>
<Button icon='plus' onClick={add}>Add Field</Button>
<Button icon='balance scale' onClick={addCountByWeight}
title='Add Unit Weight, Total Weight, and an auto-counted Count'>
Count by Weight
</Button>
</div>
</Modal.Content>
<Modal.Actions>
<Button role='cancel' onClick={onClose}>Cancel</Button>