From 552102de2e1fd194ff4cb314acb6b947d3dfc844 Mon Sep 17 00:00:00 2001
From: Sluijsens
Date: Tue, 17 Nov 2026 15:19:48 +0100
Subject: [PATCH] Mediabibliotheek: filter gebruikt/ongebruikt en link van een
gebruik naar de module
Co-Authored-By: Claude Sonnet 5.5
---
.../media/components/PhotoSelectionList.tsx | 21 +++++++++++++++++--
frontend/src/features/media/lib/usageLabel.ts | 5 +++++
.../media/pages/MediaLibraryPage.test.tsx | 14 +++++++++++++
.../features/media/pages/MediaLibraryPage.tsx | 20 +++++++++++++++++-
frontend/src/i18n/locales/en/translation.json | 6 ++++++
frontend/src/i18n/locales/nl/translation.json | 6 ++++++
6 files changed, 69 insertions(+), 3 deletions(-)
diff --git a/frontend/src/features/media/components/PhotoSelectionList.tsx b/frontend/src/features/media/components/PhotoSelectionList.tsx
index f7b4e79..3454204 100644
--- a/frontend/src/features/media/components/PhotoSelectionList.tsx
+++ b/frontend/src/features/media/components/PhotoSelectionList.tsx
@@ -2,7 +2,7 @@ import { useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { Checkbox } from '@/components/ui/checkbox';
import { formatBytes } from '../lib/format';
-import { usageLabel } from '../lib/usageLabel';
+import { usageHref, usageLabel } from '../lib/usageLabel';
import { selectAll, selectRange, stateOf, type Selection } from '../lib/selection';
export interface PhotoUse {
@@ -112,7 +112,24 @@ export function PhotoSelectionList({ items, selection, onSelectionChange, isDisa
{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('; ')}
+
+ {item.uses.map((use, index) => {
+ const label = usageLabel(t, use);
+ const href = usageHref(use);
+ return (
+
+ {index > 0 && '; '}
+ {href ? (
+
+ {label}
+
+ ) : (
+ label
+ )}
+
+ );
+ })}
+
)}
diff --git a/frontend/src/features/media/lib/usageLabel.ts b/frontend/src/features/media/lib/usageLabel.ts
index 2b1d98c..d2e32c2 100644
--- a/frontend/src/features/media/lib/usageLabel.ts
+++ b/frontend/src/features/media/lib/usageLabel.ts
@@ -13,3 +13,8 @@ export function usageLabel(t: TFunction, use: UsePlace): string {
const where = use.position ? `${place} ${use.position}` : place;
return `${t(`media.module.${use.module}`, { defaultValue: use.module })}, ${where}${use.active ? '' : ` (${t('media.use.off')})`}`;
}
+
+/** Where the admin screen of the module that uses the photo lives (null when there is none). */
+export function usageHref(use: Pick): string | null {
+ return use.module === 'hero' ? '/hero' : null;
+}
diff --git a/frontend/src/features/media/pages/MediaLibraryPage.test.tsx b/frontend/src/features/media/pages/MediaLibraryPage.test.tsx
index 90544cf..8951820 100644
--- a/frontend/src/features/media/pages/MediaLibraryPage.test.tsx
+++ b/frontend/src/features/media/pages/MediaLibraryPage.test.tsx
@@ -177,6 +177,20 @@ describe('MediaLibraryPage', () => {
await waitFor(() => expect(body).toEqual({ ids: ['hero:22222222-2222-2222-2222-222222222222'], confirmedInUse: false }));
});
+ it('filters the library on used and unused photos and links a use to its module', async () => {
+ renderWithProviders();
+ const list = await screen.findByTestId('photo-selection-list');
+ expect(within(list).getAllByRole('listitem')).toHaveLength(3);
+
+ await userEvent.click(screen.getByTestId('filter-unused'));
+ expect(within(screen.getByTestId('photo-selection-list')).getAllByRole('listitem')).toHaveLength(1);
+
+ await userEvent.click(screen.getByTestId('filter-used'));
+ const used = within(screen.getByTestId('photo-selection-list')).getAllByRole('listitem');
+ expect(used).toHaveLength(2);
+ expect(within(used[0]!).getByRole('link', { name: 'Hero, slide 1' })).toHaveAttribute('href', '/hero');
+ });
+
it('shows an error when the library cannot be loaded', async () => {
server.use(http.get('*/media-library/photos', () => new HttpResponse(null, { status: 500 })));
renderWithProviders();
diff --git a/frontend/src/features/media/pages/MediaLibraryPage.tsx b/frontend/src/features/media/pages/MediaLibraryPage.tsx
index 8662caa..7ff88e7 100644
--- a/frontend/src/features/media/pages/MediaLibraryPage.tsx
+++ b/frontend/src/features/media/pages/MediaLibraryPage.tsx
@@ -12,6 +12,7 @@ import { toPhotoItem } from '../lib/toPhotoItem';
import { useMediaPhotos, useMediaStorage, useMediaTrash, useRestorePhotos } from '../services/hooks';
type View = 'library' | 'trash';
+type UseFilter = 'all' | 'used' | 'unused';
/**
* The media library: every photo of every module, newest first, with where it is used; the storage against its limit;
@@ -27,9 +28,16 @@ export function MediaLibraryPage() {
const [chosen, setSelection] = useState(emptySelection);
const [cleanupOpen, setCleanupOpen] = useState(false);
const [deleting, setDeleting] = useState(false);
+ const [filter, setFilter] = useState('all');
const source = view === 'library' ? photos : trash;
- const items = useMemo(() => (source.data?.photos ?? []).map((p) => toPhotoItem(p, t)), [source.data, t]);
+ const items = useMemo(
+ () =>
+ (source.data?.photos ?? [])
+ .filter((p) => view === 'trash' || filter === 'all' || (filter === 'used') === p.uses.length > 0)
+ .map((p) => toPhotoItem(p, t)),
+ [source.data, t, view, filter],
+ );
// Photos that left the list (after a reload or a move) drop out of the selection.
const selection = useMemo(() => prune(chosen, items.map((i) => i.id)), [chosen, items]);
const selectedItems = items.filter((item) => selection.has(item.id));
@@ -72,6 +80,16 @@ export function MediaLibraryPage() {
))}
+ {view === 'library' && (
+
+ {(['all', 'used', 'unused'] as const).map((value) => (
+
+ ))}
+
+ )}
+
{view === 'trash' && (
{t('media.trash.note')}
diff --git a/frontend/src/i18n/locales/en/translation.json b/frontend/src/i18n/locales/en/translation.json
index 68fe6c5..7514f16 100644
--- a/frontend/src/i18n/locales/en/translation.json
+++ b/frontend/src/i18n/locales/en/translation.json
@@ -867,6 +867,12 @@
"close": "Close",
"partial_one": "{{count}} photo could not be deleted. The rest went to the trash.",
"partial_other": "{{count}} photos could not be deleted. The rest went to the trash."
+ },
+ "filter": {
+ "label": "Filter",
+ "all": "All photos",
+ "used": "Used",
+ "unused": "Unused"
}
}
}
diff --git a/frontend/src/i18n/locales/nl/translation.json b/frontend/src/i18n/locales/nl/translation.json
index d6c8049..29f047e 100644
--- a/frontend/src/i18n/locales/nl/translation.json
+++ b/frontend/src/i18n/locales/nl/translation.json
@@ -867,6 +867,12 @@
"close": "Sluiten",
"partial_one": "{{count}} foto kon niet worden verwijderd. De rest is naar de prullenbak.",
"partial_other": "{{count}} foto's konden niet worden verwijderd. De rest is naar de prullenbak."
+ },
+ "filter": {
+ "label": "Filter",
+ "all": "Alle foto's",
+ "used": "Gebruikt",
+ "unused": "Ongebruikt"
}
}
}