diff --git a/app/src/components/TaggedDeleteConfirmModal.js b/app/src/components/TaggedDeleteConfirmModal.js index 28bd6ab9..49d1ae97 100644 --- a/app/src/components/TaggedDeleteConfirmModal.js +++ b/app/src/components/TaggedDeleteConfirmModal.js @@ -4,6 +4,14 @@ import {Confirm, Icon, Table} from "./ui"; export function TaggedDeleteConfirmModal({open, taggedFileGroups, onConfirm, onCancel}) { return Tagged Files Will Be Deleted} confirmLabel='Delete' destructive diff --git a/app/src/components/TaggedDeleteConfirmModal.test.js b/app/src/components/TaggedDeleteConfirmModal.test.js index c4854c85..01c126b1 100644 --- a/app/src/components/TaggedDeleteConfirmModal.test.js +++ b/app/src/components/TaggedDeleteConfirmModal.test.js @@ -1,6 +1,7 @@ import React from 'react'; import {screen, fireEvent} from '@testing-library/react'; import {renderWithProviders} from '../test-utils'; +import {Confirm} from './ui'; import {TaggedDeleteConfirmModal} from './TaggedDeleteConfirmModal'; describe('TaggedDeleteConfirmModal', () => { @@ -79,6 +80,37 @@ describe('TaggedDeleteConfirmModal', () => { expect(screen.getAllByText(/Tagged Files Will Be Deleted/i).length).toBeGreaterThan(0); }); + it('is wider than a one-sentence confirmation, because it lists paths in a table', () => { + /* + * Every Confirm in the app was 380px, because Confirm hardcoded `size='tiny'` and + * accepted no size. 380px is right for the eleven that ask a one-line question and + * wrong for this one: two columns of file paths, and a path is long. The table + * scrolls horizontally inside the modal rather than overflowing it, so the width + * decides how much of a path is readable without dragging. + */ + /* + * Both in one render, and every modal root read: a modal is portalled to + * `document.body`, so two separate renders both land there and reading only the first + * root reports one modal's size twice. + * + * Paired with a plain confirmation so this cannot pass by Confirm having become wide + * for everyone -- the point is that this one asked and the rest did not. + */ + const {baseElement} = renderWithProviders(<> + + + ); + + const sizes = [...baseElement.querySelectorAll('.mantine-Modal-root')] + .map(root => (root.getAttribute('style') ?? '').match(/--modal-size:\s*([^;]+)/)?.[1]); + expect(sizes).toEqual(['var(--modal-size-lg)', 'var(--modal-size-sm)']); + }); + it('falls back to name when primary_path is missing', () => { renderWithProviders( setConfirmOpen(true)}> Wipe download history + +

+ A confirmation is 380px wide, which suits a question. One that has to show + what it is about takes a size, in the same vocabulary as Modal. +

@@ -948,5 +956,35 @@ export function ThemeSamplePage() { videos/Wranglerstar/ (312 files) will not be deleted.

+ + Tagged files will be deleted} + confirmLabel='Delete' + onConfirm={() => setWideConfirmOpen(false)} + onCancel={() => setWideConfirmOpen(false)} + > +

The following tagged files will be deleted:

+ + + + File + Tags + + + + + videos/Practical Engineering/Season 2024/Spillways.mp4 + favorite, water + + + archives/en.wikipedia.org/Sluice_gate.html + water + + +
+
} diff --git a/app/src/components/ui/Overlays.tsx b/app/src/components/ui/Overlays.tsx index a7c4ee45..c5b1d7a3 100644 --- a/app/src/components/ui/Overlays.tsx +++ b/app/src/components/ui/Overlays.tsx @@ -198,6 +198,11 @@ export interface ConfirmProps { /** Style the confirming button as destructive. */ destructive?: boolean; loading?: boolean; + /** + * Same vocabulary as `Modal`, forwarded to it. Defaults to `tiny`; widen it only when + * the confirmation shows something other than a question. + */ + size?: string | number; onConfirm?: () => void; onCancel?: () => void; } @@ -210,12 +215,23 @@ export function Confirm({ cancelLabel = 'Cancel', destructive, loading, + size = 'tiny', onConfirm, onCancel, }: ConfirmProps) { - // `tiny`, not Mantine's raw `sm`. Same 380px, but the audited vocabulary -- and the - // guard in ui.test.js exists to keep raw Mantine names out of call sites. - return onCancel?.()} title={title} size='tiny'> + /* + * `tiny`, not Mantine's raw `sm`. Same 380px, but the audited vocabulary -- and the + * guard in ui.test.js exists to keep raw Mantine names out of call sites. + * + * Default rather than fixed. It was fixed, which made every confirmation in the app + * 380px whatever it held. Eight of the nine call sites ask a one-line question, and so + * does every confirmation `useAPIButton` puts behind a `confirmContent` -- around thirty + * of them, all prose, which is why APIButton does not forward a size. The ninth is + * TaggedDeleteConfirmModal, which lists file paths in a two-column table and had no way + * to say so. The default stays narrow because a confirmation wider than its question + * reads as a bigger decision than it is. + */ + return onCancel?.()} title={title} size={size}> {children}
diff --git a/app/src/components/ui/ui.test.js b/app/src/components/ui/ui.test.js index 34784d5b..68f5819a 100644 --- a/app/src/components/ui/ui.test.js +++ b/app/src/components/ui/ui.test.js @@ -1528,6 +1528,41 @@ describe('modal sizes', () => { }); }); + /** + * The size Mantine was actually handed for each open modal, in source order, read off the + * inline style it writes on the modal root (`--modal-size: var(--modal-size-lg)`). + * + * Read rather than restated so a call site that names a size the table cannot translate + * shows up as the raw string it passed instead of quietly resolving to the default. + * + * All roots, not the first: a modal is portalled to `document.body`, so two renders in + * one test both land there and `querySelector` on `baseElement` returns whichever opened + * first. That is how the first version of this reported the default twice and looked like + * the size prop had no effect. + */ + const renderedModalSizes = (baseElement) => + [...baseElement.querySelectorAll('.mantine-Modal-root')] + .map(root => (root.getAttribute('style') ?? '').match(/--modal-size:\s*([^;]+)/)?.[1]); + + it('gives Confirm the tiny width by default, and lets a call site widen it', () => { + /* + * Confirm hardcoded `size='tiny'` and its props interface accepted no size at all, so + * all twelve confirmations in the app were 380px whatever they contained -- including + * TaggedDeleteConfirmModal, which renders a two-column table of file paths. No call + * site could do anything about it without editing this library. + * + * The default stays `tiny`: eleven of the twelve are one sentence, and a confirmation + * that is wider than its question reads as a bigger decision than it is. + */ + const {baseElement} = renderUI(<> + + + ); + + expect(renderedModalSizes(baseElement)) + .toEqual(['var(--modal-size-sm)', 'var(--modal-size-lg)']); + }); + it('never lets a call site name a size the table does not know', () => { /* * Two different hazards, and neither announces itself. @@ -1570,13 +1605,23 @@ describe('modal sizes', () => { const offenders = []; let scanned = 0; + let confirms = 0; for (const [file, source] of walk(path.join(__dirname, '..', '..'))) { - for (const match of source.matchAll(/ { // The premise. A scanner that silently matched nothing would report no offenders // and read exactly like a clean codebase, which is how the first version passed. expect(scanned).toBeGreaterThan(50); + // And the premise for the half of the pattern that is new: at least one confirmation + // names a size, so widening the scan is doing something rather than matching nothing. + expect(confirms).toBeGreaterThan(0); expect(offenders).toEqual([]); }); });