diff --git a/src/components/app.tsx b/src/components/app.tsx index 49e322d..aab4d0c 100644 --- a/src/components/app.tsx +++ b/src/components/app.tsx @@ -57,10 +57,10 @@ function App() { setStatusGraphic(); const res = await createTableFromSelections(selectedOptions); if (res !== "success") { - setStatusMessage(strings.fetchSuccess); + setStatusMessage(strings.fetchError); setStatusGraphic(); } else { - setStatusMessage(strings.fetchError); + setStatusMessage(strings.fetchSuccess); setStatusGraphic(); } }; diff --git a/src/constants/codapMetadata.ts b/src/constants/codapMetadata.ts index 56370df..658b122 100644 --- a/src/constants/codapMetadata.ts +++ b/src/constants/codapMetadata.ts @@ -179,5 +179,38 @@ export const attrToCODAPColumnName: IAttrToCodapColumn = { "WHEAT - ACRES HARVESTED": { "attributeNameInCodapTable": "Wheat Area Harvested", "unitInCodapTable": "Acres Harvested" - } + }, + "ECONOMIC CLASS: (1,000 TO 9,999 $)": { + "attributeNameInCodapTable": "Small Farm ($1,000 - $9,999)", + "unitInCodapTable": "" + }, + "ECONOMIC CLASS: (10,000 TO 99,999 $)": { + "attributeNameInCodapTable": "Small Medium Farm ($10,000 - $99,000)", + "unitInCodapTable": "# of Farms" + }, + "ECONOMIC CLASS: (100,000 TO 249,999 $)": { + "attributeNameInCodapTable": "Medium Farm ($100,000 - $249,000)", + "unitInCodapTable": "# of Farms" + }, + "ECONOMIC CLASS: (250,000 TO 499,999 $)": { + "attributeNameInCodapTable": "Medium Large Farm ($250,000 - $499,999)", + "unitInCodapTable": "# of Farms" + }, + "ECONOMIC CLASS: (500,000 TO 999,999 $)": { + "attributeNameInCodapTable": "Large Farm ($500,000 - $999,999)", + "unitInCodapTable": "# of Farms" + }, + "ECONOMIC CLASS: (1,000,000 OR MORE $)": { + "attributeNameInCodapTable": "Very Large Farm ($1 million or more)", + "unitInCodapTable": "# of Farms" + }, }; + +export const economicClassAttirbutes = [ + "ECONOMIC CLASS: (1,000 TO 9,999 $)", + "ECONOMIC CLASS: (10,000 TO 99,999 $)", + "ECONOMIC CLASS: (100,000 TO 249,999 $)", + "ECONOMIC CLASS: (250,000 TO 499,999 $)", + "ECONOMIC CLASS: (500,000 TO 999,999 $)", + "ECONOMIC CLASS: (1,000,000 OR MORE $)" +]; diff --git a/src/scripts/api.ts b/src/scripts/api.ts index 8aaefeb..a2dbda1 100644 --- a/src/scripts/api.ts +++ b/src/scripts/api.ts @@ -5,7 +5,7 @@ import { connect } from "./connect"; import { cropOptions, fiftyStates } from "../constants/constants"; import { countyData } from "../constants/counties"; import { flatten, getQueryParams } from "./utils"; -import { attrToCODAPColumnName } from "../constants/codapMetadata"; +import { attrToCODAPColumnName, economicClassAttirbutes } from "../constants/codapMetadata"; const baseURL = `https://quickstats.nass.usda.gov/api/api_GET/?key=9ED0BFB8-8DDD-3609-9940-A2341ED6A9E3`; @@ -109,7 +109,12 @@ export const getAllAttrs = (selectedOptions: IStateOptions) => { throw new Error("Invalid attribute"); } const {short_desc} = queryParams; - if (Array.isArray(short_desc)) { + if (attribute === "Economic Class") { + for (const econAttr of economicClassAttirbutes) { + const codapColumnName = attrToCODAPColumnName[econAttr].attributeNameInCodapTable; + allAttrs.push(codapColumnName); + } + } else if (Array.isArray(short_desc)) { for (const desc of short_desc) { const codapColumnName = attrToCODAPColumnName[desc].attributeNameInCodapTable; allAttrs.push(codapColumnName); @@ -240,8 +245,13 @@ const getAttrData = async (params: IGetAttrDataParams) => { if (res) { const {data} = res; data.map((dataItem: any) => { - const codapColumnName = attrToCODAPColumnName[dataItem.short_desc].attributeNameInCodapTable; - return values[codapColumnName] = dataItem.Value; + let codapColumnName; + if (attribute === "Economic Class") { + codapColumnName = attrToCODAPColumnName[dataItem.domaincat_desc].attributeNameInCodapTable; + } else { + codapColumnName = attrToCODAPColumnName[dataItem.short_desc].attributeNameInCodapTable; + } + return values[codapColumnName] = dataItem.Value; }); } else { // eslint-disable-next-line no-console