Mediascherm: vaste hoogte van de bulkbalk, hele tegel selecteert, kleinere tegels, 0 dagen bij opruimen
Continuous Integration / config-sls (pull_request) Successful in 9s
Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 20s
Continuous Integration / frontend-prepare (pull_request) Successful in 30s
Continuous Integration / backend-build (pull_request) Successful in 1m40s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m48s
Continuous Integration / frontend-build (pull_request) Successful in 56s
Continuous Integration / frontend-test (pull_request) Successful in 2m48s
Continuous Integration / frontend-lint (pull_request) Successful in 42s
Continuous Integration / backend-test (pull_request) Successful in 4m37s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Continuous Integration / compile-sites (pull_request) Successful in 10m43s
Continuous Integration / config-sls (pull_request) Successful in 9s
Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 20s
Continuous Integration / frontend-prepare (pull_request) Successful in 30s
Continuous Integration / backend-build (pull_request) Successful in 1m40s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m48s
Continuous Integration / frontend-build (pull_request) Successful in 56s
Continuous Integration / frontend-test (pull_request) Successful in 2m48s
Continuous Integration / frontend-lint (pull_request) Successful in 42s
Continuous Integration / backend-test (pull_request) Successful in 4m37s
Continuous Integration / publish-sls-test (pull_request) Skipped
Continuous Integration / publish-sls-production (pull_request) Skipped
Continuous Integration / deploy-sls-test (pull_request) Skipped
Continuous Integration / deploy-sls-production (pull_request) Skipped
Continuous Integration / publish-asf-test (pull_request) Skipped
Continuous Integration / deploy-asf-test (pull_request) Skipped
Continuous Integration / smoke-sls-test (pull_request) Skipped
Continuous Integration / smoke-asf-test (pull_request) Skipped
Continuous Integration / compile-sites (pull_request) Successful in 10m43s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,11 +23,13 @@ export interface BulkActionBarProps {
|
||||
/**
|
||||
* The actions on the selected photos: the count, a way to clear the selection and the actions. It sits in the header of
|
||||
* the photo list (see <c>PhotoSelectionList</c>), which is the one shared place for it. The actions are data, so more of
|
||||
* them (tags, move) can be added without touching the list. It shows nothing while nothing is selected.
|
||||
* them (tags, move) can be added without touching the list. While nothing is selected it is an empty box of the same height.
|
||||
*/
|
||||
export function BulkActionBar({ count, actions, onClear, summary }: BulkActionBarProps) {
|
||||
const { t } = useTranslation();
|
||||
if (count === 0) return null;
|
||||
// The bar keeps its height while nothing is selected (an invisible placeholder), so the photos never jump when the first
|
||||
// photo is selected.
|
||||
if (count === 0) return <div aria-hidden="true" className="h-9 flex-1" data-testid="bulk-action-bar-placeholder" />;
|
||||
return (
|
||||
<div role="toolbar" aria-label={t('media.bulk.label')} data-testid="bulk-action-bar" className="flex flex-1 flex-wrap items-center gap-3">
|
||||
<span className="text-sm font-medium" data-testid="bulk-count">
|
||||
|
||||
@@ -12,11 +12,11 @@ import { DeleteDialog } from './DeleteDialog';
|
||||
import { PhotoSelectionList } from './PhotoSelectionList';
|
||||
|
||||
const DEFAULT_DAYS = 7;
|
||||
const MIN_DAYS = 1;
|
||||
const MIN_DAYS = 0;
|
||||
const MAX_DAYS = 365;
|
||||
|
||||
/**
|
||||
* "Clean up": the photos older than the chosen number of days (by default 7), by default only the unused ones, newest
|
||||
* "Clean up": the photos not used for the chosen number of days (by default 7; 0 = every unused photo now), by default only the unused ones, newest
|
||||
* first and all selected so single photos can be taken out. Confirming moves exactly the selected photos to the trash
|
||||
* (a photo in use asks for a second confirmation naming the places).
|
||||
*/
|
||||
@@ -61,7 +61,7 @@ export function CleanupDialog({ open, onOpenChange }: { open: boolean; onOpenCha
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="cleanup-days">{t('media.cleanup.days', { count: days })}</Label>
|
||||
<Label htmlFor="cleanup-days">{days === 0 ? t('media.cleanup.daysZero') : t('media.cleanup.days', { count: days })}</Label>
|
||||
<input
|
||||
id="cleanup-days"
|
||||
type="range"
|
||||
@@ -73,6 +73,11 @@ export function CleanupDialog({ open, onOpenChange }: { open: boolean; onOpenCha
|
||||
className="w-full accent-primary"
|
||||
data-testid="cleanup-days"
|
||||
/>
|
||||
{days === 0 && (
|
||||
<p className="text-xs text-muted-foreground" data-testid="cleanup-zero-note">
|
||||
{t('media.cleanup.zeroNote')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<CheckboxField
|
||||
checked={onlyUnused}
|
||||
|
||||
@@ -13,7 +13,7 @@ const items: PhotoItem[] = [
|
||||
{ id: 'p4', name: 'Foto 4', bytes: 10, createdAt: '2026-11-14T10:00:00Z', uses: [] },
|
||||
];
|
||||
|
||||
function Harness({ disabled }: { disabled?: (item: PhotoItem) => boolean }) {
|
||||
function Harness({ disabled, layout }: { disabled?: (item: PhotoItem) => boolean; layout?: 'list' | 'tiles' }) {
|
||||
const [selection, setSelection] = useState<Selection>(emptySelection);
|
||||
return (
|
||||
<>
|
||||
@@ -22,12 +22,30 @@ function Harness({ disabled }: { disabled?: (item: PhotoItem) => boolean }) {
|
||||
selection={selection}
|
||||
onSelectionChange={setSelection}
|
||||
isDisabled={disabled}
|
||||
layout={layout}
|
||||
bulk={{ actions: [{ id: 'delete', label: 'Verwijderen', destructive: true, run: vi.fn() }], onClear: () => setSelection(emptySelection) }}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
function PhotoSelectionListWithLink() {
|
||||
const [selection, setSelection] = useState<Selection>(emptySelection);
|
||||
return (
|
||||
<PhotoSelectionList
|
||||
layout="tiles"
|
||||
items={items}
|
||||
selection={selection}
|
||||
onSelectionChange={setSelection}
|
||||
renderUse={(_use, label) => (
|
||||
<a href="#x" onClick={(event) => event.preventDefault()} data-testid="use-link-p1">
|
||||
{label}
|
||||
</a>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
beforeEach(async () => {
|
||||
await i18n.changeLanguage('nl');
|
||||
});
|
||||
@@ -140,4 +158,45 @@ describe('the bulk bar is part of the list header, above the photos', () => {
|
||||
const first = screen.getByTestId('photo-row-p1');
|
||||
expect(bar.compareDocumentPosition(first) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
|
||||
});
|
||||
it('keeps the header the same height before and after the first selection, so nothing jumps', async () => {
|
||||
render(<Harness />);
|
||||
const placeholder = screen.getByTestId('bulk-action-bar-placeholder');
|
||||
expect(placeholder).toHaveClass('h-9');
|
||||
expect(placeholder).toHaveAttribute('aria-hidden', 'true');
|
||||
|
||||
await userEvent.click(screen.getByRole('checkbox', { name: 'Foto 2' }));
|
||||
|
||||
expect(screen.queryByTestId('bulk-action-bar-placeholder')).not.toBeInTheDocument();
|
||||
// The buttons of the bar are small (h-9), the same as the placeholder.
|
||||
expect(screen.getByTestId('bulk-clear')).toHaveClass('h-9');
|
||||
});
|
||||
|
||||
it('selects a tile by clicking the photo, but not when a link on the tile is clicked', async () => {
|
||||
render(
|
||||
<>
|
||||
<PhotoSelectionListWithLink />
|
||||
</>,
|
||||
);
|
||||
|
||||
await userEvent.click(screen.getByTestId('photo-row-p2'));
|
||||
expect(screen.getByRole('checkbox', { name: 'Foto 2' })).toBeChecked();
|
||||
|
||||
await userEvent.click(screen.getByTestId('photo-row-p2'));
|
||||
expect(screen.getByRole('checkbox', { name: 'Foto 2' })).not.toBeChecked();
|
||||
|
||||
await userEvent.click(screen.getAllByTestId('use-link-p1')[0]!);
|
||||
expect(screen.getByRole('checkbox', { name: 'Foto 1' })).not.toBeChecked();
|
||||
|
||||
// The box itself toggles once (the click on the box does not also toggle the tile).
|
||||
await userEvent.click(screen.getByRole('checkbox', { name: 'Foto 3' }));
|
||||
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'} />);
|
||||
|
||||
await userEvent.click(screen.getByTestId('photo-row-p1'));
|
||||
|
||||
expect(screen.getByRole('checkbox', { name: 'Foto 1' })).not.toBeChecked();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -89,7 +89,7 @@ export function PhotoSelectionList({ items, selection, onSelectionChange, isDisa
|
||||
</span>
|
||||
</div>
|
||||
<ul
|
||||
className={layout === 'tiles' ? 'grid grid-cols-2 gap-3 py-3 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5' : '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' : 'divide-y'}
|
||||
aria-label={t('media.list.label')}
|
||||
data-layout={layout}
|
||||
data-testid="photo-items"
|
||||
@@ -149,8 +149,14 @@ export function PhotoSelectionList({ items, selection, onSelectionChange, isDisa
|
||||
return tiles ? (
|
||||
<li
|
||||
key={item.id}
|
||||
className={cn('relative overflow-hidden rounded-md border bg-card', selection.has(item.id) && 'ring-2 ring-primary')}
|
||||
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
|
||||
// (the places a photo is used) does its own thing and does not select.
|
||||
onClick={(event) => {
|
||||
if (disabled || (event.target as HTMLElement).closest('a, button, input, label')) return;
|
||||
onItemClick(item.id, !selection.has(item.id), event.shiftKey);
|
||||
}}
|
||||
>
|
||||
{/* 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>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
import { http, HttpResponse } from 'msw';
|
||||
import { screen, waitFor, within } from '@testing-library/react';
|
||||
import { fireEvent, screen, waitFor, within } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import i18n from '@/i18n/config';
|
||||
import { server } from '@/mocks/server';
|
||||
@@ -323,6 +323,22 @@ describe('MediaLibraryPage', () => {
|
||||
expect(screen.getByTestId('layout-list')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('allows 0 days in the clean-up and says what that means', async () => {
|
||||
renderPage();
|
||||
await screen.findByTestId('photo-selection-list');
|
||||
await userEvent.click(screen.getByTestId('cleanup-open'));
|
||||
const dialog = await screen.findByTestId('cleanup-dialog');
|
||||
const slider = within(dialog).getByTestId('cleanup-days');
|
||||
expect(slider).toHaveAttribute('min', '0');
|
||||
|
||||
fireEvent.change(slider, { target: { value: '0' } });
|
||||
|
||||
expect(await within(dialog).findByTestId('cleanup-zero-note')).toHaveTextContent('direct in aanmerking');
|
||||
expect(within(dialog).getByText('Direct: elke ongebruikte foto')).toBeInTheDocument();
|
||||
await waitFor(() => expect(within(dialog).getByTestId('cleanup-summary')).toBeInTheDocument());
|
||||
expect(within(dialog).getByTestId('cleanup-confirm')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows an error when the library cannot be loaded', async () => {
|
||||
server.use(http.get('*/media-library/photos', () => new HttpResponse(null, { status: 500 })));
|
||||
renderPage();
|
||||
|
||||
Reference in New Issue
Block a user