Complete grouped collaborative editorial queues and native review coverage
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { Link, useForm } from '@inertiajs/react';
|
||||
import { Management, Field, button, control } from './shared';
|
||||
import { states } from './editorial-workflow';
|
||||
import { labels as portfolioLabels } from '../portfolio/shared';
|
||||
import SubjectForm from './editorial-subject-form';
|
||||
import type { SubjectField } from './editorial-subject-form';
|
||||
|
||||
type Edition = {
|
||||
id: string;
|
||||
@@ -27,6 +29,13 @@ type Edition = {
|
||||
fields: Record<string, string | number | null>;
|
||||
territory_context?: { id: string; name: string }[];
|
||||
};
|
||||
_subject?: {
|
||||
kind: string;
|
||||
key: string;
|
||||
fields: Record<string, string | number | boolean | null>;
|
||||
new_record: boolean;
|
||||
withdraw?: boolean;
|
||||
};
|
||||
};
|
||||
files: {
|
||||
id: string;
|
||||
@@ -55,8 +64,16 @@ export default function EditorialEdition({
|
||||
canApprove,
|
||||
independentRequired,
|
||||
subject = 'resource',
|
||||
subjectKind,
|
||||
editUrl,
|
||||
subjectFields = [],
|
||||
subjectInitial = {},
|
||||
}: {
|
||||
subject?: 'resource' | 'portfolio' | 'demography';
|
||||
subject?: 'resource' | 'portfolio' | 'demography' | 'structural';
|
||||
subjectKind?: string;
|
||||
editUrl?: string;
|
||||
subjectFields?: SubjectField[];
|
||||
subjectInitial?: Record<string, string | number | boolean | null>;
|
||||
resource: {
|
||||
id: number | string;
|
||||
title: string;
|
||||
@@ -79,7 +96,10 @@ export default function EditorialEdition({
|
||||
canApprove: boolean;
|
||||
independentRequired: boolean;
|
||||
}) {
|
||||
const editionBase = `/management/editorial/${subject === 'resource' ? 'resources' : subject}/${resource.id}`;
|
||||
const editionBase =
|
||||
subject === 'structural'
|
||||
? `/management/editorial/subjects/${subjectKind}/${resource.id}`
|
||||
: `/management/editorial/${subject === 'resource' ? 'resources' : subject}/${resource.id}`;
|
||||
const form = useForm({
|
||||
version: edition?.version ?? 1,
|
||||
action: '',
|
||||
@@ -103,7 +123,9 @@ export default function EditorialEdition({
|
||||
reject: 'Rejeitar',
|
||||
legal_validate: 'Validar juridicamente',
|
||||
approve: 'Aprovar',
|
||||
publish: 'Publicar',
|
||||
publish: edition?.payload.resource._subject?.withdraw
|
||||
? 'Publicar retirada'
|
||||
: 'Publicar',
|
||||
archive: 'Arquivar',
|
||||
};
|
||||
return (
|
||||
@@ -112,7 +134,14 @@ export default function EditorialEdition({
|
||||
<Link className="underline" href="/management/editorial">
|
||||
Fila e notificações
|
||||
</Link>
|
||||
{subject === 'demography' ? (
|
||||
{subject === 'structural' ? (
|
||||
<Link
|
||||
className="underline"
|
||||
href={editUrl ?? '/management/editorial/subjects'}
|
||||
>
|
||||
Alterar no contexto original
|
||||
</Link>
|
||||
) : subject === 'demography' ? (
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/management/demography?batch=${resource.id}`}
|
||||
@@ -153,6 +182,14 @@ export default function EditorialEdition({
|
||||
{resource.public_edition_no && (
|
||||
<p>Versão pública: edição {resource.public_edition_no}.</p>
|
||||
)}
|
||||
{!edition && subject === 'structural' && (
|
||||
<SubjectForm
|
||||
base={editionBase}
|
||||
revision={1}
|
||||
fields={subjectFields}
|
||||
initial={subjectInitial}
|
||||
/>
|
||||
)}
|
||||
{edition ? (
|
||||
<>
|
||||
<h2 className="font-semibold">
|
||||
@@ -161,20 +198,75 @@ export default function EditorialEdition({
|
||||
</h2>
|
||||
{!edition.fresh && (
|
||||
<p role="alert">
|
||||
Os anexos mudaram ou deixaram de estar disponíveis.
|
||||
Guarde uma nova edição e volte a conferir antes da
|
||||
aprovação.
|
||||
O conteúdo, contexto ou anexos mudaram ou deixaram
|
||||
de estar disponíveis. Guarde uma nova edição e volte
|
||||
a conferir antes da aprovação.
|
||||
</p>
|
||||
)}
|
||||
<p className="text-sm break-all">
|
||||
Identificador da edição: {edition.id}
|
||||
<br />
|
||||
Hash do conteúdo e{' '}
|
||||
{subject === 'portfolio' ? 'contexto' : 'anexos'}:{' '}
|
||||
{edition.content_hash}
|
||||
{['portfolio', 'structural'].includes(subject)
|
||||
? 'contexto'
|
||||
: 'anexos'}
|
||||
: {edition.content_hash}
|
||||
</p>
|
||||
<h3 className="font-semibold">Conferir conteúdo</h3>
|
||||
<p>{edition.payload.resource.title}</p>
|
||||
{edition.payload.resource._subject?.withdraw && (
|
||||
<p role="status">
|
||||
Proposta de retirada: o registo actual só será
|
||||
retirado depois da publicação desta decisão.
|
||||
</p>
|
||||
)}
|
||||
{subject === 'structural' &&
|
||||
edition.payload.resource._subject && (
|
||||
<>
|
||||
<dl className="grid gap-2 sm:grid-cols-2">
|
||||
{subjectFields.map((field) => {
|
||||
const value =
|
||||
edition.payload.resource._subject
|
||||
?.fields[field.name];
|
||||
return (
|
||||
<div key={field.name}>
|
||||
<dt className="font-medium">
|
||||
{field.label}
|
||||
</dt>
|
||||
<dd className="break-words whitespace-pre-wrap">
|
||||
{value === null ||
|
||||
value === '' ||
|
||||
value === undefined
|
||||
? 'Não indicado'
|
||||
: typeof value ===
|
||||
'boolean'
|
||||
? value
|
||||
? 'Sim'
|
||||
: 'Não'
|
||||
: String(value)}
|
||||
</dd>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</dl>
|
||||
{current && (
|
||||
<SubjectForm
|
||||
key={edition.id}
|
||||
base={editionBase}
|
||||
revision={edition.revision_no}
|
||||
fields={subjectFields}
|
||||
initial={
|
||||
edition.payload.resource._subject
|
||||
.fields
|
||||
}
|
||||
withdraw={
|
||||
edition.payload.resource._subject
|
||||
.withdraw
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
<p className="whitespace-pre-wrap">
|
||||
{edition.payload.resource.description}
|
||||
</p>
|
||||
@@ -408,7 +500,10 @@ export default function EditorialEdition({
|
||||
canApprove)) &&
|
||||
(action !== 'approve' ||
|
||||
canApprove) &&
|
||||
(subject !== 'portfolio' ||
|
||||
(![
|
||||
'portfolio',
|
||||
'structural',
|
||||
].includes(subject) ||
|
||||
action !== 'publish' ||
|
||||
canApprove) &&
|
||||
(edition.fresh ||
|
||||
|
||||
@@ -0,0 +1,290 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useForm } from '@inertiajs/react';
|
||||
import { portalRequest } from '@/lib/portal-api';
|
||||
import { Field, button, control } from './shared';
|
||||
|
||||
export type SubjectField = {
|
||||
name: string;
|
||||
label: string;
|
||||
type: string;
|
||||
options: string[];
|
||||
};
|
||||
type Value = string | number | boolean | null;
|
||||
const names: Record<string, string> = {
|
||||
draft: 'Rascunho',
|
||||
planned: 'Planeado',
|
||||
active: 'Activo',
|
||||
suspended: 'Suspenso',
|
||||
completed: 'Concluído',
|
||||
cancelled: 'Cancelado',
|
||||
inactive: 'Inactivo',
|
||||
proposed: 'Proposto',
|
||||
closed: 'Encerrado',
|
||||
input: 'Insumos',
|
||||
production: 'Produção',
|
||||
processing: 'Transformação',
|
||||
logistics: 'Logística',
|
||||
market: 'Mercado',
|
||||
supplies: 'Fornece',
|
||||
processes: 'Transforma',
|
||||
distributes: 'Distribui',
|
||||
supports: 'Apoia',
|
||||
official: 'Oficial',
|
||||
influence: 'Influência',
|
||||
proximity: 'Proximidade',
|
||||
potential: 'Potencial',
|
||||
historical: 'Histórica',
|
||||
anchor: 'Âncora',
|
||||
complementary: 'Complementar',
|
||||
supporting: 'Apoio',
|
||||
primary: 'Principal',
|
||||
beneficiary: 'Beneficiária',
|
||||
served: 'Servida',
|
||||
enabled: 'Viabilizada',
|
||||
dependent: 'Dependente',
|
||||
related: 'Relacionada',
|
||||
identified: 'Identificada',
|
||||
in_review: 'Em análise',
|
||||
resolved: 'Resolvida',
|
||||
withdrawn: 'Retirada',
|
||||
};
|
||||
|
||||
function Reference({
|
||||
base,
|
||||
field,
|
||||
value,
|
||||
onChange,
|
||||
}: {
|
||||
base: string;
|
||||
field: SubjectField;
|
||||
value: Value;
|
||||
onChange: (value: Value) => void;
|
||||
}) {
|
||||
const [query, setQuery] = useState('');
|
||||
const [items, setItems] = useState<{ id: string; name: string }[]>([]);
|
||||
const [message, setMessage] = useState('');
|
||||
useEffect(() => {
|
||||
const abort = new AbortController();
|
||||
const timer = setTimeout(() => {
|
||||
void portalRequest<{ data: { id: string; name: string }[] }>(
|
||||
`${base}/choices?${new URLSearchParams({ field: field.name, q: query })}`,
|
||||
{ signal: abort.signal },
|
||||
)
|
||||
.then((data) => {
|
||||
setItems(data.data);
|
||||
setMessage('');
|
||||
})
|
||||
.catch((error) => {
|
||||
if (!abort.signal.aborted)
|
||||
setMessage(
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: 'Não foi possível consultar o catálogo.',
|
||||
);
|
||||
});
|
||||
}, 250);
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
abort.abort();
|
||||
};
|
||||
}, [base, field.name, query]);
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<input
|
||||
className={control}
|
||||
aria-label={`Pesquisar ${field.label.toLowerCase()}`}
|
||||
placeholder="Pesquisar no catálogo existente"
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
/>
|
||||
<select
|
||||
className={control}
|
||||
aria-label={field.label}
|
||||
value={String(value ?? '')}
|
||||
onChange={(event) => onChange(event.target.value || null)}
|
||||
>
|
||||
<option value="">Sem selecção</option>
|
||||
{value && !items.some((item) => item.id === value) && (
|
||||
<option value={String(value)}>
|
||||
Selecção actual preservada
|
||||
</option>
|
||||
)}
|
||||
{items.map((item) => (
|
||||
<option key={item.id} value={item.id}>
|
||||
{item.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{items.length === 100 && (
|
||||
<p className="text-sm">
|
||||
Refine a pesquisa para consultar outros resultados.
|
||||
</p>
|
||||
)}
|
||||
{message && <p role="status">{message}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function SubjectForm({
|
||||
base,
|
||||
revision,
|
||||
fields,
|
||||
initial,
|
||||
withdraw = false,
|
||||
}: {
|
||||
base: string;
|
||||
revision: number;
|
||||
fields: SubjectField[];
|
||||
initial: Record<string, Value>;
|
||||
withdraw?: boolean;
|
||||
}) {
|
||||
const [open, setOpen] = useState(false);
|
||||
const form = useForm({
|
||||
expected_revision: revision,
|
||||
withdraw,
|
||||
fields: Object.fromEntries(
|
||||
fields.map((field) => [field.name, initial[field.name] ?? null]),
|
||||
) as Record<string, Value>,
|
||||
});
|
||||
const set = (field: string, value: Value) =>
|
||||
form.setData('fields', { ...form.data.fields, [field]: value });
|
||||
return (
|
||||
<details
|
||||
className="rounded border p-4"
|
||||
onToggle={(event) => setOpen(event.currentTarget.open)}
|
||||
>
|
||||
<summary className="cursor-pointer font-medium underline">
|
||||
Alterar proposta
|
||||
</summary>
|
||||
{open && (
|
||||
<form
|
||||
className="mt-4 space-y-4"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
form.post(`${base}/drafts`, { preserveScroll: true });
|
||||
}}
|
||||
>
|
||||
<p>
|
||||
Guarde uma nova edição. As decisões anteriores mantêm-se
|
||||
no histórico e não aprovam automaticamente esta
|
||||
alteração.
|
||||
</p>
|
||||
<label className="flex gap-2">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={form.data.withdraw}
|
||||
onChange={(event) =>
|
||||
form.setData('withdraw', event.target.checked)
|
||||
}
|
||||
/>
|
||||
Propor a retirada deste registo. A situação actual
|
||||
mantém-se até à publicação expressa da decisão.
|
||||
</label>
|
||||
<div className="grid gap-4 sm:grid-cols-2">
|
||||
{fields.map((field) => (
|
||||
<Field
|
||||
key={field.name}
|
||||
label={field.label}
|
||||
error={
|
||||
(form.errors as Record<string, string>)[
|
||||
`fields.${field.name}`
|
||||
] ??
|
||||
(form.errors as Record<string, string>)[
|
||||
field.name
|
||||
]
|
||||
}
|
||||
>
|
||||
{field.type === 'reference' ? (
|
||||
<Reference
|
||||
base={base}
|
||||
field={field}
|
||||
value={form.data.fields[field.name]}
|
||||
onChange={(value) =>
|
||||
set(field.name, value)
|
||||
}
|
||||
/>
|
||||
) : field.type === 'enum' ? (
|
||||
<select
|
||||
className={control}
|
||||
value={String(
|
||||
form.data.fields[field.name] ?? '',
|
||||
)}
|
||||
onChange={(event) =>
|
||||
set(field.name, event.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccionar</option>
|
||||
{field.options.map((option) => (
|
||||
<option key={option} value={option}>
|
||||
{names[option] ?? option}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
) : field.type === 'boolean' ? (
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={Boolean(
|
||||
form.data.fields[field.name],
|
||||
)}
|
||||
onChange={(event) =>
|
||||
set(
|
||||
field.name,
|
||||
event.target.checked,
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : field.type === 'date' ? (
|
||||
<input
|
||||
className={control}
|
||||
type="date"
|
||||
value={String(
|
||||
form.data.fields[field.name] ?? '',
|
||||
).slice(0, 10)}
|
||||
onChange={(event) =>
|
||||
set(
|
||||
field.name,
|
||||
event.target.value || null,
|
||||
)
|
||||
}
|
||||
/>
|
||||
) : (
|
||||
<textarea
|
||||
className={control}
|
||||
rows={
|
||||
field.name === 'description' ||
|
||||
field.name === 'rationale'
|
||||
? 4
|
||||
: 2
|
||||
}
|
||||
value={String(
|
||||
form.data.fields[field.name] ?? '',
|
||||
)}
|
||||
onChange={(event) =>
|
||||
set(
|
||||
field.name,
|
||||
event.target.value || null,
|
||||
)
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</Field>
|
||||
))}
|
||||
</div>
|
||||
{Object.entries(form.errors)
|
||||
.filter(
|
||||
([key]) =>
|
||||
key === 'expected_revision' || key === 'fields',
|
||||
)
|
||||
.map(([key, message]) => (
|
||||
<p role="alert" key={key}>
|
||||
{message}
|
||||
</p>
|
||||
))}
|
||||
<button className={button} disabled={form.processing}>
|
||||
Guardar nova edição privada
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
</details>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Link } from '@inertiajs/react';
|
||||
import { Management } from './shared';
|
||||
import { states } from './editorial-workflow';
|
||||
|
||||
const titles: Record<string, string> = {
|
||||
projects: 'Projectos',
|
||||
clusters: 'Clusters',
|
||||
corridors: 'Corredores',
|
||||
'cluster-project': 'Projectos associados ao cluster',
|
||||
'corridor-project': 'Projectos associados ao corredor',
|
||||
'corridor-cluster': 'Clusters associados ao corredor',
|
||||
'value-chains': 'Etapas da cadeia de valor',
|
||||
'value-chain-links': 'Ligações da cadeia de valor',
|
||||
'investment-gaps': 'Lacunas de investimento',
|
||||
'zone-relations': 'Relações territoriais',
|
||||
};
|
||||
type Item = {
|
||||
id: string;
|
||||
subject_kind: string;
|
||||
subject_key: string;
|
||||
revision_no: number;
|
||||
state: string;
|
||||
title: string;
|
||||
};
|
||||
export default function Subjects({
|
||||
items,
|
||||
}: {
|
||||
items: {
|
||||
data: Item[];
|
||||
prev_page_url: string | null;
|
||||
next_page_url: string | null;
|
||||
};
|
||||
}) {
|
||||
return (
|
||||
<Management title="Revisão de estruturas e relações">
|
||||
<Link className="underline" href="/management/editorial">
|
||||
Circuito editorial
|
||||
</Link>
|
||||
<p>
|
||||
Prepare no formulário existente. Reveja e publique a edição
|
||||
aprovada, conservando o registo anterior durante a preparação.
|
||||
</p>
|
||||
{!items.data.length && <p>Não existem propostas neste percurso.</p>}
|
||||
<ul className="space-y-4">
|
||||
{items.data.map((item) => (
|
||||
<li key={item.id} className="rounded border p-4">
|
||||
<p className="text-sm">
|
||||
{titles[item.subject_kind] ?? item.subject_kind} ·{' '}
|
||||
{states[item.state] ?? item.state} · edição{' '}
|
||||
{item.revision_no}
|
||||
</p>
|
||||
<Link
|
||||
className="font-semibold underline"
|
||||
href={`/management/editorial/subjects/${item.subject_kind}/${item.subject_key}`}
|
||||
>
|
||||
{item.title}
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<nav aria-label="Páginas de propostas" className="flex gap-4">
|
||||
{items.prev_page_url && (
|
||||
<Link className="underline" href={items.prev_page_url}>
|
||||
Anterior
|
||||
</Link>
|
||||
)}
|
||||
{items.next_page_url && (
|
||||
<Link className="underline" href={items.next_page_url}>
|
||||
Seguinte
|
||||
</Link>
|
||||
)}
|
||||
</nav>
|
||||
</Management>
|
||||
);
|
||||
}
|
||||
@@ -21,6 +21,18 @@ type Item = {
|
||||
legal_required: boolean;
|
||||
};
|
||||
const eventTitles: Record<string, string> = {
|
||||
submitted: 'Submissão',
|
||||
pending_review: 'Submissão',
|
||||
review_started: 'Início da revisão',
|
||||
in_review: 'Início da revisão',
|
||||
returned: 'Devolução',
|
||||
rejected: 'Rejeição',
|
||||
approved: 'Aprovação',
|
||||
published: 'Publicação',
|
||||
archived: 'Arquivo',
|
||||
withdrawn: 'Retirada da publicação',
|
||||
publication_withdrawn: 'Retirada da publicação',
|
||||
suspended: 'Suspensão da publicação',
|
||||
submit: 'Submissão',
|
||||
start_review: 'Início da revisão',
|
||||
return: 'Devolução',
|
||||
@@ -43,6 +55,10 @@ export default function EditorialWorkflow({
|
||||
demographyUrl,
|
||||
demographyPending = 0,
|
||||
territorialUrl,
|
||||
nativePending = { clusters: 0, territories: 0 },
|
||||
subjectsUrl,
|
||||
subjectsPending = 0,
|
||||
zonesUrl,
|
||||
}: {
|
||||
resourceAccess: boolean;
|
||||
opportunitiesUrl: string | null;
|
||||
@@ -53,6 +69,10 @@ export default function EditorialWorkflow({
|
||||
demographyUrl?: string | null;
|
||||
demographyPending?: number;
|
||||
territorialUrl?: string | null;
|
||||
nativePending?: { clusters: number; territories: number; zones?: number };
|
||||
zonesUrl?: string | null;
|
||||
subjectsUrl?: string | null;
|
||||
subjectsPending?: number;
|
||||
filters?: { state?: string; kind?: string };
|
||||
items: { data: Item[]; current_page: number; last_page: number };
|
||||
notices: {
|
||||
@@ -73,6 +93,17 @@ export default function EditorialWorkflow({
|
||||
próprio.
|
||||
</p>
|
||||
<div className="flex flex-wrap gap-4">
|
||||
{zonesUrl && (
|
||||
<Link className="underline" href={zonesUrl}>
|
||||
Zonas e indicadores: {nativePending.zones ?? 0}{' '}
|
||||
pendentes
|
||||
</Link>
|
||||
)}
|
||||
{subjectsUrl && (
|
||||
<Link className="underline" href={subjectsUrl}>
|
||||
Estruturas e relações: {subjectsPending} pendentes
|
||||
</Link>
|
||||
)}
|
||||
{demographyUrl && (
|
||||
<Link className="underline" href={demographyUrl}>
|
||||
Demografia: {demographyPending} lotes pendentes
|
||||
@@ -80,7 +111,8 @@ export default function EditorialWorkflow({
|
||||
)}
|
||||
{territorialUrl && (
|
||||
<Link className="underline" href={territorialUrl}>
|
||||
Conteúdos territoriais
|
||||
Conteúdos territoriais: {nativePending.territories}{' '}
|
||||
pendentes
|
||||
</Link>
|
||||
)}
|
||||
{portfolioUrl && (
|
||||
@@ -90,7 +122,8 @@ export default function EditorialWorkflow({
|
||||
)}
|
||||
{clustersUrl && (
|
||||
<Link className="underline" href={clustersUrl}>
|
||||
Competitividade dos clusters
|
||||
Competitividade dos clusters: {nativePending.clusters}{' '}
|
||||
pendentes
|
||||
</Link>
|
||||
)}
|
||||
<Link className="underline" href="/dashboard">
|
||||
|
||||
@@ -57,9 +57,13 @@ const titles: Record<string, string> = {
|
||||
export default function TerritorialEditorial({
|
||||
roles,
|
||||
actorId,
|
||||
initialTerritory,
|
||||
noticeVersion,
|
||||
}: {
|
||||
roles: string[];
|
||||
actorId: string;
|
||||
initialTerritory?: string | null;
|
||||
noticeVersion?: number | null;
|
||||
}) {
|
||||
const [rows, setRows] = useState<Row[]>([]);
|
||||
const [next, setNext] = useState<string | null>(null);
|
||||
@@ -109,6 +113,7 @@ export default function TerritorialEditorial({
|
||||
'/api/v1/geo/sources?limit=100',
|
||||
).then((data) => setSources(data.data)),
|
||||
]).catch(fail);
|
||||
if (initialTerritory) void open(initialTerritory);
|
||||
}, []);
|
||||
const open = async (id: string) => {
|
||||
setBusy(true);
|
||||
@@ -223,6 +228,12 @@ export default function TerritorialEditorial({
|
||||
até à publicação expressa.
|
||||
</p>
|
||||
{message && <p role="status">{message}</p>}
|
||||
{noticeVersion && (
|
||||
<p>
|
||||
Este aviso refere-se à versão {noticeVersion}. Confira o
|
||||
histórico e a versão actual antes de decidir.
|
||||
</p>
|
||||
)}
|
||||
<ul className="space-y-2">
|
||||
{rows.map((row) => (
|
||||
<li key={row.id}>
|
||||
|
||||
@@ -12,6 +12,7 @@ import type { ChainLink, Gap } from './value-network';
|
||||
|
||||
function ChainForm({ clusterId, chain }: { clusterId: string; chain?: Chain }) {
|
||||
const form = useForm({
|
||||
editorial_version: chain?.editorial_version ?? null,
|
||||
code: chain?.code ?? '',
|
||||
name: chain?.name ?? '',
|
||||
stage: chain?.stage ?? 'input',
|
||||
@@ -34,6 +35,11 @@ function ChainForm({ clusterId, chain }: { clusterId: string; chain?: Chain }) {
|
||||
<h3 className="font-semibold">
|
||||
{chain ? chain.name : 'Nova etapa'}
|
||||
</h3>
|
||||
{chain?.editorial_url && (
|
||||
<Link className="underline" href={chain.editorial_url}>
|
||||
Conferir proposta e publicação
|
||||
</Link>
|
||||
)}
|
||||
<Field label="Código da etapa" error={form.errors.code}>
|
||||
<input
|
||||
className={control}
|
||||
@@ -79,8 +85,12 @@ export default function Editor({
|
||||
gaps,
|
||||
competitiveness,
|
||||
editorialDossier,
|
||||
editorialSubject,
|
||||
structuralEditorial = false,
|
||||
}: {
|
||||
editorialDossier?: string | null;
|
||||
editorialSubject?: string | null;
|
||||
structuralEditorial?: boolean;
|
||||
structure: Structure;
|
||||
record: StructureRecord | null;
|
||||
projects: { id: string; name: string; code: string }[];
|
||||
@@ -101,6 +111,8 @@ export default function Editor({
|
||||
valid_until: string | null;
|
||||
validation_status: string;
|
||||
version_no: number;
|
||||
editorial_version?: number;
|
||||
editorial_url?: string;
|
||||
editor_id: number | null;
|
||||
}[];
|
||||
}) {
|
||||
@@ -133,6 +145,7 @@ export default function Editor({
|
||||
const association = useForm({
|
||||
project_id: '',
|
||||
version_no: 0,
|
||||
editorial_version: 0,
|
||||
role: 'complementary',
|
||||
association_type: 'potential',
|
||||
source_reference: '',
|
||||
@@ -142,6 +155,23 @@ export default function Editor({
|
||||
});
|
||||
return (
|
||||
<Management title={`${record ? 'Editar' : 'Criar'} ${singular}`}>
|
||||
{editorialSubject && (
|
||||
<p>
|
||||
As alterações ficam numa proposta privada.{' '}
|
||||
<Link className="underline" href={editorialSubject}>
|
||||
Conferir edição e publicar
|
||||
</Link>
|
||||
.
|
||||
</p>
|
||||
)}
|
||||
{structuralEditorial && (
|
||||
<Link
|
||||
className="underline"
|
||||
href="/management/editorial/subjects"
|
||||
>
|
||||
Propostas de estruturas, relações e cadeias de valor
|
||||
</Link>
|
||||
)}
|
||||
<Link className="underline" href={`/management/${structure}`}>
|
||||
Voltar a {titles[structure].toLowerCase()}
|
||||
</Link>
|
||||
@@ -351,7 +381,16 @@ export default function Editor({
|
||||
{member.evidence_reference ?? 'Sem evidencia'} -{' '}
|
||||
{member.valid_from ?? 'Sem inicio'} -{' '}
|
||||
{member.valid_until ?? 'Sem termo'}
|
||||
{member.validation_status === 'pending' &&
|
||||
{member.editorial_url && (
|
||||
<Link
|
||||
className="underline"
|
||||
href={member.editorial_url}
|
||||
>
|
||||
Rever proposta e publicação
|
||||
</Link>
|
||||
)}
|
||||
{!structuralEditorial &&
|
||||
member.validation_status === 'pending' &&
|
||||
member.editor_id !== viewerId && (
|
||||
<button
|
||||
className={button}
|
||||
@@ -404,6 +443,59 @@ export default function Editor({
|
||||
member.project_id ===
|
||||
e.target.value,
|
||||
)?.version_no ?? 0,
|
||||
editorial_version:
|
||||
memberships.find(
|
||||
(member) =>
|
||||
member.project_id ===
|
||||
e.target.value,
|
||||
)?.editorial_version ?? 0,
|
||||
role:
|
||||
memberships.find(
|
||||
(member) =>
|
||||
member.project_id ===
|
||||
e.target.value,
|
||||
)?.role ?? 'complementary',
|
||||
association_type:
|
||||
memberships.find(
|
||||
(member) =>
|
||||
member.project_id ===
|
||||
e.target.value,
|
||||
)?.association_type ??
|
||||
'potential',
|
||||
source_reference:
|
||||
memberships.find(
|
||||
(member) =>
|
||||
member.project_id ===
|
||||
e.target.value,
|
||||
)?.source_reference ?? '',
|
||||
evidence_reference:
|
||||
memberships.find(
|
||||
(member) =>
|
||||
member.project_id ===
|
||||
e.target.value,
|
||||
)?.evidence_reference ?? '',
|
||||
valid_from:
|
||||
memberships
|
||||
.find(
|
||||
(member) =>
|
||||
member.project_id ===
|
||||
e.target.value,
|
||||
)
|
||||
?.valid_from?.slice(
|
||||
0,
|
||||
10,
|
||||
) ?? '',
|
||||
valid_until:
|
||||
memberships
|
||||
.find(
|
||||
(member) =>
|
||||
member.project_id ===
|
||||
e.target.value,
|
||||
)
|
||||
?.valid_until?.slice(
|
||||
0,
|
||||
10,
|
||||
) ?? '',
|
||||
}))
|
||||
}
|
||||
>
|
||||
|
||||
@@ -41,4 +41,11 @@ export const roles: Record<string, string> = {
|
||||
complementary: 'Complementar',
|
||||
supporting: 'Apoio',
|
||||
};
|
||||
export type Chain = { id: string; code: string; name: string; stage: string };
|
||||
export type Chain = {
|
||||
id: string;
|
||||
code: string;
|
||||
name: string;
|
||||
stage: string;
|
||||
editorial_version?: number;
|
||||
editorial_url?: string;
|
||||
};
|
||||
|
||||
@@ -17,6 +17,8 @@ export type Gap = {
|
||||
rationale: string;
|
||||
status: string;
|
||||
call_to_action: string;
|
||||
editorial_version?: number;
|
||||
editorial_url?: string;
|
||||
};
|
||||
const linkTypes: Record<string, string> = {
|
||||
supplies: 'Fornece a',
|
||||
@@ -72,6 +74,7 @@ function GapForm({
|
||||
gap?: Gap;
|
||||
}) {
|
||||
const form = useForm({
|
||||
editorial_version: gap?.editorial_version ?? null,
|
||||
value_chain_id: gap?.value_chain_id ?? '',
|
||||
title: gap?.title ?? '',
|
||||
location: gap?.location ?? '',
|
||||
|
||||
Reference in New Issue
Block a user