Skip to content

Commit

Permalink
Merge pull request #30 from concord-consortium/186629802-autoselect-y…
Browse files Browse the repository at this point in the history
…ield

Auto-select yield if user selects crop. (PT-186629802)
  • Loading branch information
lublagg authored Feb 20, 2024
2 parents 5f1025d + b4fd782 commit ba66606
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const Options: React.FC<IOptions> = (props) => {
const handleSelectState = (e: React.ChangeEvent<HTMLInputElement>) => {
if (Array.isArray(selectedOptions[optionKey])) {
const newArray = [...selectedOptions[optionKey]];
const newSelection: any = {[optionKey]: newArray};
const newSelection = {[optionKey]: newArray};
if (e.currentTarget.checked) {
newSelection[optionKey].push(e.target.value);
// If user selects "Age", "Gender", or "Race", auto-select "Total Farmers" as well
Expand All @@ -38,7 +38,7 @@ export const Options: React.FC<IOptions> = (props) => {
newSelection.farmDemographics.push("Total Farms");
}
// If user selects a crop and no unit is selected, auto-select Yield
if (optionKey === "crops" && !selectedOptions.cropUnits) {
if (optionKey === "crops" && !selectedOptions.cropUnits.length) {
newSelection.cropUnits = ["Yield"];
}
// If user selects a state, de-select "All States"
Expand Down Expand Up @@ -95,7 +95,7 @@ export const Options: React.FC<IOptions> = (props) => {
checked={isOptionSelected(o)}
onChange={(e) => handleSelectState(e)}
/>
<label className={css.label} htmlFor={o} key={`label-${o}`}>{o}</label>
<label className={css.label} htmlFor={o} key={`${inputType}-label-${o}`}>{o}</label>
</div>
);
})}
Expand Down

0 comments on commit ba66606

Please sign in to comment.