From a173fbf453db7f314a7782345f3b287519a03718 Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 14 Feb 2019 13:20:02 -0500 Subject: [PATCH 01/18] Update React Container Js to include Scores section to BGroup Building Table --- src/containers/BGroup/BGroup.js | 46 +++++++++++++++++++- src/containers/BGroup/BGroupBuildingTable.js | 45 ++++++++++++++++++- src/utils/restServices.js | 1 + 3 files changed, 90 insertions(+), 2 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index dffc38bd..55f591ba 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -27,7 +27,7 @@ import reportsPropTypes from '../Reports/propTypes'; import userPropType from '../User/propTypes'; import request from '../../utils/request'; import { - getHeaders, accountURL, gatewayURL, + getHeaders, accountURL, gatewayURL, scoresURL, contactsURL, sfBuildingImpactURL, } from '../../utils/restServices'; import './styles.css'; @@ -56,6 +56,8 @@ export class BGroup extends Component { projectStatusBreakdown: {}, contactAccounts: {}, contactParentAccounts: {}, + scoresLoading: false, + scoresError: false, contactLoading: false, contactError: false, impactLoading: false, @@ -161,6 +163,44 @@ export class BGroup extends Component { } + getScores = (projects) => { + // A function to get all of the contact information for buildings + this.setState({ scoresLoading: true }); + const buildingIdList = []; + const salesForceToBuilding = {}; + const projectList = projects.reduce((acc, val) => { + if (buildingIdList.indexOf(val.building_id) < 0) { + buildingIdList.push(val.building_id); + acc.push(val); + salesForceToBuilding[val.sales_force_id] = val.building_id; + } + return acc; + }, []); + const filterString = projectList.reduce((acc, val) => ( + `${acc}sales_force_id[]=${val.sales_force_id}&` + ), ''); + request(`${scoresURL}?${filterString}`, { + method: 'GET', + headers: getHeaders(), + }).then((res) => { + this.setState({ scoresLoading: false }); + const data = res.data; + if (!res.err && data) { + const contactAccounts = {}; + const contactParentAccounts = {}; + data.map((val) => { + const buildingId = salesForceToBuilding[val.sales_force_id]; + contactAccounts[buildingId] = val.account_name; + contactParentAccounts[buildingId] = val.parent_account_name; + return val; + }); + this.setState({ contactAccounts, contactParentAccounts }); + } else { + this.setState({ scoresError: true }); + } + }); + } + getContacts = (projects) => { // A function to get all of the contact information for buildings this.setState({ contactLoading: true }); @@ -350,12 +390,14 @@ export class BGroup extends Component { contactAccounts={this.state.contactAccounts} contactParentAccounts={this.state.contactParentAccounts} impact={this.state.impact} + scoresLoading={this.state.scoresLoading} 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 +496,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 +512,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 3faf0c21..50b3cdda 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, @@ -78,6 +79,7 @@ export default class BGroupBuildingTable extends Component { contactAccounts, contactParentAccounts, impact, + scoresLoading, contactLoading, utilityLoading, simulationLoading, @@ -330,7 +332,30 @@ export default class BGroupBuildingTable extends Component { ), }], ], - }, ...(!this.state.displayContact) ? [] : [{ + }, ...(!this.state.displayScores) ? [] : [{ + Header: () => ( + + Scores{' '} + + + ), + columns: [ + { + Header: 'Heat Pump', + filterMethod: genericFilterMethod, + accessor: 'contact_account', + Cell: row => ( +
+ {row.value} +
+ ), + }, + ], + }], ...(!this.state.displayContact) ? [] : [{ Header: () => ( Contact Info{' '} @@ -746,6 +771,22 @@ export default class BGroupBuildingTable extends Component { Toggle Columns + { + this.setState({ displayScores: !this.state.displayScores }); + }} + > + + {}} + />{' '} + Scores + + { @@ -914,12 +955,14 @@ BGroupBuildingTable.propTypes = { 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 cd5c030c..da92ccee 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 scoresURL = `${buildingService}/scores/`; export const documentURL = `${documentService}/document/`; export const folderURL = `${documentService}/folder/`; -- GitLab From 178d417ce8846ee86b8202126fb827fc66fffd3c Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 14 Feb 2019 15:07:34 -0500 Subject: [PATCH 02/18] Update container JS to add scores object --- src/containers/BGroup/BGroup.js | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 55f591ba..fbed5654 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -58,6 +58,7 @@ export class BGroup extends Component { contactParentAccounts: {}, scoresLoading: false, scoresError: false, + scores: {}, contactLoading: false, contactError: false, impactLoading: false, @@ -163,21 +164,11 @@ export class BGroup extends Component { } - getScores = (projects) => { + getScores = (buildingIds) => { // A function to get all of the contact information for buildings this.setState({ scoresLoading: true }); - const buildingIdList = []; - const salesForceToBuilding = {}; - const projectList = projects.reduce((acc, val) => { - if (buildingIdList.indexOf(val.building_id) < 0) { - buildingIdList.push(val.building_id); - acc.push(val); - salesForceToBuilding[val.sales_force_id] = val.building_id; - } - return acc; - }, []); - const filterString = projectList.reduce((acc, val) => ( - `${acc}sales_force_id[]=${val.sales_force_id}&` + const filterString = buildingIds.reduce((acc, val) => ( + `${acc}building_id[]=${val}&` ), ''); request(`${scoresURL}?${filterString}`, { method: 'GET', @@ -186,15 +177,7 @@ export class BGroup extends Component { this.setState({ scoresLoading: false }); const data = res.data; if (!res.err && data) { - const contactAccounts = {}; - const contactParentAccounts = {}; - data.map((val) => { - const buildingId = salesForceToBuilding[val.sales_force_id]; - contactAccounts[buildingId] = val.account_name; - contactParentAccounts[buildingId] = val.parent_account_name; - return val; - }); - this.setState({ contactAccounts, contactParentAccounts }); + this.setState({ scores: data }); } else { this.setState({ scoresError: true }); } @@ -390,6 +373,7 @@ export class BGroup extends Component { contactAccounts={this.state.contactAccounts} contactParentAccounts={this.state.contactParentAccounts} impact={this.state.impact} + scores={this.state.scores} scoresLoading={this.state.scoresLoading} contactLoading={this.state.contactLoading} utilityLoading={this.state.utilityLoading} -- GitLab From 5167863da7ffeef4d0a629e4e45675cf63d2a256 Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 14 Feb 2019 17:11:37 -0500 Subject: [PATCH 03/18] Remove filter input for Score section, add dummy test data --- src/containers/BGroup/BGroup.js | 6 ++++-- src/containers/BGroup/BGroupBuildingTable.js | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index fbed5654..aac7286c 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -175,11 +175,13 @@ export class BGroup extends Component { headers: getHeaders(), }).then((res) => { this.setState({ scoresLoading: false }); - const data = res.data; + // const data = res.data; + const data = { scores: [50, 50, 50, 50, 50] }; if (!res.err && data) { this.setState({ scores: data }); } else { - this.setState({ scoresError: true }); + this.setState({ scores: data }); + // this.setState({ scoresError: true }); } }); } diff --git a/src/containers/BGroup/BGroupBuildingTable.js b/src/containers/BGroup/BGroupBuildingTable.js index 50b3cdda..44c8c1db 100644 --- a/src/containers/BGroup/BGroupBuildingTable.js +++ b/src/containers/BGroup/BGroupBuildingTable.js @@ -346,7 +346,7 @@ export default class BGroupBuildingTable extends Component { columns: [ { Header: 'Heat Pump', - filterMethod: genericFilterMethod, + filterable: false, accessor: 'contact_account', Cell: row => (
-- GitLab From cbf91a6715ac20980cf5b6ad86e9b7e14b6e85de Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 14 Feb 2019 19:46:08 -0500 Subject: [PATCH 04/18] Updates container scripts to add heatPumpScore variable --- src/containers/BGroup/BGroup.js | 32 ++++++++++++++------ src/containers/BGroup/BGroupBuildingTable.js | 5 ++- src/utils/restServices.js | 2 +- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index aac7286c..053a0f14 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -27,7 +27,7 @@ import reportsPropTypes from '../Reports/propTypes'; import userPropType from '../User/propTypes'; import request from '../../utils/request'; import { - getHeaders, accountURL, gatewayURL, scoresURL, + getHeaders, accountURL, gatewayURL, contactsURL, sfBuildingImpactURL, } from '../../utils/restServices'; import './styles.css'; @@ -54,6 +54,7 @@ export class BGroup extends Component { buildingIdProject: {}, projectTypeBreakdown: {}, projectStatusBreakdown: {}, + heapPumpScore: {}, contactAccounts: {}, contactParentAccounts: {}, scoresLoading: false, @@ -86,6 +87,7 @@ export class BGroup extends Component { if (this.props.user.permissions['read::Gateway']) { this.getGatewayDates(buildingIds); } + this.getScores(buildingIds); this.getSimulationDates(buildingIds); this.getSfBuildingImpact(buildingIds); if (nextProps.user.permissions['read::CustomImpact']) { @@ -168,21 +170,30 @@ export class BGroup extends Component { // A function to get all of the contact information for buildings this.setState({ scoresLoading: true }); const filterString = buildingIds.reduce((acc, val) => ( - `${acc}building_id[]=${val}&` + `${acc}building_ids[]=${val}&` ), ''); - request(`${scoresURL}?${filterString}`, { + request(`${sfBuildingImpactURL}?${filterString}`, { method: 'GET', headers: getHeaders(), }).then((res) => { + const heatPumpScore = { + 1189745: { score: 50 }, + 1189744: { score: 50 }, + 1189743: { score: 50 }, + 1189742: { score: 50 }, + 1189741: { score: 50 }, + }; + this.setState({ scoresLoading: false }); - // const data = res.data; - const data = { scores: [50, 50, 50, 50, 50] }; - if (!res.err && data) { - this.setState({ scores: data }); - } else { - this.setState({ scores: data }); - // this.setState({ scoresError: true }); + this.setState({ heatPumpScore }); + + if (!res.err && heatPumpScore) { + this.setState({ scores: heatPumpScore }); } + // else { + // this.setState({ scores: data }); + // // this.setState({ scoresError: true }); + // } }); } @@ -372,6 +383,7 @@ export class BGroup extends Component { utilityAccountsStatus={this.state.utilityAccountsStatus} gatewayDates={this.state.gatewayDates} simulationDates={this.state.simulationDates} + heatPumpScore={this.state.heatPumpScore} contactAccounts={this.state.contactAccounts} contactParentAccounts={this.state.contactParentAccounts} impact={this.state.impact} diff --git a/src/containers/BGroup/BGroupBuildingTable.js b/src/containers/BGroup/BGroupBuildingTable.js index 44c8c1db..05cae7c3 100644 --- a/src/containers/BGroup/BGroupBuildingTable.js +++ b/src/containers/BGroup/BGroupBuildingTable.js @@ -76,6 +76,7 @@ export default class BGroupBuildingTable extends Component { utilityAccountsStatus, gatewayDates, simulationDates, + heatPumpScore, contactAccounts, contactParentAccounts, impact, @@ -347,7 +348,7 @@ export default class BGroupBuildingTable extends Component { { Header: 'Heat Pump', filterable: false, - accessor: 'contact_account', + accessor: 'heat_pump_score', Cell: row => (
{row.value} @@ -717,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 = heatPumpScore[val.building_id]; val.contact_account = contactAccounts[val.building_id]; val.contact_parent_account = contactParentAccounts[val.building_id]; if (impact[val.building_id]) { @@ -952,6 +954,7 @@ BGroupBuildingTable.propTypes = { utilityAccountsStatus: PropTypes.object, gatewayDates: PropTypes.object, simulationDates: PropTypes.object, + heatPumpScore: PropTypes.object, contactAccounts: PropTypes.object, contactParentAccounts: PropTypes.object, impact: PropTypes.object, diff --git a/src/utils/restServices.js b/src/utils/restServices.js index da92ccee..b33fa0fd 100644 --- a/src/utils/restServices.js +++ b/src/utils/restServices.js @@ -20,7 +20,7 @@ export const commonAreasURL = `${buildingService}/commonarea/`; export const serviceAreasURL = `${buildingService}/servicearea/`; export const spacesURL = `${buildingService}/space/`; export const turkURL = `${buildingService}/turkhit/`; -export const scoresURL = `${buildingService}/scores/`; +export const scoresURL = `${buildingService}/building/score/heatpump/`; export const documentURL = `${documentService}/document/`; export const folderURL = `${documentService}/folder/`; -- GitLab From e40aa81093dd043928d58ca06386dbb239a54f44 Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 14 Feb 2019 20:14:05 -0500 Subject: [PATCH 05/18] Fix typo, update script --- src/containers/BGroup/BGroup.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 053a0f14..c7c00bb4 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -54,7 +54,7 @@ export class BGroup extends Component { buildingIdProject: {}, projectTypeBreakdown: {}, projectStatusBreakdown: {}, - heapPumpScore: {}, + heatPumpScore: {}, contactAccounts: {}, contactParentAccounts: {}, scoresLoading: false, @@ -176,6 +176,7 @@ export class BGroup extends Component { method: 'GET', headers: getHeaders(), }).then((res) => { + // For building Group: 26 in Dev const heatPumpScore = { 1189745: { score: 50 }, 1189744: { score: 50 }, @@ -188,7 +189,7 @@ export class BGroup extends Component { this.setState({ heatPumpScore }); if (!res.err && heatPumpScore) { - this.setState({ scores: heatPumpScore }); + this.setState({ scoresLoading: false }); } // else { // this.setState({ scores: data }); -- GitLab From 66dcc1bfea6914aa63468757645b9622fc05bae2 Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Thu, 14 Feb 2019 20:48:43 -0500 Subject: [PATCH 06/18] Adjust if and else when handling data from scores loading. --- src/containers/BGroup/BGroup.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index c7c00bb4..4f49966a 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -54,12 +54,12 @@ export class BGroup extends Component { buildingIdProject: {}, projectTypeBreakdown: {}, projectStatusBreakdown: {}, - heatPumpScore: {}, contactAccounts: {}, contactParentAccounts: {}, scoresLoading: false, scoresError: false, scores: {}, + heatPumpScore: {}, contactLoading: false, contactError: false, impactLoading: false, @@ -176,7 +176,7 @@ export class BGroup extends Component { method: 'GET', headers: getHeaders(), }).then((res) => { - // For building Group: 26 in Dev + // Dummy data for building Group: 26 in Dev const heatPumpScore = { 1189745: { score: 50 }, 1189744: { score: 50 }, @@ -186,15 +186,17 @@ export class BGroup extends Component { }; this.setState({ scoresLoading: false }); - this.setState({ heatPumpScore }); - if (!res.err && heatPumpScore) { + if (!res.err && data) { this.setState({ scoresLoading: false }); + this.setState({ scores: data }); + this.setState({ heatPumpScore: data }); + } + else { + this.setState({ scores: heatPumpScore }); + this.setState({ heatPumpScore }); + // this.setState({ scoresError: true }); } - // else { - // this.setState({ scores: data }); - // // this.setState({ scoresError: true }); - // } }); } -- GitLab From ac9f90dd3e15a33c76af7f7f266c49d7e8bb3f6c Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Thu, 14 Feb 2019 21:03:16 -0500 Subject: [PATCH 07/18] Add missing data field. --- src/containers/BGroup/BGroup.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 4f49966a..409dcb6a 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -177,6 +177,7 @@ export class BGroup extends Component { headers: getHeaders(), }).then((res) => { // Dummy data for building Group: 26 in Dev + const data = res.data; const heatPumpScore = { 1189745: { score: 50 }, 1189744: { score: 50 }, -- GitLab From 4c80c89b1038514ada1af38d57ad43a1b00ac6df Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Thu, 14 Feb 2019 21:09:39 -0500 Subject: [PATCH 08/18] Fix style issue. --- src/containers/BGroup/BGroup.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 409dcb6a..31dd654d 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -192,8 +192,7 @@ export class BGroup extends Component { this.setState({ scoresLoading: false }); this.setState({ scores: data }); this.setState({ heatPumpScore: data }); - } - else { + } else { this.setState({ scores: heatPumpScore }); this.setState({ heatPumpScore }); // this.setState({ scoresError: true }); -- GitLab From e1439e7d394853ae7f0f6876771472f482430d95 Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Thu, 14 Feb 2019 21:23:55 -0500 Subject: [PATCH 09/18] Add url back for scores to getScores() --- src/containers/BGroup/BGroup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 31dd654d..cc0827cb 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, scoresURL, } from '../../utils/restServices'; import './styles.css'; @@ -172,7 +172,7 @@ export class BGroup extends Component { const filterString = buildingIds.reduce((acc, val) => ( `${acc}building_ids[]=${val}&` ), ''); - request(`${sfBuildingImpactURL}?${filterString}`, { + request(`${scoresURL}?${filterString}`, { method: 'GET', headers: getHeaders(), }).then((res) => { -- GitLab From cdb8943a2068a7989ddd30456e8a6ae26ed69373 Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Thu, 14 Feb 2019 21:32:49 -0500 Subject: [PATCH 10/18] Always use dummy heatpump score for now. --- src/containers/BGroup/BGroup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index cc0827cb..e41c7008 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -190,8 +190,8 @@ export class BGroup extends Component { if (!res.err && data) { this.setState({ scoresLoading: false }); - this.setState({ scores: data }); - this.setState({ heatPumpScore: data }); + this.setState({ scores: heatPumpScore }); + this.setState({ heatPumpScore: heatPumpScore }); } else { this.setState({ scores: heatPumpScore }); this.setState({ heatPumpScore }); -- GitLab From 75ba80992190b58211a55d959155ee7aa2548526 Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Thu, 14 Feb 2019 21:47:08 -0500 Subject: [PATCH 11/18] Handle error instead of ignoring it. --- src/containers/BGroup/BGroup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index e41c7008..3768ff8e 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -191,11 +191,11 @@ export class BGroup extends Component { if (!res.err && data) { this.setState({ scoresLoading: false }); this.setState({ scores: heatPumpScore }); - this.setState({ heatPumpScore: heatPumpScore }); + this.setState({ heatPumpScore}); } else { this.setState({ scores: heatPumpScore }); this.setState({ heatPumpScore }); - // this.setState({ scoresError: true }); + this.setState({ scoresError: true }); } }); } -- GitLab From 5d461837d684cba5f1b1cd7985465ba6d362eeb9 Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Thu, 14 Feb 2019 21:56:34 -0500 Subject: [PATCH 12/18] Fix syntax error in heatPumpScore line. --- src/containers/BGroup/BGroup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 3768ff8e..93c8b5be 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -191,7 +191,7 @@ export class BGroup extends Component { if (!res.err && data) { this.setState({ scoresLoading: false }); this.setState({ scores: heatPumpScore }); - this.setState({ heatPumpScore}); + this.setState({ heatPumpScore }); } else { this.setState({ scores: heatPumpScore }); this.setState({ heatPumpScore }); -- GitLab From a8f5911d7402b02ce0dad3fc43f80713ba2c1320 Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Fri, 15 Feb 2019 09:53:00 -0500 Subject: [PATCH 13/18] Remove error from get scores when request fails. --- src/containers/BGroup/BGroup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 93c8b5be..9b852482 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -195,7 +195,7 @@ export class BGroup extends Component { } else { this.setState({ scores: heatPumpScore }); this.setState({ heatPumpScore }); - this.setState({ scoresError: true }); + // this.setState({ scoresError: true }); } }); } -- GitLab From 6c3dbc9a20bfc5819dfda470d8af2ddf6f5e1d11 Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Fri, 15 Feb 2019 10:08:22 -0500 Subject: [PATCH 14/18] Add new url for endpoint. --- src/utils/restServices.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/restServices.js b/src/utils/restServices.js index b33fa0fd..8936101f 100644 --- a/src/utils/restServices.js +++ b/src/utils/restServices.js @@ -20,7 +20,7 @@ export const commonAreasURL = `${buildingService}/commonarea/`; export const serviceAreasURL = `${buildingService}/servicearea/`; export const spacesURL = `${buildingService}/space/`; export const turkURL = `${buildingService}/turkhit/`; -export const scoresURL = `${buildingService}/building/score/heatpump/`; +export const scoresURL = `${buildingService}/score/heatpump/`; export const documentURL = `${documentService}/document/`; export const folderURL = `${documentService}/folder/`; -- GitLab From 83f7b81040bf75e16e98d15beec7df0e2f9d3006 Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Fri, 15 Feb 2019 11:02:26 -0500 Subject: [PATCH 15/18] Remove dummy scores so bgroup 26 renders properly. --- src/containers/BGroup/BGroup.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 9b852482..70863c4e 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -178,13 +178,7 @@ export class BGroup extends Component { }).then((res) => { // Dummy data for building Group: 26 in Dev const data = res.data; - const heatPumpScore = { - 1189745: { score: 50 }, - 1189744: { score: 50 }, - 1189743: { score: 50 }, - 1189742: { score: 50 }, - 1189741: { score: 50 }, - }; + const heatPumpScore = {}; this.setState({ scoresLoading: false }); -- GitLab From d709506461442234081b7243aa713eee771c63ae Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 15 Feb 2019 11:22:43 -0500 Subject: [PATCH 16/18] Make all score variables consistent to heat pump scores --- src/containers/BGroup/BGroup.js | 39 +++++++------------- src/containers/BGroup/BGroupBuildingTable.js | 6 +-- src/utils/restServices.js | 2 +- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 9b852482..04968f87 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, scoresURL, + contactsURL, sfBuildingImpactURL, heatPumpScoresURL, } from '../../utils/restServices'; import './styles.css'; @@ -56,10 +56,9 @@ export class BGroup extends Component { projectStatusBreakdown: {}, contactAccounts: {}, contactParentAccounts: {}, - scoresLoading: false, - scoresError: false, - scores: {}, - heatPumpScore: {}, + heatPumpScoresLoading: false, + heatPumpError: false, + heatPumpScores: {}, contactLoading: false, contactError: false, impactLoading: false, @@ -87,7 +86,7 @@ export class BGroup extends Component { if (this.props.user.permissions['read::Gateway']) { this.getGatewayDates(buildingIds); } - this.getScores(buildingIds); + this.getHeatPumpScores(buildingIds); this.getSimulationDates(buildingIds); this.getSfBuildingImpact(buildingIds); if (nextProps.user.permissions['read::CustomImpact']) { @@ -166,35 +165,26 @@ export class BGroup extends Component { } - getScores = (buildingIds) => { + getHeatPumpScores = (buildingIds) => { // A function to get all of the contact information for buildings - this.setState({ scoresLoading: true }); + this.setState({ heatPumpScoresLoading: true }); const filterString = buildingIds.reduce((acc, val) => ( `${acc}building_ids[]=${val}&` ), ''); - request(`${scoresURL}?${filterString}`, { + request(`${heatPumpScoresURL}?${filterString}`, { method: 'GET', headers: getHeaders(), }).then((res) => { // Dummy data for building Group: 26 in Dev const data = res.data; - const heatPumpScore = { - 1189745: { score: 50 }, - 1189744: { score: 50 }, - 1189743: { score: 50 }, - 1189742: { score: 50 }, - 1189741: { score: 50 }, - }; + const heatPumpScores = {}; - this.setState({ scoresLoading: false }); + this.setState({ heatPumpScoresLoading: false }); if (!res.err && data) { - this.setState({ scoresLoading: false }); - this.setState({ scores: heatPumpScore }); - this.setState({ heatPumpScore }); + this.setState({ heatPumpScores }); } else { - this.setState({ scores: heatPumpScore }); - this.setState({ heatPumpScore }); + this.setState({ heatPumpScores }); // this.setState({ scoresError: true }); } }); @@ -386,12 +376,11 @@ export class BGroup extends Component { utilityAccountsStatus={this.state.utilityAccountsStatus} gatewayDates={this.state.gatewayDates} simulationDates={this.state.simulationDates} - heatPumpScore={this.state.heatPumpScore} + heatPumpScores={this.state.heatPumpScores} contactAccounts={this.state.contactAccounts} contactParentAccounts={this.state.contactParentAccounts} impact={this.state.impact} - scores={this.state.scores} - scoresLoading={this.state.scoresLoading} + heatPumpScoresLoading={this.state.heatPumpScoresLoading} contactLoading={this.state.contactLoading} utilityLoading={this.state.utilityLoading} simulationLoading={this.state.simulationLoading} diff --git a/src/containers/BGroup/BGroupBuildingTable.js b/src/containers/BGroup/BGroupBuildingTable.js index 05cae7c3..5f90f402 100644 --- a/src/containers/BGroup/BGroupBuildingTable.js +++ b/src/containers/BGroup/BGroupBuildingTable.js @@ -76,7 +76,7 @@ export default class BGroupBuildingTable extends Component { utilityAccountsStatus, gatewayDates, simulationDates, - heatPumpScore, + heatPumpScores, contactAccounts, contactParentAccounts, impact, @@ -718,7 +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 = heatPumpScore[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]) { @@ -954,7 +954,7 @@ BGroupBuildingTable.propTypes = { utilityAccountsStatus: PropTypes.object, gatewayDates: PropTypes.object, simulationDates: PropTypes.object, - heatPumpScore: PropTypes.object, + heatPumpScores: PropTypes.object, contactAccounts: PropTypes.object, contactParentAccounts: PropTypes.object, impact: PropTypes.object, diff --git a/src/utils/restServices.js b/src/utils/restServices.js index 8936101f..9e834031 100644 --- a/src/utils/restServices.js +++ b/src/utils/restServices.js @@ -20,7 +20,7 @@ export const commonAreasURL = `${buildingService}/commonarea/`; export const serviceAreasURL = `${buildingService}/servicearea/`; export const spacesURL = `${buildingService}/space/`; export const turkURL = `${buildingService}/turkhit/`; -export const scoresURL = `${buildingService}/score/heatpump/`; +export const heatPumpScoresURL = `${buildingService}/score/heatpump/`; export const documentURL = `${documentService}/document/`; export const folderURL = `${documentService}/folder/`; -- GitLab From ca6ac667265f6e96dcba5d62058b05614aec72ef Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 15 Feb 2019 11:51:54 -0500 Subject: [PATCH 17/18] adding dummy data --- src/containers/BGroup/BGroup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 04968f87..bde27250 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -177,7 +177,7 @@ export class BGroup extends Component { }).then((res) => { // Dummy data for building Group: 26 in Dev const data = res.data; - const heatPumpScores = {}; + const heatPumpScores = [{ building_id: 1189745, score: 50 }]; this.setState({ heatPumpScoresLoading: false }); -- GitLab From e7f85b5665c9b3471364e83cc7439b3553078b14 Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 15 Feb 2019 12:11:07 -0500 Subject: [PATCH 18/18] Update data format, adding reduce function to transform data for table rendering --- src/containers/BGroup/BGroup.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index bde27250..55268b52 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -176,16 +176,37 @@ export class BGroup extends Component { headers: getHeaders(), }).then((res) => { // Dummy data for building Group: 26 in Dev - const data = res.data; - const heatPumpScores = [{ building_id: 1189745, score: 50 }]; - + // 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 }); - // this.setState({ scoresError: true }); } }); } -- GitLab