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 = <> +