fix(routes-compute-routes): resolve API validation errors on optional dropdowns - #1669
Open
willum070 wants to merge 1 commit into
Open
fix(routes-compute-routes): resolve API validation errors on optional dropdowns#1669willum070 wants to merge 1 commit into
willum070 wants to merge 1 commit into
Conversation
Change-Id: Ifa79159c75cd2da592071c0d7cb4b20975fb5a8e
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.
What this PR does
Fixes an
InvalidValueErrorthrown by the Routes API in theroutes-compute-routessample when submitting the form without selecting optional preferences.Root Cause
In a previous chore update (#1574), new ESLint rules (
@typescript-eslint/prefer-nullish-coalescing) prompted a switch from logical OR (||) to nullish coalescing (??) for handling optional<select>inputs.Because
FormData.get()returns an empty string ("") for default unselected options, the nullish coalescing operator ("" ?? undefined) evaluated to""instead ofundefined. This sent an invalid empty string value to the Maps API for enum fields, causing the validation error.The Fix
Replaced the
??fallback logic with explicit ternary operators (value === '' ? undefined : value) for the following optional fields:routingPreferencepolylineQualitytransitPreference.routingPreferenceThis ensures that empty strings correctly fall back to
undefinedbefore being sent to the API, while still satisfying the strict ESLint rules that prohibit the legacy||pattern.Change-Id: Ifa79159c75cd2da592071c0d7cb4b20975fb5a8e