fix: clarify complementary field diagnostics and target exact QA controls

This commit is contained in:
2026-11-21 22:13:16 +02:00
parent 77f621b48d
commit 84018e3f25
27 changed files with 1264 additions and 39 deletions
+28 -1
View File
@@ -112,9 +112,18 @@ const routes: [RegExp, string[]][] = [
['Importar plano financeiro InvestMoz (.json, até 60 KB)'],
],
];
export function correctionFieldHints(message: string): string[] {
export function correctionFieldHints(
message: string,
availableLabels?: string[],
): string[] {
const normal = normaliseFieldLabel(message);
const quoted = [...message.matchAll(/«([^»]+)»/g)].map((m) => m[1]);
const exact = quoted.filter((h) =>
availableLabels?.some(
(label) => normaliseFieldLabel(label) === normaliseFieldLabel(h),
),
);
if (exact.length) return exact;
const mapped = routes
.filter(([pattern]) => pattern.test(normal))
.flatMap(([, labels]) => labels);
@@ -137,6 +146,24 @@ export function fieldLabelMatches(label: string, hint: string): boolean {
(b.length >= 7 && (a.startsWith(b + ' ') || b.startsWith(a + ' '))))
);
}
/** Match repeated groups by kind as well as index; personnel uses Necessidade in the editor. */
export function correctionGroupMatches(
message: string,
groupName: string,
): boolean {
const match =
/\b(produto|parcela|marco|funcao|necessidade|segmento)\s+(\d+)\b/.exec(
normaliseFieldLabel(message),
);
if (!match) return true;
const kind =
match[1] === 'funcao' || match[1] === 'necessidade'
? '(?:funcao|necessidade)'
: match[1];
return new RegExp(`\\b${kind}\\s+${match[2]}\\b`).test(
normaliseFieldLabel(groupName),
);
}
export function revealCorrectionTarget(target: HTMLElement): void {
const control = target.matches(
'input,select,textarea,button,[contenteditable="true"]',