From 300d21f0acc44174fa5ce0c10b2a79b82663ff0b Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 2 Aug 2026 17:44:25 -0600 Subject: [PATCH] ui: the map pin buttons were three sizes for three reasons Reported as "all different sizes", and the pin row's three actions measured 46x30, 30x30 and 54x36. Three causes. APIButton dropped `size`. `useAPIButton` declared `size = 'medium'` as a parameter and then never put it into the props it hands to Button, so every APIButton in the app rendered at Mantine's default regardless of what its call site asked for -- seventeen call sites pass one, from `xs` on the map pins to `big` and `huge` on Settings. The delete pin was 36px tall beside two 30px siblings because of it. Passing the parameter default through would have fixed the bug by breaking everything else -- every APIButton naming no size would have grown from `sm` to `md` -- so the default is undefined now and Button's own default stands. Eight buttons on three other pages do grow as a result, which is their call sites finally being honoured: VideoPlayer's `large`, one of Channels' `big`, and Settings' two `big` and two `huge`. An icon-only Button was not square. A Button is as wide as its content plus its horizontal padding; an ActionIcon is square by construction; and the pin row mixes the two, because AddToPlaylistButton renders an IconButton when it has no label. Their heights already agreed -- ActionIcon's scale was remapped onto Button's some commits ago -- and this is the other axis of the same alignment, keyed off Mantine's own `--button-height` so the two stay in step through every size. They were also misaligned and touching, which is a third thing: bare inline-block siblings align on text BASELINES, and a Button's baseline is not an ActionIcon's, so the middle control sat 4.3px above the other two. A Group, as every other row of buttons in the app uses. Written test-first at Roland's request. Seven cypress cases went red on the sizes -- widths 46 against 30, 54 against 36, 62 against 42, 70 against 50, and "xs is shorter than lg: expected 36 to be below 32" for the dropped size -- with both inverses green throughout: a labelled button stays as wide as its label, and an APIButton naming no size keeps the height it had. The alignment claim is measured in ui-layout.cy.js, including the premise that bare siblings really are misaligned, since three controls of identical height not lining up is not believable otherwise. The call sites are held by a source guard, because MapPins fetches from the API and builds its rows through SortableTable. That guard earned itself twice over. Written for the pin rows, it found the map-files subscribe cell putting a preview button beside a subscribe button with the same defect. Then a first attempt at a general "any cell with two controls" rule had to be abandoned: a cell whose buttons are the arms of a ternary renders only one and needs no Group, and excluding ternaries to allow for that also excluded the subscribe cell, whose `role={isSubscribed ? ... : ...}` says nothing about how many controls it holds. Named cells with a stated scope beat a general rule that quietly stops covering things. Two slips of mine in that file, both caught by running it: `expect(value, message)` is chai and throws in jest, and `onSave(pin.id, ...)` was not unique to the cell it named -- the edit row's TextInput calls it from onKeyDown in a different cell, so the check passed against the wrong one. 1132 jest / 64 suites, 243 in ui-layout.cy.js, clean npm run build. Confirmed live: three 30x30 controls, vertical spread 0, 10px gaps. --- app/src/components/Common.js | 16 ++- app/src/components/Map.js | 74 ++++++----- app/src/components/Map.test.js | 78 +++++++++++ app/src/components/ui/Button.tsx | 8 ++ app/src/components/ui/ui-layout.cy.js | 178 +++++++++++++++++++++++++- app/src/components/ui/ui.css | 17 +++ 6 files changed, 337 insertions(+), 34 deletions(-) create mode 100644 app/src/components/Map.test.js diff --git a/app/src/components/Common.js b/app/src/components/Common.js index b776fb86..d35fd03e 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -1709,7 +1709,19 @@ export function normalizeEstimate(estimate) { export function useAPIButton( color = 'violet', - size = 'medium', + /* + * Undefined, not 'medium'. `size` was never put into `buttonArgs` below, so every + * APIButton in the app rendered at Mantine's default no matter what its call site asked + * for -- seventeen of them pass a size, from `xs` on the map's pin actions to `huge` on + * Settings, and all seventeen were ignored. The map's pin row is where it showed: three + * buttons meant to be `xs`, one of them 36px tall next to two 30px ones. + * + * Defaulting to 'medium' and passing that through would have fixed the bug by breaking + * everything else -- every APIButton that names no size would have grown from `sm` to + * `md`. Undefined lets Button's own default stand, so only the call sites that asked for + * something see a change. + */ + size, floated, onClick, disabled, @@ -1795,7 +1807,7 @@ export function useAPIButton( // `color` was a Semantic color name; a role carries the meaning instead, and a // caller that really wants a color can still pass one through `props`. const buttonArgs = { - onClick: localOnClick, disabled, loading, type, + onClick: localOnClick, disabled, loading, type, size, ...props, }; if (id) { diff --git a/app/src/components/Map.js b/app/src/components/Map.js index bb649c1f..46b832f3 100644 --- a/app/src/components/Map.js +++ b/app/src/components/Map.js @@ -15,7 +15,7 @@ import { deleteMapFile, deleteMapPin, fetchMapSubscriptions, getMapFiles, getMapPins, mapSubscribe, mapUnsubscribe, rebuildMapSearchIndex, updateMapPin } from "../api"; -import {Button, Divider, Header, Icon, Modal, Table, TextInput} from "./ui"; +import {Button, Divider, Group, Header, Icon, Modal, Table, TextInput} from "./ui"; import {SortableTable} from "./SortableTable"; import {Media, StatusContext} from "../contexts/contexts"; import {MAP_VIEWER_URI} from "./Vars"; @@ -229,19 +229,23 @@ function MapCatalogRow({item, subscribedRegions, fetchData}) { {name} {humanFileSize(size_estimate)} - {bbox && + {/* See PinEditRow: a Group so the preview and subscribe controls line up and are + spaced, rather than sitting on baselines they do not share. */} + + {bbox && + {previewOpen && {pin.lat.toFixed(4)}, {pin.lon.toFixed(4)} {pin.created} - - + {/* A Group, not bare siblings: inline-block controls align on text baselines they + do not share, and JSX leaves no whitespace between them to space them out. */} + + + + ; } @@ -524,21 +533,24 @@ function MapPins() { {pin.created} - ); + + cy.get('[data-testid="labelled"]').should(($button) => { + const box = $button[0].getBoundingClientRect(); + + expect(box.width, 'wider than it is tall').to.be.greaterThan(box.height * 2); + }); + }); +}); + +describe('APIButton honours the size its call site asks for', () => { + /* + * `useAPIButton` assembled the props it hands to Button and left `size` out, so it was + * dropped at every call site -- seventeen of them, from the map pins' `xs` to Settings' + * `huge`. The map's delete pin came out 36px tall beside two 30px siblings. + */ + it('renders a small APIButton smaller than a large one', () => { + cy.mountUI(
+ {}} data-testid='small'/> + {}} data-testid='large'/> +
); + + cy.get('[data-testid="large"]').should(($large) => { + const small = Cypress.$('[data-testid="small"]')[0].getBoundingClientRect(); + + expect(small.height, 'xs is shorter than lg') + .to.be.lessThan($large[0].getBoundingClientRect().height - 4); + }); + }); + + it('matches a plain Button given the same size', () => { + // The claim that matters at the call site: an APIButton and a Button asking for the + // same size are the same control. + cy.mountUI(
+ {}} data-testid='api'/> +
); + + cy.get('[data-testid="api"]').should(($api) => { + const plain = Cypress.$('[data-testid="plain"]')[0].getBoundingClientRect(); + const api = $api[0].getBoundingClientRect(); + + expect(api.height, 'heights').to.be.closeTo(plain.height, 1); + expect(api.width, 'widths').to.be.closeTo(plain.width, 1); + }); + }); + + it('is a real constraint: an APIButton with no size keeps the default it had', () => { + /* + * `useAPIButton` declared `size = 'medium'` as a parameter default while never using + * it. Passing that through would have fixed the bug by breaking everything else -- + * every APIButton that names no size would have grown from Mantine's `sm` to `md`. + */ + cy.mountUI(
+ {}} data-testid='default'/> +
); + + cy.get('[data-testid="default"]').should(($api) => { + const plain = Cypress.$('[data-testid="plain"]')[0].getBoundingClientRect(); + + expect($api[0].getBoundingClientRect().height, 'unchanged default') + .to.be.closeTo(plain.height, 1); + }); + }); +}); + +describe('a row of icon controls sits level and spaced', () => { + /* + * The map's pin actions are three icon controls in one table cell: edit (Button), + * add-to-playlist (IconButton) and delete (APIButton). They were laid out as bare + * siblings, so they were inline-block boxes aligned on their BASELINES -- and a Button's + * baseline is not an ActionIcon's, so the middle one sat 4.3px higher than the other two. + * They also touched, because JSX leaves no whitespace between elements. + * + * Both are what `Group` is for, which is how every other row of buttons in the app is + * built. Measured on the running app at tops 258.6 / 254.2 / 258.6 before the fix. + */ + const controls = <> +