Wiring organizations entity with Backend Database, with a TSV fallback - #785
Draft
Shikhar16078 wants to merge 1 commit into
Draft
Wiring organizations entity with Backend Database, with a TSV fallback#785Shikhar16078 wants to merge 1 commit into
Shikhar16078 wants to merge 1 commit into
Conversation
Wires the Organization entity onto the same API/TSV pattern territories use: with VITE_API_URL set, try the API first; on any failure, fall back to organizations.tsv instead of leaving the app stuck. Unlike territories, organizations have no supplemental TSV files to skip and no derived values to withhold, so the fallback needs no external tracker - it's entirely self-contained in loadOrganizations(). loadOrganizationsFromApi.ts maps the API response onto OrganizationData, matching the TSV parser's exact behavior field-for-field (including two of its quirks: an empty Headquarters column stays '' rather than becoming undefined, and an empty endonym is dropped from `names` the same way a falsy check would). Verified with a live parity test against all 57 organizations in the database, plus unit tests for the mapping and the fallback/success paths.
Shikhar16078
force-pushed
the
migration/backend-organization
branch
from
September 8, 2026 19:27
0b31c9e to
e8af43f
Compare
Contributor
Cloudflare Pages preview
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary: Wires the Organization entity onto the PostgREST API introduced by the backend migration, following the same pattern established for Territory: try the API first when
VITE_API_URLis configured, fall back toorganizations.tsvon any failure. This is one entity's slice of the wider migration.Changes
loadOrganizations()now triesloadOrganizationsFromApi()first when the API is enabled, and falls back to the TSV file (with a console warning) if that fails.loadOrganizationsFromApi.tsmaps theorganization+ embeddedentityrows from PostgREST ontoOrganizationData, matchingparseOrganizationLine's exact behavior — including its quirks (hqIDstays''rather thanundefinedwhen absent;namesuses a truthy filter, dropping empty strings as well as null/undefined).org.-prefixed ids, bare territory codes), and there are no supplemental TSV files to skip.organization/entitytables the ETL already populates fromorganizations.tsv.orUndefined()helper intoapiConfig.ts(Territory's loader keeps its own private copy, left untouched — out of scope for this PR).Out of scope/Future work: Territory still has no fallback to TSV on this branch if its API call fails — that work is on a separate, unmerged branch. This PR does not touch Territory. Two known, pre-existing issues are also explicitly not addressed here: a React StrictMode double-invoke race in
DataProvider.tsx, and an API response of[]being read as a successful (if empty) load. Both belong in their own PR.Test Plan
How to test the changes in this PR: Start the local backend (
brew services start postgresql@18, thenpostgrest backend/tools/postgrest.conf), setVITE_API_URL=http://localhost:3000in.env, runnpm run dev, and load any Organization page/detail view. Stop PostgREST and reload — organizations should still populate via the TSV fallback, withOrganization API load failed; falling back to TSV files.in the console and no "Error loading data" alert.Checklist
Summary
Testing
npm run lintnpm run build— passes for this PR's own files; a pre-existing type error in a teammate'sloadLanguagesFromApi.test.tscurrently blocks the fulltsc -bonmigration/backenditself, unrelated to this changenpm run test— 434 passed, 0 failed, 11 skipped (gated live-backend parity tests)loadOrganizationsFromApi.test.ts,loadOrganizationsParity.test.ts,loadOrganizations.test.ts)npm run dev-- tried out the website directlyChanges
Visual changes
Data changes
public/data/public/data/src/features/data/including how we aggregate data or compute derived valuesInternal changes
Docs
docs/api-data-source.md).