feat(qa): complete market milestones and personnel report tables

This commit is contained in:
2026-11-20 12:45:14 +02:00
parent f3148d1674
commit 4fb9296f70
14 changed files with 1041 additions and 7 deletions
@@ -3,6 +3,9 @@ import {
type ProjectMilestone,
type TeamNeed,
} from '@/lib/project-dossier';
import { restoreBusinessPlanSnapshot } from '@/lib/business-financial-plan';
import { buildComplementaryTables } from '@/lib/complementary-report';
import { InvestmentReportTables } from './investment-report-tables';
const teamKeys = [
'competency',
@@ -28,15 +31,84 @@ function update<T extends Record<string, string>>(
return rows.map((row, i) => (i === index ? { ...row, [key]: value } : row));
}
function unreadable(value: string, rows: unknown[], optional: string[]) {
try {
const parsed: unknown = JSON.parse(value || '[]');
return (
!Array.isArray(parsed) ||
parsed.length !== rows.length ||
parsed.length > 100 ||
parsed.some((row) =>
optional.some(
(key) => key in row && typeof row[key] !== 'string',
),
)
);
} catch {
return true;
}
}
function SupplementaryFields({
row,
fields,
change,
}: {
row: Record<string, string | undefined>;
fields: readonly (readonly [string, string, string])[];
change: (key: string, value: string) => void;
}) {
return (
<>
{fields.map(([key, label, type]) => (
<label className="grid min-w-0 gap-1 text-sm" key={key}>
{label}
<input
className="min-w-0 rounded border p-2"
type={type}
min={type === 'number' ? 0 : undefined}
step={
type === 'number'
? key === 'monthly_salary'
? '0.01'
: '1'
: undefined
}
value={row[key] ?? ''}
onChange={(e) => change(key, e.target.value)}
/>
</label>
))}
</>
);
}
export function ProjectTeamPlanner({
value,
onChange,
financialPlanSnapshot = '',
}: {
value: string;
onChange: (value: string) => void;
financialPlanSnapshot?: string;
}) {
const rows = readRows<TeamNeed>(value, teamKeys);
const persist = (next: TeamNeed[]) => onChange(JSON.stringify(next));
if (
unreadable(value, rows, [
'department',
'quantity',
'monthly_salary',
'start_month',
'end_month',
])
)
return (
<p role="alert">
O plano de equipa guardado contém linhas não reconhecidas. O
original foi preservado e não será substituído por este editor.
</p>
);
return (
<section
className="space-y-4"
@@ -47,6 +119,12 @@ export function ProjectTeamPlanner({
custo e prazo. Não é uma certificação nem uma correspondência
automática a prestadores.
</p>
<p className="text-sm">
Para o mapa de pessoal: função, departamento, quantidade,
remuneração mensal e meses inicial/final são necessários. Os
restantes campos são opcionais; não confundir custo de formação
ou contratação com salário.
</p>
{rows.map((row, index) => (
<fieldset
key={index}
@@ -55,6 +133,42 @@ export function ProjectTeamPlanner({
<legend className="font-medium">
Necessidade {index + 1}
</legend>
<SupplementaryFields
row={row}
fields={[
[
'department',
'Departamento (mapa de pessoal)',
'text',
],
[
'quantity',
'Quantidade de pessoas (inteiro)',
'number',
],
[
'monthly_salary',
'Remuneração mensal por pessoa (moeda do projecto)',
'number',
],
[
'start_month',
'Mês inicial no plano (1 = Janeiro do ano inicial)',
'number',
],
['end_month', 'Mês final no plano', 'number'],
]}
change={(key, value) =>
persist(
update(
rows,
index,
key as keyof TeamNeed,
value,
),
)
}
/>
<label className="text-sm">
Competência ou função
<input
@@ -180,6 +294,14 @@ export function ProjectTeamPlanner({
>
Adicionar competência ou lacuna
</button>
<InvestmentReportTables
tables={[
buildComplementaryTables(
{ project_team_snapshot: value },
restoreBusinessPlanSnapshot(financialPlanSnapshot),
)[2],
]}
/>
</section>
);
}
@@ -194,6 +316,13 @@ export function ProjectMilestonePlanner({
const rows = readRows<ProjectMilestone>(value, milestoneKeys);
const persist = (next: ProjectMilestone[]) =>
onChange(JSON.stringify(next));
if (unreadable(value, rows, ['start_date', 'responsible', 'department']))
return (
<p role="alert">
O plano de marcos guardado contém linhas não reconhecidas. O
original foi preservado e não será substituído por este editor.
</p>
);
return (
<section className="space-y-4" aria-label="Marcos de execução">
<p className="text-sm text-slate-700">
@@ -201,12 +330,35 @@ export function ProjectMilestonePlanner({
valores são declarados; não alteram automaticamente o plano
financeiro.
</p>
<p className="text-sm">
Para completar o relatório, indique título, início, término,
responsável, departamento e orçamento. O montante realizado é
opcional.
</p>
{rows.map((row, index) => (
<fieldset
key={index}
className="grid gap-3 rounded border p-3 sm:grid-cols-2"
>
<legend className="font-medium">Marco {index + 1}</legend>
<SupplementaryFields
row={row}
fields={[
['start_date', 'Data de início', 'date'],
['responsible', 'Responsável pelo marco', 'text'],
['department', 'Departamento do marco', 'text'],
]}
change={(key, value) =>
persist(
update(
rows,
index,
key as keyof ProjectMilestone,
value,
),
)
}
/>
<label className="text-sm">
Marco ou resultado
<input
@@ -334,6 +486,14 @@ export function ProjectMilestonePlanner({
>
Adicionar marco
</button>
<InvestmentReportTables
tables={[
buildComplementaryTables(
{ project_execution_snapshot: value },
null,
)[1],
]}
/>
</section>
);
}