Complete grouped collaborative editorial queues and native review coverage
tests / ci (push) Canceled after 0s

This commit is contained in:
2026-11-14 11:15:09 +02:00
parent f40924f1be
commit a4541298c0
36 changed files with 2691 additions and 89 deletions
+239 -13
View File
@@ -89,6 +89,15 @@ const labels: Record<string, string> = {
const label = (value?: string | null) =>
value ? (labels[value] ?? value) : 'Não informado';
type Zone = {
editorial_enabled?: boolean;
editorial_workflow?: {
state: string;
fresh: boolean;
content_version: number;
hash: string;
can_approve: boolean;
independent_required: boolean;
} | null;
operational_details?: ParkDetails;
operational_details_public?: ParkDetails;
details_available?: boolean;
@@ -248,6 +257,206 @@ type Props = {
prev_page_url: string | null;
} | null;
};
function ZoneHistory({
id,
revisions,
}: {
id: string;
revisions: Props['revisions'];
}) {
const [selected, setSelected] = useState<{
version_no: number;
fields: { name?: string; description?: string };
observations: {
label?: string;
value?: string;
unit?: string;
scope?: string;
period_start?: string;
period_end?: string;
source_reference?: string;
}[];
} | null>(null);
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
async function inspect(version: number) {
setLoading(true);
setError('');
setSelected(null);
try {
setSelected(
await api(
`/api/v2/investment/admin/zones/${id}/revisions/${version}`,
),
);
} catch (e) {
setError(
e instanceof Error
? e.message
: 'Não foi possível conferir esta versão.',
);
} finally {
setLoading(false);
}
}
return (
<section className={card}>
<h2 className="text-xl font-bold">Histórico editorial</h2>
{revisions.map((r) => (
<p key={r.version_no}>
Versão {r.version_no} · {r.action} · {r.created_at}{' '}
<button
type="button"
className={button}
disabled={loading}
onClick={() => inspect(r.version_no)}
>
Conferir versão {r.version_no}
</button>
</p>
))}
{error && <p role="alert">{error}</p>}
{selected && (
<div className="space-y-2 border-t pt-3">
<h3 className="font-bold">
Consulta da versão {selected.version_no}
</h3>
<p>
Esta consulta preserva a versão actual e a preparação em
curso.
</p>
<p>{selected.fields.name}</p>
<p className="whitespace-pre-line">
{selected.fields.description}
</p>
{selected.observations.map((row, index) => (
<div key={index}>
<strong>{row.label}</strong>
<p>
{row.value} {row.unit}
</p>
<p>
{row.scope} · {row.period_start} –{' '}
{row.period_end}
</p>
<p>{row.source_reference}</p>
</div>
))}
</div>
)}
</section>
);
}
function ZoneReview({
zone,
busy,
dirty,
action,
}: {
zone: Zone;
busy: boolean;
dirty: boolean;
action: (url: string, data: unknown) => Promise<void>;
}) {
const [reason, setReason] = useState('');
const workflow = zone.editorial_workflow;
const labels: Record<string, string> = {
submit: 'Submeter à revisão',
start_review: 'Iniciar revisão',
approve: 'Aprovar esta edição',
return: 'Devolver com fundamento',
reject: 'Rejeitar',
archive: 'Arquivar proposta privada',
};
const states: Record<string, string> = {
draft: 'Rascunho',
submitted: 'Submetido',
in_review: 'Em revisão',
approved: 'Aprovado',
returned: 'Devolvido',
rejected: 'Rejeitado',
archived: 'Arquivado',
};
const actions: Record<string, string[]> = {
not_started: ['submit'],
draft: ['submit', 'archive'],
submitted: ['start_review', 'archive'],
in_review: ['return', 'reject', 'approve', 'archive'],
approved: ['archive'],
returned: ['submit', 'archive'],
rejected: ['archive'],
archived: [],
};
return (
<section className={card}>
<h2 className="text-xl font-bold">
Revisão da zona e dos indicadores
</h2>
<p>
{workflow
? states[workflow.state]
: 'Prepare a revisão da edição actual.'}{' '}
A aprovação é separada da publicação. A apresentação anterior
mantém-se durante a revisão.
</p>
{workflow && (
<p>
Edição do conteúdo: {workflow.content_version} · versão de
trabalho: {zone.version_no}.
</p>
)}
{workflow && !workflow.fresh && (
<p role="alert">
O conteúdo, fonte ou anexos mudaram. Guarde uma nova
preparação e volte a conferir.
</p>
)}
{dirty && (
<p>Guarde as alterações antes de decidir sobre a edição.</p>
)}
<Field label="Fundamento da decisão">
<textarea
className={input}
value={reason}
onChange={(event) => setReason(event.target.value)}
/>
</Field>
<div className="mt-3 flex flex-wrap gap-3">
{(actions[workflow?.state ?? 'not_started'] ?? [])
.filter(
(name) => name !== 'approve' || workflow?.can_approve,
)
.map((name) => (
<button
key={name}
className={button}
type="button"
disabled={
busy ||
dirty ||
reason.trim().length < 10 ||
Boolean(
workflow &&
!workflow.fresh &&
['submit', 'approve'].includes(name),
)
}
onClick={() =>
void action(
`/api/v2/investment/admin/zones/${zone.id}/editorial/${name}`,
{ version_no: zone.version_no, reason },
)
}
>
{labels[name]}
</button>
))}
</div>
</section>
);
}
export default function ZonePage(props: Props) {
return (
<Editor
@@ -340,8 +549,19 @@ function Editor({
setBusy(true);
setMessage('');
try {
await api(url, data);
router.reload();
const result = await api(url, data);
if (
result &&
typeof result === 'object' &&
typeof result.editorial_url === 'string' &&
result.editorial_url.startsWith(
'/management/editorial/subjects/',
)
) {
router.visit(result.editorial_url);
} else {
router.reload();
}
} catch (e) {
setMessage(e instanceof Error ? e.message : 'Falha na operação.');
} finally {
@@ -1342,6 +1562,14 @@ function Editor({
Guardar outra localização
</button>
</section>
{z.editorial_enabled && (
<ZoneReview
zone={z}
busy={busy}
dirty={form.isDirty}
action={action}
/>
)}
<section className={card}>
<h2 className="text-xl font-bold">
Publicação informativa
@@ -1359,6 +1587,14 @@ function Editor({
disabled={
busy ||
form.isDirty ||
(z.editorial_enabled &&
(z.editorial_workflow?.state !==
'approved' ||
!z.editorial_workflow?.fresh ||
(z.editorial_workflow
?.independent_required &&
!z.editorial_workflow
?.can_approve))) ||
(z.category === 'industrial_park' &&
!profileAvailable)
}
@@ -1518,17 +1754,7 @@ function Editor({
</div>
))}
</section>
<section className={card}>
<h2 className="text-xl font-bold">
Histórico editorial
</h2>
{revisions.map((r) => (
<p key={r.version_no}>
Versão {r.version_no} · {r.action} ·{' '}
{r.created_at}
</p>
))}
</section>
<ZoneHistory id={z.id} revisions={revisions} />
{targets && (
<ZoneRelations
id={z.id}