Mediabibliotheek: filter gebruikt/ongebruikt en link van een gebruik naar de module
Continuous Integration / config-sls (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 15s
Continuous Integration / config-asf (pull_request) Successful in 8s
Continuous Integration / frontend-prepare (pull_request) Successful in 38s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m12s
Continuous Integration / frontend-build (pull_request) Successful in 52s
Continuous Integration / backend-build (pull_request) Successful in 1m12s
Continuous Integration / frontend-lint (pull_request) Successful in 39s
Continuous Integration / compile-sites (pull_request) Canceled after 5m28s
Continuous Integration / publish-sls-test (pull_request) Canceled after 0s
Continuous Integration / publish-sls-production (pull_request) Canceled after 0s
Continuous Integration / deploy-sls-test (pull_request) Canceled after 0s
Continuous Integration / deploy-sls-production (pull_request) Canceled after 0s
Continuous Integration / publish-asf-test (pull_request) Canceled after 0s
Continuous Integration / deploy-asf-test (pull_request) Canceled after 0s
Continuous Integration / smoke-sls-test (pull_request) Canceled after 0s
Continuous Integration / smoke-asf-test (pull_request) Canceled after 0s
Continuous Integration / backend-test (pull_request) Canceled after 1m12s
Continuous Integration / frontend-test (pull_request) Canceled after 2m14s
Continuous Integration / config-sls (pull_request) Successful in 7s
Continuous Integration / changes (pull_request) Successful in 15s
Continuous Integration / config-asf (pull_request) Successful in 8s
Continuous Integration / frontend-prepare (pull_request) Successful in 38s
Continuous Integration / vulnerability-scan (pull_request) Successful in 1m12s
Continuous Integration / frontend-build (pull_request) Successful in 52s
Continuous Integration / backend-build (pull_request) Successful in 1m12s
Continuous Integration / frontend-lint (pull_request) Successful in 39s
Continuous Integration / compile-sites (pull_request) Canceled after 5m28s
Continuous Integration / publish-sls-test (pull_request) Canceled after 0s
Continuous Integration / publish-sls-production (pull_request) Canceled after 0s
Continuous Integration / deploy-sls-test (pull_request) Canceled after 0s
Continuous Integration / deploy-sls-production (pull_request) Canceled after 0s
Continuous Integration / publish-asf-test (pull_request) Canceled after 0s
Continuous Integration / deploy-asf-test (pull_request) Canceled after 0s
Continuous Integration / smoke-sls-test (pull_request) Canceled after 0s
Continuous Integration / smoke-asf-test (pull_request) Canceled after 0s
Continuous Integration / backend-test (pull_request) Canceled after 1m12s
Continuous Integration / frontend-test (pull_request) Canceled after 2m14s
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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')}
|
||||
</span>
|
||||
) : (
|
||||
<span>{item.uses.map((use) => usageLabel(t, use)).join('; ')}</span>
|
||||
<span>
|
||||
{item.uses.map((use, index) => {
|
||||
const label = usageLabel(t, use);
|
||||
const href = usageHref(use);
|
||||
return (
|
||||
<span key={`${use.module}-${use.kind}-${use.position ?? index}`}>
|
||||
{index > 0 && '; '}
|
||||
{href ? (
|
||||
<a href={href} className="underline underline-offset-2 hover:text-primary" data-testid={`photo-use-link-${item.id}`}>
|
||||
{label}
|
||||
</a>
|
||||
) : (
|
||||
label
|
||||
)}
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</span>
|
||||
)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -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<UsePlace, 'module'>): string | null {
|
||||
return use.module === 'hero' ? '/hero' : null;
|
||||
}
|
||||
|
||||
@@ -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(<MediaLibraryPage />);
|
||||
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(<MediaLibraryPage />);
|
||||
|
||||
@@ -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<Selection>(emptySelection);
|
||||
const [cleanupOpen, setCleanupOpen] = useState(false);
|
||||
const [deleting, setDeleting] = useState(false);
|
||||
const [filter, setFilter] = useState<UseFilter>('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() {
|
||||
))}
|
||||
</div>
|
||||
|
||||
{view === 'library' && (
|
||||
<div className="flex gap-2" role="group" aria-label={t('media.filter.label')}>
|
||||
{(['all', 'used', 'unused'] as const).map((value) => (
|
||||
<Button key={value} type="button" size="sm" variant={filter === value ? 'secondary' : 'ghost'} aria-pressed={filter === value} onClick={() => setFilter(value)} data-testid={`filter-${value}`}>
|
||||
{t(`media.filter.${value}`)}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{view === 'trash' && (
|
||||
<p className="text-sm text-muted-foreground" data-testid="trash-note">
|
||||
{t('media.trash.note')}
|
||||
|
||||
Reference in New Issue
Block a user