mattrguerra/meridian-ops-boardmainPrivate on GitHub, published here in full

plinth-people.ts

Language TypeScript2.7 KB65 lines

config/plinth-people.ts

  1. /**
  2. * Plinth account label -> display name.
  3. *
  4. * Plinth stores assignments as account labels, not names, and they arrive on
  5. * the orders.fetch response as production_owner and account_owner. As seen in
  6. * the assignment dropdown:
  7. *
  8. * Rafael-Prod-Desk
  9. * Sam-Accounts-Desk
  10. * Hazel (Desk 2) (the account label; Rosa holds it now)
  11. * Marco-Acct7-Desk
  12. * Devin
  13. *
  14. * Three naming patterns across five accounts, so a regex alone will not
  15. * do it: "Hazel (Desk 2)" and a bare "Devin" need different handling from
  16. * the hyphenated ones. An explicit map is authoritative; the regex is a fallback
  17. * so a new account still renders as something readable instead of raw.
  18. *
  19. * Role is not in the label. Marco is a designer and his account reads
  20. * "Marco-Acct7-Desk"; Sam is Client Success and reads "Sam-Accounts-Desk".
  21. * The Accounts/Prod tokens in these strings are not reliable role markers. Role
  22. * comes from which field the value sits in (production_owner means designer,
  23. * account_owner means CS) and never from the label text.
  24. */
  25. /** Authoritative. Add every account here as it appears. */
  26. export const PLINTH_ACCOUNT_NAMES: Record<string, string> = {
  27. 'rafael-prod-desk': 'Rafael Montero',
  28. 'sam-accounts-desk': 'Sam Whitaker',
  29. // The label did not change when the person did. Rosa Galván took over as the
  30. // account owner in place of Hazel, and Plinth kept the field
  31. // name and value, so the orders assigned to that value are now hers. The Plinth
  32. // string stays and the name it maps to moves, which also means orders
  33. // assigned before the change resolve to Rosa. That is intended, not a bug:
  34. // the alternative is half the CS queue resolving to nobody.
  35. 'hazel (desk 2)': 'Rosa Galván',
  36. 'marco-acct7-desk': 'Marco Ibáñez',
  37. devin: 'Devin',
  38. }
  39. /**
  40. * Best-effort cleanup for an account label not in the map.
  41. *
  42. * Takes the leading token before a hyphen or a parenthetical, which handles the
  43. * observed patterns. Deliberately conservative: if it cannot do better it
  44. * returns the original rather than mangling it, because a wrong name on a
  45. * bandwidth row is worse than an ugly one.
  46. */
  47. export function displayName(accountLabel: string | null | undefined): string | null {
  48. if (!accountLabel) return null
  49. const raw = accountLabel.trim()
  50. if (!raw) return null
  51. const mapped = PLINTH_ACCOUNT_NAMES[raw.toLowerCase()]
  52. if (mapped) return mapped
  53. const leading = raw.split(/\s*[-(]/)[0]?.trim()
  54. return leading && leading.length >= 2 ? leading : raw
  55. }
  56. /** True when the label is not in the authoritative map: worth flagging on the page. */
  57. export function isUnmappedAccount(accountLabel: string | null | undefined): boolean {
  58. if (!accountLabel?.trim()) return false
  59. return !(accountLabel.trim().toLowerCase() in PLINTH_ACCOUNT_NAMES)
  60. }