Skip to content

Commit

Permalink
Merge pull request #10 from concord-consortium/185951117-bug-fixes
Browse files Browse the repository at this point in the history
Addressing QA issues (PT-185951117)
  • Loading branch information
lublagg authored Oct 5, 2023
2 parents d87a4c1 + 06e1dc7 commit fd28975
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
3 changes: 3 additions & 0 deletions src/components/attribute-options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export const AttributeOptions: React.FC<IProps> = (props) => {

return (
<>
<div className={css.header}>
Choose attributes to include in your dataset from the list below.
</div>
{
attributeOptions.map((attr) => {
return (
Expand Down
3 changes: 3 additions & 0 deletions src/components/options.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,8 @@
.instructions {
padding-left: 6px;
margin-top: 6px;
}

.header {
margin-bottom: 15px;
}
19 changes: 16 additions & 3 deletions src/components/options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ export const Options: React.FC<IOptions> = (props) => {
newSelection[optionKey].push(e.target.value);
// If user selects "Age", "Gender", or "Race", auto-select "Total Farmers" as well
if (optionKey === "farmerDemographics" && !newArray.includes("Total Farmers")) {
newSelection.farmDemographics.push("Total Farmers");
newSelection.farmerDemographics.push("Total Farmers");
}
// If user selects any option under Farm Demographics, auto-select "Total Farms" as well
if (optionKey === "farmDemographics" && !newArray.includes("Total Farms")) {
newSelection.farmDemographics.push("Total Farms");
}
// If user selects a crop and no unit is selected, auto-select Yield
if (optionKey === "crops" && !selectedOptions.cropUnits) {
newSelection.cropUnits = "Yield";
}
// If user selects a state, de-select "All States"
if (optionKey === "states" && newArray.includes("All States")) {
Expand All @@ -43,10 +51,15 @@ export const Options: React.FC<IOptions> = (props) => {
}
} else {
if (isOptionSelected(e.target.value)) {
const includes = (opt: string) => selectedOptions.farmerDemographics.includes(opt);
const includesAny = (opts: string[], key: keyof IStateOptions) => opts.some(opt => selectedOptions[key].includes(opt));

Check warning on line 54 in src/components/options.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

This line has a length of 129. Maximum allowed is 120

Check warning on line 54 in src/components/options.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

This line has a length of 129. Maximum allowed is 120
// "Total Farmers" can only be unselected if race, gender, and age are unselected
if (optionKey === "farmerDemographics" && e.target.value === "Total Farmers") {
const shouldFilter = !includes("Race") && !includes("Gender") && !includes("Age");
const shouldFilter = !includesAny(["Race", "Gender", "Age"], "farmerDemographics");
if (shouldFilter) {
newSelection[optionKey] = newArray.filter((o) => o !== e.target.value);
}
} else if (optionKey === "farmDemographics" && e.target.value === "Total Farms") {
const shouldFilter = !includesAny(["Economic Class", "Acres Operated", "Organic", "Organization Type"], "farmDemographics");

Check warning on line 62 in src/components/options.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

This line has a length of 136. Maximum allowed is 120

Check warning on line 62 in src/components/options.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

This line has a length of 136. Maximum allowed is 120
if (shouldFilter) {
newSelection[optionKey] = newArray.filter((o) => o !== e.target.value);
}
Expand Down
25 changes: 3 additions & 22 deletions src/components/summary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from "react";
import { IStateOptions } from "../constants/types";
import { attributeOptions } from "../constants/constants";
import { flatten } from "../scripts/utils";

interface IProps {
category: string;
Expand All @@ -18,28 +19,8 @@ export const Summary: React.FC<IProps> = ({category, selectedOptions}) => {
`${place}${colon}${states}`
);
} else if (category === "Attributes") {
const resultString = attributeOptions.filter((attr) => {
const value = selectedOptions[attr.key];
const valueIsArrayWithLength = Array.isArray(value) && value.length > 0;
const valueIsDefined = typeof value === "string" && value;
return valueIsArrayWithLength || valueIsDefined;
}).map((attr) => {
const value = selectedOptions[attr.key];
const valueIsArrayWithLength = Array.isArray(value) && value.length > 0;
const valueIsDefined = typeof value === "string" && value;
const label = attr.label && (valueIsArrayWithLength || valueIsDefined) ? `${attr.label}: ` : "";

if (valueIsArrayWithLength) {
return `${label}${value.join(", ")}`;
} else if (value) {
return `${attr.label}: ${value}`;
} else {
return null;
}
})
.filter((item) => item !== null);
const finalString = resultString.join(", ");
return finalString;
const result = flatten(attributeOptions.filter((opt) => selectedOptions[opt.key]).map((opt) => selectedOptions[opt.key]));

Check warning on line 22 in src/components/summary.tsx

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

This line has a length of 130. Maximum allowed is 120

Check warning on line 22 in src/components/summary.tsx

View workflow job for this annotation

GitHub Actions / S3 Deploy

This line has a length of 130. Maximum allowed is 120
return result.join(", ");
} else if (category === "Years") {
return selectedOptions.years.join(", ");
}
Expand Down
2 changes: 1 addition & 1 deletion src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const cropUnitOptions: IAttrOptions = {
key: "cropUnits",
label: "Crop Production",
options: ["Area Harvested", "Yield"],
instructions: "(Choose units)"
instructions: "(Choose unit)"
};
export const cropOptions: IAttrOptions = {
key: "crops",
Expand Down

0 comments on commit fd28975

Please sign in to comment.