feat(editorial): review demographic batches before explicit publication

This commit is contained in:
2026-11-14 08:35:11 +02:00
parent 2459d0ca37
commit 3c4c2599f7
17 changed files with 825 additions and 62 deletions
@@ -3,6 +3,7 @@ import { Frame, card, button } from '@/pages/investment/shared';
import { states } from './shared';
type Access = {
demography?: { index: string };
portfolio?: { index: string };
clusters?: { index: string };
editorial?: { index: string };
@@ -29,6 +30,22 @@ export default function ContentHub({
acção respeita a sua autorização actual.
</p>
<div className="grid gap-4 md:grid-cols-2">
{access.demography && (
<section className={card}>
<h2 className="text-xl font-semibold">
Indicadores demográficos
</h2>
<p>
Conferir originais, observações e correspondências
dos novos lotes. Rever, aprovar e publicar
separadamente, conservando os dados anteriormente
disponibilizados.
</p>
<Link className={button} href={access.demography.index}>
Gerir lotes e revisões
</Link>
</section>
)}
{access.portfolio && (
<section className={card}>
<h2 className="text-xl font-semibold">
+98 -33
View File
@@ -1,4 +1,4 @@
import { router } from '@inertiajs/react';
import { Link, router, useForm } from '@inertiajs/react';
import { useState } from 'react';
import { Management, button, control } from './shared';
@@ -38,7 +38,11 @@ export default function DemographyManagement({
batches,
preview,
qa = true,
editorialEnabled = false,
editorialRevision = 0,
}: {
editorialEnabled?: boolean;
editorialRevision?: number;
qa?: boolean;
batches: {
id: string;
@@ -55,6 +59,7 @@ export default function DemographyManagement({
const [mapping, setMapping] = useState<Record<string, string>>({});
const [message, setMessage] = useState('');
const [busy, setBusy] = useState(false);
const review = useForm({ expected_revision: editorialRevision });
async function execute(path: string, body: FormData | object) {
setBusy(true);
setMessage('');
@@ -77,7 +82,11 @@ export default function DemographyManagement({
},
body: body instanceof FormData ? body : JSON.stringify(body),
});
const data = await response.json();
const data = await response.json().catch(() => null);
if (!data)
throw new Error(
'O servidor não confirmou a operação. Confira o estado guardado antes de repetir.',
);
if (!response.ok)
throw new Error(
data.message ?? 'Não foi possível executar a operação.',
@@ -100,8 +109,10 @@ export default function DemographyManagement({
>
<p>
Preparar não grava observações. Confirmar importa para consulta
administrativa. Aprovar disponibiliza a série nas análises deste
ambiente; desactivar conserva dados e histórico.
administrativa.{' '}
{editorialEnabled
? 'A revisão, a aprovação e a publicação dos novos lotes são operações distintas. Os lotes anteriormente disponibilizados permanecem preservados.'
: 'Aprovar disponibiliza a série nas análises deste ambiente; desactivar conserva dados e histórico.'}
</p>
<form
className="space-y-3"
@@ -257,36 +268,90 @@ export default function DemographyManagement({
</button>
) : (
<>
{preview.status !== 'approved' && (
<button
disabled={busy || reason.length < 10}
className={button}
onClick={() =>
void execute(
`/management/demography/${preview.id}/transition`,
{ action: 'approved', reason },
)
}
>
{qa
? 'Aprovar utilização em QA'
: 'Aprovar utilização'}
</button>
)}
{preview.status !== 'disabled' && (
<button
disabled={busy || reason.length < 10}
className={button}
onClick={() =>
void execute(
`/management/demography/${preview.id}/transition`,
{ action: 'disabled', reason },
)
}
>
Desactivar série
</button>
{editorialEnabled && (
<div className="space-y-2">
{editorialRevision > 0 && (
<Link
className="underline"
href={`/management/editorial/demography/${preview.id}`}
>
Continuar revisão e consultar
versões
</Link>
)}
{preview.status === 'approved' ? (
<p>
{editorialRevision
? 'Lote publicado; consulte a edição e o histórico.'
: 'Lote anteriormente disponibilizado, preservado sem nova aprovação.'}
</p>
) : (
<button
type="button"
className={button}
disabled={
busy || review.processing
}
onClick={() => {
review.transform(() => ({
expected_revision:
editorialRevision,
}));
review.post(
`/management/editorial/demography/${preview.id}/drafts`,
);
}}
>
{editorialRevision
? 'Preparar nova edição de revisão'
: 'Preparar revisão para publicação'}
</button>
)}
</div>
)}
{!editorialEnabled &&
preview.status !== 'approved' && (
<button
disabled={
busy || reason.length < 10
}
className={button}
onClick={() =>
void execute(
`/management/demography/${preview.id}/transition`,
{
action: 'approved',
reason,
},
)
}
>
{qa
? 'Aprovar utilização em QA'
: 'Aprovar utilização'}
</button>
)}
{preview.status !== 'disabled' &&
(!editorialEnabled ||
editorialRevision === 0) && (
<button
disabled={
busy || reason.length < 10
}
className={button}
onClick={() =>
void execute(
`/management/demography/${preview.id}/transition`,
{
action: 'disabled',
reason,
},
)
}
>
Desactivar série
</button>
)}
</>
)}
</div>
@@ -17,6 +17,11 @@ type Edition = {
description?: string;
editorial_content?: string | null;
source?: string;
publication_version?: string;
observations?: number;
sha256?: string;
dataset_hash?: string;
report?: { issue_counts?: Record<string, number> };
content?: Record<string, string | null>;
_structure?: {
fields: Record<string, string | number | null>;
@@ -51,7 +56,7 @@ export default function EditorialEdition({
independentRequired,
subject = 'resource',
}: {
subject?: 'resource' | 'portfolio';
subject?: 'resource' | 'portfolio' | 'demography';
resource: {
id: number | string;
title: string;
@@ -74,7 +79,7 @@ export default function EditorialEdition({
canApprove: boolean;
independentRequired: boolean;
}) {
const editionBase = `/management/editorial/${subject === 'portfolio' ? 'portfolio' : 'resources'}/${resource.id}`;
const editionBase = `/management/editorial/${subject === 'resource' ? 'resources' : subject}/${resource.id}`;
const form = useForm({
version: edition?.version ?? 1,
action: '',
@@ -107,7 +112,14 @@ export default function EditorialEdition({
<Link className="underline" href="/management/editorial">
Fila e notificações
</Link>
{subject === 'portfolio' ? (
{subject === 'demography' ? (
<Link
className="underline"
href={`/management/demography?batch=${resource.id}`}
>
Conferir lote, correspondências e advertências
</Link>
) : subject === 'portfolio' ? (
<Link
className="underline"
href={`/management/portfolio/${resource.id}`}
@@ -166,6 +178,53 @@ export default function EditorialEdition({
<p className="whitespace-pre-wrap">
{edition.payload.resource.description}
</p>
{subject === 'demography' && (
<section className="space-y-2 rounded border p-3">
<p>Fonte: {edition.payload.resource.source}</p>
<p>
Exemplar/versão fornecida:{' '}
{edition.payload.resource.publication_version}
</p>
<p>
{edition.payload.resource.observations}{' '}
observações conferidas, sem alteração dos
valores originais.
</p>
<a
className="underline"
href={`${editionBase}/original`}
>
Consultar original fornecido
</a>
<p className="text-sm break-all">
SHA256 do original:{' '}
{edition.payload.resource.sha256}
</p>
<p className="text-sm break-all">
Integridade das observações:{' '}
{edition.payload.resource.dataset_hash}
</p>
<ul>
{Object.entries(
edition.payload.resource.report
?.issue_counts ?? {},
).map(([code, count]) => (
<li key={code}>
{code}: {count} advertências conservadas
</li>
))}
</ul>
<p>
Aprovar esta edição não disponibiliza a série.
Confirme publicar numa operação separada.
</p>
{edition.payload.links?.map((link) => (
<p key={link.target_key}>
Território: {link.context?.name}
</p>
))}
</section>
)}
{subject === 'portfolio' && (
<>
<p>Fonte: {edition.payload.resource.source}</p>
@@ -426,8 +485,9 @@ export default function EditorialEdition({
</>
) : (
<p>
Prepare uma edição no editor existente para iniciar a
revisão.
{subject === 'demography' && resource.published
? 'Este lote já estava disponibilizado e permanece preservado. Uma nova fonte deve entrar como um lote próprio.'
: 'Prepare uma edição no editor existente para iniciar a revisão.'}
</p>
)}
<h2 className="font-semibold">Versões conservadas</h2>
@@ -40,6 +40,8 @@ export default function EditorialWorkflow({
clustersUrl,
portfolioUrl,
portfolioPending = 0,
demographyUrl,
demographyPending = 0,
}: {
resourceAccess: boolean;
opportunitiesUrl: string | null;
@@ -47,6 +49,8 @@ export default function EditorialWorkflow({
clustersUrl?: string | null;
portfolioUrl?: string | null;
portfolioPending?: number;
demographyUrl?: string | null;
demographyPending?: number;
filters?: { state?: string; kind?: string };
items: { data: Item[]; current_page: number; last_page: number };
notices: {
@@ -67,6 +71,11 @@ export default function EditorialWorkflow({
próprio.
</p>
<div className="flex flex-wrap gap-4">
{demographyUrl && (
<Link className="underline" href={demographyUrl}>
Demografia: {demographyPending} lotes pendentes
</Link>
)}
{portfolioUrl && (
<Link className="underline" href={portfolioUrl}>
Carteira: {portfolioPending} fichas pendentes