ReviewOS

also looking at this

stacks/analyticshq

fix(dashboard): the regions panel says California, not CA

#63
Merged glennmichael123 wants to merge fix/region-panel-shows-names into main
4 files +145 -9
resources/views/dashboard.stxmodified+15-8
Changes to resources/views/dashboard.stx
@@ -17,7 +17,7 @@ import { CH_SEARCH, CH_SOCIAL, channelOf, channelPredicate, countryName, eventUr
1717import { installTargets } from '../../app/Analytics/install'
1818import { listReachableSites, listSiteMembers } from '../../app/Analytics/access'
1919import { planForSite } from '../../app/Analytics/entitlements'
20import { foldRegions, splitRegion } from '../../app/Analytics/regions'
20import { foldRegions, splitRegion, subdivisionName } from '../../app/Analytics/regions'
2121import { cityLabel, foldCities, splitCity } from '../../app/Analytics/cities'
2222import { liveSnapshot } from '../../app/Analytics/realtime'
2323import { niceCeil, xTicks, yTicks } from '../../app/Support/chart-axis'
@@ -983,14 +983,20 @@ const countryRows = countries.map((c) => {
983983 * per-row floor when no other breakdown on this page does. The traffic still
984984 * counts in the total; what is withheld is which state it came from.
985985 *
986 * ## Why the label is a code and not a name
986 * ## Why the label is a name and not a code
987987 *
988988 * `US-CA` is what the column holds, what addFilterUrl puts in the query string,
989 * and what the filter matches, so the code has to survive on the row. Spelling
990 * it out would mean shipping a table of every ISO 3166-2 subdivision name — some
991 * four thousand of them — to render a panel that is off by default. The flag
992 * carries the country and the code carries the state, which is how most of these
993 * are written down anyway.
989 * and what the filter matches — none of which is affected by how the row reads.
990 *
991 * It used to read as the bare code, because spelling it out "would mean shipping
992 * a table of every ISO 3166-2 subdivision name". That table is already shipped:
993 * `subdivisions.json`, which geo.ts has needed since region geo started working
994 * at all. Read backwards it answers this question for nothing.
995 *
996 * The code was only ever legible by accident. `US-CA` passes for California to
997 * an American reader; `PH-07` says nothing to anyone, and a bare `CA` beside a
998 * flag is equally the code for Canada. A subdivision the table cannot name still
999 * shows its code, which is honest about not knowing rather than inventing.
9941000 */
9951001const REGION_FLOOR = siteFloor
9961002const foldedRegions = foldRegions(regions, REGION_FLOOR, 8)
@@ -1013,7 +1019,8 @@ const regionRows = foldedRegions.rows.map((r) => {
10131019 // built out of the wrong two letters.
10141020 if (!parts)
10151021 return { ...r, label: r.region }
1016 return { ...r, label: regionCountry ? parts.subdivision : `${flag(parts.country)} ${parts.subdivision}` }
1022 const named = subdivisionName(r.region) ?? parts.subdivision
1023 return { ...r, label: regionCountry ? named : `${flag(parts.country)} ${named}` }
10171024})
10181025if (foldedRegions.other) {
10191026 regionRows.push({