Fix compressed draft saves provenance and Beira documentary continuity
tests / ci (push) Canceled after 0s
tests / ci (push) Canceled after 0s
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { simulationDraftEtag } from '@/lib/simulation-draft-etag';
|
||||
import { SimulationPublishedIva, type PublishedIvaInput } from './simulation-published-iva';
|
||||
import { SimulationMonthlyIva } from './simulation-monthly-iva';
|
||||
import { inheritSimulatorFields, reusedInvestmentValue } from '@/lib/context-inheritance';
|
||||
@@ -1248,7 +1249,7 @@ export function SimulationForm() {
|
||||
if (payload.data) {
|
||||
if (cancelled) return;
|
||||
draftIdRef.current = payload.data.id;
|
||||
draftEtagRef.current = response.headers.get('ETag');
|
||||
draftEtagRef.current = simulationDraftEtag(response.headers.get('ETag'));
|
||||
setDraftVersionNo(payload.data.version_no);
|
||||
setDraftExpiresAt(payload.data.expires_at ?? null);
|
||||
if (canSavePersonalData)
|
||||
@@ -1370,7 +1371,7 @@ export function SimulationForm() {
|
||||
if (currentDraft) {
|
||||
draftIdRef.current = currentDraft.id;
|
||||
draftEtagRef.current =
|
||||
currentResponse.headers.get('ETag');
|
||||
simulationDraftEtag(currentResponse.headers.get('ETag'));
|
||||
sessionStorage.setItem(draftIdKey, currentDraft.id);
|
||||
}
|
||||
}
|
||||
@@ -1432,7 +1433,7 @@ export function SimulationForm() {
|
||||
);
|
||||
draftIdRef.current = payload.data.id;
|
||||
setServerFieldErrors({});
|
||||
draftEtagRef.current = response.headers.get('ETag');
|
||||
draftEtagRef.current = simulationDraftEtag(response.headers.get('ETag'));
|
||||
setDraftVersionNo(payload.data.version_no);
|
||||
lastSavedFingerprintRef.current = fingerprint;
|
||||
sessionStorage.setItem(draftIdKey, payload.data.id);
|
||||
@@ -1593,7 +1594,7 @@ export function SimulationForm() {
|
||||
)
|
||||
throw new Error('Não foi possível abrir este dossier privado.');
|
||||
draftIdRef.current = payload.data.id;
|
||||
draftEtagRef.current = response.headers.get('ETag');
|
||||
draftEtagRef.current = simulationDraftEtag(response.headers.get('ETag'));
|
||||
setDraftVersionNo(payload.data.version_no);
|
||||
setDraftExpiresAt(null);
|
||||
setSelectedAccountDraftId(payload.data.id);
|
||||
@@ -1656,7 +1657,7 @@ export function SimulationForm() {
|
||||
);
|
||||
const record = (payload as { data: ApiSimulationDraftV1 }).data;
|
||||
draftIdRef.current = record.id;
|
||||
draftEtagRef.current = response.headers.get('ETag');
|
||||
draftEtagRef.current = simulationDraftEtag(response.headers.get('ETag'));
|
||||
setDraftVersionNo(record.version_no);
|
||||
setDraftExpiresAt(null);
|
||||
setSelectedAccountDraftId(record.id);
|
||||
@@ -1756,7 +1757,7 @@ export function SimulationForm() {
|
||||
(payload as { expires_at: string }).expires_at,
|
||||
);
|
||||
draftEtagRef.current =
|
||||
response.headers.get('ETag') ?? draftEtagRef.current;
|
||||
simulationDraftEtag(response.headers.get('ETag')) ?? draftEtagRef.current;
|
||||
}
|
||||
setContinueLaterSaved(true);
|
||||
setSaveStatus(
|
||||
@@ -2375,7 +2376,7 @@ export function SimulationForm() {
|
||||
);
|
||||
const draftId = draftIdValue;
|
||||
draftIdRef.current = draftId;
|
||||
draftEtagRef.current = currentResponse.headers.get('ETag');
|
||||
draftEtagRef.current = simulationDraftEtag(currentResponse.headers.get('ETag'));
|
||||
if (!draftEtagRef.current)
|
||||
throw new Error(
|
||||
'O servidor não devolveu a versão actual do rascunho. Recarregue e tente novamente.',
|
||||
@@ -2409,7 +2410,7 @@ export function SimulationForm() {
|
||||
throw new Error(
|
||||
'O servidor devolveu uma confirmação de anexação inválida.',
|
||||
);
|
||||
draftEtagRef.current = response.headers.get('ETag');
|
||||
draftEtagRef.current = simulationDraftEtag(response.headers.get('ETag'));
|
||||
const sources = payload.data?.simulation_sources;
|
||||
if (Array.isArray(sources)) setSimulationSources(sources);
|
||||
setDraft((currentDraft) => ({
|
||||
|
||||
@@ -72,6 +72,26 @@ export function reusedInvestmentValue(scope: string, key: string, values: Record
|
||||
} catch { return null; }
|
||||
}
|
||||
|
||||
/** Report the lineage without changing a stored answer or disclosing the tracking hash. */
|
||||
export function investmentFieldOrigin(values: Record<string, unknown>, key: string, fallback: string): string {
|
||||
try {
|
||||
const reuse = JSON.parse(String(values.context_reuse ?? ''));
|
||||
if (reuse.version !== 1 || !/^dossier:.+:simulator$/.test(reuse.scope) || !reuse.inherited?.[key]) return fallback;
|
||||
const snapshot = JSON.parse(String(values.context_applicability_snapshot ?? ''));
|
||||
const origin = snapshot.field_provenance?.[key];
|
||||
const source = origin?.kind === 'opportunity' ? `oportunidade «${origin.title ?? 'referência guardada'}»`
|
||||
: origin?.kind === 'process_declaration' || origin?.kind === 'dossier' ? 'dados introduzidos pelo utilizador no dossier'
|
||||
: origin?.kind === 'sector' ? `catálogo sectorial «${origin.title ?? 'referência guardada'}»`
|
||||
: origin?.kind === 'territory' ? `catálogo territorial «${origin.title ?? 'referência guardada'}»`
|
||||
: origin?.kind === 'linked_simulation' ? 'simulador ligado ao mesmo dossier'
|
||||
: 'dossier de investimento';
|
||||
const version = origin?.version ? `, versão ${origin.version}` : '';
|
||||
return reuse.inherited[key] === signature(values[key])
|
||||
? `Herdado de ${source}${version}`
|
||||
: `Alterado posteriormente pelo utilizador; origem anterior: ${source}${version}`;
|
||||
} catch { return fallback; }
|
||||
}
|
||||
|
||||
export function inheritSimulatorFields<T extends Record<string,unknown>>(draft:T): T {
|
||||
const source:Record<string,unknown>={};
|
||||
const plan=draft.business_plan_snapshot ? restoreBusinessPlanSnapshot(String(draft.business_plan_snapshot)) : null;
|
||||
|
||||
@@ -229,8 +229,8 @@ function makeSections(
|
||||
{
|
||||
field: 'Projecto',
|
||||
value: absent(text(draft, 'project_title')),
|
||||
origin: 'Informação introduzida no dossier',
|
||||
classification: 'Declarada pelo utilizador',
|
||||
origin: rows.find(row => row[1] === 'Título')?.[3] ?? 'Informação introduzida no dossier',
|
||||
classification: 'Origem indicada no dossier',
|
||||
},
|
||||
{
|
||||
field: 'Data de geração',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { displayValue } from './display-value.ts';
|
||||
import { investmentFieldOrigin } from './context-inheritance.ts';
|
||||
import { investmentLandPreparation } from './investment-land-preparation.ts';
|
||||
import { monthlyIvaInput, monthlyIvaKey, readMonthlyIvaRecord, readMonthlyIvaSettings } from './monthly-iva.ts';
|
||||
import { modeloAPurchaseReferences } from './iva-modelo-a.ts';
|
||||
@@ -705,7 +706,11 @@ export function buildProjectDossierRows(
|
||||
if (land.need === 'yes') rows.push(['Localização', 'Situação do terreno', String(draft.land_status_label ?? ({ owned: 'Próprio', duat: 'DUAT', leased: 'Arrendado', requested: 'Pedido em curso', unknown: 'Por determinar' } as Record<string, string>)[String(draft.land_status)] ?? 'Informação em falta'), 'Informação declarada; não comprova título ou disponibilidade']);
|
||||
else rows.push(['Localização', 'Preparação do terreno', land.need === 'no' ? 'Situação do terreno não aplicável à preparação actual; valores anteriores conservados.' : 'Definir se precisa de terra; pode continuar a preparar o investimento.', 'Sem inferência de dispensa legal']);
|
||||
}
|
||||
return rows;
|
||||
const lineageFields: Record<string, string> = {'Título':'project_title','Resumo':'project_summary','Sector':'sector_id','Província':'province_id','Distrito':'district_id','Posto administrativo':'admin_post_id','Localidade':'locality_id'};
|
||||
return rows.map(row => {
|
||||
const key = lineageFields[row[1]];
|
||||
return key && row[2] ? [row[0], row[1], row[2], investmentFieldOrigin(draft, key, row[3])] : row;
|
||||
});
|
||||
}
|
||||
|
||||
export function exportProjectDossierCsv(
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
/** Compression can mark the representation weak; the draft version token itself is unchanged. */
|
||||
export function simulationDraftEtag(header: string | null): string | null {
|
||||
if (header && /^W\/"sfd-[0-9a-f-]{36}-v[1-9][0-9]*"$/i.test(header)) return header.slice(2);
|
||||
return header;
|
||||
}
|
||||
Reference in New Issue
Block a user