91 lines
3.5 KiB
TypeScript
91 lines
3.5 KiB
TypeScript
import { publicReference, uniquePresentation } from '@/lib/public-presentation';
|
|
import PublicReference from './public-reference';
|
|
import { usePage } from '@inertiajs/react';
|
|
import EvidenceDetails from './evidence-details';
|
|
|
|
export type TerritorialSourceEvidence = {
|
|
association: string;
|
|
role: string;
|
|
source_reference: string | null;
|
|
source_quote: string | null;
|
|
supports: string;
|
|
traceability: string;
|
|
official_source_accepted: boolean;
|
|
existing_validation: string | null;
|
|
};
|
|
export default function TerritorialSources({
|
|
sources,
|
|
}: {
|
|
sources?: TerritorialSourceEvidence[];
|
|
}) {
|
|
const management = usePage().url.startsWith('/management/');
|
|
const visible = uniquePresentation(
|
|
(sources ?? []).filter(
|
|
(row) =>
|
|
management ||
|
|
publicReference(row.source_reference) ||
|
|
publicReference(row.source_quote) ||
|
|
publicReference(row.supports),
|
|
),
|
|
(row) =>
|
|
JSON.stringify([
|
|
row.association,
|
|
row.role,
|
|
management
|
|
? row.source_reference
|
|
: publicReference(row.source_reference),
|
|
publicReference(row.source_quote),
|
|
publicReference(row.supports),
|
|
...(management ? [row.traceability] : []),
|
|
]),
|
|
);
|
|
if (!visible.length) return null;
|
|
return (
|
|
<EvidenceDetails title="Fontes das relações territoriais">
|
|
{visible.map((source, i) => (
|
|
<article className="border-t pt-3" key={i}>
|
|
<h3 className="font-semibold">
|
|
{source.role} — {source.association}
|
|
</h3>
|
|
{(management ||
|
|
publicReference(source.source_reference)) && (
|
|
<p>
|
|
Fonte:{' '}
|
|
{management ? (
|
|
source.source_reference
|
|
) : (
|
|
<PublicReference
|
|
value={source.source_reference}
|
|
/>
|
|
)}
|
|
</p>
|
|
)}
|
|
{(publicReference(source.source_quote) ||
|
|
publicReference(source.supports)) && (
|
|
<p>
|
|
{publicReference(source.source_quote) ||
|
|
publicReference(source.supports)}
|
|
</p>
|
|
)}
|
|
<EvidenceDetails title="Proveniência e versão da referência">
|
|
<p>
|
|
{source.official_source_accepted
|
|
? 'Fonte oficial identificada.'
|
|
: 'Ligação ao exemplar oficial por recuperar.'}
|
|
</p>
|
|
{(management ||
|
|
publicReference(source.traceability)) && (
|
|
<p>{source.traceability}</p>
|
|
)}
|
|
{(management
|
|
? source.existing_validation
|
|
: publicReference(source.existing_validation)) && (
|
|
<p>{source.existing_validation}</p>
|
|
)}
|
|
</EvidenceDetails>
|
|
</article>
|
|
))}
|
|
</EvidenceDetails>
|
|
);
|
|
}
|