feat(editorial): separate cluster analysis approval and publication in QA
This commit is contained in:
@@ -14,6 +14,7 @@ import type {
|
||||
Force,
|
||||
} from '@/lib/cluster-competitiveness';
|
||||
import { button, control } from '../management/shared';
|
||||
import { states as editorialStates } from '../management/editorial-workflow';
|
||||
|
||||
const labels = {
|
||||
evidence: 'Observações e evidências locais',
|
||||
@@ -33,22 +34,67 @@ export type CompetitivenessState = {
|
||||
at: string;
|
||||
} | null;
|
||||
history: { version: number; action: string; at: string; actor: number }[];
|
||||
editorial_enabled?: boolean;
|
||||
workflow?: {
|
||||
state: string;
|
||||
edition: number;
|
||||
hash: string;
|
||||
fresh: boolean;
|
||||
contributors: number[];
|
||||
independent_required: boolean;
|
||||
};
|
||||
published?: CompetitivenessState['approved'];
|
||||
};
|
||||
const actions: Record<string, string> = {
|
||||
saved: 'Gravação',
|
||||
approved: 'Aprovação pública',
|
||||
approved: 'Aprovação',
|
||||
withdrawn: 'Retirada da aprovação',
|
||||
restored: 'Recuperação do histórico',
|
||||
submitted: 'Submissão',
|
||||
review_started: 'Início da revisão',
|
||||
returned: 'Devolução',
|
||||
rejected: 'Rejeição',
|
||||
published: 'Publicação',
|
||||
archived: 'Arquivo',
|
||||
};
|
||||
const editorialActions: Record<string, [string, string][]> = {
|
||||
draft: [
|
||||
['submitted', 'Submeter para revisão'],
|
||||
['archived', 'Arquivar rascunho'],
|
||||
],
|
||||
returned: [
|
||||
['submitted', 'Voltar a submeter'],
|
||||
['archived', 'Arquivar rascunho'],
|
||||
],
|
||||
submitted: [
|
||||
['review_started', 'Iniciar revisão'],
|
||||
['archived', 'Arquivar edição'],
|
||||
],
|
||||
in_review: [
|
||||
['returned', 'Devolver para correcção'],
|
||||
['rejected', 'Rejeitar com fundamento'],
|
||||
['approved', 'Aprovar edição'],
|
||||
['archived', 'Arquivar edição'],
|
||||
],
|
||||
approved: [
|
||||
['published', 'Publicar edição aprovada'],
|
||||
['archived', 'Arquivar edição'],
|
||||
],
|
||||
rejected: [['archived', 'Arquivar edição']],
|
||||
published: [['archived', 'Arquivar e retirar publicação']],
|
||||
archived: [],
|
||||
};
|
||||
|
||||
export default function Competitiveness({
|
||||
clusterId,
|
||||
sector,
|
||||
initial,
|
||||
viewerId,
|
||||
}: {
|
||||
clusterId: string;
|
||||
sector: string;
|
||||
initial?: CompetitivenessState | null;
|
||||
viewerId?: number;
|
||||
}) {
|
||||
const [draft, setDraft] = useState(
|
||||
() => initial?.draft ?? newCompetitivenessDraft(clusterId, sector),
|
||||
@@ -69,6 +115,8 @@ export default function Competitiveness({
|
||||
server.draft ?? newCompetitivenessDraft(clusterId, sector),
|
||||
);
|
||||
const endpoint = `/management/clusters/${clusterId}/competitiveness`;
|
||||
const editorial = server.editorial_enabled || !!server.workflow;
|
||||
const publicVersion = server.workflow ? server.published : server.approved;
|
||||
function errorMessage(error: unknown) {
|
||||
if (error instanceof PortalApiError) {
|
||||
if (error.status === 409)
|
||||
@@ -164,11 +212,36 @@ export default function Competitiveness({
|
||||
{dirty
|
||||
? 'Existem alterações por guardar.'
|
||||
: 'Campos correspondem à versão recuperada.'}{' '}
|
||||
{server.approved
|
||||
? `Consulta pública: versão aprovada ${server.approved.version}; novas edições conservam essa versão até outra aprovação.`
|
||||
{publicVersion
|
||||
? `Consulta pública: versão ${publicVersion.version}; novas edições conservam essa versão até outra publicação ou retirada explícita.`
|
||||
: 'Sem análise aprovada para consulta pública.'}
|
||||
</p>
|
||||
<fieldset disabled={busy} className="space-y-4">
|
||||
{editorial && (
|
||||
<p>
|
||||
Aprovar e publicar são operações distintas. Estado da
|
||||
edição: {editorialStates[server.workflow?.state ?? 'draft']}
|
||||
. A publicação anterior mantém-se durante a revisão.
|
||||
</p>
|
||||
)}
|
||||
{server.workflow && !server.workflow.fresh && (
|
||||
<p role="alert">
|
||||
O contexto do cluster mudou. Guarde uma nova edição e volte
|
||||
a conferir antes de aprovar ou publicar.
|
||||
</p>
|
||||
)}
|
||||
{server.workflow && !server.editorial_enabled && (
|
||||
<p role="alert">
|
||||
O circuito está desactivado neste ambiente. A publicação e o
|
||||
histórico foram preservados; a edição está temporariamente
|
||||
só para consulta.
|
||||
</p>
|
||||
)}
|
||||
<fieldset
|
||||
disabled={
|
||||
busy || (!!server.workflow && !server.editorial_enabled)
|
||||
}
|
||||
className="space-y-4"
|
||||
>
|
||||
<label className="block">
|
||||
Sector analisado
|
||||
<input
|
||||
@@ -333,7 +406,10 @@ export default function Competitiveness({
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={!dirty}
|
||||
disabled={
|
||||
!dirty &&
|
||||
!(server.editorial_enabled && !server.workflow)
|
||||
}
|
||||
onClick={() => command('saved', { draft })}
|
||||
>
|
||||
Guardar rascunho no servidor
|
||||
@@ -446,13 +522,23 @@ export default function Competitiveness({
|
||||
)}
|
||||
</details>
|
||||
<details className="rounded border p-3">
|
||||
<summary>Aprovação para consulta pública</summary>
|
||||
<summary>
|
||||
{editorial
|
||||
? 'Revisão e publicação'
|
||||
: 'Aprovação para consulta pública'}
|
||||
</summary>
|
||||
<p>
|
||||
Aprovar torna a versão guardada consultável na ficha
|
||||
pública deste cluster, quando essa ficha estiver
|
||||
publicada. Guardar um rascunho não o publica. A
|
||||
evidência de aprovação e as identidades do histórico
|
||||
ficam na gestão.
|
||||
{editorial ? (
|
||||
'Aprovar regista a decisão sobre esta edição. Publicar disponibiliza-a na ficha pública do cluster. As edições seguintes exigem nova aprovação.'
|
||||
) : (
|
||||
<>
|
||||
Aprovar torna a versão guardada consultável na
|
||||
ficha pública deste cluster, quando essa ficha
|
||||
estiver publicada. Guardar um rascunho não o
|
||||
publica. A evidência de aprovação e as
|
||||
identidades do histórico ficam na gestão.
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
<label className="block">
|
||||
Evidência / motivo da aprovação ou retirada
|
||||
@@ -463,31 +549,86 @@ export default function Competitiveness({
|
||||
onChange={(e) => setReason(e.target.value)}
|
||||
/>
|
||||
</label>
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={
|
||||
dirty ||
|
||||
!diagnosticReady(draft) ||
|
||||
server.version === 0 ||
|
||||
reason.trim().length < 10
|
||||
}
|
||||
onClick={() => command('approved', { reason })}
|
||||
>
|
||||
Aprovar versão guardada para consulta pública
|
||||
</button>{' '}
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={
|
||||
dirty ||
|
||||
!server.approved ||
|
||||
reason.trim().length < 10
|
||||
}
|
||||
onClick={() => command('withdrawn', { reason })}
|
||||
>
|
||||
Retirar aprovação pública
|
||||
</button>
|
||||
{editorial ? (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{(
|
||||
editorialActions[
|
||||
server.workflow?.state ?? 'draft'
|
||||
] ?? []
|
||||
).map(([action, label]) => (
|
||||
<button
|
||||
key={action}
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={
|
||||
dirty ||
|
||||
reason.trim().length < 10 ||
|
||||
server.version === 0 ||
|
||||
!server.workflow ||
|
||||
([
|
||||
'submitted',
|
||||
'approved',
|
||||
'published',
|
||||
].includes(action) &&
|
||||
(!diagnosticReady(draft) ||
|
||||
server.workflow?.fresh ===
|
||||
false)) ||
|
||||
(action === 'approved' &&
|
||||
!!server.workflow
|
||||
?.independent_required &&
|
||||
server.workflow.contributors.includes(
|
||||
viewerId ?? -1,
|
||||
))
|
||||
}
|
||||
onClick={() => command(action, { reason })}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
{publicVersion && (
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={
|
||||
dirty || reason.trim().length < 10
|
||||
}
|
||||
onClick={() =>
|
||||
command('withdrawn', { reason })
|
||||
}
|
||||
>
|
||||
Retirar publicação actual
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={
|
||||
dirty ||
|
||||
!diagnosticReady(draft) ||
|
||||
server.version === 0 ||
|
||||
reason.trim().length < 10
|
||||
}
|
||||
onClick={() => command('approved', { reason })}
|
||||
>
|
||||
Aprovar versão guardada para consulta pública
|
||||
</button>{' '}
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
disabled={
|
||||
dirty ||
|
||||
!server.approved ||
|
||||
reason.trim().length < 10
|
||||
}
|
||||
onClick={() => command('withdrawn', { reason })}
|
||||
>
|
||||
Retirar aprovação pública
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{dirty && (
|
||||
<p>
|
||||
Guarde primeiro as alterações ou recupere a versão
|
||||
|
||||
@@ -307,6 +307,7 @@ export default function Editor({
|
||||
clusterId={record.id}
|
||||
sector={record.sector ?? ''}
|
||||
initial={competitiveness}
|
||||
viewerId={viewerId}
|
||||
/>
|
||||
<section className="max-w-3xl space-y-4">
|
||||
<h2 className="text-xl font-semibold">
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
import type { Paginated } from '../management/shared';
|
||||
import { titles, statuses } from './types';
|
||||
import type { Structure, StructureRecord } from './types';
|
||||
import { states as editorialStates } from '../management/editorial-workflow';
|
||||
|
||||
export default function Index({
|
||||
structure,
|
||||
@@ -16,7 +17,7 @@ export default function Index({
|
||||
filters,
|
||||
}: {
|
||||
structure: Structure;
|
||||
records: Paginated<StructureRecord>;
|
||||
records: Paginated<StructureRecord & { editorial_state?: string }>;
|
||||
filters: { q?: string };
|
||||
}) {
|
||||
const form = useForm({ q: filters.q ?? '' });
|
||||
@@ -61,6 +62,18 @@ export default function Index({
|
||||
{record.code} · {statuses[structure][record.status]}
|
||||
</p>
|
||||
{record.sector && <p>{record.sector}</p>}
|
||||
{record.editorial_state && (
|
||||
<p>
|
||||
Competitividade:{' '}
|
||||
{editorialStates[record.editorial_state] ??
|
||||
{
|
||||
legacy_published:
|
||||
'Publicação anterior preservada',
|
||||
not_started: 'Sem análise guardada',
|
||||
}[record.editorial_state] ??
|
||||
record.editorial_state}
|
||||
</p>
|
||||
)}
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user