From 4a5166271442425d1cba588417f198124753aba4 Mon Sep 17 00:00:00 2001 From: Roland Date: Wed, 5 Aug 2026 17:06:56 -0600 Subject: [PATCH] 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 `

` -- 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 ``, 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) --- app/src/App.css | 3 + app/src/components/Common.test.js | 120 +++++++++++++++++- app/src/components/Docs.js | 13 +- app/src/components/FileBrowser.js | 1 - app/src/components/Playlists.js | 16 ++- app/src/components/VideoPlayer.js | 4 +- app/src/components/admin/ControllerPage.js | 9 +- app/src/components/admin/Downloads.js | 2 + .../calculators/OneTimePadCalculator.js | 10 +- .../calculators/RationCalculator.js | 20 +-- .../collections/CollectionEditForm.js | 41 +++--- .../components/inventory/FieldSchemaEditor.js | 22 ++-- 12 files changed, 200 insertions(+), 61 deletions(-) diff --git a/app/src/App.css b/app/src/App.css index 5d7d3c95..b768c854 100644 --- a/app/src/App.css +++ b/app/src/App.css @@ -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. */ } diff --git a/app/src/components/Common.test.js b/app/src/components/Common.test.js index 565575ba..b8bf7e38 100644 --- a/app/src/components/Common.test.js +++ b/app/src/components/Common.test.js @@ -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 ``" 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 `` is its own. - const closes = text.indexOf('', 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 diff --git a/app/src/components/Docs.js b/app/src/components/Docs.js index 162e8be6..815b1654 100644 --- a/app/src/components/Docs.js +++ b/app/src/components/Docs.js @@ -408,9 +408,16 @@ function DocPage() { - {/* 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. + */}

{formatButtons} {actionButtons} diff --git a/app/src/components/FileBrowser.js b/app/src/components/FileBrowser.js index f4434bde..0a0f46ca 100644 --- a/app/src/components/FileBrowser.js +++ b/app/src/components/FileBrowser.js @@ -571,7 +571,6 @@ export function FileBrowser() { onClick={onCollapseAll} disabled={!openFolders || openFolders.length === 0} label='Close all folders' - style={{marginLeft: '0.5em'}} />
- {editable && - @@ -503,7 +503,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) { disabled={!videoFile.url} >Refresh -

+ diff --git a/app/src/components/admin/ControllerPage.js b/app/src/components/admin/ControllerPage.js index 303bb2f8..5c39d240 100644 --- a/app/src/components/admin/ControllerPage.js +++ b/app/src/components/admin/ControllerPage.js @@ -286,6 +286,7 @@ function MobileServiceRow({service, onAction}) {
{service.description}
}
+
{isRunning ? ( +
{service.port || '-'} +
{isRunning ? ( +
setForm({...form, protocol: value})} /> -
+
- +
+ + +
Pad characters
diff --git a/app/src/components/calculators/RationCalculator.js b/app/src/components/calculators/RationCalculator.js index c34bb4fe..212a295e 100644 --- a/app/src/components/calculators/RationCalculator.js +++ b/app/src/components/calculators/RationCalculator.js @@ -283,15 +283,17 @@ function SupplyPlan({name, items, fields, caloriesKey, countKey, currentDays, to {projectedDays ? <> to reach about {formatDuration(projectedDays)} of food. : '.'}

- - +
+ + +
{/* Hidden printable block — `printShoppingList` makes this the only thing printed. */} {actionButtons} - {onCancel && } - + {/* + * 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. + */} +
+ {onCancel && } + +
diff --git a/app/src/components/inventory/FieldSchemaEditor.js b/app/src/components/inventory/FieldSchemaEditor.js index a6218835..510cf3f8 100644 --- a/app/src/components/inventory/FieldSchemaEditor.js +++ b/app/src/components/inventory/FieldSchemaEditor.js @@ -81,10 +81,12 @@ export function FieldSchemaEditor({fields, open, onClose, onSave}) { {draft.map((f, index) => - move(index, -1)} - disabled={index === 0} label='Move up'/> - move(index, 1)} - disabled={index === draft.length - 1} label='Move down'/> +
+ move(index, -1)} + disabled={index === 0} label='Move up'/> + move(index, 1)} + disabled={index === draft.length - 1} label='Move down'/> +
)}
- - +
+ + +