From 7de7bd5eb1df85f5d9dd19d47c300bb735352988 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Mon, 27 Apr 2020 21:30:38 -0400 Subject: [PATCH 1/4] Refactor reducer related consistency code --- .../AddressSearchBuildings/index.js | 14 ++-- src/components/BuildingListTable/index.js | 12 ++-- src/components/BuildingOverview/index.js | 6 +- src/components/ProjectOverview/index.js | 22 +++--- src/components/SideBarDetail/index.js | 4 +- src/components/Utilities/index.js | 4 +- src/containers/BGroup/BGroup.js | 4 +- .../Blocnote/BudgetSimulator/index.js | 4 +- .../Blocnote/FinancialInputs/index.js | 4 +- src/containers/Blocnote/index.js | 4 +- src/containers/Building/index.js | 20 +++--- src/containers/Dimensions/index.js | 12 ++-- src/containers/Envelope/index.js | 4 +- src/containers/Performance/index.js | 6 +- src/containers/Project/index.js | 24 +++---- src/containers/Questionnaire/index.js | 4 +- src/containers/SearchBar/index.js | 20 +++--- src/containers/SearchBar/propTypes.js | 6 +- src/reducers.js | 72 +++++++++---------- src/screens/BuildingsHomePage/index.js | 30 ++++---- src/screens/HomePage/index.js | 24 +++---- src/screens/ProjectsHomePage/index.js | 22 +++--- 22 files changed, 163 insertions(+), 159 deletions(-) diff --git a/src/components/AddressSearchBuildings/index.js b/src/components/AddressSearchBuildings/index.js index 139149e0..d004d688 100644 --- a/src/components/AddressSearchBuildings/index.js +++ b/src/components/AddressSearchBuildings/index.js @@ -27,19 +27,19 @@ class AddressSearchBuildings extends Component { } componentDidMount() { - // Use the buildings stored in cookies to populate the buildingList - const buildingList = localStorage.activeBuildings; - if (buildingList !== undefined) { - this.props.buildingsSearched(JSON.parse(buildingList)); + // Use the buildings stored in cookies to populate the buildings + const buildings = localStorage.activeBuildings; + if (buildings !== undefined) { + this.props.buildingsSearched(JSON.parse(buildings)); } } componentWillReceiveProps(nextProps) { if ( - this.props.buildingList !== nextProps.buildingList + this.props.buildings !== nextProps.buildings ) { this.setState({ - address: nextProps.buildingList.address, + address: nextProps.buildings.address, }); } } @@ -113,7 +113,7 @@ class AddressSearchBuildings extends Component { } AddressSearchBuildings.propTypes = { - buildingList: PropTypes.objectOf, + buildings: PropTypes.objectOf, searchBuildings: PropTypes.func, buildingsSearched: PropTypes.func, setAddress: PropTypes.func, diff --git a/src/components/BuildingListTable/index.js b/src/components/BuildingListTable/index.js index 9d1df765..13e1bb4f 100644 --- a/src/components/BuildingListTable/index.js +++ b/src/components/BuildingListTable/index.js @@ -3,12 +3,12 @@ import ReactGA from 'react-ga'; import PropTypes from 'prop-types'; import { browserHistory } from 'react-router'; import './styles.css'; -import { buildingList, loadErrorPropTypes } from '../../containers/SearchBar/propTypes'; +import { buildings, loadErrorPropTypes } from '../../containers/SearchBar/propTypes'; import Loading from '../../components/Loading'; /* eslint-disable no-param-reassign */ export default function BuildingListTable({ - buildings, + buildingList, loading, loadBuildings, error, @@ -24,7 +24,7 @@ export default function BuildingListTable({ return
; } - if (!buildings || buildings.length === 0) { + if (!buildingList || buildingList.length === 0) { return (
{ + const lotGrouping = buildingList.reduce((acc, building) => { if (building.bbl in acc) { acc[building.bbl] += 1; } else { @@ -110,7 +110,7 @@ export default function BuildingListTable({ return acc; }, {}); - const buildingItems = buildings.map((building) => { + const buildingItems = buildingList.map((building) => { let bblTd = (); if (building.bbl in lotGrouping || !bblDisplay) { bblTd = ( @@ -167,7 +167,7 @@ export default function BuildingListTable({ } BuildingListTable.propTypes = { - buildings: buildingList, + buildingList: buildings, loading: PropTypes.bool, error: loadErrorPropTypes.error, loadBuildings: PropTypes.func, diff --git a/src/components/BuildingOverview/index.js b/src/components/BuildingOverview/index.js index fbd573c6..3a05a269 100644 --- a/src/components/BuildingOverview/index.js +++ b/src/components/BuildingOverview/index.js @@ -17,8 +17,8 @@ export default class BuildingOverview extends Component { if (this.props.projects.loading) { return ; } - const projectList = this.props.projects.projects; - if (!projectList || projectList.length <= 0) { + const projects = this.props.projects.projects; + if (!projects || projects.length <= 0) { return (

No projects

@@ -26,7 +26,7 @@ export default class BuildingOverview extends Component { ); } - return projectList.map(project => ( + return projects.map(project => ( { - let projectList = localStorage.activeProjects; - if (projectList !== undefined) { - projectList = JSON.parse(projectList); + let projects = localStorage.activeProjects; + if (projects !== undefined) { + projects = JSON.parse(projects); const addList = [{ building_id: this.state.buildingId, id: this.state.projectId, @@ -147,7 +147,7 @@ class ProjectOverview extends Component { slug: project.slug, state: project.state, }]; - projectList = projectList.filter((val, index) => { + projects = projects.filter((val, index) => { // Make sure the list is smaller than 300 if (index >= 300) { return false; @@ -159,16 +159,16 @@ class ProjectOverview extends Component { return !sameProject; }); addList.map((val) => { - projectList.unshift(val); + projects.unshift(val); return val; }); } else { - projectList = [{ + projects = [{ building_id: this.state.buildingId, id: this.state.projectId, }]; } - localStorage.setItem('activeProjects', JSON.stringify(projectList)); + localStorage.setItem('activeProjects', JSON.stringify(projects)); } render() { @@ -333,8 +333,12 @@ function mapDispatchToProps(dispatch) { }, dispatch); } -function mapStateToProps({ documents, projectList, user }) { - return { documents, projects: projectList, user }; +function mapStateToProps({ documents, projects, user }) { + return { + documents, + projects, + user, + }; } export default connect(mapStateToProps, mapDispatchToProps)(ProjectOverview); diff --git a/src/components/SideBarDetail/index.js b/src/components/SideBarDetail/index.js index d5c015da..bcd772a7 100644 --- a/src/components/SideBarDetail/index.js +++ b/src/components/SideBarDetail/index.js @@ -5,7 +5,7 @@ import { UncontrolledTooltip } from 'reactstrap'; import { Icon } from 'react-fa'; import './styles.css'; import { contactsPropTypes } from '../../containers/Project/propTypes'; -import buildingDetailPropType from '../../containers/Building/propTypes'; +import buildingPropType from '../../containers/Building/propTypes'; import { dimensionSVG, utilitySVG, @@ -207,7 +207,7 @@ export default function SideBarDetail({ building, children, contacts, user }) { SideBarDetail.propTypes = { children: PropTypes.element, - building: buildingDetailPropType, + building: buildingPropType, contacts: PropTypes.shape(contactsPropTypes), user: userPropType, }; diff --git a/src/components/Utilities/index.js b/src/components/Utilities/index.js index bda57cde..0a0c39fa 100644 --- a/src/components/Utilities/index.js +++ b/src/components/Utilities/index.js @@ -1,7 +1,7 @@ import React, { Component } from 'react'; import ReactGA from 'react-ga'; import PropTypes from 'prop-types'; -import buildingDetailPropTypes from '../../containers/Building/propTypes'; +import buildingPropTypes from '../../containers/Building/propTypes'; import request from '../../utils/request'; import ErrorAlert from '../../components/ErrorAlert'; @@ -449,7 +449,7 @@ class Utilities extends Component { Utilities.propTypes = { buildingId: PropTypes.string, - building: buildingDetailPropTypes, + building: buildingPropTypes, user: userPropType, }; diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 287edbd2..76d39c4d 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -584,9 +584,9 @@ BGroup.defaultProps = { const mapStateToProps = state => ( { bGroup: state.bGroup, - projects: state.projectList, + projects: state.projects, report: state.report, - buildings: state.buildingList, + buildings: state.buildings, } ); diff --git a/src/containers/Blocnote/BudgetSimulator/index.js b/src/containers/Blocnote/BudgetSimulator/index.js index 68237c1c..f582b08e 100644 --- a/src/containers/Blocnote/BudgetSimulator/index.js +++ b/src/containers/Blocnote/BudgetSimulator/index.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import LinkBarDetail from '../../../components/LinkBarDetail'; -import buildingDetailPropTypes from '../../Building/propTypes'; +import buildingPropTypes from '../../Building/propTypes'; import Loading from '../../../components/Loading'; import BugetTable from '../../../components/Blocnote/BudgetSimulator/BugetTable'; import BudgetChart from '../../../components/Blocnote/BudgetSimulator/BudgetChart'; @@ -98,7 +98,7 @@ class BudgetSimulator extends Component { } BudgetSimulator.propTypes = { - building: buildingDetailPropTypes, + building: buildingPropTypes, blocnote: blocnoteProps, loadBudgetSimulator: PropTypes.func, buildingId: PropTypes.string, diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index c35c4734..3d96f828 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import LinkBarDetail from '../../../components/LinkBarDetail'; -import buildingDetailPropTypes from '../../Building/propTypes'; +import buildingPropTypes from '../../Building/propTypes'; import Loading from '../../../components/Loading'; import { loadFinanceOverview, loadBills, loadBillsOverview, @@ -268,7 +268,7 @@ class FinancialInputs extends Component { FinancialInputs.propTypes = { buildingId: PropTypes.string, - building: buildingDetailPropTypes, + building: buildingPropTypes, blocnote: blocnoteProps, loadFinanceOverview: PropTypes.func, loadBills: PropTypes.func, diff --git a/src/containers/Blocnote/index.js b/src/containers/Blocnote/index.js index cb1b322e..c7f1921d 100644 --- a/src/containers/Blocnote/index.js +++ b/src/containers/Blocnote/index.js @@ -5,7 +5,7 @@ import { bindActionCreators } from 'redux'; import { Table } from 'reactstrap'; import { Link } from 'react-router'; import LinkBarDetail from '../../components/LinkBarDetail'; -import buildingDetailPropTypes from '../Building/propTypes'; +import buildingPropTypes from '../Building/propTypes'; import { loadLandingData } from './actions'; import Loading from '../../components/Loading'; import blocnoteProps from './propTypes'; @@ -153,7 +153,7 @@ class Blocnote extends Component { } Blocnote.propTypes = { - building: buildingDetailPropTypes, + building: buildingPropTypes, loadLandingData: PropTypes.func, blocnote: blocnoteProps, }; diff --git a/src/containers/Building/index.js b/src/containers/Building/index.js index c9e37de1..447b941b 100644 --- a/src/containers/Building/index.js +++ b/src/containers/Building/index.js @@ -75,15 +75,15 @@ class Building extends Component { updateStorage = (props) => { - let buildingList = localStorage.activeBuildings; + let buildings = localStorage.activeBuildings; const placeName = props.overview.place_name; - if (buildingList !== undefined) { - buildingList = JSON.parse(buildingList); + if (buildings !== undefined) { + buildings = JSON.parse(buildings); const addList = [{ ...props.overview, place_name: placeName, }]; - buildingList = buildingList.filter((val, index) => { + buildings = buildings.filter((val, index) => { // Make sure the list is smaller than 300 if (index >= 300) { return false; @@ -103,16 +103,16 @@ class Building extends Component { return !sameLot; }); addList.map((val) => { - buildingList.unshift(val); + buildings.unshift(val); return val; }); } else { - buildingList = [{ + buildings = [{ ...props.overview, place_name: placeName, }]; } - localStorage.setItem('activeBuildings', JSON.stringify(buildingList)); + localStorage.setItem('activeBuildings', JSON.stringify(buildings)); } render() { @@ -190,12 +190,12 @@ function mapDispatchToProps(dispatch) { }, dispatch); } -function mapStateToProps({ buildingDetail, documents, projectList }) { - const { overview } = buildingDetail; +function mapStateToProps({ building, documents, projects }) { + const { overview } = building; return { overview, documents, - projects: projectList, + projects, }; } diff --git a/src/containers/Dimensions/index.js b/src/containers/Dimensions/index.js index 531536a9..c8798bde 100644 --- a/src/containers/Dimensions/index.js +++ b/src/containers/Dimensions/index.js @@ -50,9 +50,9 @@ class Dimensions extends Component { hitDecision={this.props.hitDecision} deleteHit={this.props.deleteHit} address={` - ${this.props.buildingDetail.overview.street_address} - ${this.props.buildingDetail.overview.borough}, New York - ${this.props.buildingDetail.overview.zipcode} + ${this.props.building.overview.street_address} + ${this.props.building.overview.borough}, New York + ${this.props.building.overview.zipcode} USA`} building_id={parseInt(this.props.buildingId, 10)} hit={this.props.dimensions.hit} @@ -67,7 +67,7 @@ class Dimensions extends Component { Dimensions.propTypes = { buildingId: PropTypes.string, building: completeOverviewPropTypes, - buildingDetail: PropTypes.shape(overviewPropTypes), + building: PropTypes.shape(overviewPropTypes), dimensions: PropTypes.shape({ hit: turkHitPropTypes, }), @@ -87,8 +87,8 @@ function mapDispatchToProps(dispatch) { }, dispatch); } -function mapStateToProps({ dimensions, buildingDetail, user }) { - return { dimensions, buildingDetail, user }; +function mapStateToProps({ dimensions, building, user }) { + return { dimensions, building, user }; } export default connect(mapStateToProps, mapDispatchToProps)(Dimensions); diff --git a/src/containers/Envelope/index.js b/src/containers/Envelope/index.js index 49cd923e..6a8c6060 100644 --- a/src/containers/Envelope/index.js +++ b/src/containers/Envelope/index.js @@ -16,7 +16,7 @@ import { Icon } from 'react-fa'; import LinkBarDetail from '../../components/LinkBarDetail'; import RetrofitTable from './retrofitTable'; -import buildingDetailPropTypes from '../../containers/Building/propTypes'; +import buildingPropTypes from '../../containers/Building/propTypes'; import { loadSimStatus, runSimulation, loadMonthlyHeatingConsumption, loadHeatLossComponentBreakdown, loadDesignLoad, loadUtilityBillBreakdown, @@ -457,7 +457,7 @@ class Envelope extends Component { } Envelope.propTypes = { - building: buildingDetailPropTypes, + building: buildingPropTypes, envelope: envelopeProps, eng: engPropTypes, loadSimStatus: PropTypes.func, diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 5234f1cf..88eeea55 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -22,7 +22,7 @@ import { loadRetrofitProperties, } from '../Eng/actions'; import engPropTypes from '../Eng/propTypes'; -import buildingDetailPropTypes from '../../containers/Building/propTypes'; +import buildingPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; import Impacts from '../../components/Performance/Impacts'; import Occupants from '../../components/Performance/Occupants'; @@ -217,7 +217,7 @@ class Performance extends Component { } Performance.propTypes = { - building: buildingDetailPropTypes, + building: buildingPropTypes, loadOccupants: PropTypes.func, loadOccupantsLog: PropTypes.func, loadThermalComfort: PropTypes.func, @@ -258,7 +258,7 @@ const mapDispatchToProps = dispatch => ( ); const mapStateToProps = state => ({ - performance: state.bloclink, + performance: state.performance, user: state.user, eng: state.eng, }); diff --git a/src/containers/Project/index.js b/src/containers/Project/index.js index 58d4f525..2f9ab6d9 100644 --- a/src/containers/Project/index.js +++ b/src/containers/Project/index.js @@ -26,8 +26,8 @@ class ProjectSearchBar extends Component { constructor(props) { super(props); this.state = { - type: this.props.projectList.type, - term: this.props.projectList.term, + type: this.props.projects.type, + term: this.props.projects.term, searchByDropdownOpen: false, }; } @@ -36,21 +36,21 @@ class ProjectSearchBar extends Component { if (!(this.state.term === '' && this.state.type === 'name')) { this.getProjects(this.state); } else { - // Use the projects stored in cookies to populate the projectList - const projectList = localStorage.activeProjects; - if (projectList !== undefined) { - this.props.projectsLoaded({ data: JSON.parse(projectList) }); + // Use the projects stored in cookies to populate the projects + const projects = localStorage.activeProjects; + if (projects !== undefined) { + this.props.projectsLoaded({ data: JSON.parse(projects) }); } } } componentWillReceiveProps(nextProps) { if ( - this.props.projectList !== nextProps.projectList + this.props.projects !== nextProps.projects ) { this.setState({ - type: nextProps.projectList.type, - term: nextProps.projectList.term, + type: nextProps.projects.type, + term: nextProps.projects.term, }); } } @@ -230,7 +230,7 @@ class ProjectSearchBar extends Component { } ProjectSearchBar.propTypes = { - projectList: completeProjectPropTypes, + projects: completeProjectPropTypes, updateProjectSearchParams: PropTypes.func, loadProjects: PropTypes.func, projectsLoaded: PropTypes.func, @@ -245,8 +245,8 @@ function mapDispatchToProps(dispatch) { }, dispatch); } -function mapStateToProps({ projectList }) { - return { projectList }; +function mapStateToProps({ projects }) { + return { projects }; } export default connect(mapStateToProps, mapDispatchToProps)(ProjectSearchBar); diff --git a/src/containers/Questionnaire/index.js b/src/containers/Questionnaire/index.js index bf4aa04e..742c2bb6 100644 --- a/src/containers/Questionnaire/index.js +++ b/src/containers/Questionnaire/index.js @@ -4,7 +4,7 @@ import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { Button } from 'reactstrap'; import Loading from '../../components/Loading'; -import buildingDetailPropTypes from '../Building/propTypes'; +import buildingPropTypes from '../Building/propTypes'; import { loadQuestionnaire, submitQuestionnaire, @@ -431,7 +431,7 @@ class Questionnaire extends Component { } Questionnaire.propTypes = { - building: buildingDetailPropTypes, + building: buildingPropTypes, loadQuestionnaire: PropTypes.func, submitQuestionnaire: PropTypes.func, editQuestionnaire: PropTypes.func, diff --git a/src/containers/SearchBar/index.js b/src/containers/SearchBar/index.js index 6ddf2ef9..2a19f88b 100644 --- a/src/containers/SearchBar/index.js +++ b/src/containers/SearchBar/index.js @@ -9,7 +9,7 @@ import { buildingsSearched, } from './actions'; import './styles.css'; -import { buildingListPropTypes } from './propTypes'; +import { buildingsPropTypes } from './propTypes'; const mapAccess = { @@ -34,19 +34,19 @@ class SearchBar extends Component { } componentDidMount() { - // Use the buildings stored in cookies to populate the buildingList - const buildingList = localStorage.activeBuildings; - if (buildingList !== undefined) { - this.props.buildingsSearched(JSON.parse(buildingList)); + // Use the buildings stored in cookies to populate the buildings + const buildings = localStorage.activeBuildings; + if (buildings !== undefined) { + this.props.buildingsSearched(JSON.parse(buildings)); } } componentWillReceiveProps(nextProps) { if ( - this.props.buildingList !== nextProps.buildingList + this.props.buildings !== nextProps.buildings ) { this.setState({ - address: nextProps.buildingList.address, + address: nextProps.buildings.address, }); } } @@ -119,7 +119,7 @@ class SearchBar extends Component { } SearchBar.propTypes = { - buildingList: buildingListPropTypes, + buildings: buildingsPropTypes, searchBuildings: PropTypes.func, buildingsSearched: PropTypes.func, }; @@ -131,8 +131,8 @@ function mapDispatchToProps(dispatch) { }, dispatch); } -function mapStateToProps({ buildingList }) { - return { buildingList }; +function mapStateToProps({ buildings }) { + return { buildings }; } export default connect(mapStateToProps, mapDispatchToProps)(SearchBar); diff --git a/src/containers/SearchBar/propTypes.js b/src/containers/SearchBar/propTypes.js index 2eafabea..7ad06875 100644 --- a/src/containers/SearchBar/propTypes.js +++ b/src/containers/SearchBar/propTypes.js @@ -10,7 +10,7 @@ export const loadErrorPropTypes = { ]), }; -export const buildingList = arrayOf( +export const buildings = arrayOf( shape({ street_address: string, bbl: number, @@ -28,8 +28,8 @@ export const searchParams = shape({ term: string, }); -export const buildingListPropTypes = PropTypes.shape({ +export const buildingsPropTypes = PropTypes.shape({ ...searchParams, - buildings: buildingList, + buildings, ...loadErrorPropTypes, }); diff --git a/src/reducers.js b/src/reducers.js index 1cf26cca..52d7e7db 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -1,44 +1,44 @@ import { combineReducers } from 'redux'; import { routerReducer } from 'react-router-redux'; -import SearchBarReducer from './containers/SearchBar/reducer'; -import ProjectSearchBarReducer from './containers/Project/reducer'; -import BuildingReducer from './containers/Building/reducer'; -import DimensionsReducer from './containers/Dimensions/reducer'; -import documents from './containers/Documents/reducer'; -import eng from './containers/Eng/reducer'; -import envelope from './containers/Envelope/reducer'; -import buildingReport from './containers/BuildingReports/reducer'; -import report from './containers/Reports/reducer'; -import bGroup from './containers/BGroup/reducer'; -import user from './containers/User/reducer'; -import sensors from './containers/Sensors/reducer'; -import buildingArea from './containers/BuildingArea/reducer'; -import weather from './containers/Weather/reducer'; -import events from './containers/Event/reducer'; -import blocnote from './containers/Blocnote/reducer'; -import bloclink from './containers/Performance/reducer'; -import questionnaire from './containers/Questionnaire/reducer'; +import buildingSearchReducer from './containers/SearchBar/reducer'; +import projectReducer from './containers/Project/reducer'; +import buildingReducer from './containers/Building/reducer'; +import dimensionReducer from './containers/Dimensions/reducer'; +import documentReducer from './containers/Documents/reducer'; +import engReducer from './containers/Eng/reducer'; +import envelopeReducer from './containers/Envelope/reducer'; +import buildingReportsReducer from './containers/BuildingReports/reducer'; +import reportReducer from './containers/Reports/reducer'; +import bGroupReducer from './containers/BGroup/reducer'; +import userReducer from './containers/User/reducer'; +import sensorReducer from './containers/Sensors/reducer'; +import buildingAreaReducer from './containers/BuildingArea/reducer'; +import weatherReducer from './containers/Weather/reducer'; +import eventReducer from './containers/Event/reducer'; +import blocnoteReducer from './containers/Blocnote/reducer'; +import performanceReducer from './containers/Performance/reducer'; +import questionnaireReducer from './containers/Questionnaire/reducer'; export default combineReducers({ routing: routerReducer, - buildingList: SearchBarReducer, - projectList: ProjectSearchBarReducer, - buildingDetail: BuildingReducer, - dimensions: DimensionsReducer, - documents, - eng, - envelope, - buildingReport, - report, - bGroup, - user, - sensors, - buildingArea, - weather, - events, - blocnote, - bloclink, - questionnaire, + buildings: buildingSearchReducer, + projects: projectReducer, + building: buildingReducer, + dimensions: dimensionReducer, + documents: documentReducer, + eng: engReducer, + envelope: envelopeReducer, + buildingReport: buildingReportsReducer, + report: reportReducer, + bGroup: bGroupReducer, + user: userReducer, + sensors: sensorReducer, + buildingArea: buildingAreaReducer, + weather: weatherReducer, + events: eventReducer, + blocnote: blocnoteReducer, + performance: performanceReducer, + questionnaire: questionnaireReducer, }); diff --git a/src/screens/BuildingsHomePage/index.js b/src/screens/BuildingsHomePage/index.js index a984fcc6..5a747d0d 100644 --- a/src/screens/BuildingsHomePage/index.js +++ b/src/screens/BuildingsHomePage/index.js @@ -5,7 +5,7 @@ import { bindActionCreators } from 'redux'; import NavBar from '../../components/NavBar'; import AddressSearchBuildings from '../../components/AddressSearchBuildings'; import BuildingListTable from '../../components/BuildingListTable'; -import { buildingListPropTypes } from '../../containers/SearchBar/propTypes'; +import { buildingsPropTypes } from '../../containers/SearchBar/propTypes'; import { searchBuildings, buildingsSearched, @@ -27,9 +27,9 @@ class BuildingsHomePage extends Component { componentWillReceiveProps(nextProps) { if ( - this.props.buildingList !== nextProps.buildingList - && this.props.buildingList.buildings.length !== 0 - && nextProps.buildingList.buildings.length === 0 + this.props.buildings !== nextProps.buildings + && this.props.buildings.buildings.length !== 0 + && nextProps.buildings.buildings.length === 0 ) { this.props.createBuilding(this.state.address); } @@ -51,9 +51,9 @@ class BuildingsHomePage extends Component { buildingsSearched={this.props.buildingsSearched} searchBuildings={this.props.searchBuildings} logoOnClick={() => { - const buildingList = localStorage.activeBuildings; - if (buildingList !== undefined) { - this.props.buildingsSearched(JSON.parse(buildingList)); + const buildings = localStorage.activeBuildings; + if (buildings !== undefined) { + this.props.buildingsSearched(JSON.parse(buildings)); } }} user={this.props.user} @@ -61,15 +61,15 @@ class BuildingsHomePage extends Component {
- There was a problem retrieving the buildings. | {this.props.buildingList.error.message} + There was a problem retrieving the buildings. | {this.props.buildings.error.message}
@@ -78,15 +78,15 @@ class BuildingsHomePage extends Component { } BuildingsHomePage.propTypes = { - buildingList: buildingListPropTypes, + buildings: buildingsPropTypes, searchBuildings: PropTypes.func, buildingsSearched: PropTypes.func, createBuilding: PropTypes.func, user: userPropType, }; -function mapStateToProps({ buildingList }) { - return { buildingList }; +function mapStateToProps({ buildings }) { + return { buildings }; } function mapDispatchToProps(dispatch) { return bindActionCreators({ diff --git a/src/screens/HomePage/index.js b/src/screens/HomePage/index.js index 58cc99b6..aa37acbe 100644 --- a/src/screens/HomePage/index.js +++ b/src/screens/HomePage/index.js @@ -125,12 +125,12 @@ class HomePage extends Component { } renderViewedProjects = () => { - const projectListJSON = localStorage.activeProjects; - let projectList = []; - if (projectListJSON !== null && projectListJSON !== undefined) { - projectList = JSON.parse(projectListJSON).slice(0, HomePage.recentViewedProjectLimit); + const projectsJSON = localStorage.activeProjects; + let projects = []; + if (projectsJSON !== null && projectsJSON !== undefined) { + projects = JSON.parse(projectsJSON).slice(0, HomePage.recentViewedProjectLimit); } - const content = projectList.map(i => ( + const content = projects.map(i => (
Building {i.building_id}
@@ -152,12 +152,12 @@ class HomePage extends Component { } renderViewedBuildings = () => { - const buildingListJSON = localStorage.activeBuildings; - let buildingList = []; - if (buildingListJSON !== null && buildingListJSON !== undefined) { - buildingList = JSON.parse(buildingListJSON).slice(0, HomePage.recentViewedBuildingLimit); + const buildingsJSON = localStorage.activeBuildings; + let buildings = []; + if (buildingsJSON !== null && buildingsJSON !== undefined) { + buildings = JSON.parse(buildingsJSON).slice(0, HomePage.recentViewedBuildingLimit); } - const content = buildingList.map(i => ( + const content = buildings.map(i => (
Building {i.building_id}
@@ -322,8 +322,8 @@ function mapDispatchToProps(dispatch) { }, dispatch); } -function mapStateToProps({ projectList }) { - return { recentProjects: projectList.recentProjects }; +function mapStateToProps({ projects }) { + return { recentProjects: projects.recentProjects }; } export default connect(mapStateToProps, mapDispatchToProps)(HomePage); diff --git a/src/screens/ProjectsHomePage/index.js b/src/screens/ProjectsHomePage/index.js index 6838ec04..e594d8d9 100644 --- a/src/screens/ProjectsHomePage/index.js +++ b/src/screens/ProjectsHomePage/index.js @@ -29,25 +29,25 @@ class ProjectHomePage extends Component { displayAudit={false} SearchBar={ProjectSearchBar} logoOnClick={() => { - const projectList = localStorage.activeProjects; - if (projectList !== undefined) { - this.props.projectsLoaded({ data: JSON.parse(projectList) }); + const projects = localStorage.activeProjects; + if (projects !== undefined) { + this.props.projectsLoaded({ data: JSON.parse(projects) }); } }} />
- There was a problem retrieving the projects. | {this.props.projectList.error.message} + There was a problem retrieving the projects. | {this.props.projects.error.message}
@@ -56,15 +56,15 @@ class ProjectHomePage extends Component { } ProjectHomePage.propTypes = { - projectList: completeProjectPropTypes, + projects: completeProjectPropTypes, updateProjectSearchParams: PropTypes.func, loadProjects: PropTypes.func, projectsLoaded: PropTypes.func, user: userPropType, }; -function mapStateToProps({ projectList }) { - return { projectList }; +function mapStateToProps({ projects }) { + return { projects }; } function mapDispatchToProps(dispatch) { return bindActionCreators({ -- GitLab From 6c525fe18fc4bff6ea9a91926343a90383d8f709 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 28 Apr 2020 14:04:15 -0400 Subject: [PATCH 2/4] Fix buildings not loading issues --- src/components/BuildingListTable/index.js | 12 ++-- src/containers/Dimensions/index.js | 1 - src/reducers.js | 72 +++++++++++------------ 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/components/BuildingListTable/index.js b/src/components/BuildingListTable/index.js index 13e1bb4f..35459415 100644 --- a/src/components/BuildingListTable/index.js +++ b/src/components/BuildingListTable/index.js @@ -3,12 +3,12 @@ import ReactGA from 'react-ga'; import PropTypes from 'prop-types'; import { browserHistory } from 'react-router'; import './styles.css'; -import { buildings, loadErrorPropTypes } from '../../containers/SearchBar/propTypes'; +import { loadErrorPropTypes } from '../../containers/SearchBar/propTypes'; import Loading from '../../components/Loading'; /* eslint-disable no-param-reassign */ export default function BuildingListTable({ - buildingList, + buildings, loading, loadBuildings, error, @@ -24,7 +24,7 @@ export default function BuildingListTable({ return
; } - if (!buildingList || buildingList.length === 0) { + if (!buildings || buildings.length === 0) { return (
{ + const lotGrouping = buildings.reduce((acc, building) => { if (building.bbl in acc) { acc[building.bbl] += 1; } else { @@ -110,7 +110,7 @@ export default function BuildingListTable({ return acc; }, {}); - const buildingItems = buildingList.map((building) => { + const buildingItems = buildings.map((building) => { let bblTd = (); if (building.bbl in lotGrouping || !bblDisplay) { bblTd = ( @@ -167,7 +167,7 @@ export default function BuildingListTable({ } BuildingListTable.propTypes = { - buildingList: buildings, + buildings: PropTypes.arrayOf, loading: PropTypes.bool, error: loadErrorPropTypes.error, loadBuildings: PropTypes.func, diff --git a/src/containers/Dimensions/index.js b/src/containers/Dimensions/index.js index c8798bde..2400ebff 100644 --- a/src/containers/Dimensions/index.js +++ b/src/containers/Dimensions/index.js @@ -66,7 +66,6 @@ class Dimensions extends Component { Dimensions.propTypes = { buildingId: PropTypes.string, - building: completeOverviewPropTypes, building: PropTypes.shape(overviewPropTypes), dimensions: PropTypes.shape({ hit: turkHitPropTypes, diff --git a/src/reducers.js b/src/reducers.js index 52d7e7db..78fd4b3c 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -1,44 +1,44 @@ import { combineReducers } from 'redux'; import { routerReducer } from 'react-router-redux'; -import buildingSearchReducer from './containers/SearchBar/reducer'; -import projectReducer from './containers/Project/reducer'; -import buildingReducer from './containers/Building/reducer'; -import dimensionReducer from './containers/Dimensions/reducer'; -import documentReducer from './containers/Documents/reducer'; -import engReducer from './containers/Eng/reducer'; -import envelopeReducer from './containers/Envelope/reducer'; -import buildingReportsReducer from './containers/BuildingReports/reducer'; -import reportReducer from './containers/Reports/reducer'; -import bGroupReducer from './containers/BGroup/reducer'; -import userReducer from './containers/User/reducer'; -import sensorReducer from './containers/Sensors/reducer'; -import buildingAreaReducer from './containers/BuildingArea/reducer'; -import weatherReducer from './containers/Weather/reducer'; -import eventReducer from './containers/Event/reducer'; -import blocnoteReducer from './containers/Blocnote/reducer'; -import performanceReducer from './containers/Performance/reducer'; -import questionnaireReducer from './containers/Questionnaire/reducer'; +import buildings from './containers/SearchBar/reducer'; +import projects from './containers/Project/reducer'; +import building from './containers/Building/reducer'; +import dimensions from './containers/Dimensions/reducer'; +import documents from './containers/Documents/reducer'; +import eng from './containers/Eng/reducer'; +import envelope from './containers/Envelope/reducer'; +import buildingReport from './containers/BuildingReports/reducer'; +import report from './containers/Reports/reducer'; +import bGroup from './containers/BGroup/reducer'; +import user from './containers/User/reducer'; +import sensors from './containers/Sensors/reducer'; +import buildingArea from './containers/BuildingArea/reducer'; +import weather from './containers/Weather/reducer'; +import events from './containers/Event/reducer'; +import blocnote from './containers/Blocnote/reducer'; +import performance from './containers/Performance/reducer'; +import questionnaire from './containers/Questionnaire/reducer'; export default combineReducers({ routing: routerReducer, - buildings: buildingSearchReducer, - projects: projectReducer, - building: buildingReducer, - dimensions: dimensionReducer, - documents: documentReducer, - eng: engReducer, - envelope: envelopeReducer, - buildingReport: buildingReportsReducer, - report: reportReducer, - bGroup: bGroupReducer, - user: userReducer, - sensors: sensorReducer, - buildingArea: buildingAreaReducer, - weather: weatherReducer, - events: eventReducer, - blocnote: blocnoteReducer, - performance: performanceReducer, - questionnaire: questionnaireReducer, + buildings, + projects, + building, + dimensions, + documents, + eng, + envelope, + buildingReport, + report, + bGroup, + user, + sensors, + buildingArea, + weather, + events, + blocnote, + performance, + questionnaire, }); -- GitLab From 3d48f5e28d3cae04c9d8ac712a3f20c6b9999e36 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 28 Apr 2020 16:42:11 -0400 Subject: [PATCH 3/4] Fix BGroup buildings not showing issue --- src/containers/BGroup/reducer.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/containers/BGroup/reducer.js b/src/containers/BGroup/reducer.js index b920b223..1de2c1cf 100644 --- a/src/containers/BGroup/reducer.js +++ b/src/containers/BGroup/reducer.js @@ -88,13 +88,15 @@ export default (state = initState, action) => { bGroupDetailError: false, }; - case BGROUP_DETAIL_SUCCEEDED: + case BGROUP_DETAIL_SUCCEEDED: { + console.log(action.bGroup.data); // eslint-disable-line no-console return { ...state, bGroupDetail: action.bGroup.data, bGroupDetailLoading: false, bGroupDetailError: false, }; + } case BGROUP_DETAIL_FAILED: return { ...state, bGroupDetailLoading: false, bGroupDetailError: action.error }; @@ -108,16 +110,17 @@ export default (state = initState, action) => { case DELETE_BGROUP_FAILED: return { ...state, deleteBGroupLoading: false, deleteBGroupError: action.error }; - case BGROUP_BUILDINGS_REQUESTED: + case BGROUP_BUILDINGS_REQUESTED: { return { ...state, bGroupBuildingsLoading: true, bGroupBuildingsError: false, bGroupBuildings: [], }; + } case BGROUP_BUILDINGS_SUCCEEDED: { - const buildings = action.buildings.data.map(i => ({ ...i, first_address: i.address_list.split(',')[0] })); + const buildings = action.buildings.data.map(i => ({ ...i, first_address: i.address_list !== null ? i.address_list.split(',')[0] : '' })); return { ...state, bGroupBuildings: buildings, -- GitLab From c259333cfc106cb763090ee8b5a247450e14bbc2 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 28 Apr 2020 18:03:46 -0400 Subject: [PATCH 4/4] Remove unnecessary brackets --- src/containers/BGroup/reducer.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/containers/BGroup/reducer.js b/src/containers/BGroup/reducer.js index 1de2c1cf..b7b66ab5 100644 --- a/src/containers/BGroup/reducer.js +++ b/src/containers/BGroup/reducer.js @@ -88,15 +88,13 @@ export default (state = initState, action) => { bGroupDetailError: false, }; - case BGROUP_DETAIL_SUCCEEDED: { - console.log(action.bGroup.data); // eslint-disable-line no-console + case BGROUP_DETAIL_SUCCEEDED: return { ...state, bGroupDetail: action.bGroup.data, bGroupDetailLoading: false, bGroupDetailError: false, }; - } case BGROUP_DETAIL_FAILED: return { ...state, bGroupDetailLoading: false, bGroupDetailError: action.error }; @@ -110,14 +108,13 @@ export default (state = initState, action) => { case DELETE_BGROUP_FAILED: return { ...state, deleteBGroupLoading: false, deleteBGroupError: action.error }; - case BGROUP_BUILDINGS_REQUESTED: { + case BGROUP_BUILDINGS_REQUESTED: return { ...state, bGroupBuildingsLoading: true, bGroupBuildingsError: false, bGroupBuildings: [], }; - } case BGROUP_BUILDINGS_SUCCEEDED: { const buildings = action.buildings.data.map(i => ({ ...i, first_address: i.address_list !== null ? i.address_list.split(',')[0] : '' })); -- GitLab