Commit 1ec251b
Fix SegmentedControl to handle invalid selected values gracefully (#14059)
## Summary
This PR adds validation to the SegmentedControl component to gracefully
handle cases where the selected value doesn't match any available
option, and fixes a bug in TracksPreview where an invalid enum value was
being passed.
## Key Changes
- **SegmentedControl**: Added fallback logic to validate that the
selected value exists in the options list. If the selected value is
invalid, it falls back to the first available option instead of
rendering an unmatched state.
- **TracksPreview**: Fixed a bug where `UploadType.INDIVIDUAL_TRACK`
(singular) was being passed to SegmentedControl, but the available
options only included `UploadType.INDIVIDUAL_TRACKS` (plural). Added a
mapping to convert the singular enum value to the plural one that
matches the available options.
## Implementation Details
- The SegmentedControl now performs an `options.some()` check to verify
the selected value exists before using it
- If validation fails, it safely falls back to `options[0]?.key` or the
raw selected value as a last resort
- This prevents UI inconsistencies and ensures the component always
renders in a valid state
https://claude.ai/code/session_01S8Yn3jaHMpAZ2LRKDoDPfA
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 6fc39c6 commit 1ec251b
3 files changed
Lines changed: 17 additions & 2 deletions
File tree
- .changeset
- packages
- harmony/src/components/segmented-control
- web/src/pages/upload-page/components
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
| |||
0 commit comments