diff --git a/src/components/AddressSearchBGroup/index.js b/src/components/AddressSearchBGroup/index.js
index b89040fafc08d384df2d8335025d03592133bbda..1301adaae53e4788ba856dacd8dc04c7e2ab6b61 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 9c3c1e8f87d5b32952fb79040de53fb77b927889..83d62f616bfbeabe161d0137fe9185a39d50a08b 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 601400d3635bdcf7fe91beefe22dc51442fbb225..287edbd25c79825dd78677ecb536f16ec59be97c 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 f6e1f820c9e25a4a1125f20459c3372eb005bccc..c5550bb8fc783d31043b8def1f563b2299f2536f 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 bc1025893d4219c9f78037a9fae61b8f28278131..7fd6ef04c3112fec906462bd28fe5baba83e7dd0 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: 181725,
+ // 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,