Skip to content

Commit

Permalink
Merge pull request #1182 from cityofaustin/md-patch-no-council-districts
Browse files Browse the repository at this point in the history
Handle child projects with no components/geography
  • Loading branch information
mddilley authored Oct 26, 2023
2 parents 6be2f54 + bf14729 commit 8a629e2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ const ProjectSummary = ({ loading, error, data, refetch, listViewQuery }) => {

const [snackbarState, setSnackbarState] = useState(false);

const childProjectGeography = data?.childProjects.map(
(project) => project.project_geography[0]
);
/* Not all child components have components and geography data */
const childProjectGeography = data?.childProjects
.filter((project) => project.project_geography.length > 0)
.map((project) => project.project_geography[0]);
/**
* Updates the state of snackbar state
* @param {String|JSX.Element} message - The message to be displayed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React from "react";
import { Box, Grid, Typography } from "@mui/material";

// reduce the array of geography objects into an array of city council districts
// reduce the array of project_geography objects into an array of city council districts
const reduceDistricts = (data) => {
const initialValue = [];
const districts = data.reduce(
(acc, component) => [...acc, component["council_districts"]],
initialValue
);
const districts = data.reduce((acc, geography) => {
/* Not all components have geography data */
const geographyCouncilDistricts = geography
? geography.council_districts
: [];
return [...acc, geographyCouncilDistricts];
}, initialValue);

// flatten the array of arrays and remove empty districts
const districtsArray = districts.flat().filter((d) => d);
Expand Down

0 comments on commit 8a629e2

Please sign in to comment.