Mediascherm: paneel Controle bibliotheek (read-check in gewone taal, stand van de schakelaars)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { CheckCircle2, ListChecks, TriangleAlert } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { useReadCheck } from '../services/hooks';
|
||||
|
||||
/**
|
||||
* "Library check": a small panel for administrators that compares the library's own tables with the modules (the hero) in
|
||||
* plain words and shows the state of the migration switches (copy, write-through, reading). It only asks the server when the
|
||||
* button is clicked; it changes nothing.
|
||||
*/
|
||||
export function LibraryCheck() {
|
||||
const { t } = useTranslation();
|
||||
const [asked, setAsked] = useState(false);
|
||||
const check = useReadCheck(asked);
|
||||
|
||||
return (
|
||||
<section className="space-y-2 rounded-md border p-3" aria-labelledby="library-check-title" data-testid="library-check">
|
||||
<div className="flex flex-wrap items-center justify-between gap-2">
|
||||
<h2 id="library-check-title" className="text-sm font-medium">
|
||||
{t('media.check.title')}
|
||||
</h2>
|
||||
<Button type="button" variant="outline" size="sm" disabled={check.isFetching} onClick={() => (asked ? void check.refetch() : setAsked(true))} data-testid="library-check-run">
|
||||
<ListChecks className="mr-1.5 size-4" aria-hidden="true" />
|
||||
{check.isFetching ? t('media.check.running') : t('media.check.run')}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">{t('media.check.hint')}</p>
|
||||
{check.isError && (
|
||||
<p role="alert" className="text-sm text-destructive" data-testid="library-check-error">
|
||||
{t('media.check.error')}
|
||||
</p>
|
||||
)}
|
||||
{check.data && (
|
||||
<div className="space-y-2" role="status" data-testid="library-check-result">
|
||||
<p className="text-sm" data-testid="library-check-switches">
|
||||
{t('media.check.switches', {
|
||||
copy: check.data.copyOnStartup ? t('media.check.on') : t('media.check.off'),
|
||||
write: check.data.dualWrite ? t('media.check.on') : t('media.check.off'),
|
||||
read: t(`media.check.read.${check.data.mode}`),
|
||||
})}
|
||||
</p>
|
||||
{check.data.modules.length === 0 && <p className="text-sm text-muted-foreground">{t('media.check.noModules')}</p>}
|
||||
{check.data.modules.map((module) => (
|
||||
<div key={module.module} data-testid={`library-check-${module.module}`}>
|
||||
{module.matches ? (
|
||||
<p className="flex items-center gap-2 text-sm text-green-700 dark:text-green-400">
|
||||
<CheckCircle2 className="size-4 shrink-0" aria-hidden="true" />
|
||||
{t('media.check.matches', { module: t(`media.module.${module.module}`, { defaultValue: module.module }), photos: module.photos, uses: module.uses })}
|
||||
</p>
|
||||
) : (
|
||||
<div className="space-y-1">
|
||||
<p className="flex items-center gap-2 text-sm font-medium text-destructive">
|
||||
<TriangleAlert className="size-4 shrink-0" aria-hidden="true" />
|
||||
{t('media.check.differs', { module: t(`media.module.${module.module}`, { defaultValue: module.module }), count: module.differences.length })}
|
||||
</p>
|
||||
<ul className="list-disc space-y-0.5 pl-6 text-xs" data-testid={`library-check-${module.module}-differences`}>
|
||||
{module.differences.map((difference) => (
|
||||
<li key={difference}>{difference}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user