Complete private legacy article editing and previews in QA
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
export type EditorialArticle = {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
body: string;
|
||||
html?: string | null;
|
||||
image_url: string | null;
|
||||
original_url: string;
|
||||
source_url?: string | null;
|
||||
published_at?: string | null;
|
||||
modified_at?: string | null;
|
||||
legacy_id?: number | null;
|
||||
image_source_url?: string | null;
|
||||
image_notice?: string | null;
|
||||
image_references?: string[];
|
||||
metadata_version?: number;
|
||||
private_preview?: boolean;
|
||||
};
|
||||
export default function EditorialReading({
|
||||
article,
|
||||
}: {
|
||||
article: EditorialArticle;
|
||||
}) {
|
||||
return (
|
||||
<div className="space-y-5">
|
||||
{article.private_preview && (
|
||||
<p
|
||||
role="status"
|
||||
className="rounded border border-amber-500 bg-amber-50 p-3 text-slate-900"
|
||||
>
|
||||
Prévia privada — não publica o artigo nem altera os direitos
|
||||
do original.
|
||||
</p>
|
||||
)}
|
||||
<h1 className="text-3xl font-bold">{article.title}</h1>
|
||||
{article.description && <p>{article.description}</p>}
|
||||
{article.author && <p>Autor / entidade: {article.author}</p>}
|
||||
{article.legacy_id && (
|
||||
<p>
|
||||
Arquivo do portal antigo · artigo {article.legacy_id}.
|
||||
Conteúdo editorial preservado; não corresponde por si a
|
||||
oportunidade concreta ou regra executável.
|
||||
</p>
|
||||
)}
|
||||
{(article.published_at || article.modified_at) && (
|
||||
<p>
|
||||
Origem: publicado em{' '}
|
||||
{article.published_at ?? 'data não indicada'} · modificado
|
||||
em {article.modified_at ?? 'data não indicada'}. A edição no
|
||||
portal conserva estas datas de origem.
|
||||
</p>
|
||||
)}
|
||||
{article.image_url && (
|
||||
<img
|
||||
className="max-h-96 w-full object-contain"
|
||||
src={article.image_url}
|
||||
alt={`Imagem do artigo ${article.title}`}
|
||||
/>
|
||||
)}
|
||||
{article.image_notice && (
|
||||
<p role="note" className="rounded border p-3">
|
||||
{article.image_notice}
|
||||
</p>
|
||||
)}
|
||||
{article.html ? (
|
||||
<article
|
||||
className="prose dark:prose-invert max-w-none overflow-x-auto"
|
||||
dangerouslySetInnerHTML={{ __html: article.html }}
|
||||
/>
|
||||
) : (
|
||||
<article className="space-y-5">
|
||||
{article.body.split(/\n\s*\n/).map((p, i) => (
|
||||
<p className="whitespace-pre-wrap" key={i}>
|
||||
{p}
|
||||
</p>
|
||||
))}
|
||||
</article>
|
||||
)}
|
||||
{!!article.image_references?.length && (
|
||||
<section aria-label="Imagens referenciadas no corpo original">
|
||||
<h2>Imagens referenciadas no corpo original</h2>
|
||||
<p>
|
||||
Referências preservadas; não confirmam um ficheiro
|
||||
disponível na biblioteca.
|
||||
</p>
|
||||
<ul>
|
||||
{article.image_references.map((url, i) => (
|
||||
<li key={url}>
|
||||
<a
|
||||
className="underline"
|
||||
href={url}
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Referência da imagem {i + 1}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
<nav aria-label="Origem do artigo" className="flex flex-wrap gap-4">
|
||||
{article.source_url && (
|
||||
<a
|
||||
className="underline"
|
||||
href={article.source_url}
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Consultar página de origem
|
||||
</a>
|
||||
)}
|
||||
{article.image_source_url && (
|
||||
<a
|
||||
className="underline"
|
||||
href={article.image_source_url}
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Referência da imagem de origem
|
||||
</a>
|
||||
)}
|
||||
<a href={article.original_url} className="underline">
|
||||
Consultar documento original
|
||||
</a>
|
||||
</nav>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,35 @@
|
||||
import { Link, useForm } from '@inertiajs/react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Management, Field, button, control } from '../management/shared';
|
||||
type Content = { body: string; image_resource_id: number | null };
|
||||
import EditorialReading, {
|
||||
type EditorialArticle,
|
||||
} from '@/components/editorial-reading';
|
||||
type Content = {
|
||||
body: string;
|
||||
image_resource_id: number | null;
|
||||
image_mode?: string;
|
||||
};
|
||||
export default function ArticleEditor({
|
||||
resource,
|
||||
content,
|
||||
source,
|
||||
images,
|
||||
revisions,
|
||||
}: {
|
||||
resource: { id: number; title: string; metadata_version: number };
|
||||
resource: {
|
||||
id: number;
|
||||
title: string;
|
||||
metadata_version: number;
|
||||
published: boolean;
|
||||
};
|
||||
content: Content | null;
|
||||
source?: {
|
||||
source_url?: string;
|
||||
image_source_url?: string;
|
||||
published_at?: string;
|
||||
modified_at?: string;
|
||||
legacy_id?: number;
|
||||
} | null;
|
||||
images: { id: number; title: string }[];
|
||||
revisions: {
|
||||
revision_no: number;
|
||||
@@ -16,28 +37,107 @@ export default function ArticleEditor({
|
||||
created_at: string;
|
||||
}[];
|
||||
}) {
|
||||
const form = useForm({
|
||||
const initial = () => ({
|
||||
body: content?.body ?? '',
|
||||
image_resource_id: content?.image_resource_id
|
||||
? String(content.image_resource_id)
|
||||
: '',
|
||||
image_mode:
|
||||
content?.image_mode ??
|
||||
(content?.image_resource_id ? 'selected' : 'none'),
|
||||
metadata_version: resource.metadata_version,
|
||||
});
|
||||
const form = useForm(initial());
|
||||
const [preview, setPreview] = useState<EditorialArticle | null>(null);
|
||||
const [error, setError] = useState('');
|
||||
const [busy, setBusy] = useState(false);
|
||||
useEffect(() => {
|
||||
form.setData(initial());
|
||||
setPreview(null);
|
||||
setError('');
|
||||
}, [resource.id, resource.metadata_version]);
|
||||
useEffect(() => {
|
||||
setPreview(null);
|
||||
}, [form.data.body, form.data.image_mode, form.data.image_resource_id]);
|
||||
const showPreview = async () => {
|
||||
setBusy(true);
|
||||
setError('');
|
||||
try {
|
||||
const token = document.cookie
|
||||
.split('; ')
|
||||
.find((v) => v.startsWith('XSRF-TOKEN='))
|
||||
?.slice(11);
|
||||
const response = await fetch(
|
||||
`/management/portal-services/resources/${resource.id}/article/preview`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
'X-XSRF-TOKEN': decodeURIComponent(token ?? ''),
|
||||
},
|
||||
body: JSON.stringify(form.data),
|
||||
},
|
||||
);
|
||||
const data = await response
|
||||
.json()
|
||||
.catch(() => ({
|
||||
message:
|
||||
'Não foi possível abrir a prévia. Recupere o editor e confirme a sessão e o MFA existentes.',
|
||||
}));
|
||||
if (!response.ok)
|
||||
throw new Error(
|
||||
Object.values(data.errors ?? {})
|
||||
.flat()
|
||||
.join(' ') ||
|
||||
data.message ||
|
||||
'Não foi possível preparar a prévia.',
|
||||
);
|
||||
setPreview(data.article);
|
||||
} catch (e) {
|
||||
setError(
|
||||
e instanceof Error
|
||||
? e.message
|
||||
: 'Não foi possível preparar a prévia.',
|
||||
);
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
};
|
||||
return (
|
||||
<Management title={`Editar artigo — ${resource.title}`}>
|
||||
<p>
|
||||
O original permanece intacto na biblioteca. Guardar o corpo
|
||||
retira a publicação até à sua ação expressa no acervo.
|
||||
O original, a origem e as versões permanecem na biblioteca.
|
||||
Guardar cria uma revisão editorial e retira a publicação até à
|
||||
sua acção expressa no acervo.
|
||||
</p>
|
||||
<p role="status">
|
||||
Revisão guardada {resource.metadata_version} ·{' '}
|
||||
{resource.published ? 'Publicado' : 'Rascunho privado'}
|
||||
</p>
|
||||
{source && (
|
||||
<p>
|
||||
Original {source.legacy_id} · publicado em{' '}
|
||||
{source.published_at} · modificado em {source.modified_at}.
|
||||
A imagem de origem mantém a sua referência mesmo quando não
|
||||
existe exemplar disponível.
|
||||
</p>
|
||||
)}
|
||||
<form
|
||||
className="max-w-3xl space-y-5"
|
||||
onSubmit={(e) => {
|
||||
e.preventDefault();
|
||||
setError('');
|
||||
form.put(
|
||||
`/management/portal-services/resources/${resource.id}/article`,
|
||||
);
|
||||
}}
|
||||
>
|
||||
{!!Object.keys(form.errors).length && (
|
||||
<div role="alert">
|
||||
{Object.values(form.errors).join(' ')}
|
||||
</div>
|
||||
)}
|
||||
<Field label="Corpo do artigo" error={form.errors.body}>
|
||||
<textarea
|
||||
className={control}
|
||||
@@ -46,36 +146,93 @@ export default function ArticleEditor({
|
||||
onChange={(e) => form.setData('body', e.target.value)}
|
||||
/>
|
||||
<p>
|
||||
Texto simples. Separe os parágrafos com uma linha em
|
||||
branco.
|
||||
Texto simples, com uma linha em branco entre parágrafos.
|
||||
Se mantiver o texto original, a leitura conserva também
|
||||
a sua formatação; as correcções ficam numa edição
|
||||
separada.
|
||||
</p>
|
||||
</Field>
|
||||
<Field
|
||||
label="Imagem da biblioteca"
|
||||
error={form.errors.image_resource_id}
|
||||
label="Tratamento da imagem"
|
||||
error={form.errors.image_mode}
|
||||
>
|
||||
<select
|
||||
className={control}
|
||||
value={form.data.image_resource_id}
|
||||
value={form.data.image_mode}
|
||||
onChange={(e) =>
|
||||
form.setData('image_resource_id', e.target.value)
|
||||
form.setData('image_mode', e.target.value)
|
||||
}
|
||||
>
|
||||
<option value="">Sem imagem</option>
|
||||
{images.map((i) => (
|
||||
<option key={i.id} value={i.id}>
|
||||
{i.title}
|
||||
</option>
|
||||
))}
|
||||
<option value="original">
|
||||
Manter referência e imagem de origem disponível
|
||||
</option>
|
||||
<option value="selected">
|
||||
Escolher imagem pública da biblioteca
|
||||
</option>
|
||||
<option value="none">
|
||||
Não mostrar imagem nesta edição
|
||||
</option>
|
||||
</select>
|
||||
</Field>
|
||||
<button className={button} disabled={form.processing}>
|
||||
Guardar artigo como rascunho
|
||||
</button>{' '}
|
||||
<Link className="underline" href="/management/portal-services">
|
||||
Voltar ao acervo
|
||||
</Link>
|
||||
{form.data.image_mode === 'selected' && (
|
||||
<Field
|
||||
label="Imagem da biblioteca"
|
||||
error={form.errors.image_resource_id}
|
||||
>
|
||||
<select
|
||||
className={control}
|
||||
value={form.data.image_resource_id}
|
||||
onChange={(e) =>
|
||||
form.setData(
|
||||
'image_resource_id',
|
||||
e.target.value,
|
||||
)
|
||||
}
|
||||
>
|
||||
<option value="">Seleccione uma imagem</option>
|
||||
{images.map((i) => (
|
||||
<option key={i.id} value={i.id}>
|
||||
{i.title}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</Field>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-4">
|
||||
<button className={button} disabled={form.processing}>
|
||||
Guardar artigo como rascunho
|
||||
</button>
|
||||
<button
|
||||
className={button}
|
||||
type="button"
|
||||
disabled={busy}
|
||||
onClick={() => void showPreview()}
|
||||
>
|
||||
Pré-visualizar alterações
|
||||
</button>
|
||||
<Link
|
||||
className="underline"
|
||||
href={`/management/portal-services/resources/${resource.id}/article/preview`}
|
||||
>
|
||||
Ler revisão guardada
|
||||
</Link>
|
||||
<Link
|
||||
className="underline"
|
||||
href="/management/portal-services"
|
||||
>
|
||||
Voltar ao acervo para metadados e publicação
|
||||
</Link>
|
||||
</div>
|
||||
</form>
|
||||
{error && <p role="alert">{error}</p>}
|
||||
{preview && (
|
||||
<section
|
||||
aria-label="Prévia das alterações"
|
||||
className="my-6 max-w-3xl rounded border p-5"
|
||||
>
|
||||
<EditorialReading article={preview} />
|
||||
</section>
|
||||
)}
|
||||
<h2>Histórico</h2>
|
||||
<ul>
|
||||
{revisions.map((r) => (
|
||||
@@ -86,8 +243,10 @@ export default function ArticleEditor({
|
||||
))}
|
||||
</ul>
|
||||
<p>
|
||||
Título, descrição, autor e fonte são editados em Editar
|
||||
metadados no acervo.
|
||||
Título, descrição, autor, fonte, direitos e acesso são
|
||||
corrigidos em Editar metadados no acervo. Carregue e analise
|
||||
imagens na biblioteca antes de as seleccionar. Publicar continua
|
||||
a ser uma acção separada.
|
||||
</p>
|
||||
</Management>
|
||||
);
|
||||
|
||||
@@ -1,42 +1,27 @@
|
||||
import { Head, Link } from '@inertiajs/react';
|
||||
import { PortalMenu } from '@/layouts/portal-navigation';
|
||||
export default function Article({
|
||||
article,
|
||||
}: {
|
||||
article: {
|
||||
id: number;
|
||||
title: string;
|
||||
description: string | null;
|
||||
author: string | null;
|
||||
body: string;
|
||||
image_url: string | null;
|
||||
original_url: string;
|
||||
};
|
||||
}) {
|
||||
import EditorialReading, {
|
||||
type EditorialArticle,
|
||||
} from '@/components/editorial-reading';
|
||||
export default function Article({ article }: { article: EditorialArticle }) {
|
||||
return (
|
||||
<>
|
||||
<Head title={article.title} />
|
||||
<PortalMenu />
|
||||
<main className="mx-auto max-w-3xl space-y-6 p-6">
|
||||
<h1 className="text-3xl font-bold">{article.title}</h1>
|
||||
{article.description && <p>{article.description}</p>}
|
||||
{article.author && <p>Autor / entidade: {article.author}</p>}
|
||||
{article.image_url && (
|
||||
<img src={article.image_url} alt="Imagem do artigo" />
|
||||
)}
|
||||
<article className="space-y-5">
|
||||
{article.body.split(/\n\s*\n/).map((p, i) => (
|
||||
<p className="whitespace-pre-wrap" key={i}>
|
||||
{p}
|
||||
</p>
|
||||
))}
|
||||
</article>
|
||||
<Link href={article.original_url} className="underline">
|
||||
Consultar documento original
|
||||
</Link>
|
||||
<EditorialReading article={article} />
|
||||
<p>
|
||||
<Link href="/documentos" className="underline">
|
||||
Voltar à biblioteca
|
||||
<Link
|
||||
href={
|
||||
article.private_preview
|
||||
? `/management/portal-services/resources/${article.id}/article`
|
||||
: '/documentos'
|
||||
}
|
||||
className="underline"
|
||||
>
|
||||
{article.private_preview
|
||||
? 'Voltar ao editor'
|
||||
: 'Voltar à biblioteca'}
|
||||
</Link>
|
||||
</p>
|
||||
</main>
|
||||
|
||||
@@ -1385,6 +1385,7 @@ export default function Manage({
|
||||
>
|
||||
Editar artigo
|
||||
</a>
|
||||
<a className={button} href={`/management/portal-services/resources/${r.id}/article/preview`}>Ler / pré-visualizar artigo</a>
|
||||
<button
|
||||
type="button"
|
||||
className={button}
|
||||
|
||||
Reference in New Issue
Block a user