Merge remote-tracking branch 'origin/feature/media-library-screen' into feature/media-library-phase2

# Conflicts:
#	aidlc-docs/features/media-library/assumptions-and-open-questions.md
This commit is contained in:
2026-11-17 23:05:43 +01:00
5 changed files with 81 additions and 16 deletions
@@ -77,3 +77,4 @@ Kept while Bryan is away (2026-11-17): no questions to him, a most probable assu
| 46 | **Phase 2 is built in three switchable steps; the Hero tables stay the truth until phase 3** (2026-11-17, design on `feature/media-library-phase2`). | A write-through to the library tables (`Media:Library:DualWrite`), a nullable crop and set per slide (additive; null = today's behaviour and addresses), and a read switch with a compare mode (`Media:Library:ReadFromLibrary`). All switches off by default, test only, rollback by switching off. Details and back-up/rollback plan: `inception/application-design/phase2-design.md`. | Replace the Hero tables in one go: cannot be rolled back by a switch. | `phase2-design.md` |
| 47 | **Crop per slide (step B), built 2026-11-17.** | A slide can have its own crop (nullable columns on `HeroSlides`, migration `AddSlideCrop`, additive); null = the slide uses its photo's crop and set, so no existing address changes. The crop is edited per slide (`PUT/DELETE hero/slides/{id}/focus`, applied at once); a crop equal to the photo's shares the photo's set; equal crops share one set. A slide that is not saved yet cannot be cropped (the button says so): its crop would have no slide to belong to. The "crop is shared" hint of assumption 36 is gone. The photo's own crop stays the default and is no longer edited from the screen (the endpoint remains). | Let an unsaved slide carry its crop in the save request: more code on both sides. | `HeroSlide`, `HeroMapping.Effective`, `HeroImageService.RenderSlideAsync`, `HeroPage` |
| 48 | **Step A (write-through) mirrors the whole module after each change** (2026-11-17). | Simplest consistent form: the same verified copier runs for the `hero` module after every saved change, one at a time, only with `Media:Library:DualWrite` on (default off); a failure never fails the Hero request. At this size (a few dozen photos) a full mirror is cheap and cannot drift from the copy. | Per-change incremental writes: more code, more ways to drift. | `IMediaLibrarySync`, `MediaLibrarySync`, `HeroImageService.SyncLibraryAsync` |
| 49 | **Compact tiles in the clean-up and the delete confirmation** (product owner request, 2026-11-17). | `PhotoSelectionList` has a third layout `compact` (3/4/6/8 columns, square small thumbnails, name and a short usage line on one truncated line each, full name, date, size and usage in the tooltip; checkbox chip, whole-tile select, select all and the bulk bar unchanged). The clean-up dialog uses it. The "places that lose the photo" list in the second step of `DeleteDialog` is a read-only compact grid of the same kind. `PurgeDialog` shows no photo list (only a count), so it is unchanged; the library tiles and the ImagePicker are unchanged. | Long row lists again in the dialogs (much scrolling, little overview). | `PhotoSelectionList.tsx` (`layout="compact"`), `CleanupDialog.tsx`, `DeleteDialog.tsx` (`delete-places`) |
@@ -108,6 +108,7 @@ export function CleanupDialog({ open, onOpenChange }: { open: boolean; onOpenCha
items={items}
selection={selection}
onSelectionChange={setSelection}
layout="compact"
bulk={{
actions: [],
onClear: () => setSelection(new Set()),
@@ -85,12 +85,23 @@ function DeleteDialogBody({ items, onClose, onDone }: { items: readonly PhotoIte
</p>
)}
{step === 'second' && (
<ul className="max-h-60 space-y-1 overflow-y-auto text-sm" data-testid="delete-places">
{inUse.map((item) => (
<li key={item.id}>
<span className="font-medium">{item.name}</span>: {item.uses.map((use) => usageLabel(t, use)).join('; ')}
</li>
))}
<ul className="grid max-h-60 grid-cols-3 gap-2 overflow-y-auto sm:grid-cols-4" data-testid="delete-places">
{inUse.map((item) => {
const places = item.uses.map((use) => usageLabel(t, use)).join('; ');
return (
<li key={item.id} className="overflow-hidden rounded-md border bg-card" title={`${item.name}: ${places}`} data-testid={`delete-place-${item.id}`}>
{item.thumbnailUrl ? (
<img src={item.thumbnailUrl} alt="" loading="lazy" className="aspect-square w-full object-cover" />
) : (
<span className="flex aspect-square w-full items-center justify-center bg-muted text-[10px] text-muted-foreground">{t('media.list.noThumbnail')}</span>
)}
<div className="min-w-0 px-1.5 py-1">
<p className="truncate text-xs font-medium">{item.name}</p>
<p className="truncate text-[11px] leading-tight">{places}</p>
</div>
</li>
);
})}
</ul>
)}
{trash.isError && (
@@ -13,7 +13,7 @@ const items: PhotoItem[] = [
{ id: 'p4', name: 'Foto 4', bytes: 10, createdAt: '2026-11-14T10:00:00Z', uses: [] },
];
function Harness({ disabled, layout }: { disabled?: (item: PhotoItem) => boolean; layout?: 'list' | 'tiles' }) {
function Harness({ disabled, layout }: { disabled?: (item: PhotoItem) => boolean; layout?: 'list' | 'tiles' | 'compact' }) {
const [selection, setSelection] = useState<Selection>(emptySelection);
return (
<>
@@ -192,6 +192,20 @@ describe('the bulk bar is part of the list header, above the photos', () => {
expect(screen.getByRole('checkbox', { name: 'Foto 3' })).toBeChecked();
});
it('compact layout: small tiles, the whole tile selects, name and usage stay available', async () => {
render(<Harness layout="compact" />);
expect(screen.getByTestId('photo-items')).toHaveAttribute('data-layout', 'compact');
expect(screen.getByTestId('photo-chip-p1')).toBeInTheDocument();
expect(screen.getByTestId('photo-usage-p1')).toBeInTheDocument();
expect(screen.getByTestId('photo-row-p1')).toHaveAttribute('title', expect.stringContaining('Foto 1'));
await userEvent.click(screen.getByTestId('photo-row-p1'));
expect(screen.getByRole('checkbox', { name: 'Foto 1' })).toBeChecked();
await userEvent.click(screen.getByTestId('photo-select-all'));
expect(screen.getByRole('checkbox', { name: 'Foto 3' })).toBeChecked();
});
it('does not select a disabled tile by clicking it', async () => {
render(<Harness layout="tiles" disabled={(item) => item.id === 'p1'} />);
@@ -39,8 +39,8 @@ interface PhotoSelectionListProps {
renderUse?: (use: PhotoUse, label: string) => ReactNode;
/** The actions on the selection. They appear in the header of the list, above the photos, once something is selected. */
bulk?: Omit<BulkActionBarProps, 'count'>;
/** A list of rows (default) or a grid of tiles with big thumbnails. Everything works in both. */
layout?: 'list' | 'tiles';
/** A list of rows (default), a grid of tiles with big thumbnails, or a dense grid of small thumbnails ('compact', for the dialogs). Everything works in all. */
layout?: 'list' | 'tiles' | 'compact';
}
/**
@@ -89,7 +89,13 @@ export function PhotoSelectionList({ items, selection, onSelectionChange, isDisa
</span>
</div>
<ul
className={layout === 'tiles' ? 'grid grid-cols-3 gap-3 py-3 sm:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6' : 'divide-y'}
className={
layout === 'tiles'
? 'grid grid-cols-3 gap-3 py-3 sm:grid-cols-4 lg:grid-cols-5 xl:grid-cols-6'
: layout === 'compact'
? 'grid grid-cols-3 gap-2 py-2 sm:grid-cols-4 md:grid-cols-6 lg:grid-cols-8'
: 'divide-y'
}
aria-label={t('media.list.label')}
data-layout={layout}
data-testid="photo-items"
@@ -97,7 +103,8 @@ export function PhotoSelectionList({ items, selection, onSelectionChange, isDisa
{items.map((item) => {
const disabled = isDisabled?.(item) ?? false;
const labelId = `photo-${item.id}-label`;
const tiles = layout === 'tiles';
const compact = layout === 'compact';
const tiles = layout === 'tiles' || compact;
const checkbox = (
<Checkbox
aria-labelledby={labelId}
@@ -109,13 +116,43 @@ export function PhotoSelectionList({ items, selection, onSelectionChange, isDisa
/>
);
const thumbnail = item.thumbnailUrl ? (
<img src={item.thumbnailUrl} alt="" loading="lazy" className={cn('object-cover', tiles ? 'aspect-[3/2] w-full' : 'size-14 shrink-0 rounded')} />
<img src={item.thumbnailUrl} alt="" loading="lazy" className={cn('object-cover', compact ? 'aspect-square w-full' : tiles ? 'aspect-[3/2] w-full' : 'size-14 shrink-0 rounded')} />
) : (
<span className={cn('flex items-center justify-center bg-muted text-xs text-muted-foreground', tiles ? 'aspect-[3/2] w-full' : 'size-14 shrink-0 rounded')}>
<span className={cn('flex items-center justify-center bg-muted text-xs text-muted-foreground', compact ? 'aspect-square w-full text-[10px]' : tiles ? 'aspect-[3/2] w-full' : 'size-14 shrink-0 rounded')}>
{t('media.list.noThumbnail')}
</span>
);
const details = (
// The compact tile keeps everything in the tooltip: the full name, date and size, and where the photo is used.
const usageText = item.deletedAt
? t('media.trash.since', { date: dateFormat.format(new Date(item.deletedAt)) })
: item.uses.length === 0
? item.unusedSince
? t('media.use.noneSince', { date: dateFormat.format(new Date(item.unusedSince)) })
: t('media.use.none')
: item.uses.map((use) => usageLabel(t, use)).join('; ');
const tooltip = `${item.name} (${dateFormat.format(new Date(item.createdAt))} · ${formatBytes(item.bytes, i18n.language)}): ${usageText}`;
const details = compact ? (
<div className="min-w-0">
<p id={labelId} className="truncate text-xs font-medium" title={tooltip}>
{item.name}
</p>
<p className="truncate text-[11px] leading-tight" data-testid={`photo-usage-${item.id}`} title={usageText}>
{item.deletedAt || item.uses.length === 0 ? (
<span className="text-muted-foreground">{usageText}</span>
) : (
item.uses.map((use, index) => {
const label = usageLabel(t, use);
return (
<span key={`${use.module}-${use.kind}-${use.position ?? index}`}>
{index > 0 && '; '}
{renderUse ? renderUse(use, label) : label}
</span>
);
})
)}
</p>
</div>
) : (
<div className="min-w-0 flex-1">
<p id={labelId} className="truncate text-sm font-medium">
{item.name}
@@ -149,6 +186,7 @@ export function PhotoSelectionList({ items, selection, onSelectionChange, isDisa
return tiles ? (
<li
key={item.id}
title={compact ? tooltip : undefined}
className={cn('relative overflow-hidden rounded-md border bg-card', !disabled && 'cursor-pointer', selection.has(item.id) && 'ring-2 ring-primary')}
data-testid={`photo-row-${item.id}`}
// The whole tile selects (the box stays for keyboards and screen readers). A link or button on the tile
@@ -159,9 +197,9 @@ export function PhotoSelectionList({ items, selection, onSelectionChange, isDisa
}}
>
{/* flex (not a block with an inline box inside): no line box, so no extra space under the checkbox and equal padding on all four sides */}
<div className="absolute left-2 top-2 z-[1] flex rounded bg-background/90 p-1 shadow-sm" data-testid={`photo-chip-${item.id}`}>{checkbox}</div>
<div className={cn('absolute z-[1] flex rounded bg-background/90 shadow-sm', compact ? 'left-1 top-1 p-0.5' : 'left-2 top-2 p-1')} data-testid={`photo-chip-${item.id}`}>{checkbox}</div>
{thumbnail}
<div className="p-2">{details}</div>
<div className={compact ? 'px-1.5 py-1' : 'p-2'}>{details}</div>
</li>
) : (
<li key={item.id} className="flex items-center gap-3 px-2 py-2" data-testid={`photo-row-${item.id}`}>