Skip to content

fix(grid): accept 8-char extended locators in the logging form & stations API#249

Merged
patrickrb merged 1 commit into
mainfrom
optio/task-161bff3e-812e-4275-9c2b-6f2620ce3bc8
Jul 24, 2026
Merged

fix(grid): accept 8-char extended locators in the logging form & stations API#249
patrickrb merged 1 commit into
mainfrom
optio/task-161bff3e-812e-4275-9c2b-6f2620ce3bc8

Conversation

@patrickrb

Copy link
Copy Markdown
Owner

Problem

Commit #246 taught the app to understand 8-character (extended) Maidenhead locatorsisValidGrid and gridToLatLon in src/lib/grid.ts accept and geolocate them — and #248 uses the on-air station's grid as the origin for the live distance/bearing readout. VHF/UHF/microwave and satellite operators log 8-char locators for the extra precision.

But three input validators never got the memo and kept their own 4/6-character-only regex (/^[A-R]{2}[0-9]{2}([A-X]{2})?$/):

  • the new-contact logging form's inline validateGridLocator
  • POST /api/stations
  • PUT /api/stations/[id]

So the app that computes a distance from an 8-char grid wouldn't let you enter one:

  • Typing FN31pr55 into the logging form's grid field showed "Invalid grid locator format" and blocked the save.
  • Saving a station with an 8-char grid — the very locator used as the distance origin — returned HTTP 400.

This is the same "local list/regex drifts behind the canonical src/lib module" class of bug fixed for band and mode filters in #241/#242.

Solution

Add one canonical helper to the grid module and route all three call sites through it:

// src/lib/grid.ts
export function gridLocatorError(grid: string): string | null {
  if (!grid.trim()) return null;           // grid is optional everywhere it's validated
  return isValidGrid(grid) ? null : 'Invalid grid locator format (e.g., FN31, FN31pr, or FN31pr55)';
}

Because it delegates to isValidGrid, the logging form and the stations API can no longer drift from the rest of the app. No schema or response-shape changes; validation is only loosened to accept locators the app already stores and geolocates, so it's fully backwards compatible.

Testing

  • Added unit coverage for gridLocatorError (blank/whitespace → no error; 4/6/8-char → valid; malformed → message) in tests/grid.spec.ts.
  • npx playwright test grid.spec.ts30/30 pass.
  • npm run typecheck, npm run lint, npm run build — all clean.

Future follow-up

  • POST /api/stations and PUT /api/stations/[id] share a fair amount of validation logic (callsign, grid, power, zones) that could be extracted into one shared validator; out of scope here.
  • The client station create/edit forms (/stations/new, /stations/[id]/edit) rely on server-side validation for the grid; adding matching inline feedback via gridLocatorError would be a nice parity touch.

🤖 Generated with Claude Code

… API

Commit #246 added canonical 8-character (extended) Maidenhead support to
`src/lib/grid.ts` (`isValidGrid`, `gridToLatLon`), and #248 uses the on-air
station's grid as the distance/bearing origin. But three input validators
kept their own 4/6-only regex and drifted behind:

- `new-contact` form's inline `validateGridLocator`
- `POST /api/stations`
- `PUT /api/stations/[id]`

Result: typing an 8-char grid (e.g. `FN31pr55`) into the logging form showed
"Invalid grid locator format" and blocked save, and saving an 8-char station
grid — the exact locator used as the distance origin — 400'd. VHF/UHF/
microwave and satellite operators log 8-char locators for the extra precision,
so this silently rejected valid input.

Centralize the check as `gridLocatorError(grid)` in the canonical grid module
(null for blank/valid, message otherwise) and route all three call sites
through it, so the form and the API can never drift from `isValidGrid` again.

Tested: added unit coverage for `gridLocatorError` (blank, 4/6/8-char, malformed);
`grid.spec.ts` 30/30 pass; typecheck, lint, and build all clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nodelog Ready Ready Preview, Comment Jul 24, 2026 2:07pm

Request Review

@patrickrb
patrickrb merged commit ca9dbee into main Jul 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant