Fichas: cada campo vazio mostra se já foi verificado na fonte, e a gestão regista a verificação

Mapa de erros 4.9, decisão do proprietário: os campos «Não documentado»
das fichas (posto administrativo, localidade, coordenadas, polígono, data
da fonte) continuam a ser mostrados e o portal distingue omissão de falta
de informação. Cada campo vazio passa a dizer o seu estado: «Não
documentado — por verificar na fonte», «Não consta da fonte» ou «Consta da
fonte; em carregamento no portal».

O estado é decidido por uma pessoa, nunca pelo portal: a nova página de
gestão «Lacunas nas fichas» (/management/lacunas) lista os campos vazios
das fichas publicadas, filtra por estado e regista a verificação com nota
e evento de auditoria. Só se pode registar um campo que esteja de facto
vazio nessa localização. Nova tabela information_gaps (migração).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
Claude
2026-12-05 08:02:00 +02:00
committed by nala
parent 9e8ca986ae
commit a2b1ce35e1
10 changed files with 472 additions and 10 deletions
@@ -28,6 +28,8 @@ export type DocumentedLocation = {
source_date?: string | null;
geometry: { coordinates: [number, number] };
}[];
/** State of each empty field, checked against the source (mapa de erros 4.9). */
gaps?: Record<string, string>;
};
export type StructureGeography = {
source_evidence?: TerritorialSourceEvidence[];
@@ -59,6 +61,24 @@ export type StructureGeography = {
chains?: { id: string; code: string; name: string; stage: string }[];
};
const gapLabels: Record<string, string> = {
to_verify: 'Não documentado — por verificar na fonte',
not_in_source: 'Não consta da fonte',
missing_in_portal: 'Consta da fonte; em carregamento no portal',
};
/** What an empty field says: never a bare «Não documentado» without its verification state. */
const gapFields = [
'admin_post',
'locality',
'coordinates',
'polygon',
'source_date',
];
const gapLabel = (location: DocumentedLocation, field: string) =>
gapFields.includes(field)
? gapLabels[location.gaps?.[field] ?? 'to_verify']
: 'Não documentado';
const roles: Record<string, string> = {
opportunity: 'Localização declarada da oportunidade',
primary: 'Localização principal',
@@ -93,7 +113,7 @@ export function LocationList({
<dd>
{location.path.find(
(node) => node.location_type === type,
)?.name ?? 'Não documentado'}
)?.name ?? gapLabel(location, type)}
</dd>
</div>
))}
@@ -145,7 +165,7 @@ export function LocationList({
</p>
))}
{!location.coordinates.length && (
<p>Coordenadas não documentadas.</p>
<p>Coordenadas: {gapLabel(location, 'coordinates')}.</p>
)}
{publicReference(location.source_reference) && (
<p className="text-sm">
@@ -161,7 +181,8 @@ export function LocationList({
)}
<p className="text-sm">
Data da fonte:{' '}
{location.source_date?.trim() || 'Não documentada'}
{location.source_date?.trim() ||
gapLabel(location, 'source_date')}
</p>
{uniquePresentation(location.boundaries ?? [], (b) =>
JSON.stringify([
@@ -194,7 +215,7 @@ export function LocationList({
</p>
))}
{!location.boundaries?.length && (
<p>Polígono não documentado.</p>
<p>Polígono: {gapLabel(location, 'polygon')}.</p>
)}
<Link
className="underline"
@@ -0,0 +1,154 @@
import { Link, router } from '@inertiajs/react';
import { useState } from 'react';
import { Management, button, control } from './shared';
import { api } from '@/pages/investment/shared';
type Item = {
dossier_id: string;
dossier: string;
location_id: string;
location: string;
field: string;
field_label: string;
status: string;
source_reference: string | null;
};
/** Mapa de erros 4.9: each empty field of a published record is checked against its source by a person. */
export default function InformationGaps({
items,
status,
statuses,
installed,
}: {
items: Item[];
status: string;
statuses: Record<string, string>;
installed: boolean;
}) {
return (
<Management title="Lacunas de informação nas fichas">
<p>
Cada campo vazio das fichas publicadas é mostrado ao investidor
com o estado indicado aqui. Compare com o documento de origem e
indique se a informação não consta da fonte ou se consta e falta
carregá-la no portal. O portal não decide isto sozinho.
</p>
{!installed && (
<p role="status">
O registo de lacunas ainda não está instalado neste ambiente
(migração por executar).
</p>
)}
<nav className="my-3 flex flex-wrap gap-3" aria-label="Estado">
{[...Object.entries(statuses), ['all', 'Todas']].map(
([key, label]) => (
<Link
key={key}
className={
key === status ? 'font-bold' : 'underline'
}
href={`/management/lacunas?status=${key}`}
>
{label}
</Link>
),
)}
</nav>
{items.length === 0 ? (
<p>Sem lacunas neste estado.</p>
) : (
<ul className="space-y-3">
{items.map((item) => (
<GapRow
key={`${item.dossier_id}:${item.location_id}:${item.field}`}
item={item}
statuses={statuses}
/>
))}
</ul>
)}
</Management>
);
}
function GapRow({
item,
statuses,
}: {
item: Item;
statuses: Record<string, string>;
}) {
const [value, setValue] = useState(item.status);
const [note, setNote] = useState('');
const [busy, setBusy] = useState(false);
const [error, setError] = useState('');
return (
<li className="rounded border p-3">
<p>
<Link
className="font-semibold underline"
href={`/carteira/${item.dossier_id}`}
>
{item.dossier}
</Link>{' '}
· {item.location} · <strong>{item.field_label}</strong>
</p>
<div className="mt-2 flex flex-wrap items-end gap-2">
<label className="grid gap-1 text-sm">
Estado
<select
className={control}
value={value}
onChange={(e) => setValue(e.target.value)}
>
{Object.entries(statuses).map(([key, label]) => (
<option key={key} value={key}>
{label}
</option>
))}
</select>
</label>
<label className="grid min-w-64 flex-1 gap-1 text-sm">
Nota (o que foi consultado)
<input
className={control}
value={note}
maxLength={2000}
onChange={(e) => setNote(e.target.value)}
/>
</label>
<button
type="button"
className={button}
disabled={busy || value === item.status}
onClick={async () => {
setBusy(true);
setError('');
try {
await api('/management/lacunas', {
dossier_id: item.dossier_id,
location_id: item.location_id,
field: item.field,
status: value,
note,
});
router.reload();
} catch (cause) {
setError(
cause instanceof Error
? cause.message
: 'Não foi possível guardar.',
);
} finally {
setBusy(false);
}
}}
>
{busy ? 'A guardar…' : 'Guardar'}
</button>
</div>
{error && <p role="alert">{error}</p>}
</li>
);
}
+1
View File
@@ -78,6 +78,7 @@ export function Management({
Revisão da origem das oportunidades
</Link>
<Link href="/management/history">Histórico</Link>
<Link href="/management/lacunas">Lacunas nas fichas</Link>
<Link href="/management/demography">Demografia INE</Link>
<Link href="/management/crm/leads">CRM</Link>
<Link href="/management/crm/investors">Investidores</Link>