Skip to content

fix(settings): allow negative coordinates in position config - #1381

Open
dzienisz wants to merge 3 commits into
meshtastic:mainfrom
dzienisz:fix/negative-position-coordinates
Open

fix(settings): allow negative coordinates in position config#1381
dzienisz wants to merge 3 commits into
meshtastic:mainfrom
dzienisz:fix/negative-position-coordinates

Conversation

@dzienisz

@dzienisz dzienisz commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #1308.

Number.parseFloat("-").toString() produced "NaN" while typing a negative latitude/longitude, preventing users in the southern/western hemisphere from entering coordinates. This change preserves intermediate values (-, empty string, trailing decimal point) and only normalizes complete numbers.

Also fixes the latitude/longitude field length limits so negative values with 7 decimal places fit (-34.1147648 / -180.0000000).

Adds Zod refine validation on latitude and longitude to enforce a maximum of 7 decimal places, matching the wire format precision (latitudeI/longitudeI are stored as degrees × 10⁷).

Adds unit tests for the position schema covering positive/negative coordinates, 7 decimal precision, and out-of-range values.

Generated with Devin

Summary by CodeRabbit

  • Bug Fixes
    • Improved numeric input handling by preserving temporary values such as empty fields, negative signs, and trailing decimals.
    • Prevented invalid numeric entries from being replaced with “NaN.”
    • Increased the maximum input lengths for latitude and longitude values.
    • Added validation to reject latitude and longitude values with more than seven decimal places while retaining range checks.
    • Empty latitude and longitude fields are now treated as unset rather than zero.

@vercel

vercel Bot commented Aug 3, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Meshtastic Team on Vercel.

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Aug 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2d7c85a4-12be-4e9a-bac5-aee7c4819eb4

📥 Commits

Reviewing files that changed from the base of the PR and between ff5e127 and 0f9a45e.

📒 Files selected for processing (4)
  • apps/web/src/components/Form/FormInput.test.ts
  • apps/web/src/components/Form/FormInput.tsx
  • apps/web/src/validation/config/position.test.ts
  • apps/web/src/validation/config/position.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Numeric input handling now preserves intermediate and invalid values. Position fields support longer coordinate values. Position validation limits optional latitude and longitude values to seven decimal places while retaining range checks.

Changes

Numeric position input handling

Layer / File(s) Summary
Preserve numeric input states
apps/web/src/components/Form/FormInput.tsx, apps/web/src/components/Form/FormInput.test.ts
normalizeNumberInput preserves intermediate and invalid numeric text. Complete finite numbers are normalized with Number(...).toString().
Validate position values
apps/web/src/validation/config/position.ts, apps/web/src/components/PageComponents/Settings/Position.tsx, apps/web/src/validation/config/position.test.ts
Latitude and longitude retain range checks, allow at most seven decimal places, coerce empty strings to undefined, and support maximum lengths of 11 and 12 characters. Tests cover valid coordinates, excessive precision, boundaries, and empty values.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 0f9a4

The change allows negative latitude and longitude entry while preserving valid range and precision checks. No actionable merge-blocking risk remains beyond normal checks and review.

Poem

A rabbit keeps the minus sign near,
The trailing dot stays clear.
Complete numbers settle in line,
Seven decimal places define.
Empty fields disappear.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary change: enabling negative coordinates in the position configuration.
Description check ✅ Passed The description explains the bug, links issue #1308, summarizes the implementation, and identifies the added unit tests. It omits the template headings and checklist, but the required information is m…
Linked Issues check ✅ Passed The changes satisfy issue #1308 by preserving negative-coordinate input, supporting the required field lengths, enforcing valid coordinate ranges and seven-decimal precision, and adding relevant tests…
Out of Scope Changes check ✅ Passed The changed input handling, field limits, validation, and tests are directly related to fixing negative coordinate entry and enforcing the documented coordinate format.
Full details: Description check

Explanation

The description explains the bug, links issue #1308, summarizes the implementation, and identifies the added unit tests. It omits the template headings and checklist, but the required information is mostly present.

Full details: Linked Issues check

Explanation

The changes satisfy issue #1308 by preserving negative-coordinate input, supporting the required field lengths, enforcing valid coordinate ranges and seven-decimal precision, and adding relevant tests.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/components/Form/FormInput.tsx`:
- Around line 73-75: Update the onChange normalization around parsed in
FormInput so numeric validation covers the complete newValue rather than
accepting parseFloat prefixes. Preserve intermediate empty, negative, and
decimal-typing states, accept only finite complete numeric values (including
-34.1147648), and retain invalid text such as "1e", "12abc", "1.2.3", and
"Infinity"; add regression tests for the specified cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3e792b89-18de-453a-9a77-c6a6f620759f

📥 Commits

Reviewing files that changed from the base of the PR and between 9a47442 and 2b016f0.

📒 Files selected for processing (2)
  • apps/web/src/components/Form/FormInput.tsx
  • apps/web/src/components/PageComponents/Settings/Position.tsx
💤 Files with no reviewable changes (1)
  • apps/web/src/components/PageComponents/Settings/Position.tsx

Comment thread apps/web/src/components/Form/FormInput.tsx Outdated
@dzienisz
dzienisz force-pushed the fix/negative-position-coordinates branch from 2b016f0 to ce35dc3 Compare August 3, 2026 19:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/validation/config/position.ts`:
- Around line 24-35: Update the latitude and longitude schemas in the position
validation definition to normalize blank string inputs to undefined before
numeric coercion, preserving optional behavior for cleared fields. Ensure
clearing either coordinate, or both coordinates, produces undefined rather than
numeric zero in the form output consumed by submit.
- Around line 6-10: Update maxDecimalPlaces to account for exponent digits when
validating decimal precision, rather than relying only on splitting
value.toString() at the decimal point. Ensure exponential values such as 1.2e-7
are rejected when their effective decimal places exceed places, while preserving
the existing undefined and valid-precision behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a9d656bb-d944-4eb8-80b7-8b93708f6c19

📥 Commits

Reviewing files that changed from the base of the PR and between 2b016f0 and ce35dc3.

📒 Files selected for processing (3)
  • apps/web/src/components/Form/FormInput.tsx
  • apps/web/src/components/PageComponents/Settings/Position.tsx
  • apps/web/src/validation/config/position.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/src/components/Form/FormInput.tsx

Comment thread apps/web/src/validation/config/position.ts
Comment thread apps/web/src/validation/config/position.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/validation/config/position.test.ts`:
- Around line 53-67: Extend the tests around PositionValidationSchema to cover
both sides of each coordinate bound: reject latitude -91 and longitude 181, and
verify the inclusive boundary values -90, 90, -180, and 180 are accepted using
validBase.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: dab35dee-e7ee-455d-8eac-b526957fd03f

📥 Commits

Reviewing files that changed from the base of the PR and between ce35dc3 and ff5e127.

📒 Files selected for processing (1)
  • apps/web/src/validation/config/position.test.ts

Comment thread apps/web/src/validation/config/position.test.ts Outdated
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
web-test Ready Ready Preview Aug 8, 2026 7:36pm

Request Review

@danditomaso

Copy link
Copy Markdown
Collaborator

Thank you for the contribution. Please resolve the CodeRabbit comments on the PR, many are valid concerned about the submitted code.

Kamil Dzieniszewski added 2 commits August 29, 2026 13:33
…sion

Preserve intermediate input values (-, empty string, trailing decimal point)
in number fields instead of converting them to "NaN".

Raise the latitude/longitude fieldLength limits so negative values with
7 decimal places fit (-34.1147648 / -180.0000000).

Add Zod refine validation that enforces a maximum of 7 decimal places on
latitude and longitude, replacing the incorrect string-length-based check.

Fixes meshtastic#1308

Generated with [Devin](https://devin.ai)
Covers positive/negative latitude and longitude with 7 decimal places,
rejection of values exceeding 7 decimal places, and rejection of values
outside the valid range.

Generated with [Devin](https://devin.ai)
@dzienisz
dzienisz force-pushed the fix/negative-position-coordinates branch from d1f81fc to d1f3ccc Compare August 29, 2026 11:33
@dzienisz

Copy link
Copy Markdown
Contributor Author
Screenshot 2026-08-29 at 15 32 12 Screenshot 2026-08-29 at 15 32 17

@dzienisz

Copy link
Copy Markdown
Contributor Author

@danditomaso check it now

@danditomaso

Copy link
Copy Markdown
Collaborator

@danditomaso check it now

Looks good! Thanks for fixing this!

@danditomaso
danditomaso enabled auto-merge August 29, 2026 14:09
@danditomaso
danditomaso self-requested a review August 29, 2026 14:09
const maxDecimalPlaces = (places: number) => (value: number | undefined) => {
if (value === undefined) return true;
// Account for exponential notation, e.g. 1.2e-7 has 8 decimal places.
const [mantissa = "", exponent = "0"] = value.toString().split(/e/i);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't catch this before, what is a mantissa?

- Validate the complete numeric string in FormInput instead of accepting
  parseFloat prefixes, preserving invalid text like "12abc" or "1.2.3"
  for validation to catch; extract normalizeNumberInput with unit tests
- Count decimal places across exponential notation (e.g. 1.2e-7) in the
  position precision refinement
- Map empty coordinate strings to undefined before numeric coercion so
  cleared fields do not submit a 0,0 fixed position
- Test both inclusive ends of latitude/longitude ranges
auto-merge was automatically disabled August 29, 2026 14:39

Head branch was pushed to by a user without write access

@dzienisz
dzienisz force-pushed the fix/negative-position-coordinates branch from 0f9a45e to d0d753e Compare August 29, 2026 14:39
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.

[Bug]: Cannot enter negative degrees on config position page

3 participants