Mediabibliotheek fase A: read-only gebruikscontract, Hero-provider, opruimselectie en selectiecomponenten
Continuous Integration / config-sls (pull_request) Successful in 7s
Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 26s
Continuous Integration / compile-sites (pull_request) Successful in 1m50s
Continuous Integration / backend-build (pull_request) Successful in 1m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m53s
Continuous Integration / frontend-prepare (pull_request) Successful in 2m18s
Continuous Integration / frontend-build (pull_request) Successful in 56s
Continuous Integration / frontend-lint (pull_request) Successful in 2m20s
Continuous Integration / frontend-test (pull_request) Successful in 2m31s
Continuous Integration / backend-test (pull_request) Successful in 3m7s
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 / config-sls (pull_request) Successful in 7s
Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 26s
Continuous Integration / compile-sites (pull_request) Successful in 1m50s
Continuous Integration / backend-build (pull_request) Successful in 1m53s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m53s
Continuous Integration / frontend-prepare (pull_request) Successful in 2m18s
Continuous Integration / frontend-build (pull_request) Successful in 56s
Continuous Integration / frontend-lint (pull_request) Successful in 2m20s
Continuous Integration / frontend-test (pull_request) Successful in 2m31s
Continuous Integration / backend-test (pull_request) Successful in 3m7s
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
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
import { useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Checkbox } from '@/components/ui/checkbox';
|
||||
import { selectAll, selectRange, stateOf, type Selection } from '../lib/selection';
|
||||
|
||||
export interface PhotoUse {
|
||||
/** The module key, for example `hero`; the screen translates it. */
|
||||
module: string;
|
||||
/** The kind of place, for example `slide`. */
|
||||
kind: string;
|
||||
position?: number | null;
|
||||
active: boolean;
|
||||
}
|
||||
|
||||
export interface PhotoItem {
|
||||
id: string;
|
||||
thumbnailUrl?: string | null;
|
||||
name: string;
|
||||
bytes: number;
|
||||
createdAt: string;
|
||||
uses: readonly PhotoUse[];
|
||||
}
|
||||
|
||||
interface PhotoSelectionListProps {
|
||||
items: readonly PhotoItem[];
|
||||
selection: Selection;
|
||||
onSelectionChange: (selection: Selection) => void;
|
||||
/** Photos that cannot be selected (for example in use during a clean-up). */
|
||||
isDisabled?: (item: PhotoItem) => boolean;
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number, language: string) {
|
||||
const units = ['B', 'KB', 'MB', 'GB'];
|
||||
let value = bytes;
|
||||
let unit = 0;
|
||||
while (value >= 1024 && unit < units.length - 1) {
|
||||
value /= 1024;
|
||||
unit++;
|
||||
}
|
||||
return `${new Intl.NumberFormat(language, { maximumFractionDigits: unit === 0 ? 0 : 1 }).format(value)} ${units[unit]}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* The photos with a checkbox each: click or Space to toggle, shift-click for a range, a "select all" box in the header
|
||||
* (with the in-between state), and a live announcement of the count. One component for the library and the clean-up.
|
||||
*/
|
||||
export function PhotoSelectionList({ items, selection, onSelectionChange, isDisabled }: PhotoSelectionListProps) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const anchor = useRef<string | null>(null);
|
||||
const selectable = items.filter((item) => !isDisabled?.(item));
|
||||
const selectableIds = selectable.map((item) => item.id);
|
||||
const state = stateOf(selection, selectableIds);
|
||||
const dateFormat = new Intl.DateTimeFormat(i18n.language, { dateStyle: 'medium', timeStyle: 'short' });
|
||||
|
||||
const onItemClick = (id: string, checked: boolean, shift: boolean) => {
|
||||
onSelectionChange(selectRange(selection, selectableIds, shift ? anchor.current : null, id, checked));
|
||||
anchor.current = id;
|
||||
};
|
||||
|
||||
const usageLabel = (use: PhotoUse) => {
|
||||
const place = t(`media.use.${use.kind}`, { defaultValue: use.kind });
|
||||
const where = use.position ? `${place} ${use.position}` : place;
|
||||
return `${t(`media.module.${use.module}`, { defaultValue: use.module })}, ${where}${use.active ? '' : ` (${t('media.use.off')})`}`;
|
||||
};
|
||||
|
||||
if (items.length === 0) {
|
||||
return (
|
||||
<p className="rounded-md border border-dashed p-6 text-center text-sm text-muted-foreground" data-testid="photo-list-empty">
|
||||
{t('media.list.empty')}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div data-testid="photo-selection-list">
|
||||
<div className="flex items-center gap-3 border-b px-2 py-2">
|
||||
<Checkbox
|
||||
aria-label={t('media.list.selectAll')}
|
||||
data-testid="photo-select-all"
|
||||
checked={state === 'all'}
|
||||
indeterminate={state === 'some'}
|
||||
disabled={selectableIds.length === 0}
|
||||
onChange={() => onSelectionChange(state === 'all' ? new Set() : selectAll(selectableIds))}
|
||||
/>
|
||||
<span className="text-sm text-muted-foreground">{t('media.list.selectAll')}</span>
|
||||
<span className="sr-only" role="status" aria-live="polite" data-testid="photo-selection-status">
|
||||
{t('media.bulk.selected', { count: selection.size })}
|
||||
</span>
|
||||
</div>
|
||||
<ul className="divide-y" aria-label={t('media.list.label')}>
|
||||
{items.map((item) => {
|
||||
const disabled = isDisabled?.(item) ?? false;
|
||||
const labelId = `photo-${item.id}-label`;
|
||||
return (
|
||||
<li key={item.id} className="flex items-center gap-3 px-2 py-2" data-testid={`photo-row-${item.id}`}>
|
||||
<Checkbox
|
||||
aria-labelledby={labelId}
|
||||
data-testid={`photo-select-${item.id}`}
|
||||
checked={selection.has(item.id)}
|
||||
disabled={disabled}
|
||||
onChange={() => undefined}
|
||||
onClick={(event) => onItemClick(item.id, event.currentTarget.checked, event.shiftKey)}
|
||||
/>
|
||||
{item.thumbnailUrl ? (
|
||||
<img src={item.thumbnailUrl} alt="" loading="lazy" className="size-14 shrink-0 rounded object-cover" />
|
||||
) : (
|
||||
<span className="flex size-14 shrink-0 items-center justify-center rounded bg-muted text-xs text-muted-foreground">
|
||||
{t('media.list.noThumbnail')}
|
||||
</span>
|
||||
)}
|
||||
<div className="min-w-0 flex-1">
|
||||
<p id={labelId} className="truncate text-sm font-medium">
|
||||
{item.name}
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{dateFormat.format(new Date(item.createdAt))} · {formatBytes(item.bytes, i18n.language)}
|
||||
</p>
|
||||
<p className="text-xs" data-testid={`photo-usage-${item.id}`}>
|
||||
{item.uses.length === 0 ? (
|
||||
<span className="text-muted-foreground">{t('media.use.none')}</span>
|
||||
) : (
|
||||
<span>{item.uses.map(usageLabel).join('; ')}</span>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user