From 691a9a04a91c008168d3839ac7c69523170f9691 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Wed, 15 Apr 2026 12:42:48 +0530 Subject: [PATCH] refactor: filter out stale profile field values by requiring backend-resolved labels --- src/utils/profileDataMapper.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/utils/profileDataMapper.ts b/src/utils/profileDataMapper.ts index a0c15d6..c10d77d 100644 --- a/src/utils/profileDataMapper.ts +++ b/src/utils/profileDataMapper.ts @@ -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)