Mapa de erros 4.7: uma ideia nova não se perde ao escolher o dossier
tests / ci (push) Canceled after 0s

Quem chega com um artigo, sector ou parque vê primeiro a criação de um
dossier novo para essa ideia; nos dossiers existentes, a acção principal é
continuar com a referência, e abrir o dossier sem ela fica explícito.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
Claude
2026-12-04 17:30:39 +02:00
committed by nala
parent 589d6627e5
commit 52c6c543bb
2 changed files with 90 additions and 48 deletions
+83 -48
View File
@@ -77,6 +77,63 @@ export default function InvestmentContexts({
: {}),
...(guideSelection ? { investment_guide: guideSelection } : {}),
});
// A new reference (park, sector, article) is only kept through the explicit
// "continuar" action; opening an old dossier by its title would drop it.
const carrying = Boolean(zoneSource || sectorSource || contentSource);
const createForm = (
<form
className="max-w-xl space-y-4 rounded-xl border p-5"
onSubmit={(event) => {
event.preventDefault();
form.post('/investimentos');
}}
>
<h2 className="text-lg font-semibold">
{carrying
? 'Criar um dossier novo para esta ideia'
: 'Preparar um investimento'}
</h2>
{carrying && (
<p className="text-sm">
A referência escolhida fica guardada no dossier novo. Os
dossiers que já tem não são alterados.
</p>
)}
<label className="grid gap-1">
Título
<input
required
maxLength={200}
className="rounded border p-2"
value={form.data.title}
onChange={(event) =>
form.setData('title', event.target.value)
}
/>
</label>
<label className="flex gap-2">
<input
type="checkbox"
checked={form.data.reuse_consent}
onChange={(event) =>
form.setData('reuse_consent', event.target.checked)
}
/>
Autorizo reutilizar o meu perfil neste dossier privado.
</label>
{Object.values(form.errors).map((error, index) => (
<p key={index} role="alert">
{error}
</p>
))}
<button
disabled={form.processing}
className="bg-primary text-primary-foreground rounded px-4 py-2"
>
Criar e guardar dossier
</button>
</form>
);
return (
<main className="mx-auto max-w-5xl space-y-6 p-4 md:p-8">
<Head title="Os meus investimentos" />
@@ -155,13 +212,24 @@ export default function InvestmentContexts({
</p>
</section>
)}
<p>
Prepare cada investimento no seu dossier. Pode trabalhar em
várias etapas em paralelo.
</p>
{carrying && createForm}
{carrying && contexts.length > 0 ? (
<h2 className="text-lg font-semibold">
Ou continuar num dossier que já tem
</h2>
) : (
<p>
Prepare cada investimento no seu dossier. Pode trabalhar
em várias etapas em paralelo.
</p>
)}
<ul className="grid gap-4 md:grid-cols-2">
{contexts.map((item) => (
<li key={item.id} className="rounded-xl border p-4">
{carrying && (
<h3 className="font-semibold">{item.title}</h3>
)}
{!carrying && (
<Link
className="font-semibold underline"
href={
@@ -180,6 +248,7 @@ export default function InvestmentContexts({
>
{item.title}
</Link>
)}
<p className="text-sm">
Guardado em{' '}
{new Date(item.updated_at).toLocaleString('pt-MZ')}
@@ -251,56 +320,22 @@ export default function InvestmentContexts({
Continuar neste dossier com o artigo
</button>
)}
{carrying && (
<Link
className="mt-3 block text-sm underline"
href={`/investimentos/${item.id}`}
>
Abrir este dossier sem acrescentar a nova
referência
</Link>
)}
</li>
))}
</ul>
{!contexts.length && (
<p>Ainda não criou um investimento neste percurso.</p>
)}
<form
className="max-w-xl space-y-4 rounded-xl border p-5"
onSubmit={(event) => {
event.preventDefault();
form.post('/investimentos');
}}
>
<h2 className="text-lg font-semibold">
Preparar um investimento
</h2>
<label className="grid gap-1">
Título
<input
required
maxLength={200}
className="rounded border p-2"
value={form.data.title}
onChange={(event) =>
form.setData('title', event.target.value)
}
/>
</label>
<label className="flex gap-2">
<input
type="checkbox"
checked={form.data.reuse_consent}
onChange={(event) =>
form.setData('reuse_consent', event.target.checked)
}
/>
Autorizo reutilizar o meu perfil neste dossier privado.
</label>
{Object.values(form.errors).map((error, index) => (
<p key={index} role="alert">
{error}
</p>
))}
<button
disabled={form.processing}
className="bg-primary text-primary-foreground rounded px-4 py-2"
>
Criar e guardar dossier
</button>
</form>
{!carrying && createForm}
<nav className="flex flex-wrap gap-4" aria-label="Ferramentas">
<Link className="underline" href="/simulador-fiscal">
Simulador
@@ -86,6 +86,13 @@ test('selected mining context reaches both new and existing dossier actions',()=
nodes(tree).find(n=>n.type==='form').props.onSubmit({preventDefault(){}});
assert.equal(posted[1][0],'/investimentos');
assert.deepEqual(posted[1][1].sector_reference,initial.sector_reference);
// Mapa de erros 4.7: the new idea is offered a new dossier first, and an old
// dossier is never opened by its title in a way that drops the reference.
const all=nodes(tree);
assert.ok(all.findIndex(n=>n.type==='form')<all.findIndex(n=>n.type==='ul'));
const open=all.filter(n=>n.type===Link && n.props.href==='/investimentos/SYNTHETIC-case');
assert.equal(open.length,1);
assert.match(String(open[0].props.children),/sem acrescentar a nova referência/);
});
const energySource=JSON.parse(fs.readFileSync(new URL('database/data/energy-reference-20261111.json',root)));