Task Description
Add an autoSelect prop to the <Select/> component that automatically selects a fallback option when the current value is not present in the options list.
Requirements
Background
Several game system config forms (e.g. TeamYankeeV2GameSystemConfigFields, FlamesOfWarV4GameSystemConfigFields) use useAutoFillSelect to auto-correct select values when the available options change dynamically. For example, changing the era changes the available dynamic points versions, and if the current selection is no longer valid, it needs to be replaced.
The current approach uses a dedicated useEffect per select field. This creates chains of cascading effects: one setValue triggers a re-render, which runs the next effect, which may call another setValue, and so on. This is a React anti-pattern (effects that synchronize derived state) and makes the behavior harder to follow.
Moving this logic into <Select/> itself is cleaner because each select already knows its options and current value. The cascading dependency problem resolves naturally through React's render cycle without fields needing cross-field awareness.
Implementation Details
- The
autoSelect prop should be optional and typed as 'first' | 'last'
- When the value is invalid and
autoSelect is set, call onChange from within the component (e.g. in a useEffect or during render via a ref check) with the appropriate fallback value
- Ensure this doesn't cause infinite render loops — only trigger when the value is actually not in the options
- The existing
useAutoFillSelect hook uses 'last' as its fallback strategy, so migrated usages should use autoSelect="last"
Additional Context
- Current hook:
src/hooks/useAutoFillSelect.ts
- Primary consumers:
TeamYankeeV2GameSystemConfigFields.tsx, FlamesOfWarV4GameSystemConfigFields.tsx
- The
<Select/> component is a generic shared component, so the change should be backwards-compatible (prop is optional, no behavior change without it)
Task Description
Add an
autoSelectprop to the<Select/>component that automatically selects a fallback option when the current value is not present in the options list.Requirements
autoSelectprop to<Select/>accepting'first'or'last'autoSelectis set and the current value is not found inoptions, triggeronChangewith the first or last option's value (based on the prop)autoSelectis not set, preserve current behavior (no auto-correction)useAutoFillSelectwith the newautoSelectpropuseAutoFillSelecthook once all usages are migratedBackground
Several game system config forms (e.g.
TeamYankeeV2GameSystemConfigFields,FlamesOfWarV4GameSystemConfigFields) useuseAutoFillSelectto auto-correct select values when the available options change dynamically. For example, changing the era changes the available dynamic points versions, and if the current selection is no longer valid, it needs to be replaced.The current approach uses a dedicated
useEffectper select field. This creates chains of cascading effects: onesetValuetriggers a re-render, which runs the next effect, which may call anothersetValue, and so on. This is a React anti-pattern (effects that synchronize derived state) and makes the behavior harder to follow.Moving this logic into
<Select/>itself is cleaner because each select already knows its options and current value. The cascading dependency problem resolves naturally through React's render cycle without fields needing cross-field awareness.Implementation Details
autoSelectprop should be optional and typed as'first' | 'last'autoSelectis set, callonChangefrom within the component (e.g. in auseEffector during render via a ref check) with the appropriate fallback valueuseAutoFillSelecthook uses'last'as its fallback strategy, so migrated usages should useautoSelect="last"Additional Context
src/hooks/useAutoFillSelect.tsTeamYankeeV2GameSystemConfigFields.tsx,FlamesOfWarV4GameSystemConfigFields.tsx<Select/>component is a generic shared component, so the change should be backwards-compatible (prop is optional, no behavior change without it)