From 3007dbfd26dbf4787be96115a2275cc77254873a Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 10 Apr 2020 23:06:43 -0400 Subject: [PATCH 1/2] Add create building updates --- src/components/AddressSearchBGroup/index.js | 22 +++++++++----------- src/components/NavBar/index.js | 8 +++---- src/containers/BGroup/BGroup.js | 18 ++++++++++++---- src/containers/BGroup/BGroupBuildingTable.js | 13 ++++++------ src/containers/SearchBar/sagas.js | 2 +- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/src/components/AddressSearchBGroup/index.js b/src/components/AddressSearchBGroup/index.js index b89040fa..1301adaa 100644 --- a/src/components/AddressSearchBGroup/index.js +++ b/src/components/AddressSearchBGroup/index.js @@ -23,6 +23,7 @@ class AddressSearchBGroup extends Component { searchClicked: false, addClicked: false, bGroupBuildings: this.props.bGroupBuildings, + buildings: [], }; } @@ -33,6 +34,9 @@ class AddressSearchBGroup extends Component { address: nextProps.buildings[0].placeName, }); } + if (this.props.buildings.length === 0 && nextProps.buildings.length > 0) { + this.setState({ buildings: nextProps.buildings }); + } } handleOnSelected = (viewport, item) => { @@ -43,11 +47,12 @@ class AddressSearchBGroup extends Component { searchClicked: true, }, () => { this.props.searchBuildings(this.state.address); + this.props.setAddress(this.state.address); }); } handleOnAddBuilding = () => { - this.props.addSelectedAddress(); + this.props.addSelectedAddress(this.state.buildings[0]); this.setState({ addClicked: true }); } @@ -90,9 +95,9 @@ class AddressSearchBGroup extends Component { let result = ''; const bGroupBuildingIDs = this.state.bGroupBuildings.map(building => building.building_id); - if (this.props.buildings !== undefined && this.props.buildings.length > 0) { + if (this.state.buildings.length > 0) { if (this.state.searchClicked) { - if (bGroupBuildingIDs.includes(this.props.buildings[0].building_id)) { + if (bGroupBuildingIDs.includes(this.state.buildings[0].building_id)) { result = (
This address already exists in the building group, please enter another one. @@ -109,7 +114,7 @@ class AddressSearchBGroup extends Component { } } if (this.state.addClicked && - !bGroupBuildingIDs.includes(this.props.buildings[0].building_id)) { + !bGroupBuildingIDs.includes(this.state.buildings[0].building_id)) { result = (
Building has been successfully added to the group! @@ -118,14 +123,6 @@ class AddressSearchBGroup extends Component { } } - if (this.state.searchClicked && - (this.props.buildings === undefined || this.props.buildings.length === 0)) { - result = ( -
- There is an error in building address search, please contact admin. -
- ); - } const content = (
@@ -155,6 +152,7 @@ AddressSearchBGroup.propTypes = { searchBuildings: PropTypes.func, buildingsSearched: PropTypes.func, addSelectedAddress: PropTypes.func, + setAddress: PropTypes.func, }; export default AddressSearchBGroup; diff --git a/src/components/NavBar/index.js b/src/components/NavBar/index.js index 9c3c1e8f..83d62f61 100644 --- a/src/components/NavBar/index.js +++ b/src/components/NavBar/index.js @@ -27,14 +27,14 @@ export default class NavBar extends Component { this.setState({ collapsed }) ) - buildingsSearched = buildings => ( - this.props.buildingsSearched(buildings) - ) - searchBuildings = address => ( this.props.searchBuildings(address) ) + buildingsSearched = buildings => ( + this.props.buildingsSearched(buildings) + ) + toggleNavbar = () => ( this.setState({ collapsed: !this.state.collapsed, diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 601400d3..287edbd2 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -20,7 +20,7 @@ import { } from './actions'; import { searchBuildings, - buildingsSearched, + createBuilding, } from '../SearchBar/actions'; // import { loadBuildings } from '../Building/actions'; import BGroupProjectOverview from './BGroupProjectOverview'; @@ -75,6 +75,7 @@ export class BGroup extends Component { impactError: false, impact: {}, overviewTab: this.props.user.permissions['view::bgroupProjectsSummary'] && this.props.displayProjectOverview ? 'projects' : 'buildings', + address: '', } componentDidMount() { @@ -106,6 +107,7 @@ export class BGroup extends Component { } } } + if (nextProps.projects.projects !== this.props.projects.project) { const projectTypeBreakdown = {}; const projectStatusBreakdown = {}; @@ -136,6 +138,14 @@ export class BGroup extends Component { } } + setAddress = (address) => { + this.setState({ address }, () => { + if (this.props.buildings.buildings.length === 0) { + this.props.createBuilding(this.state.address); + } + }); + } + getSfBuildingImpact = (buildingIds) => { // A function to get impat data for each building this.setState({ impactLoading: true }); @@ -210,8 +220,6 @@ export class BGroup extends Component { }; return acc; }, {}); - console.log("heatPumpScores"); // eslint-disable-line - console.log(heatPumpScores); // eslint-disable-line this.setState({ heatPumpScores }); } else { // this.setState({ heatPumpError: true }); @@ -422,6 +430,7 @@ export class BGroup extends Component { buildings={this.props.buildings.buildings} // searchedBuildings={this.props.searchedBuildings} searchBuildings={this.props.searchBuildings} + setAddress={this.setAddress} bGroup={this.props.bGroup} addBuildingToBGroup={this.props.addBuildingToBGroup} deleteBuildingFromBGroup={this.props.deleteBuildingFromBGroup} @@ -527,6 +536,7 @@ BGroup.propTypes = { bGroupId: PropTypes.string, }), searchBuildings: PropTypes.func, + createBuilding: PropTypes.func, bGroup: PropTypes.object, // eslint-disable-line loadBGroupBuildings: PropTypes.func, loadBGroupDetail: PropTypes.func, @@ -583,7 +593,7 @@ const mapStateToProps = state => ( const mapDispatchToProps = dispatch => ( bindActionCreators({ searchBuildings, - buildingsSearched, + createBuilding, loadBGroupBuildings, loadBGroupDetail, addBuildingToBGroup, diff --git a/src/containers/BGroup/BGroupBuildingTable.js b/src/containers/BGroup/BGroupBuildingTable.js index f6e1f820..c5550bb8 100644 --- a/src/containers/BGroup/BGroupBuildingTable.js +++ b/src/containers/BGroup/BGroupBuildingTable.js @@ -39,16 +39,15 @@ export default class BGroupBuildingTable extends Component { clearTimeout(this.updateNumRows); } - handleSearchBuildings = (address) => { + searchBuildings = (address) => { this.props.searchBuildings(address); } - handleAddBuilding = () => { - const item = this.props.buildings[0]; + handleAddBuilding = (building) => { this.props.addBuildingToBGroup( this.props.bGroupId, - { building_ids: [item.building_id] }, - item.placeName, + { building_ids: [building.building_id] }, + building.placeName, ); this.setState({ increaseNum: true }); } @@ -895,8 +894,9 @@ export default class BGroupBuildingTable extends Component {
@@ -1126,4 +1126,5 @@ BGroupBuildingTable.propTypes = { toggleProjects: PropTypes.bool, toggleImpact: PropTypes.bool, onBuildingFilter: PropTypes.func, + setAddress: PropTypes.func, }; diff --git a/src/containers/SearchBar/sagas.js b/src/containers/SearchBar/sagas.js index bc102589..abf514a1 100644 --- a/src/containers/SearchBar/sagas.js +++ b/src/containers/SearchBar/sagas.js @@ -51,7 +51,7 @@ function* createBuilding(action) { bbl: 3012410005, bin: 3031524, borough: 'BROOKLYN', - building_id: 181725, + building_id: 181727, lot_id: 759242, street_address: '838 PARK PLACE', targeting_score: 73.9496248660236, -- GitLab From c469a2b5a674281c09b466b8f770b1f672bf2f96 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 10 Apr 2020 23:25:27 -0400 Subject: [PATCH 2/2] Add generate random building id updates --- src/containers/SearchBar/sagas.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/containers/SearchBar/sagas.js b/src/containers/SearchBar/sagas.js index abf514a1..7fd6ef04 100644 --- a/src/containers/SearchBar/sagas.js +++ b/src/containers/SearchBar/sagas.js @@ -51,7 +51,9 @@ function* createBuilding(action) { bbl: 3012410005, bin: 3031524, borough: 'BROOKLYN', - building_id: 181727, + // building_id: 181727, + // Following code generate random building id + building_id: Math.floor((Math.random() * (200000 - 170000)) + 170000), lot_id: 759242, street_address: '838 PARK PLACE', targeting_score: 73.9496248660236, -- GitLab