plinth-people.ts
Language TypeScript2.7 KB65 lines
/*** Plinth account label -> display name.** Plinth stores assignments as account labels, not names, and they arrive on* the orders.fetch response as production_owner and account_owner. As seen in* the assignment dropdown:** Rafael-Prod-Desk* Sam-Accounts-Desk* Hazel (Desk 2) (the account label; Rosa holds it now)* Marco-Acct7-Desk* Devin** Three naming patterns across five accounts, so a regex alone will not* do it: "Hazel (Desk 2)" and a bare "Devin" need different handling from* the hyphenated ones. An explicit map is authoritative; the regex is a fallback* so a new account still renders as something readable instead of raw.** Role is not in the label. Marco is a designer and his account reads* "Marco-Acct7-Desk"; Sam is Client Success and reads "Sam-Accounts-Desk".* The Accounts/Prod tokens in these strings are not reliable role markers. Role* comes from which field the value sits in (production_owner means designer,* account_owner means CS) and never from the label text.*//** Authoritative. Add every account here as it appears. */export const PLINTH_ACCOUNT_NAMES: Record<string, string> = {'rafael-prod-desk': 'Rafael Montero','sam-accounts-desk': 'Sam Whitaker',// The label did not change when the person did. Rosa Galván took over as the// account owner in place of Hazel, and Plinth kept the field// name and value, so the orders assigned to that value are now hers. The Plinth// string stays and the name it maps to moves, which also means orders// assigned before the change resolve to Rosa. That is intended, not a bug:// the alternative is half the CS queue resolving to nobody.'hazel (desk 2)': 'Rosa Galván','marco-acct7-desk': 'Marco Ibáñez',devin: 'Devin',}/*** Best-effort cleanup for an account label not in the map.** Takes the leading token before a hyphen or a parenthetical, which handles the* observed patterns. Deliberately conservative: if it cannot do better it* returns the original rather than mangling it, because a wrong name on a* bandwidth row is worse than an ugly one.*/export function displayName(accountLabel: string | null | undefined): string | null {if (!accountLabel) return nullconst raw = accountLabel.trim()if (!raw) return nullconst mapped = PLINTH_ACCOUNT_NAMES[raw.toLowerCase()]if (mapped) return mappedconst leading = raw.split(/\s*[-(]/)[0]?.trim()return leading && leading.length >= 2 ? leading : raw}/** True when the label is not in the authoritative map: worth flagging on the page. */export function isUnmappedAccount(accountLabel: string | null | undefined): boolean {if (!accountLabel?.trim()) return falsereturn !(accountLabel.trim().toLowerCase() in PLINTH_ACCOUNT_NAMES)}