Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute dropdown menu (PT-185951117) #3

Merged
merged 13 commits into from
Sep 20, 2023
111 changes: 84 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.5.0",
"classnames": "^2.3.2",
"fetch-jsonp": "^1.3.0",
"iframe-phone": "^1.3.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/components/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ button {
font-family: 'Montserrat', sans-serif;
font-size: 12px;
font-weight: 500;
&:hover {
&:hover:not(:disabled) {
cursor: pointer;
background: $teal-light-12;
}
Expand Down
69 changes: 43 additions & 26 deletions src/components/app.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
import React, {useState} from "react";
import React, {useEffect, useState} from "react";
import { Dropdown } from "./dropdown";
import css from "./app.scss";
import classnames from "classnames";
import { Information } from "./information";
import { defaultSelectedOptions } from "./constants";
import { attributeOptions, categories, defaultSelectedOptions } from "../constants/constants";
import { IStateOptions } from "../constants/types";
import { createTableFromSelections } from "../scripts/api";
import { connect } from "../scripts/connect";


import css from "./app.scss";

function App() {
const [showInfo, setShowInfo] = useState<boolean>(false);
const [selectedOptions, setSelectedOptions] = useState<typeof defaultSelectedOptions>(defaultSelectedOptions);
const [selectedOptions, setSelectedOptions] = useState<IStateOptions>(defaultSelectedOptions);
const [getDataDisabled, setGetDataDisabled] = useState<boolean>(true);

useEffect(() => {
const init = async () => {
await connect.initialize();
};
init();
}, []);

useEffect(() => {
const {geographicLevel, states, years} = selectedOptions;
const attrKeys = attributeOptions.filter((attr) => attr.key !== "cropUnits").map((attr) => attr.key);
const selectedAttrKeys = attrKeys.filter((key) => selectedOptions[key].length > 0);
if (selectedAttrKeys.length && geographicLevel && states.length && years.length) {
setGetDataDisabled(false);
} else {
setGetDataDisabled(true);
}
}, [selectedOptions]);

const handleSetSelectedOptions = (option: string, value: string | string[]) => {
const newSelectedOptions = {...selectedOptions, [option]: value};
Expand All @@ -19,6 +42,10 @@ function App() {
setShowInfo(true);
};

const handleGetData = async () => {
await createTableFromSelections(selectedOptions);
};

return (
<div className={css.pluginContent}>
{ showInfo &&
Expand All @@ -37,31 +64,21 @@ function App() {
</div>
</div>
<div className={css.scrollArea}>
<Dropdown
sectionName={"Place"}
sectionAltText={"Place alt text"}
sectionDescription={"Place description"}
handleSetSelectedOptions={handleSetSelectedOptions}
selectedOptions={selectedOptions}
/>
<Dropdown
sectionName={"Attributes"}
sectionAltText={"Attributes alt text"}
sectionDescription={"Attributes description"}
handleSetSelectedOptions={handleSetSelectedOptions}
selectedOptions={selectedOptions}
/>
<Dropdown
sectionName={"Years"}
sectionAltText={"Years alt text"}
sectionDescription={"Years description"}
handleSetSelectedOptions={handleSetSelectedOptions}
selectedOptions={selectedOptions}
/>
{categories.map((cat) => {
return (
<Dropdown
key={cat.header}
category={cat.header}
sectionAltText={cat.altText}
handleSetSelectedOptions={handleSetSelectedOptions}
selectedOptions={selectedOptions}
/>
);
})}
</div>
<div className={css.summary}>
<span className={css.statusGraphic}></span>
<button className={css.getDataButton}>Get Data</button>
<button className={css.getDataButton} disabled={getDataDisabled} onClick={handleGetData}>Get Data</button>
</div>
</div>

Expand Down
Loading
Loading