diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index dffc38bd1fbda9f4d8f5742c95e0adc84b6d2913..55268b529c4f1a8da89c67ccdc60b6dd13a17ba7 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -28,7 +28,7 @@ import userPropType from '../User/propTypes'; import request from '../../utils/request'; import { getHeaders, accountURL, gatewayURL, - contactsURL, sfBuildingImpactURL, + contactsURL, sfBuildingImpactURL, heatPumpScoresURL, } from '../../utils/restServices'; import './styles.css'; @@ -56,6 +56,9 @@ export class BGroup extends Component { projectStatusBreakdown: {}, contactAccounts: {}, contactParentAccounts: {}, + heatPumpScoresLoading: false, + heatPumpError: false, + heatPumpScores: {}, contactLoading: false, contactError: false, impactLoading: false, @@ -83,6 +86,7 @@ export class BGroup extends Component { if (this.props.user.permissions['read::Gateway']) { this.getGatewayDates(buildingIds); } + this.getHeatPumpScores(buildingIds); this.getSimulationDates(buildingIds); this.getSfBuildingImpact(buildingIds); if (nextProps.user.permissions['read::CustomImpact']) { @@ -161,6 +165,52 @@ export class BGroup extends Component { } + getHeatPumpScores = (buildingIds) => { + // A function to get all of the contact information for buildings + this.setState({ heatPumpScoresLoading: true }); + const filterString = buildingIds.reduce((acc, val) => ( + `${acc}building_ids[]=${val}&` + ), ''); + request(`${heatPumpScoresURL}?${filterString}`, { + method: 'GET', + headers: getHeaders(), + }).then((res) => { + // Dummy data for building Group: 26 in Dev + // const data = res.data; + this.setState({ heatPumpScoresLoading: false }); + const data = [ + { building_id: 1189745, score: 50 }, + { building_id: 1189744, score: 40 }, + { building_id: 1189743, score: 30 }, + { building_id: 1189742, score: 20 }, + { building_id: 1189741, score: 10 }, + ]; + + if (!res.err && data) { + const heatPumpScores = data.reduce((acc, val) => { + if (!acc[val.building_id]) { + acc[val.building_id] = []; + } + + acc[val.building_id].push(val.score); + return acc; + }, {}); + this.setState({ heatPumpScores }); + } else { + // this.setState({ heatPumpError: true }); + const heatPumpScores = data.reduce((acc, val) => { + if (!acc[val.building_id]) { + acc[val.building_id] = []; + } + + acc[val.building_id].push(val.score); + return acc; + }, {}); + this.setState({ heatPumpScores }); + } + }); + } + getContacts = (projects) => { // A function to get all of the contact information for buildings this.setState({ contactLoading: true }); @@ -347,15 +397,18 @@ export class BGroup extends Component { utilityAccountsStatus={this.state.utilityAccountsStatus} gatewayDates={this.state.gatewayDates} simulationDates={this.state.simulationDates} + heatPumpScores={this.state.heatPumpScores} contactAccounts={this.state.contactAccounts} contactParentAccounts={this.state.contactParentAccounts} impact={this.state.impact} + heatPumpScoresLoading={this.state.heatPumpScoresLoading} contactLoading={this.state.contactLoading} utilityLoading={this.state.utilityLoading} simulationLoading={this.state.simulationLoading} gatewayLoading={this.state.gatewayLoading} impactLoading={this.state.impactLoading} displayToggleColumns={this.props.displayToggleColumns} + toggleScores={this.props.toggleScores} toggleContacts={this.props.toggleContacts} toggleAnalysis={this.props.toggleAnalysis} toggleProjects={this.props.toggleProjects} @@ -454,6 +507,7 @@ BGroup.propTypes = { displayAllGroupsButton: PropTypes.bool, displayEditButton: PropTypes.bool, displayToggleColumns: PropTypes.bool, + toggleScores: PropTypes.bool, toggleContacts: PropTypes.bool, toggleAnalysis: PropTypes.bool, toggleProjects: PropTypes.bool, @@ -469,6 +523,7 @@ BGroup.defaultProps = { displayAllGroupsButton: true, displayEditButton: true, displayToggleColumns: true, + toggleScores: true, toggleContacts: false, toggleAnalysis: true, toggleProjects: true, diff --git a/src/containers/BGroup/BGroupBuildingTable.js b/src/containers/BGroup/BGroupBuildingTable.js index 3faf0c211b164f4049a611861458d77d7474d4fb..5f90f4028d5f5d7ca4b04f0187b124a0508904a7 100644 --- a/src/containers/BGroup/BGroupBuildingTable.js +++ b/src/containers/BGroup/BGroupBuildingTable.js @@ -21,6 +21,7 @@ export default class BGroupBuildingTable extends Component { // This relies on the fact that bgroup has already loaded // when this component is allowed to mount numRows: this.props.bGroup.bGroupBuildings.length, + displayScores: this.props.toggleScores, displayContact: this.props.toggleContacts, displayAnalysis: this.props.toggleAnalysis, displayProjects: this.props.toggleProjects, @@ -75,9 +76,11 @@ export default class BGroupBuildingTable extends Component { utilityAccountsStatus, gatewayDates, simulationDates, + heatPumpScores, contactAccounts, contactParentAccounts, impact, + scoresLoading, contactLoading, utilityLoading, simulationLoading, @@ -330,7 +333,30 @@ export default class BGroupBuildingTable extends Component { ), }], ], - }, ...(!this.state.displayContact) ? [] : [{ + }, ...(!this.state.displayScores) ? [] : [{ + Header: () => ( + + Scores{' '} + + + ), + columns: [ + { + Header: 'Heat Pump', + filterable: false, + accessor: 'heat_pump_score', + Cell: row => ( +
+ {row.value} +
+ ), + }, + ], + }], ...(!this.state.displayContact) ? [] : [{ Header: () => ( Contact Info{' '} @@ -692,6 +718,7 @@ export default class BGroupBuildingTable extends Component { } val.gateway_install = gatewayDates[val.building_id]; val.building_simulation = simulationDates[val.building_id]; + val.heat_pump_score = heatPumpScores[val.building_id]; val.contact_account = contactAccounts[val.building_id]; val.contact_parent_account = contactParentAccounts[val.building_id]; if (impact[val.building_id]) { @@ -746,6 +773,22 @@ export default class BGroupBuildingTable extends Component { Toggle Columns + { + this.setState({ displayScores: !this.state.displayScores }); + }} + > + + {}} + />{' '} + Scores + + { @@ -911,15 +954,18 @@ BGroupBuildingTable.propTypes = { utilityAccountsStatus: PropTypes.object, gatewayDates: PropTypes.object, simulationDates: PropTypes.object, + heatPumpScores: PropTypes.object, contactAccounts: PropTypes.object, contactParentAccounts: PropTypes.object, impact: PropTypes.object, + scoresLoading: PropTypes.bool, contactLoading: PropTypes.bool, utilityLoading: PropTypes.bool, simulationLoading: PropTypes.bool, gatewayLoading: PropTypes.bool, impactLoading: PropTypes.bool, displayToggleColumns: PropTypes.bool, + toggleScores: PropTypes.bool, toggleContacts: PropTypes.bool, toggleAnalysis: PropTypes.bool, toggleProjects: PropTypes.bool, diff --git a/src/utils/restServices.js b/src/utils/restServices.js index cd5c030ce7b6b9e353b43d48e46f61dc9cc15f3f..9e83403123f4ff5c0984fb6c787731d6a2b44582 100644 --- a/src/utils/restServices.js +++ b/src/utils/restServices.js @@ -20,6 +20,7 @@ export const commonAreasURL = `${buildingService}/commonarea/`; export const serviceAreasURL = `${buildingService}/servicearea/`; export const spacesURL = `${buildingService}/space/`; export const turkURL = `${buildingService}/turkhit/`; +export const heatPumpScoresURL = `${buildingService}/score/heatpump/`; export const documentURL = `${documentService}/document/`; export const folderURL = `${documentService}/folder/`;