Skip to content

Commit

Permalink
Add support for counties.
Browse files Browse the repository at this point in the history
  • Loading branch information
lublagg committed Sep 19, 2023
1 parent 1c0c59c commit c879b5e
Show file tree
Hide file tree
Showing 16 changed files with 3,837 additions and 472 deletions.
4 changes: 2 additions & 2 deletions src/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import React, {useEffect, useState} from "react";
import { Dropdown } from "./dropdown";
import classnames from "classnames";
import { Information } from "./information";
import { attributeOptions, categories, defaultSelectedOptions } from "./constants";
import { IStateOptions } from "./types";
import { attributeOptions, categories, defaultSelectedOptions } from "../constants/constants";
import { IStateOptions } from "../constants/types";
import { createTableFromSelections } from "../scripts/api";
import { connect } from "../scripts/connect";

Expand Down
4 changes: 2 additions & 2 deletions src/components/attribute-options.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import { Options } from "./options";
import { attributeOptions } from "./constants";
import { attributeOptions } from "../constants/constants";
import classnames from "classnames";
import { IStateOptions } from "./types";
import { IStateOptions } from "../constants/types";

import css from "./options.scss";

Expand Down
2 changes: 1 addition & 1 deletion src/components/dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from "react";
import classnames from "classnames";
import { PlaceOptions } from "./place-options";
import { defaultSelectedOptions } from "./constants";
import { defaultSelectedOptions } from "../constants/constants";
import { AttributeOptions } from "./attribute-options";

import css from "./dropdown.scss";
Expand Down
2 changes: 1 addition & 1 deletion 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 "./types";
import { IStateOptions, OptionKey } from "../constants/types";

import css from "./options.scss";

Expand Down
4 changes: 2 additions & 2 deletions src/components/place-options.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { placeOptions } from "./constants";
import { IStateOptions } from "./types";
import { placeOptions } from "../constants/constants";
import { IStateOptions } from "../constants/types";
import { Options } from "./options";

import css from "./options.scss";
Expand Down
4 changes: 2 additions & 2 deletions src/components/summary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from "react";
import { IStateOptions } from "./types";
import { attributeOptions } from "./constants";
import { IStateOptions } from "../constants/types";
import { attributeOptions } from "../constants/constants";

interface IProps {
category: string;
Expand Down
4 changes: 0 additions & 4 deletions src/components/utils.ts

This file was deleted.

11 changes: 5 additions & 6 deletions src/components/years-options.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useEffect, useState } from "react";
import { attributeOptions, yearsOptions } from "./constants";
import { IStateOptions } from "./types";
import { attributeOptions, yearsOptions } from "../constants/constants";
import { IStateOptions } from "../constants/types";
import { Options } from "./options";
import { queryData } from "../scripts/query-headers";
import { flatten } from "./utils";
import { queryData } from "../constants/query-headers";
import { flatten } from "../scripts/utils";

import css from "./options.scss";

Expand All @@ -24,11 +24,10 @@ export const YearsOptions: React.FC<IProps> = (props) => {
return;
}

const yearKeyToUse = selectedOptions.geographicLevel === "County" ? "county" : "state";
const allSelectedAttrs = flatten(selectedAttrKeys.map((key) => selectedOptions[key]));
const newAvailableYears = allSelectedAttrs.reduce((years, attr) => {
const subAttrData = queryData.find((d) => d.plugInAttribute === attr);
const availableYears = subAttrData?.years[yearKeyToUse];
const availableYears = subAttrData?.years[selectedOptions.geographicLevel];
if (availableYears) {
availableYears.forEach((y) => {
years.add(y);
Expand Down
106 changes: 55 additions & 51 deletions src/components/constants.ts → src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,62 +7,66 @@ export const geographicLevelOptions: IAttrOptions = {
options : ["State", "County"]
};

export const fiftyStates = [
"Alabama",
"Alaska",
"Arizona",
"Arkansas",
"California",
"Colorado",
"Connecticut",
"Delaware",
"Florida",
"Georgia",
"Hawaii",
"Idaho",
"Illinois",
"Indiana",
"Iowa",
"Kansas",
"Kentucky",
"Louisiana",
"Maine",
"Maryland",
"Massachusetts",
"Michigan",
"Minnesota",
"Mississippi",
"Missouri",
"Montana",
"Nebraska",
"Nevada",
"New Hampshire",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
"North Dakota",
"Ohio",
"Oklahoma",
"Oregon",
"Pennsylvania",
"Rhode Island",
"South Carolina",
"South Dakota",
"Tennessee",
"Texas",
"Utah",
"Vermont",
"Virginia",
"Washington",
"West Virginia",
"Wisconsin",
"Wyoming"
]

Check warning on line 61 in src/constants/constants.ts

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

Missing semicolon

export const stateOptions: IAttrOptions = {
label: null,
key: "states",
instructions: "Choose states to include in your dataset from the list below",
options: [
"All States",
"Alabama",
"Alaska",
"Arizona",
"Arkansas",
"California",
"Colorado",
"Connecticut",
"Delaware",
"Florida",
"Georgia",
"Hawaii",
"Idaho",
"Illinois",
"Indiana",
"Iowa",
"Kansas",
"Kentucky",
"Louisiana",
"Maine",
"Maryland",
"Massachusetts",
"Michigan",
"Minnesota",
"Mississippi",
"Missouri",
"Montana",
"Nebraska",
"Nevada",
"New Hampshire",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
"North Dakota",
"Ohio",
"Oklahoma",
"Oregon",
"Pennsylvania",
"Rhode Island",
"South Carolina",
"South Dakota",
"Tennessee",
"Texas",
"Utah",
"Vermont",
"Virginia",
"Washington",
"West Virginia",
"Wisconsin",
"Wyoming"
...fiftyStates
]
};

Expand Down Expand Up @@ -128,4 +132,4 @@ export const defaultSelectedOptions: IStateOptions = {
cropUnits: "",
crops: [],
years: []
};
};

Check warning on line 135 in src/constants/constants.ts

View workflow job for this annotation

GitHub Actions / Build and Run Jest Tests

Newline required at end of file but not found
Loading

0 comments on commit c879b5e

Please sign in to comment.