Mediabibliotheek: een algemene voortgangsbalk voor upload, verwerken en uitsnede
Continuous Integration / config-asf (pull_request) Successful in 7s
Continuous Integration / config-sls (pull_request) Successful in 8s
Continuous Integration / changes (pull_request) Successful in 13s
Continuous Integration / frontend-prepare (pull_request) Successful in 27s
Continuous Integration / compile-sites (pull_request) Successful in 2m5s
Continuous Integration / vulnerability-scan (pull_request) Successful in 2m12s
Continuous Integration / frontend-build (pull_request) Successful in 38s
Continuous Integration / frontend-lint (pull_request) Successful in 35s
Continuous Integration / frontend-test (pull_request) Successful in 2m47s
Continuous Integration / backend-build (pull_request) Successful in 14m35s
Continuous Integration / backend-test (pull_request) Successful in 3m43s
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:
2026-11-17 19:22:01 +01:00
co-authored by Claude Sonnet 5.5
parent 9bc4153c70
commit a045e93105
9 changed files with 1921 additions and 1877 deletions
@@ -1,6 +1,8 @@
import { Check, Loader2 } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Button } from '@/components/ui/button';
import { ProcessingProgress } from '@/features/media/components/ProcessingProgress';
import { photoProgress, recutProgress, type UploadStage } from '@/features/media/lib/photoProgress';
import { useRetryHeroImage } from '../services/hooks';
import type { HeroImageDto } from '../services/types';
@@ -13,46 +15,32 @@ export function Spinner({ className = 'size-4' }: { className?: string }) {
* Shown above the form while photos of the saved hero are still being prepared in the background: how many are ready,
* what that means for the website, and a way to try again for a photo that failed.
*/
export function ProcessingStatus({ images }: { images: HeroImageDto[] }) {
export function ProcessingStatus({ images, pendingUploads = [] }: { images: HeroImageDto[]; pendingUploads?: UploadStage[] }) {
const { t } = useTranslation();
const retry = useRetryHeroImage();
const total = images.length;
const waiting = images.filter((image) => image.processing);
if (waiting.length === 0) return null;
if (waiting.length === 0 && pendingUploads.length === 0) return null;
const done = total - waiting.length;
// The counter and the one bar cover the current batch: the files that are still being uploaded and the photos that are
// being processed. The bar is the overall progress of the whole chain, upload and processing together.
const total = images.length + pendingUploads.length;
const done = images.length - waiting.length;
const failed = waiting.filter((image) => image.failed);
const working = waiting.length - failed.length;
// The photo the server is busy with right now, and how far along it is (a photo that waits has no step yet).
const busy = waiting.find((image) => image.renderTotal) ?? null;
const fraction = busy && busy.renderTotal ? (busy.renderDone ?? 0) / busy.renderTotal : 0;
const percent = total === 0 ? 0 : Math.min(100, ((done + fraction) / total) * 100);
const working = waiting.length - failed.length + pendingUploads.length;
const percents = [
...images.map((image) => photoProgress({ ready: !image.processing, upload: 'done', renderDone: image.renderDone, renderTotal: image.renderTotal })),
...pendingUploads.map((stage) => photoProgress({ upload: stage })),
];
const percent = percents.length === 0 ? 0 : percents.reduce((sum, value) => sum + value, 0) / percents.length;
return (
<div className="space-y-3 rounded-md border bg-muted/40 p-4" data-testid="hero-processing">
{working > 0 && (
<div className="space-y-2" role="status">
<p className="flex items-center gap-2 text-sm font-medium">
<Spinner />
<span data-testid="hero-processing-count">{t('hero.processing.count', { done, total })}</span>
<p className="text-sm font-medium" data-testid="hero-processing-count">
{t('hero.processing.count', { done, total })}
</p>
<div
role="progressbar"
aria-label={t('hero.processing.label')}
aria-valuemin={0}
aria-valuemax={total}
aria-valuenow={done}
aria-valuetext={t('hero.processing.count', { done, total })}
className="h-2 w-full overflow-hidden rounded bg-muted"
data-testid="hero-processing-bar"
>
<div className="h-full bg-primary transition-all" style={{ width: `${percent}%` }} />
</div>
{busy && (
<p className="text-sm" data-testid="hero-processing-current">
{t('hero.processing.current', { n: done + 1, total, step: busy.renderDone ?? 0, steps: busy.renderTotal })}
</p>
)}
<ProcessingProgress percent={percent} testId="hero-processing-bar" />
<p className="text-sm text-muted-foreground">{t('hero.processing.explain')}</p>
<p className="text-sm text-muted-foreground">
{t('hero.processing.stuck')}{' '}
@@ -97,16 +85,17 @@ export function PhotoPlaceholder({ failed, testId, step }: { failed: boolean; te
const { t } = useTranslation();
return (
<div
className={`flex h-20 w-28 flex-col items-center justify-center gap-1 rounded p-1 text-center text-xs ${failed ? 'bg-destructive/10 text-destructive' : 'hero-shimmer bg-muted'}`}
className={`flex h-20 w-28 flex-col items-center justify-center gap-1 rounded p-1.5 text-center text-xs ${failed ? 'bg-destructive/10 text-destructive' : 'hero-shimmer bg-muted'}`}
role="status"
aria-busy={!failed}
title={t('hero.slides.processingHint')}
data-testid={testId}
>
{failed ? null : <Spinner className="size-3.5" />}
<span>{failed ? t('hero.slides.failed') : t('hero.slides.processing')}</span>
{!failed && step ? <span className="tabular-nums opacity-80" data-testid={`${testId}-step`}>{step.done}/{step.total}</span> : null}
{!failed && !step ? <span className="opacity-70" data-testid={`${testId}-queued`}>{t('hero.slides.queued')}</span> : null}
{failed ? (
<span>{t('hero.slides.failed')}</span>
) : (
<ProcessingProgress compact className="w-full" testId={`${testId}-progress`} percent={photoProgress({ upload: 'done', renderDone: step?.done, renderTotal: step?.total })} />
)}
</div>
);
}
@@ -118,7 +107,6 @@ export function PhotoPlaceholder({ failed, testId, step }: { failed: boolean; te
*/
export function RecutThumbnail({ src, failed, testId, step }: { src: string; failed: boolean; testId: string; step?: { done: number; total: number } | null }) {
const { t } = useTranslation();
const percent = step && step.total > 0 ? Math.min(100, Math.round((step.done / step.total) * 100)) : 0;
return (
<div className={`relative h-20 w-28 shrink-0 overflow-hidden rounded ${failed ? 'ring-2 ring-destructive' : ''}`} title={t('hero.slides.recutHint')} data-testid={testId}>
<img src={src} alt="" className="h-full w-full object-cover" />
@@ -127,28 +115,7 @@ export function RecutThumbnail({ src, failed, testId, step }: { src: string; fai
role="status"
aria-busy={!failed}
>
{failed ? (
<span>{t('hero.slides.failed')}</span>
) : (
<>
<div className="flex items-center justify-between gap-1">
<span data-testid={`${testId}-text`}>{t('hero.slides.processing')}</span>
<span className="tabular-nums" data-testid={`${testId}-percent`}>{percent}%</span>
</div>
<div
role="progressbar"
aria-label={t('hero.slides.processing')}
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={percent}
aria-valuetext={`${percent}%`}
className="h-1.5 w-full overflow-hidden rounded bg-muted"
data-testid={`${testId}-bar`}
>
<div className="h-full bg-primary transition-all motion-reduce:transition-none" style={{ width: `${percent}%` }} />
</div>
</>
)}
{failed ? <span>{t('hero.slides.failed')}</span> : <ProcessingProgress compact testId={`${testId}-progress`} percent={recutProgress(step?.done, step?.total)} />}
</div>
</div>
);
@@ -1,7 +1,6 @@
import { AlertCircle, Check, Clock } from 'lucide-react';
import { AlertCircle, Check, Clock, Upload } from 'lucide-react';
import { useTranslation } from 'react-i18next';
import { Button } from '@/components/ui/button';
import { Spinner } from './ProcessingStatus';
export interface UploadItem {
key: number;
@@ -11,7 +10,7 @@ export interface UploadItem {
message?: string;
}
/** The files of the last choice, one row each: waiting, busy (spinner), added, or failed with the reason. */
/** The files of the last choice, one row each: waiting, busy, added, or failed with the reason. */
export function UploadProgress({ items, busy, onClose }: { items: UploadItem[]; busy: boolean; onClose: () => void }) {
const { t } = useTranslation();
if (items.length === 0) return null;
@@ -27,7 +26,7 @@ export function UploadProgress({ items, busy, onClose }: { items: UploadItem[];
{items.map((item) => (
<li key={item.key} className="flex items-start gap-2" data-testid={`hero-upload-item-${item.key}`} data-status={item.status}>
<span className="mt-0.5 shrink-0">
{item.status === 'uploading' && <Spinner />}
{item.status === 'uploading' && <Upload className="size-4" aria-hidden="true" />}
{item.status === 'waiting' && <Clock className="size-4 text-muted-foreground" aria-hidden="true" />}
{item.status === 'done' && <Check className="size-4 text-green-600" aria-hidden="true" />}
{item.status === 'failed' && <AlertCircle className="size-4 text-destructive" aria-hidden="true" />}
@@ -51,8 +51,8 @@ describe('Hero page', () => {
expect(await screen.findByTestId('hero-processing-count', {}, T)).toHaveTextContent(/0 van 2|0 of 2/);
const bar = screen.getByRole('progressbar', { name: /verwerkt|processed|Verwerking|Processing/i });
expect(bar).toHaveAttribute('aria-valuenow', '0');
expect(bar).toHaveAttribute('aria-valuemax', '2');
expect(bar).toHaveAttribute('aria-valuenow', '30');
expect(bar).toHaveAttribute('aria-valuemax', '100');
});
it('keeps unsaved edits when the background refresh brings a finished photo', async () => {
@@ -680,9 +680,15 @@ describe('Order by dragging, wording and calm waiting', () => {
expect(box).toHaveClass('hero-shimmer');
expect(box).toHaveTextContent(/Wordt verwerkt|Processing/);
}
expect(screen.getByTestId('hero-slide-0-processing-step')).toHaveTextContent('3/16');
expect(screen.getByTestId('hero-slide-1-processing-queued')).toBeInTheDocument();
expect(screen.getByTestId('hero-slide-2-processing-queued')).toBeInTheDocument();
// The same pattern everywhere: the same text and a bar, no step counts on the photo itself.
for (const i of [0, 1, 2]) {
expect(screen.getByTestId(`hero-slide-${i}-processing-progress-text`)).toHaveTextContent(/^(Wordt verwerkt…|Processing…)$/);
expect(screen.getByTestId(`hero-slide-${i}-processing-progress-bar`)).toHaveAttribute('role', 'progressbar');
}
expect(screen.getByTestId('hero-slide-0-processing')).not.toHaveTextContent('3/16');
expect(Number(screen.getByTestId('hero-slide-0-processing-progress-bar').getAttribute('aria-valuenow'))).toBeGreaterThan(
Number(screen.getByTestId('hero-slide-1-processing-progress-bar').getAttribute('aria-valuenow')),
);
expect(screen.getByTestId('hero-processing-count')).toHaveTextContent(/0 van 3|0 of 3/);
});
@@ -718,9 +724,14 @@ describe('Progress of a photo that is being prepared', () => {
await openPage();
expect(await screen.findByTestId('hero-processing-current', {}, T)).toHaveTextContent(/foto 1 van 2.*stap 7 van 16|photo 1 of 2.*step 7 of 16/);
expect(screen.getByTestId('hero-slide-1-processing-step')).toHaveTextContent('7/16');
expect(screen.queryByTestId('hero-slide-2-processing-step')).not.toBeInTheDocument();
// One overall bar (upload and processing together) and no step counts anywhere.
const bar = await screen.findByTestId('hero-processing-bar-bar', {}, T);
expect(bar).toHaveAttribute('role', 'progressbar');
expect(screen.getByTestId('hero-processing-bar-text')).toHaveTextContent(/^(Wordt verwerkt…|Processing…)$/);
expect(screen.queryByTestId('hero-processing-current')).not.toBeInTheDocument();
expect(screen.getByTestId('hero-slide-1-processing')).not.toHaveTextContent('7/16');
expect(Number(bar.getAttribute('aria-valuenow'))).toBeGreaterThan(0);
expect(Number(bar.getAttribute('aria-valuenow'))).toBeLessThan(100);
});
});
@@ -739,12 +750,12 @@ describe('A changed focus point makes a new crop in the background', () => {
const recut = await screen.findByTestId('hero-slide-0-recut', {}, T);
expect(recut.querySelector('img')).not.toBeNull();
expect(screen.getByTestId('hero-slide-0-recut-text')).toHaveTextContent(/^(Wordt verwerkt…|Processing…)$/);
const bar = screen.getByTestId('hero-slide-0-recut-bar');
expect(screen.getByTestId('hero-slide-0-recut-progress-text')).toHaveTextContent(/^(Wordt verwerkt…|Processing…)$/);
const bar = screen.getByTestId('hero-slide-0-recut-progress-bar');
expect(bar).toHaveAttribute('aria-valuemin', '0');
expect(bar).toHaveAttribute('aria-valuemax', '100');
expect(bar).toHaveAttribute('aria-valuenow', '0');
expect(screen.getByTestId('hero-slide-0-recut-percent')).toHaveTextContent('0%');
expect(screen.getByTestId('hero-slide-0-recut-progress-percent')).toHaveTextContent('0%');
expect(recut.querySelector('.animate-spin')).toBeNull();
expect(screen.queryByTestId('hero-processing-count')).not.toBeInTheDocument();
expect(screen.queryByTestId('hero-slide-1-recut')).not.toBeInTheDocument();
@@ -762,8 +773,8 @@ describe('A changed focus point makes a new crop in the background', () => {
await openPage();
await screen.findByTestId('hero-slide-0-recut', {}, T);
expect(screen.getByTestId('hero-slide-0-recut-bar')).toHaveAttribute('aria-valuenow', '25');
expect(screen.getByTestId('hero-slide-0-recut-percent')).toHaveTextContent('25%');
expect(screen.getByTestId('hero-slide-0-recut-progress-bar')).toHaveAttribute('aria-valuenow', '25');
expect(screen.getByTestId('hero-slide-0-recut-progress-percent')).toHaveTextContent('25%');
});
it('shows a failed new crop with the retry', async () => {
@@ -928,7 +939,7 @@ describe('Each photo shows by itself when its processing is finished', () => {
await userEvent.upload(screen.getByTestId('hero-upload'), jpg('nieuw.jpg'));
expect(await screen.findByTestId('hero-processing-count', {}, T)).toHaveTextContent(/^(0 van 1|0 of 1)/);
expect(screen.getByTestId('hero-processing-bar')).toHaveAttribute('aria-valuemax', '1');
expect(screen.getByTestId('hero-processing-bar-bar')).toHaveAttribute('aria-valuemax', '100');
});
it('counts a batch of uploads as that batch only (0 of x), and the next upload starts a new count', async () => {
@@ -1023,7 +1034,7 @@ describe('The picture of a slide is the way to adjust its crop', () => {
await waitFor(() => expect(getFocusRequests()).toHaveLength(1));
expect(getFocusRequests()[0].body.focus).toEqual({ x: 0.5, y: 0.2, zoom: 1 });
const recut = await screen.findByTestId('hero-slide-1-recut', {}, T);
expect(within(recut).getByTestId('hero-slide-1-recut-bar')).toHaveAttribute('role', 'progressbar');
expect(within(recut).getByTestId('hero-slide-1-recut-progress-bar')).toHaveAttribute('role', 'progressbar');
expect(screen.queryByTestId('hero-slide-0-recut')).not.toBeInTheDocument();
expect(getSavedHeroRequests()).toHaveLength(0);
@@ -423,7 +423,10 @@ function HeroEditor({ hero }: { hero: HeroAdminDto }) {
return (
<form onSubmit={(event) => void handleSubmit(onSubmit, onInvalid)(event)} className="space-y-8" noValidate data-testid="hero-form">
<ProcessingStatus images={statusImages} />
<ProcessingStatus
images={statusImages}
pendingUploads={uploads.filter((u) => u.status === 'waiting' || u.status === 'uploading').map((u) => (u.status === 'uploading' ? 'uploading' : 'waiting'))}
/>
<FormErrorBanner error={serverError !== null ? { message: serverError } : null} onDismiss={() => setServerError(null)} />
<HeroTabs
@@ -0,0 +1,34 @@
import { useTranslation } from 'react-i18next';
import { cn } from '@/lib/utils';
/**
* THE progress pattern for everything that takes time in the library (upload, processing, a new crop): the same text
* ("Wordt verwerkt…"), one bar from 0 to 100 percent and the percentage. No spinner and no step counts, so it reads the same
* everywhere and works without motion. The caller decides what the percentage means (see <c>photoProgress</c>).
*/
export function ProcessingProgress({ percent, testId, compact = false, className }: { percent: number; testId: string; compact?: boolean; className?: string }) {
const { t } = useTranslation();
const value = Math.max(0, Math.min(100, Math.round(percent)));
return (
<div className={cn('space-y-1', compact ? 'text-xs' : 'text-sm', className)} data-testid={testId}>
<div className="flex items-center justify-between gap-2">
<span data-testid={`${testId}-text`}>{t('media.progress.working')}</span>
<span className="tabular-nums" data-testid={`${testId}-percent`}>
{value}%
</span>
</div>
<div
role="progressbar"
aria-label={t('media.progress.working')}
aria-valuemin={0}
aria-valuemax={100}
aria-valuenow={value}
aria-valuetext={`${value}%`}
className={cn('w-full overflow-hidden rounded bg-muted', compact ? 'h-1.5' : 'h-2')}
data-testid={`${testId}-bar`}
>
<div className="h-full bg-primary transition-all motion-reduce:transition-none" style={{ width: `${value}%` }} />
</div>
</div>
);
}
@@ -0,0 +1,27 @@
/**
* One percentage for the whole chain of a photo that is added: the upload takes the first part, the background processing
* (cutting the variants, step by step on the server) the rest. A new crop has no upload, so it runs over the full bar.
*/
export const UPLOAD_SHARE = 30;
export type UploadStage = 'waiting' | 'uploading' | 'done';
/** The processing part, 0 to 1, from the steps the server reports (no steps yet = not started). */
export function renderFraction(renderDone?: number | null, renderTotal?: number | null): number {
return renderTotal ? Math.max(0, Math.min(1, (renderDone ?? 0) / renderTotal)) : 0;
}
/** Overall percentage (0-100) of a photo: its upload stage, then its processing steps. `ready` photos are at 100. */
export function photoProgress(options: { ready?: boolean; upload?: UploadStage; renderDone?: number | null; renderTotal?: number | null }): number {
if (options.ready) return 100;
if (options.upload === 'waiting') return 0;
if (options.upload === 'uploading') return UPLOAD_SHARE / 2;
const processing = renderFraction(options.renderDone, options.renderTotal);
// An upload that is done (or a photo that was uploaded before) has its upload part behind it.
return options.upload === undefined && options.renderTotal == null && processing === 0 ? UPLOAD_SHARE : UPLOAD_SHARE + (100 - UPLOAD_SHARE) * processing;
}
/** A new crop only has the processing part. */
export function recutProgress(renderDone?: number | null, renderTotal?: number | null): number {
return Math.round(renderFraction(renderDone, renderTotal) * 100);
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff