refactor: filter out stale profile field values by requiring backend-resolved labels
This commit is contained in:
@@ -291,13 +291,21 @@ export function mapFieldValuesToAvailability(fieldValues: FieldValueResponse[]):
|
||||
return trimmed;
|
||||
};
|
||||
|
||||
// Prefer backend-resolved labels, fall back to raw value with snake_case formatting
|
||||
const resolvedLabels = rawValues.map((val, i) => {
|
||||
// Use backend-resolved labels only. Drop stale/orphan values whose option is no longer
|
||||
// defined in the profile field (backend returns no label for them) — prevents old
|
||||
// selections from lingering when admin renames/removes options.
|
||||
const resolvedLabels: string[] = [];
|
||||
rawValues.forEach((val, i) => {
|
||||
const fromBackend = labelValues[i];
|
||||
if (fromBackend && typeof fromBackend === 'string' && fromBackend.trim()) {
|
||||
return formatIfSnakeCase(fromBackend);
|
||||
resolvedLabels.push(formatIfSnakeCase(fromBackend));
|
||||
return;
|
||||
}
|
||||
return formatIfSnakeCase(val);
|
||||
// No backend label → likely a stale option; skip unless it's already a human-readable string
|
||||
const raw = String(val || '').trim();
|
||||
if (!raw) return;
|
||||
if (/^[a-z0-9]+(_[a-z0-9]+)+$/i.test(raw)) return; // skip snake_case orphans
|
||||
resolvedLabels.push(formatIfSnakeCase(raw));
|
||||
});
|
||||
|
||||
// Deduplicate by normalized comparison (case/whitespace insensitive)
|
||||
|
||||
Reference in New Issue
Block a user