Skip to content

Commit

Permalink
Merge pull request #28 from concord-consortium/186629802-select-both-…
Browse files Browse the repository at this point in the history
…acres-yield

User can select both Yield and Acres Harvested options.
  • Loading branch information
lublagg authored Feb 15, 2024
2 parents 7a0fd66 + 40487b1 commit 5f1025d
Show file tree
Hide file tree
Showing 6 changed files with 214 additions and 131 deletions.
2 changes: 1 addition & 1 deletion src/components/attribute-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const AttributeOptions: React.FC<IProps> = (props) => {
<div key={`options-container-${attr.key}`} className={classnames(getClasses(attr.key))}>
<Options
key={`options-${attr.key}`}
inputType={attr.key === "cropUnits" ? "radio" : "checkbox"}
inputType={"checkbox"}
options={attr.options}
optionKey={attr.key}
{...commonProps}
Expand Down
10 changes: 5 additions & 5 deletions src/components/options.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { IStateOptions, OptionKey } from "../constants/types";
import { GeographicLevel, IStateOptions, OptionKey } from "../constants/types";

import css from "./options.scss";

Expand Down Expand Up @@ -39,7 +39,7 @@ export const Options: React.FC<IOptions> = (props) => {
}
// If user selects a crop and no unit is selected, auto-select Yield
if (optionKey === "crops" && !selectedOptions.cropUnits) {
newSelection.cropUnits = "Yield";
newSelection.cropUnits = ["Yield"];
}
// If user selects a state, de-select "All States"
if (optionKey === "states" && newArray.includes("All States")) {
Expand Down Expand Up @@ -68,16 +68,16 @@ export const Options: React.FC<IOptions> = (props) => {
// Otherwise deselect crop units, too
newSelection.crops = newArray.filter((o) => o !== e.target.value);
if (newSelection.crops.length === 0) {
newSelection.cropUnits = "";
newSelection.cropUnits = [];
}
} else {
newSelection[optionKey] = newArray.filter((o) => o !== e.target.value);
}
}
}
handleSetSelectedOptions(newSelection);
} else if (optionKey === "geographicLevel" || optionKey === "cropUnits") {
handleSetSelectedOptions({[optionKey]: e.target.value});
} else if (optionKey === "geographicLevel") {
handleSetSelectedOptions({geographicLevel: e.target.value as GeographicLevel});
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const defaultSelectedOptions: IStateOptions = {
farmerDemographics: [],
farmDemographics: [],
economicsAndWages: [],
cropUnits: "",
cropUnits: [],
crops: [],
years: []
};
32 changes: 26 additions & 6 deletions src/constants/queryHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ const sharedLaborHeaders = {
const sharedCropHeaders = {
sect_desc: "Crops",
domain_desc: "Total",
geographicAreas: ["State", "County"],
years: {
"County": allYears,
"State": allYears
}
geographicAreas: ["State", "County"]
};

export const queryData: Array<IQueryHeaders> = [
Expand Down Expand Up @@ -133,7 +129,7 @@ export const queryData: Array<IQueryHeaders> = [
geographicAreas: ["State"],
years: {
"County": [],
"State": allYears.filter(y => Number(y) >= 1998)
"State": allYears.filter(y => Number(y) >= 1987)
}
},
{
Expand Down Expand Up @@ -213,6 +209,10 @@ export const queryData: Array<IQueryHeaders> = [
["Area Harvested"]: ["CORN, GRAIN - ACRES HARVESTED"],
["Yield"]: ["CORN, GRAIN - YIELD, MEASURED IN BU / ACRE"]
},
years: {
"County": allYears,
"State": allYears
},
...sharedCropHeaders
},
{
Expand All @@ -227,6 +227,10 @@ export const queryData: Array<IQueryHeaders> = [
["Area Harvested"]: ["COTTON - ACRES HARVESTED"],
["Yield"]: ["COTTON - YIELD, MEASURED IN LB / ACRE"]
},
years: {
"County": allYears,
"State": allYears
},
...sharedCropHeaders
},
{
Expand All @@ -241,6 +245,10 @@ export const queryData: Array<IQueryHeaders> = [
["Area Harvested"]: ["GRAPES - ACRES BEARING"],
["Yield"]: ["GRAPES - YIELD, MEASURED IN TONS / ACRE"]
},
years: {
"County": allYears.filter(y => y === "2002" || Number(y) >= 2007),
"State": allYears.filter(y => y === "2002" || Number(y) >= 2007)
},
...sharedCropHeaders
},
{
Expand All @@ -255,6 +263,10 @@ export const queryData: Array<IQueryHeaders> = [
["Area Harvested"]: ["OATS - ACRES HARVESTED"],
["Yield"]: ["OATS - YIELD, MEASURED IN BU / ACRE"]
},
years: {
"County": allYears,
"State": allYears
},
...sharedCropHeaders
},
{
Expand All @@ -269,6 +281,10 @@ export const queryData: Array<IQueryHeaders> = [
["Area Harvested"]: ["SOYBEANS - ACRES HARVESTED"],
["Yield"]: ["SOYBEANS - YIELD, MEASURED IN BU / ACRE"]
},
years: {
"County": allYears,
"State": allYears
},
...sharedCropHeaders
},
{
Expand All @@ -283,6 +299,10 @@ export const queryData: Array<IQueryHeaders> = [
["Area Harvested"]: ["WHEAT - ACRES HARVESTED"],
["Yield"]: ["WHEAT - YIELD, MEASURED IN BU / ACRE"]
},
years: {
"County": allYears,
"State": allYears
},
...sharedCropHeaders
}
];
4 changes: 2 additions & 2 deletions src/constants/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface IStateOptions {
farmerDemographics: string[],
farmDemographics: string[],
economicsAndWages: string[],
cropUnits: string,
cropUnits: string[],
crops: string[]
years: string[]
}
Expand Down Expand Up @@ -106,4 +106,4 @@ export interface IReqCount {
renameable?: boolean;
deleteable?: boolean;
hidden?: boolean;
}
}
Loading

0 comments on commit 5f1025d

Please sign in to comment.