fix: correct V13 and public presentation patterns in isolated QA
This commit is contained in:
@@ -14,6 +14,7 @@ const catalogueKeys: Record<string, string[]> = {
|
||||
'legal_regime',
|
||||
'development_status',
|
||||
'availability_status',
|
||||
'activity',
|
||||
'province',
|
||||
],
|
||||
'/oportunidades': [
|
||||
@@ -49,6 +50,34 @@ const catalogueKeys: Record<string, string[]> = {
|
||||
'subsector_id',
|
||||
],
|
||||
};
|
||||
/** Remove actual filter keys, including indexed arrays and dependent selections. */
|
||||
export function catalogueFilterHref(
|
||||
pageUrl: string,
|
||||
keys: string[],
|
||||
remove?: string,
|
||||
): string {
|
||||
const url = new URL(pageUrl, 'https://portal.invalid');
|
||||
const dependencies: Record<string, string[]> = {
|
||||
province_id: ['district_id', 'admin_post_id', 'locality_id'],
|
||||
district_id: ['admin_post_id', 'locality_id'],
|
||||
admin_post_id: ['locality_id'],
|
||||
sector: ['subsector_id', 'chain_id'],
|
||||
};
|
||||
const selected = new Set(
|
||||
remove ? [remove, ...(dependencies[remove] ?? [])] : keys,
|
||||
);
|
||||
const presentKeys = Array.from(url.searchParams.keys());
|
||||
for (const key of presentKeys)
|
||||
if (
|
||||
selected.has(key) ||
|
||||
[...selected].some((base) =>
|
||||
key.startsWith(base.replace(/\[\]$/, '') + '['),
|
||||
)
|
||||
)
|
||||
url.searchParams.delete(key);
|
||||
url.searchParams.delete('page');
|
||||
return url.pathname + url.search;
|
||||
}
|
||||
function family(path: string): string {
|
||||
if (path.startsWith('/management/portfolio')) return '/carteira';
|
||||
if (path.startsWith('/management/investment/zones')) return '/zonas';
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
/** Presentation routing for existing diagnostics only; never validates or edits values. */
|
||||
export const normaliseFieldLabel = (value: string) =>
|
||||
value
|
||||
.normalize('NFD')
|
||||
.replace(/[\u0300-\u036f]/g, '')
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, ' ')
|
||||
.trim();
|
||||
const routes: [RegExp, string[]][] = [
|
||||
[
|
||||
/unidades.*produto|quantidade.*produto/,
|
||||
['Unidades por mes', 'Unidades mensais base'],
|
||||
],
|
||||
[/preco.*produto|preco por unidade/, ['Preço por unidade']],
|
||||
[/custo variavel.*produto/, ['Custo variável por unidade']],
|
||||
[/prazo.*dias/, ['Prazo (dias)', 'Prazo contratual (dias)']],
|
||||
[
|
||||
/preencha.*montantes.*relatorio/,
|
||||
[
|
||||
'Activos fixos anteriores (valor líquido)',
|
||||
'Outros activos anteriores',
|
||||
'Capital e resultados anteriores',
|
||||
],
|
||||
],
|
||||
[
|
||||
/capital discriminado|capital proprio.*coincide|capital do proprietario/,
|
||||
[
|
||||
'Capital próprio',
|
||||
'Capital do proprietário',
|
||||
'Capital do investidor',
|
||||
'Capital adicional angariado',
|
||||
],
|
||||
],
|
||||
[
|
||||
/saldos de abertura|capital e resultados anteriores/,
|
||||
[
|
||||
'Capital e resultados anteriores',
|
||||
'Saldo de caixa inicial',
|
||||
'Activos fixos anteriores (valor líquido)',
|
||||
'Outros activos anteriores',
|
||||
'Existências iniciais',
|
||||
'Valores a receber',
|
||||
'Valores a pagar',
|
||||
],
|
||||
],
|
||||
[
|
||||
/depreciacao.*excede|base depreciavel/,
|
||||
[
|
||||
'Base depreciável contabilística',
|
||||
'Vida útil (meses)',
|
||||
'Aquisição de activos',
|
||||
'Activos fixos anteriores (valor líquido)',
|
||||
],
|
||||
],
|
||||
[
|
||||
/reembolso.*excede|divida declarada/,
|
||||
['Reembolso de capital', 'Empréstimo recebido', 'Suprimentos'],
|
||||
],
|
||||
[
|
||||
/existencias iniciais.*produto/,
|
||||
['Existências iniciais', 'Existências iniciais do produto'],
|
||||
],
|
||||
[
|
||||
/stock insuficiente|existencias insuficientes/,
|
||||
[
|
||||
'Existências iniciais',
|
||||
'Encomenda',
|
||||
'Prazo de recepcao',
|
||||
'Unidades por mes',
|
||||
],
|
||||
],
|
||||
[
|
||||
/aquisicoes.*necessidades|arranque.*aquisicao/,
|
||||
[
|
||||
'Aquisição de activos',
|
||||
'Caixa requerida',
|
||||
'Outros activos correntes requeridos',
|
||||
'Activos de longo prazo requeridos',
|
||||
],
|
||||
],
|
||||
[/ano inicial/, ['Ano inicial']],
|
||||
[/fonte.*pressuposto fiscal/, ['Fonte ou pressuposto fiscal']],
|
||||
[
|
||||
/imposto estimado.*pagamento fiscal/,
|
||||
['Imposto estimado', 'Pagamento fiscal'],
|
||||
],
|
||||
[
|
||||
/recebimentos manuais|natureza.*cobrancas/,
|
||||
['Natureza dos recebimentos manuais', 'Recebimentos mensais'],
|
||||
],
|
||||
[
|
||||
/mapa de pessoal|folha salarial/,
|
||||
[
|
||||
'Quantidade',
|
||||
'Remuneração mensal',
|
||||
'Meses activos',
|
||||
'Custo mensal de pessoal',
|
||||
'Moeda do custo',
|
||||
],
|
||||
],
|
||||
[
|
||||
/percentagem.*recebiveis|cobrancas.*recebiveis/,
|
||||
[
|
||||
'Percentagem do saldo inicial',
|
||||
'Percentagem de cobrança dos valores a receber de abertura',
|
||||
],
|
||||
],
|
||||
[/recuperacao.*mes|mes unico/, ['Mês']],
|
||||
[/moeda.*pessoal|moeda da folha/, ['Moeda do custo', 'Moeda do plano']],
|
||||
[
|
||||
/ficheiro|snapshot|importa/,
|
||||
['Importar plano financeiro InvestMoz (.json, até 60 KB)'],
|
||||
],
|
||||
];
|
||||
export function correctionFieldHints(message: string): string[] {
|
||||
const normal = normaliseFieldLabel(message);
|
||||
const quoted = [...message.matchAll(/«([^»]+)»/g)].map((m) => m[1]);
|
||||
const mapped = routes
|
||||
.filter(([pattern]) => pattern.test(normal))
|
||||
.flatMap(([, labels]) => labels);
|
||||
const prefix = message.split(':')[0].split('/').at(-1)?.trim() ?? '';
|
||||
return [
|
||||
...new Set([
|
||||
...quoted,
|
||||
...mapped,
|
||||
...(prefix.length >= 4 ? [prefix] : []),
|
||||
]),
|
||||
];
|
||||
}
|
||||
export function fieldLabelMatches(label: string, hint: string): boolean {
|
||||
const a = normaliseFieldLabel(label),
|
||||
b = normaliseFieldLabel(hint);
|
||||
return (
|
||||
!!a &&
|
||||
!!b &&
|
||||
(a === b ||
|
||||
(b.length >= 7 && (a.startsWith(b + ' ') || b.startsWith(a + ' '))))
|
||||
);
|
||||
}
|
||||
export function revealCorrectionTarget(target: HTMLElement): void {
|
||||
const control = target.matches(
|
||||
'input,select,textarea,button,[contenteditable="true"]',
|
||||
)
|
||||
? target
|
||||
: (target.querySelector<HTMLElement>(
|
||||
'input:not([type="hidden"]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),[contenteditable="true"]',
|
||||
) ?? target);
|
||||
for (
|
||||
let node: HTMLElement | null = control.parentElement;
|
||||
node;
|
||||
node = node.parentElement
|
||||
)
|
||||
if (node instanceof HTMLDetailsElement) node.open = true;
|
||||
control.scrollIntoView({ block: 'center', behavior: 'auto' });
|
||||
control.focus({ preventScroll: true });
|
||||
}
|
||||
export function focusCorrectionId(id: string): void {
|
||||
let attempts = 0;
|
||||
const locate = () => {
|
||||
const target = document.getElementById(id);
|
||||
if (target) revealCorrectionTarget(target);
|
||||
else if (++attempts < 10) requestAnimationFrame(locate);
|
||||
};
|
||||
requestAnimationFrame(locate);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
/** Public presentation only. Originals, source records and management fields stay intact. */
|
||||
export function publicReference(
|
||||
value: string | null | undefined,
|
||||
): string | null {
|
||||
const text = value?.trim();
|
||||
if (!text) return null;
|
||||
if (/^(?:javascript|data|vbscript|file):/i.test(text)) return null;
|
||||
if (/^https?:\/\//i.test(text)) {
|
||||
try {
|
||||
const u = new URL(text);
|
||||
if (
|
||||
u.username ||
|
||||
u.password ||
|
||||
/^(?:localhost|127\.|10\.|192\.168\.|172\.(?:1[6-9]|2\d|3[01])\.|\[?::1)/i.test(
|
||||
u.hostname,
|
||||
)
|
||||
)
|
||||
return null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (
|
||||
/(?:\/(?:outputs|resources\/js|node_modules|tests)\/|\.(?:tsx?|jsx?|sql|py|cjs|mjs)(?:[?#]|$))/i.test(
|
||||
new URL(text).pathname,
|
||||
)
|
||||
)
|
||||
return null;
|
||||
return text;
|
||||
}
|
||||
if (
|
||||
/(?:[A-Z]:[\\/]|\\\\|file:\/\/|(?:^|[\s/])(?:outputs|resources|storage|vendor|node_modules|docs|tests|app)[\\/]|\b(?:localhost|127\.0\.0\.\d|0\.0\.0\.0)\b|\.(?:tsx?|jsx?|py|php|sql|md|json|log|cjs|mjs)(?:\b|$)|\b(?:MASTER|AUD|QA|REQ|ME|PN)[-_ ](?:[A-Z]*\d|[A-Z0-9]{6,})|\bgit\s+(?:commit|branch|diff)\b)/i.test(
|
||||
text,
|
||||
)
|
||||
)
|
||||
return null;
|
||||
return text;
|
||||
}
|
||||
export function uniquePresentation<T>(
|
||||
rows: readonly T[],
|
||||
key: (row: T) => string,
|
||||
): T[] {
|
||||
const seen = new Set<string>();
|
||||
return rows.filter((row) => {
|
||||
const id = key(row);
|
||||
if (seen.has(id)) return false;
|
||||
seen.add(id);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
export function publicLocation(
|
||||
path: { name: string; location_type?: string }[] | undefined,
|
||||
fallback: (string | null | undefined)[] = [],
|
||||
): string {
|
||||
const names = (path?.length ? path.map((p) => p.name) : fallback).filter(
|
||||
(v): v is string => !!v?.trim(),
|
||||
);
|
||||
return (
|
||||
names.map((v) => v.trim()).join(' · ') || 'Localização por confirmar'
|
||||
);
|
||||
}
|
||||
|
||||
export function publicSourceHref(
|
||||
value: string | null | undefined,
|
||||
): string | undefined {
|
||||
const text = publicReference(value);
|
||||
return text && /^https?:\/\//i.test(text) ? text : undefined;
|
||||
}
|
||||
|
||||
/** Replace known editorial cross-reference codes with their published names. */
|
||||
export function publicPortfolioText(
|
||||
value: string,
|
||||
names: Record<string, string>,
|
||||
): string {
|
||||
const codes = Object.keys(names)
|
||||
.filter(Boolean)
|
||||
.sort((a, b) => b.length - a.length);
|
||||
if (!codes.length) return value;
|
||||
const escaped = codes.map((code) =>
|
||||
code.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'),
|
||||
);
|
||||
return value.replace(
|
||||
new RegExp(
|
||||
`(?<![\\p{L}\\p{N}_])(${escaped.join('|')})(?![\\p{L}\\p{N}_])`,
|
||||
'gu',
|
||||
),
|
||||
(code) => names[code],
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user