From 22eb51f5802f9e655a0fa68ea37c3e378a171dd5 Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 2 May 2019 15:08:46 -0400 Subject: [PATCH 01/50] Add MV route and container files --- src/components/SideBarDetail/index.js | 6 +++ src/containers/Performance/actions.js | 10 ++++ src/containers/Performance/constants.js | 3 ++ src/containers/Performance/index.js | 69 +++++++++++++++++++++++++ src/routes.js | 4 ++ 5 files changed, 92 insertions(+) create mode 100644 src/containers/Performance/actions.js create mode 100644 src/containers/Performance/constants.js create mode 100644 src/containers/Performance/index.js diff --git a/src/components/SideBarDetail/index.js b/src/components/SideBarDetail/index.js index bf06ec46..0b181771 100644 --- a/src/components/SideBarDetail/index.js +++ b/src/components/SideBarDetail/index.js @@ -210,6 +210,12 @@ export default function SideBarDetail({ building, children, contacts, user }) { Reports +
  • + + {blocnoteSVG} + Performance + +
  • + + +
    + {/* Map, Construction table & run-sim btn */} +
    +
    + {' '} +
    +
    + {' '} +
    +
    +
    {/* Container */} + + ); + } +} + +Performance.propTypes = { + building: buildingDetailPropTypes, + loadPerformance: PropTypes.func, +}; + +const mapDispatchToProps = dispatch => ( + bindActionCreators({ + loadPerformance, + }, dispatch) +); + +const mapStateToProps = state => ({ + performance: state.performance, + eng: state.eng, +}); + +export default connect(mapStateToProps, mapDispatchToProps)(Performance); diff --git a/src/routes.js b/src/routes.js index 381b8699..9ea75214 100644 --- a/src/routes.js +++ b/src/routes.js @@ -23,6 +23,7 @@ import Sensors from './containers/Sensors/Sensors'; import SensorInstall from './containers/Sensors/SensorInstall'; import GatewayList from './components/SensorInstall/GatewayList'; import BuildingReports from './containers/BuildingReports'; +import Performance from './containers/Performance'; import Wrapper from './containers/Wrapper'; import { BGroupOverview, BGroup } from './containers/BGroup'; import NavOnly from './screens/NavOnly/NavOnly'; @@ -57,6 +58,9 @@ export default ( + + + -- GitLab From e79f8ee5e97ae8850e561bbaf3aaaf1f416ec712 Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 3 May 2019 12:11:41 -0400 Subject: [PATCH 02/50] Add actions, constants, index file --- src/containers/Performance/actions.js | 18 +++++++++++------ src/containers/Performance/constants.js | 9 ++++++--- src/containers/Performance/index.js | 27 ++++++++++++++++++------- 3 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 4e889fc7..13e51833 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -1,10 +1,16 @@ import { - LOAD_PERFORMANCE, - PERFORMANCE_SUCCESS, - PERFORMANCE_ERROR, + LOAD_OCCUPANTS, + OCCUPANTS_SUCCESS, + OCCUPANTS_ERROR, + LOAD_THERMAL_COMFORT, + THERMAL_COMFORT_SUCCESS, + THERMAL_COMFORT_ERROR, } from './constants'; import { makeActionCreator } from '../../utils/reduxHelpers'; -export const loadPerformance = makeActionCreator(LOAD_PERFORMANCE, 'buildingId'); -export const performanceLoaded = makeActionCreator(PERFORMANCE_SUCCESS, 'payload'); -export const performanceLoadingError = makeActionCreator(PERFORMANCE_ERROR, 'error'); +export const loadOccupants = makeActionCreator(LOAD_OCCUPANTS, 'buildingId'); +export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCESS, 'payload'); +export const occupantsLoadingError = makeActionCreator(OCCUPANTS_ERROR, 'error'); +export const loadThermalComfort = makeActionCreator(LOAD_THERMAL_COMFORT, 'buildingId'); +export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCESS, 'payload'); +export const thermalComfortLoadingError = makeActionCreator(THERMAL_COMFORT_ERROR, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index b3b8ea32..059b46d5 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -1,3 +1,6 @@ -export const LOAD_PERFORMANCE = 'LOAD_PERFORMANCE'; -export const PERFORMANCE_SUCCESS = 'PERFORMANCE_SUCCESS'; -export const PERFORMANCE_ERROR = 'PERFORMANCE_ERROR'; +export const LOAD_OCCUPANTS = 'LOAD_OCCUPANTS'; +export const OCCUPANTS_SUCCESS = 'OCCUPANTS_SUCCESS'; +export const OCCUPANTS_ERROR = 'OCCUPANTS_ERROR'; +export const LOAD_THERMAL_COMFORT = 'LOAD_THERMAL_COMFORT'; +export const THERMAL_COMFORT_SUCCESS = 'THERMAL_COMFORT_SUCCESS'; +export const THERMAL_COMFORT_ERROR = 'THERMAL_COMFORT_ERROR'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 5bf07cbf..8e921c03 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -3,10 +3,13 @@ import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { - loadPerformance, + loadOccupants, + loadThermalComfort, } from './actions'; import buildingDetailPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; +import Occupants from '../../components/Performance/Occupants'; +import ThermalComfort from '../../components/Performance/ThermalComfort'; class Performance extends Component { @@ -14,12 +17,15 @@ class Performance extends Component { super(props); this.state = { weather: 'jfk', + occupants: null, + thermalComfort: null, }; } componentDidMount() { const buildingId = this.props.building.building_id; - this.props.loadPerformance(buildingId); + this.props.loadOccupants(buildingId); + this.props.loadThermalComfort(buildingId); } render() { @@ -38,10 +44,14 @@ class Performance extends Component { {/* Map, Construction table & run-sim btn */}
    - {' '} +
    - {' '} +
    {/* Container */} @@ -52,17 +62,20 @@ class Performance extends Component { Performance.propTypes = { building: buildingDetailPropTypes, - loadPerformance: PropTypes.func, + loadOccupants: PropTypes.func, + loadThermalComfort: PropTypes.func, }; const mapDispatchToProps = dispatch => ( bindActionCreators({ - loadPerformance, + loadOccupants, + loadThermalComfort, }, dispatch) ); const mapStateToProps = state => ({ - performance: state.performance, + occupants: state.occupants, + thermalComfort: state.thermalComfort, eng: state.eng, }); -- GitLab From 9d58266674e1ff899aa8c2b4d47da3ae38d9b4ec Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 7 May 2019 10:18:38 -0400 Subject: [PATCH 03/50] Add Occupants, ThermalComfort components and index container --- src/components/Performance/Occupants.js | 96 ++++++++++++ src/components/Performance/ThermalComfort.js | 145 +++++++++++++++++++ src/components/Performance/styles.css | 13 ++ src/containers/Performance/index.js | 7 +- 4 files changed, 257 insertions(+), 4 deletions(-) create mode 100644 src/components/Performance/Occupants.js create mode 100644 src/components/Performance/ThermalComfort.js create mode 100644 src/components/Performance/styles.css diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js new file mode 100644 index 00000000..5c2f1a43 --- /dev/null +++ b/src/components/Performance/Occupants.js @@ -0,0 +1,96 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { + Table, + Input, + Button, +} from 'reactstrap'; +import './styles.css'; + + +class Occupants extends Component { + constructor(props) { + super(props); + this.state = { + totalUnits: props.totalUnits, + preVacantUnits: props.preVacantUnits, + postVacantUnits: props.postVacantUnits, + }; + } + + handleOnChange = () => { + this.setState({ displayChart: !this.state.displayChart }); + } + + render() { + return ( +
    +
    +
    +

    + Occupants +

    +
    +
    + + {' '} +
    +
    + + + + + + + + + + + + + +
    + Number of Units + + +
    + Vacant Units (Pre-retrofit) + + +
    + Vacant Units (Post-retrofit) + + +
    +
    + ); + } +} + +Occupants.propTypes = { + totalUnits: PropTypes.number, + preVacantUnits: PropTypes.number, + postVacantUnits: PropTypes.number, +}; + +Occupants.defaultProps = { + totalUnits: 0, + preVacantUnits: 0, + postVacantUnits: 0, +}; + +export default Occupants; diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js new file mode 100644 index 00000000..fcaa11f5 --- /dev/null +++ b/src/components/Performance/ThermalComfort.js @@ -0,0 +1,145 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { + Table, + Input, + InputGroup, + InputGroupAddon, + Button, +} from 'reactstrap'; +import './styles.css'; + + +class ThermalComfort extends Component { + constructor(props) { + super(props); + this.state = { + preHeatingSetPoint: props.preHeatingSetPoint, + postHeatingSetPoint: props.postHeatingSetPoint, + preCoolingSetPoint: props.preCoolingSetPoint, + postCoolingSetPoint: props.postCoolingSetPoint, + }; + } + + toggleDisplayChart = () => { + this.setState({ displayChart: !this.state.displayChart }); + } + + render() { + return ( +
    +
    +
    +

    + Thermal Comfort +

    +
    +
    + + {' '} +
    +
    + + + + + + + + + + + + + + + + + +
    + Heating Set Point (Pre-retrofit) + + + + + F + + +
    + Heating Set point (Post-retrofit) + + + + + F + + +
    + Cooling Set Point (Pre-retrofit) + + + + + F + + +
    + Cooling Set Point (Post-retrofit) + + + + + F + + +
    +
    + ); + } +} + +ThermalComfort.propTypes = { + preHeatingSetPoint: PropTypes.number, + postHeatingSetPoint: PropTypes.number, + preCoolingSetPoint: PropTypes.number, + postCoolingSetPoint: PropTypes.number, +}; + +export default ThermalComfort; diff --git a/src/components/Performance/styles.css b/src/components/Performance/styles.css new file mode 100644 index 00000000..97b24ba8 --- /dev/null +++ b/src/components/Performance/styles.css @@ -0,0 +1,13 @@ +.test { + display: block !important; +} + +.header { + margin-bottom: 25px; + padding-left: 10px; +} + +.rightAlign { + text-align: right; + padding-right: 28px !important; +} diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 8e921c03..f4ec518d 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -40,15 +40,14 @@ class Performance extends Component { links={[]} /> -
    - {/* Map, Construction table & run-sim btn */} +
    -
    +
    -
    +
    -- GitLab From db898ea5acc2f31a918724f48e26f801d8243f6a Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 9 May 2019 12:25:50 -0400 Subject: [PATCH 04/50] Update Occupants and Thermal Comfort with modals --- src/components/Performance/Occupants.js | 6 ++ src/components/Performance/ThermalComfort.js | 91 +++++++++++++++++++- src/containers/Performance/index.js | 22 ++++- 3 files changed, 113 insertions(+), 6 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 5c2f1a43..854dcd9a 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -32,6 +32,12 @@ class Occupants extends Component {
    + {' '}
    + {' '} @@ -130,6 +152,16 @@ class ThermalComfort extends Component { + + Modal title + + This is Modal body! + + + {' '} + + +
    ); } @@ -142,4 +174,59 @@ ThermalComfort.propTypes = { postCoolingSetPoint: PropTypes.number, }; +Modal.propTypes = { + // boolean to control the state of the popover + isOpen: PropTypes.bool, + autoFocus: PropTypes.bool, + // if modal should be centered vertically in viewport + centered: PropTypes.bool, + // corresponds to bootstrap's modal sizes, ie. 'lg' or 'sm' + size: PropTypes.string, + // callback for toggling isOpen in the controlling component + toggle: PropTypes.func, + role: PropTypes.string, // defaults to "dialog" + // used to reference the ID of the title element in the modal + labelledBy: PropTypes.string, + keyboard: PropTypes.bool, + // control backdrop, see http://v4-alpha.getbootstrap.com/components/modal/#options + backdrop: PropTypes.oneOfType([ + PropTypes.bool, + PropTypes.oneOf(['static']), + ]), + // if body of modal should be scrollable when content is long + scrollable: PropTypes.bool, + // external: PropTypes.node, + // called on componentDidMount + onEnter: PropTypes.func, + // called on componentWillUnmount + onExit: PropTypes.func, + // called when done transitioning in + onOpened: PropTypes.func, + // called when done transitioning out + onClosed: PropTypes.func, + className: PropTypes.string, + wrapClassName: PropTypes.string, + modalClassName: PropTypes.string, + backdropClassName: PropTypes.string, + contentClassName: PropTypes.string, + // boolean to control whether the fade transition occurs (default: true) + fade: PropTypes.bool, + cssModule: PropTypes.objectOf, + // zIndex defaults to 1000. + zIndex: PropTypes.oneOfType([ + PropTypes.number, + PropTypes.string, + ]), + // backdropTransition - controls backdrop transition + // timeout is 150ms by default to match bootstrap + // see Fade for more details + backdropTransition: PropTypes.shape, + // modalTransition - controls modal transition + // timeout is 300ms by default to match bootstrap + // see Fade for more details + innerRef: PropTypes.objectOf, + // if modal should be destructed/removed from DOM after closing + unmountOnClose: PropTypes.bool, // defaults to true +}; + export default ThermalComfort; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index f4ec518d..a483bafe 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -17,8 +17,6 @@ class Performance extends Component { super(props); this.state = { weather: 'jfk', - occupants: null, - thermalComfort: null, }; } @@ -29,6 +27,17 @@ class Performance extends Component { } render() { + const occupants = { + totalUnits: null, + preVacantUnits: null, + postVacantUnits: null, + }; + const thermalComfort = { + preHeatingSetPoint: null, + postHeatingSetPoint: null, + preCoolingSetPoint: null, + postCoolingSetPoint: null, + }; return (
    -- GitLab From 8e093e3a41c6882d3fe1dbe4b74576944c3dcbb3 Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 10 May 2019 14:27:03 -0400 Subject: [PATCH 05/50] Updates to occupants and index --- src/components/Performance/Occupants.js | 50 ++++++++++++++++++++++++- src/containers/Performance/index.js | 2 +- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 854dcd9a..fa3be3f9 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -1,4 +1,5 @@ import React, { Component } from 'react'; +import Modal from 'react-modal'; import PropTypes from 'prop-types'; import { Table, @@ -8,6 +9,19 @@ import { import './styles.css'; +const customStyles = { + content: { + top: '50%', + left: '50%', + right: 'auto', + bottom: 'auto', + marginRight: '-50%', + transform: 'translate(-50%, -50%)', + }, +}; +// Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/) +Modal.setAppElement('body'); + class Occupants extends Component { constructor(props) { super(props); @@ -15,9 +29,23 @@ class Occupants extends Component { totalUnits: props.totalUnits, preVacantUnits: props.preVacantUnits, postVacantUnits: props.postVacantUnits, + modalIsOpen: false, }; - } + this.openModal = this.openModal.bind(this); + this.afterOpenModal = this.afterOpenModal.bind(this); + this.closeModal = this.closeModal.bind(this); + } + openModal() { + this.setState({ modalIsOpen: true }); + } + afterOpenModal() { + // references are now sync'd and can be accessed. + this.subtitle.style.color = '#f00'; + } + closeModal() { + this.setState({ modalIsOpen: false }); + } handleOnChange = () => { this.setState({ displayChart: !this.state.displayChart }); } @@ -34,7 +62,7 @@ class Occupants extends Component {
    {' '} @@ -47,6 +75,24 @@ class Occupants extends Component { {' '}
    + +

    Hello

    + +
    I am a modal
    +
    + + + + + +
    +
    ); diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 04a58767..5a356dd3 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -24,8 +24,8 @@ class IncomeStatements extends Component { const obj = { GRDropdownOpen: false, - GRDropdownValue: 'Select Growth Rate', - selectedDropdownId: 0, + GRDropdownId: props.data.growth_rate !== null ? props.data.growth_rate : 0, + GRDropdownValue: props.data.growth_rate !== null ? `${String(props.data.growth_rate * 100)}%` : 'Select Growth Rate', growthRateOptions: [ { id: '-2', key: '-2', name: 'CAGR=1.58%' }, { id: '-1', key: '-1', name: 'Average' }, @@ -127,8 +127,8 @@ class IncomeStatements extends Component { } changeGrowthRate(e) { + this.setState({ GRDropdownId: e.currentTarget.id }); this.setState({ GRDropdownValue: e.currentTarget.textContent }); - this.setState({ selectedDropdownId: e.currentTarget.id }); } buildHeader = () => { @@ -222,7 +222,7 @@ class IncomeStatements extends Component { hist.push(obj); }); const growthRate = {}; - growthRate['growth-rate'] = String(this.state.selectedDropdownId); + growthRate['growth-rate'] = String(this.state.GRDropdownId); hist.push(growthRate); this.props.updateIncomeStatements( this.props.buildingId, diff --git a/src/containers/Blocnote/sagas.js b/src/containers/Blocnote/sagas.js index 59a9aacb..53768134 100644 --- a/src/containers/Blocnote/sagas.js +++ b/src/containers/Blocnote/sagas.js @@ -132,7 +132,7 @@ function* updateBillsSummary(action) { request, SagaRequests.generateURL(url, action), { - method: 'PUT', + method: 'POST', headers: getHeaders(), body: JSON.stringify(action.payload), } -- GitLab From 625338f5406337284f886f61a6719db9af302614 Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 10 May 2019 22:51:21 -0400 Subject: [PATCH 07/50] Update Cost estimation and Saving estimation format --- .../Blocnote/BudgetSimulator/BugetTable.js | 5 +- .../PreliminaryFinance/CostEstimation.js | 57 ++++++++++--------- .../PreliminaryFinance/SavingEstimation.js | 15 ++--- .../PreliminaryFinance/SavingEstimationRow.js | 8 ++- .../PreliminaryFinance/SelectScenario.js | 1 - .../Blocnote/FinancialInputs/index.js | 6 +- 6 files changed, 52 insertions(+), 40 deletions(-) diff --git a/src/components/Blocnote/BudgetSimulator/BugetTable.js b/src/components/Blocnote/BudgetSimulator/BugetTable.js index 85f575ee..c44e3a75 100644 --- a/src/components/Blocnote/BudgetSimulator/BugetTable.js +++ b/src/components/Blocnote/BudgetSimulator/BugetTable.js @@ -22,6 +22,7 @@ class BudgetTable extends Component { backgroundColor: '#EEEEEE', color: '#000000', fontWeight: 'bold', + padding: '15px', }; const header = [...['Savings'], ...this.props.savingPotentialList] .map((columnName) => { @@ -67,9 +68,9 @@ class BudgetTable extends Component {
    diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index a483bafe..bae57c91 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -39,7 +39,7 @@ class Performance extends Component { postCoolingSetPoint: null, }; return ( -
    +
    Date: Fri, 10 May 2019 17:16:03 -0400 Subject: [PATCH 06/50] Fix bills summary update issue and show all bill sections --- src/components/Blocnote/FinancialInputs/BillsOverview.js | 7 +++++-- .../Blocnote/FinancialInputs/BillsSummaryTable.js | 4 ++-- .../Blocnote/FinancialInputs/IncomeStatements.js | 8 ++++---- src/containers/Blocnote/sagas.js | 2 +- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index 1fa5a241..0c7b04f4 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -17,7 +17,9 @@ class BillsOverview extends Component { this.toggleEstimation = this.toggleEstimation.bind(this); this.changeEstimation = this.changeEstimation.bind(this); const data = {}; + let estimationDropDownValue = 'Select Estimation'; if (Object.keys(this.props.data).length !== 0) { + estimationDropDownValue = this.props.data.estimation_algorithm; ['electric', 'water', 'gas', 'oil'].forEach((billName) => { Object.entries(this.props.data[billName]).forEach((bill) => { const keyName = `${billName}-value-${bill[0]}`; @@ -28,10 +30,10 @@ class BillsOverview extends Component { this.state = { estimationDropdownOpen: false, - estimationDropDownValue: 'Select Estimation', + estimationDropDownValue, estimationOptions: [ { id: 'RoughEstimation', key: 'RoughEstimation', name: 'Rough Estimation' }, - { id: 'Fancy Estimation', key: 'FancyEstimation', name: 'Fancy Estimation' }, + { id: 'FancyEstimation', key: 'FancyEstimation', name: 'Fancy Estimation' }, ], action: null, postBills: data, @@ -243,6 +245,7 @@ class BillsOverview extends Component { BillsOverview.propTypes = { data: PropTypes.shape({ + estimation_algorithm: PropTypes.string, electric: PropTypes.objectOf, electric_user: PropTypes.string, gas: PropTypes.objectOf, diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js index a165391d..3e4f0730 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js @@ -51,7 +51,7 @@ class BillsSummaryTable extends Component { updateBillsSummary = (billData) => { this.props.updateBillsSummary( this.props.buildingId, - billData, + Object.assign(billData, { utility_type: this.props.billName }), ); this.setState({ action: 'updated' }); } @@ -121,7 +121,7 @@ class BillsSummaryTable extends Component { color: '#999999', }} > - Currently no bill. + Currently no annual charge.
    - {header} diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 6f561c36..9354b137 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -94,7 +94,7 @@ class CostEstimation extends Component { fontSize: '13px', }; - if (this.state.costEstimation !== null) { + if (this.state.costEstimation.length !== 0) { rows = this.state.costEstimation.map((costItem, id) => { return ( ); }); + } else { + rows = ( + + + + ); } return (
    + {this.props.tableName} - +
    + There is no cost estimation. +
    - - + {rows} - - - - -
    Cost Estimation + + +
    Item Estimated CostOptionOption
    - -
    ); diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index eaa72e31..b7798b43 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -52,23 +52,24 @@ class SavingEstimation extends Component { return (
    - +
    - + - + diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js index ca392f04..2602bf5f 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js @@ -33,8 +33,12 @@ class SavingEstimationRow extends Component { console.log(this.state); // eslint-disable-line return ( - @@ -252,7 +229,6 @@ class Retrofits extends Component { + Retrofit   {historyButton} - {saveButton}
    @@ -312,7 +288,9 @@ Retrofits.propTypes = { fontWeight: PropTypes.string, }), buildingId: PropTypes.number, - updateRetrofits: PropTypes.func, + createRetrofit: PropTypes.func, + updateRetrofit: PropTypes.func, + deleteRetrofit: PropTypes.func, error: PropTypes.bool, loading: PropTypes.bool, }; diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index bffc966b..c4ce803a 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -114,7 +114,9 @@ class ThermalComfort extends Component { .filter(entry => entry[0] !== 'id' && entry[0] !== 'building_id') .map(entry => { return ( -
    +
    {entry[0]} : {entry[1]}
    ); -- GitLab From 5d87098a7bfa2b28dc662a89379bc85365bdbf7a Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Thu, 13 Jun 2019 18:13:37 -0400 Subject: [PATCH 43/50] Fix retrofit delete issue --- src/components/Performance/RetrofitRow.js | 41 ++++++++++++++--------- src/components/Performance/Retrofits.js | 3 ++ 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js index 47b96497..ceae6dc6 100644 --- a/src/components/Performance/RetrofitRow.js +++ b/src/components/Performance/RetrofitRow.js @@ -38,9 +38,7 @@ class RetrofitRow extends Component { return { id, key: retrofit.id, name: retrofit.retrofit_name }; }) : [], primaryUtilityDropdownOpen: false, - primaryUtilityDropDownValue: props.primaryUtility, secondUtilityDropdownOpen: false, - secondUtilityDropDownValue: props.secondUtility, utilityNames: props.utilityNames !== undefined ? props.utilityNames.map((utilityName, id) => { return { id, key: id, name: utilityName }; }) : [], @@ -57,6 +55,22 @@ class RetrofitRow extends Component { return retrofitName; }; + updateRetrofit = () => { + console.log(this.state.primary_utility); // eslint-disable-line + console.log(this.state.second_utility); // eslint-disable-line + const retrofit = { + id: this.props.id, + retrofit_id: this.state.retrofit_id, + install_start_date: this.state.install_start_date, + install_end_date: this.state.install_end_date, + primary_utility: this.state.primary_utility, + second_utility: this.state.second_utility, + notes: this.state.notes, + }; + console.log(retrofit); // eslint-disable-line + this.props.onChangeEvent(retrofit); + }; + toggleRetrofit() { this.setState({ retrofitDropdownOpen: !this.state.retrofitDropdownOpen, @@ -83,25 +97,20 @@ class RetrofitRow extends Component { } changePrimaryUtility(e) { - this.setState({ primaryUtilityDropDownValue: e.currentTarget.textContent }); + this.setState({ primary_utility: e.currentTarget.textContent }, () => { + this.updateRetrofit(); + }); } changeSecondUtility(e) { - this.setState({ secondUtilityDropDownValue: e.currentTarget.textContent }); + this.setState({ second_utility: e.currentTarget.textContent }, () => { + this.updateRetrofit(); + }); } handleOnChange = (event) => { this.setState({ [event.target.name]: event.target.value }, () => { - console.log(this.state.notes); // eslint-disable-line - this.props.onChangeEvent({ - id: this.props.id, - retrofit_id: this.state.retrofit_id, - install_start_date: this.state.install_start_date, - install_end_date: this.state.install_end_date, - primary_utility: this.state.primary_utility, - second_utility: this.state.second_utility, - notes: this.state.notes, - }); + this.updateRetrofit(); }); } @@ -259,7 +268,7 @@ class RetrofitRow extends Component { className="btn-block" > - {this.state.primaryUtilityDropDownValue} + {this.state.primary_utility} - {this.state.secondUtilityDropDownValue} + {this.state.second_utility} retrofit.id !== id); + alert('Retrofit deleted!'); this.setState({ retrofits: retrofitsCopy, action: 'deleted', -- GitLab From 5ee275691a48753ba3c57d2677a15b2992e83173 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Thu, 13 Jun 2019 18:29:07 -0400 Subject: [PATCH 44/50] Remove logs, fix delete issues --- src/components/Performance/RetrofitRow.js | 7 +- src/components/Performance/Retrofits.js | 1 + src/containers/Performance/actions.js | 25 ++++-- src/containers/Performance/constants.js | 13 ++- src/containers/Performance/index.js | 42 +++------ src/containers/Performance/reducer.js | 105 +++++++++++++++++++++- src/containers/Performance/sagas.js | 58 ++++++++++-- 7 files changed, 201 insertions(+), 50 deletions(-) diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js index ceae6dc6..d4780b13 100644 --- a/src/components/Performance/RetrofitRow.js +++ b/src/components/Performance/RetrofitRow.js @@ -56,8 +56,6 @@ class RetrofitRow extends Component { }; updateRetrofit = () => { - console.log(this.state.primary_utility); // eslint-disable-line - console.log(this.state.second_utility); // eslint-disable-line const retrofit = { id: this.props.id, retrofit_id: this.state.retrofit_id, @@ -67,7 +65,6 @@ class RetrofitRow extends Component { second_utility: this.state.second_utility, notes: this.state.notes, }; - console.log(retrofit); // eslint-disable-line this.props.onChangeEvent(retrofit); }; @@ -165,8 +162,8 @@ class RetrofitRow extends Component { const retrofitMeta = this.state.retrofitMeta.map(e => { return ( {e.name} diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js index 782e70de..18f219da 100644 --- a/src/components/Performance/Retrofits.js +++ b/src/components/Performance/Retrofits.js @@ -119,6 +119,7 @@ class Retrofits extends Component { this.props.buildingId, { id }, ); + const retrofitsCopy = this.state.retrofits.filter(retrofit => retrofit.id !== id); alert('Retrofit deleted!'); this.setState({ diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 4f90cd91..5098bf13 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -26,15 +26,21 @@ import { UPDATE_THERMAL_COMFORT_REQUESTED, UPDATE_THERMAL_COMFORT_SUCCEEDED, UPDATE_THERMAL_COMFORT_FAILED, - UPDATE_RETROFITS_REQUESTED, - UPDATE_RETROFITS_SUCCEEDED, - UPDATE_RETROFITS_FAILED, + UPDATE_MYRETROFIT_REQUESTED, + UPDATE_MYRETROFIT_SUCCEEDED, + UPDATE_MYRETROFIT_FAILED, CREATE_OCCUPANTS_LOG_REQUESTED, CREATE_OCCUPANTS_LOG_SUCCEEDED, CREATE_OCCUPANTS_LOG_FAILED, CREATE_THERMAL_COMFORT_LOG_REQUESTED, CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, CREATE_THERMAL_COMFORT_LOG_FAILED, + CREATE_MYRETROFIT_REQUESTED, + CREATE_MYRETROFIT_SUCCEEDED, + CREATE_MYRETROFIT_FAILED, + DELETE_MYRETROFIT_REQUESTED, + DELETE_MYRETROFIT_SUCCEEDED, + DELETE_MYRETROFIT_FAILED, } from './constants'; import { makeActionCreator } from '../../utils/reduxHelpers'; @@ -69,9 +75,9 @@ export const updateThermalComfort = makeActionCreator(UPDATE_THERMAL_COMFORT_REQ export const updateThermalComfortSucceeded = makeActionCreator(UPDATE_THERMAL_COMFORT_SUCCEEDED, 'instance'); export const updateThermalComfortFailed = makeActionCreator(UPDATE_THERMAL_COMFORT_FAILED, 'error'); -export const updateRetrofits = makeActionCreator(UPDATE_RETROFITS_REQUESTED, 'buildingId', 'payload'); -export const updateRetrofitsSucceeded = makeActionCreator(UPDATE_RETROFITS_SUCCEEDED, 'payload', 'instance'); -export const updateRetrofitsFailed = makeActionCreator(UPDATE_RETROFITS_FAILED, 'error'); +export const updateMyRetrofit = makeActionCreator(UPDATE_MYRETROFIT_REQUESTED, 'buildingId', 'payload'); +export const updateMyRetrofitSucceeded = makeActionCreator(UPDATE_MYRETROFIT_SUCCEEDED, 'payload', 'instance'); +export const updateMyRetrofitFailed = makeActionCreator(UPDATE_MYRETROFIT_FAILED, 'error'); export const createOccupantsLog = makeActionCreator(CREATE_OCCUPANTS_LOG_REQUESTED, 'buildingId', 'payload'); export const createOccupantsLogSucceeded = makeActionCreator(CREATE_OCCUPANTS_LOG_SUCCEEDED, 'instance'); @@ -79,3 +85,10 @@ export const createOccupantsLogFailed = makeActionCreator(CREATE_OCCUPANTS_LOG_F export const createThermalComfortLog = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_REQUESTED, 'buildingId', 'payload'); export const createThermalComfortLogSucceeded = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, 'instance'); export const createThermalComfortLogFailed = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_FAILED, 'error'); +export const createMyRetrofit = makeActionCreator(CREATE_MYRETROFIT_REQUESTED, 'buildingId', 'payload'); +export const createMyRetrofitSucceeded = makeActionCreator(CREATE_MYRETROFIT_SUCCEEDED, 'instance'); +export const createMyRetrofitFailed = makeActionCreator(CREATE_MYRETROFIT_FAILED, 'error'); + +export const deleteMyRetrofit = makeActionCreator(DELETE_MYRETROFIT_REQUESTED, 'buildingId', 'payload'); +export const deleteMyRetrofitSucceeded = makeActionCreator(DELETE_MYRETROFIT_SUCCEEDED, 'instance'); +export const deleteMyRetrofitFailed = makeActionCreator(DELETE_MYRETROFIT_FAILED, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index 37c7ccf3..8ec48d2d 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -28,9 +28,9 @@ export const UPDATE_OCCUPANTS_FAILED = 'UPDATE_OCCUPANTS_FAILED'; export const UPDATE_THERMAL_COMFORT_REQUESTED = 'UPDATE_THERMAL_COMFORT_REQUESTED'; export const UPDATE_THERMAL_COMFORT_SUCCEEDED = 'UPDATE_THERMAL_COMFORT_SUCCEEDED'; export const UPDATE_THERMAL_COMFORT_FAILED = 'UPDATE_THERMAL_COMFORT_FAILED'; -export const UPDATE_RETROFITS_REQUESTED = 'UPDATE_RETROFITS_REQUESTED'; -export const UPDATE_RETROFITS_SUCCEEDED = 'UPDATE_RETROFITS_SUCCEEDED'; -export const UPDATE_RETROFITS_FAILED = 'UPDATE_RETROFITS_FAILED'; +export const UPDATE_MYRETROFIT_REQUESTED = 'UPDATE_MYRETROFIT_REQUESTED'; +export const UPDATE_MYRETROFIT_SUCCEEDED = 'UPDATE_MYRETROFIT_SUCCEEDED'; +export const UPDATE_MYRETROFIT_FAILED = 'UPDATE_MYRETROFIT_FAILED'; export const CREATE_OCCUPANTS_LOG_REQUESTED = 'CREATE_OCCUPANTS_LOG_REQUESTED'; export const CREATE_OCCUPANTS_LOG_SUCCEEDED = 'CREATE_OCCUPANTS_LOG_SUCCEEDED'; @@ -38,3 +38,10 @@ export const CREATE_OCCUPANTS_LOG_FAILED = 'CREATE_OCCUPANTS_LOG_FAILED'; export const CREATE_THERMAL_COMFORT_LOG_REQUESTED = 'CREATE_THERMAL_COMFORT_LOG_REQUESTED'; export const CREATE_THERMAL_COMFORT_LOG_SUCCEEDED = 'CREATE_THERMAL_COMFORT_LOG_SUCCEEDED'; export const CREATE_THERMAL_COMFORT_LOG_FAILED = 'CREATE_THERMAL_COMFORT_LOG_FAILED'; +export const CREATE_MYRETROFIT_REQUESTED = 'CREATE_MYRETROFIT_REQUESTED'; +export const CREATE_MYRETROFIT_SUCCEEDED = 'CREATE_MYRETROFIT_SUCCEEDED'; +export const CREATE_MYRETROFIT_FAILED = 'CREATE_MYRETROFIT_FAILED'; + +export const DELETE_MYRETROFIT_REQUESTED = 'DELETE_MYRETROFIT_REQUESTED'; +export const DELETE_MYRETROFIT_SUCCEEDED = 'DELETE_MYRETROFIT_SUCCEEDED'; +export const DELETE_MYRETROFIT_FAILED = 'DELETE_MYRETROFIT_FAILED'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index aa9f8186..6cfa2e6c 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -13,7 +13,9 @@ import { loadRetrofitMeta, updateOccupants, updateThermalComfort, - updateRetrofits, + createMyRetrofit, + updateMyRetrofit, + deleteMyRetrofit, } from './actions'; import buildingDetailPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; @@ -122,31 +124,7 @@ class Performance extends Component { } const retrofitsData = retrofits.data.retrofits === null ? [] : retrofits.data.retrofits; - // let retrofitNames = []; - // if (retrofitMeta.data.data !== null) { - // retrofitNames = retrofitMeta.data.data.map(item => { - // return item.retrofit_name; - // }); - // } - - // const retrofits = [ - // { - // retrofit_name: 'Weather Stripping', - // install_start_date: '2019-04-20', - // install_end_date: '2019-05-20', - // primary_utility: 'Natural Gas', - // second_utility: 'Oil', - // notes: 'Test notes 1', - // }, - // { - // retrofit_name: 'Toilet Replacement', - // install_start_date: '2019-03-20', - // install_end_date: '2019-04-12', - // primary_utility: 'Water', - // second_utility: 'Natural Gas', - // notes: 'Test notes 2', - // }, - // ]; + console.log(retrofitsData); // eslint-disable-line mainContent = (
    @@ -183,7 +161,9 @@ class Performance extends Component { retrofits={retrofitsData} retrofitsLog={retrofitsLog.data.data} utilityNames={['Natural Gas', 'Water', 'Electricity', 'Oil']} - updateRetrofits={this.props.updateRetrofits} + createRetrofit={this.props.createMyRetrofit} + updateRetrofit={this.props.updateMyRetrofit} + deleteRetrofit={this.props.deleteMyRetrofit} userId={userId} blockStyle={blockStyle} headerStyle={headerStyle} @@ -224,7 +204,9 @@ Performance.propTypes = { loadRetrofitMeta: PropTypes.func, updateOccupants: PropTypes.func, updateThermalComfort: PropTypes.func, - updateRetrofits: PropTypes.func, + createMyRetrofit: PropTypes.func, + updateMyRetrofit: PropTypes.func, + deleteMyRetrofit: PropTypes.func, user: PropTypes.objectOf, performance: PropTypes.objectOf, }; @@ -240,7 +222,9 @@ const mapDispatchToProps = dispatch => ( loadRetrofitMeta, updateOccupants, updateThermalComfort, - updateRetrofits, + createMyRetrofit, + updateMyRetrofit, + deleteMyRetrofit, }, dispatch) ); diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index eca58f89..3b3c1ef4 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -23,6 +23,15 @@ import { UPDATE_OCCUPANTS_REQUESTED, UPDATE_OCCUPANTS_SUCCEEDED, UPDATE_OCCUPANTS_FAILED, + UPDATE_MYRETROFIT_REQUESTED, + UPDATE_MYRETROFIT_SUCCEEDED, + UPDATE_MYRETROFIT_FAILED, + CREATE_MYRETROFIT_REQUESTED, + CREATE_MYRETROFIT_SUCCEEDED, + CREATE_MYRETROFIT_FAILED, + DELETE_MYRETROFIT_REQUESTED, + DELETE_MYRETROFIT_SUCCEEDED, + DELETE_MYRETROFIT_FAILED, } from './constants'; const PerformanceInitialState = { @@ -64,7 +73,6 @@ const PerformanceInitialState = { }; export default function (state = PerformanceInitialState, action) { - console.log(action); // eslint-disable-line switch (action.type) { case OCCUPANTS_REQUESTED: return { @@ -298,6 +306,101 @@ export default function (state = PerformanceInitialState, action) { }, }; + case CREATE_MYRETROFIT_REQUESTED: + return { + ...state, + retrofits: { + ...state.retrofits, + loading: true, + error: false, + }, + }; + + case CREATE_MYRETROFIT_SUCCEEDED: { + const retrofits = state.retrofits.data.retrofits; + retrofits.splice(-1, 1); + retrofits.push(action.instance.instance); + return { + ...state, + retrofits: { + data: { + retrofits, + }, + loading: false, + error: false, + }, + }; + } + case CREATE_MYRETROFIT_FAILED: + return { + ...state, + retrofits: { + loading: false, + error: action.error, + }, + }; + + case UPDATE_MYRETROFIT_REQUESTED: + return { + ...state, + retrofits: { + ...state.retrofits, + loading: true, + error: false, + }, + }; + + case UPDATE_MYRETROFIT_SUCCEEDED: + return { + ...state, + retrofits: { + ...state.retrofits, + loading: false, + error: false, + }, + }; + + case UPDATE_MYRETROFIT_FAILED: + return { + ...state, + retrofits: { + loading: false, + error: action.error, + }, + }; + + case DELETE_MYRETROFIT_REQUESTED: + return { + ...state, + retrofits: { + ...state.retrofits, + loading: true, + error: false, + }, + }; + + case DELETE_MYRETROFIT_SUCCEEDED: { + return { + ...state, + retrofits: { + data: { + retrofits: + state.retrofits.data.retrofits.filter(retrofit => retrofit.id !== action.instance.id), + }, + loading: false, + error: false, + }, + }; + } + case DELETE_MYRETROFIT_FAILED: + return { + ...state, + retrofits: { + loading: false, + error: action.error, + }, + }; + default: return state; } diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js index adcde2a3..21c84776 100644 --- a/src/containers/Performance/sagas.js +++ b/src/containers/Performance/sagas.js @@ -12,7 +12,9 @@ import { RETROFIT_META_REQUESTED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_THERMAL_COMFORT_REQUESTED, - UPDATE_RETROFITS_REQUESTED, + CREATE_MYRETROFIT_REQUESTED, + UPDATE_MYRETROFIT_REQUESTED, + DELETE_MYRETROFIT_REQUESTED, CREATE_OCCUPANTS_LOG_REQUESTED, CREATE_THERMAL_COMFORT_LOG_REQUESTED, } from './constants'; @@ -27,9 +29,11 @@ import { retrofitMetaLoaded, retrofitMetaFailed, updateOccupantsSucceeded, updateOccupantsFailed, updateThermalComfortSucceeded, updateThermalComfortFailed, - updateRetrofitsSucceeded, updateRetrofitsFailed, + updateMyRetrofitSucceeded, updateMyRetrofitFailed, + createMyRetrofitSucceeded, createMyRetrofitFailed, createOccupantsLogSucceeded, createOccupantsLogFailed, createThermalComfortLogSucceeded, createThermalComfortLogFailed, + deleteMyRetrofitSucceeded, deleteMyRetrofitFailed, } from './actions'; function* loadOccupants(action) { @@ -105,7 +109,27 @@ function* updateThermalComfort(action) { } } -function* updateRetrofits(action) { +function* createMyRetrofit(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofits/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + console.log(res); // eslint-disable-line + yield put(createMyRetrofitSucceeded(res)); + } else { + yield put(createMyRetrofitFailed(res.err)); + } +} + +function* updateMyRetrofit(action) { const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofits/`; const res = yield call( request, @@ -118,9 +142,29 @@ function* updateRetrofits(action) { ); if (!res.err) { - yield put(updateRetrofitsSucceeded(action.payload)); + console.log(res); // eslint-disable-line + yield put(updateMyRetrofitSucceeded(res)); + } else { + yield put(updateMyRetrofitFailed(res.err)); + } +} + +function* deleteMyRetrofit(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofits/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'DELETE', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(deleteMyRetrofitSucceeded(action.payload)); } else { - yield put(updateRetrofitsFailed(res.err)); + yield put(deleteMyRetrofitFailed(res.err)); } } @@ -172,9 +216,11 @@ function* bloclinkWatcher() { yield takeEvery(RETROFIT_META_REQUESTED, loadRetrofitMeta); yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); - yield takeEvery(UPDATE_RETROFITS_REQUESTED, updateRetrofits); + yield takeEvery(UPDATE_MYRETROFIT_REQUESTED, updateMyRetrofit); yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); yield takeEvery(CREATE_THERMAL_COMFORT_LOG_REQUESTED, createThermalComfortLog); + yield takeEvery(CREATE_MYRETROFIT_REQUESTED, createMyRetrofit); + yield takeEvery(DELETE_MYRETROFIT_REQUESTED, deleteMyRetrofit); } export default bloclinkWatcher; -- GitLab From 4ce0076cf92dab98ff1d831b6aac979fed851a5a Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 14 Jun 2019 11:20:29 -0400 Subject: [PATCH 45/50] Select retrofit dropdown issue and error message format --- src/components/Performance/Occupants.js | 35 +++++++++++-- src/components/Performance/ResultMessage.js | 43 ++++++++++++--- src/components/Performance/RetrofitRow.js | 21 ++------ src/components/Performance/Retrofits.js | 47 ++++++----------- src/components/Performance/ThermalComfort.js | 31 +++++++++-- src/containers/Performance/index.js | 55 +++++++------------- 6 files changed, 133 insertions(+), 99 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 668e4d3c..c634c1c4 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -7,6 +7,7 @@ import { Button, } from 'reactstrap'; import './styles.css'; +import ResultMessage from './ResultMessage'; const customStyles = { @@ -34,12 +35,14 @@ class Occupants extends Component { preVacantUnits: props.preVacantUnits, postVacantUnits: props.postVacantUnits, modalIsOpen: false, - action: null, occupantsLog: (this.props.occupantsLog.length > global.expandNum) ? this.props.occupantsLog.slice(0, global.expandNum) : this.props.occupantsLog, showNextButton: (this.props.occupantsLog.length > global.expandNum) === true, currentLogPos: 0, showlastButton: false, + action: null, + messageContent: null, + messageStyle: 'default', }; this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); @@ -99,9 +102,7 @@ class Occupants extends Component { user_id: this.props.userId, } ); - this.setState({ action: 'updated' }, () => { - alert('Update successful.'); - }); + this.setState({ action: 'updated' }); } } @@ -153,6 +154,25 @@ class Occupants extends Component { ); } + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { + this.state.messageContent = 'Updating ...'; + } + + if (this.props.error && typeof this.props.error === 'object') { + this.state.messageStyle = 'error'; + this.state.messageContent = this.props.error.response.statusText; + } + + if (!this.props.error && !this.props.loading + && this.props.data !== null + && this.state.action === 'updated') { + this.state.messageStyle = 'success'; + this.state.messageContent = 'Saved!'; + } + return (
    @@ -162,6 +182,10 @@ class Occupants extends Component {
    + {' '}{' '}
       + style={this.state.messageStyle} + content={this.state.messageContent} + /> {' '}{' '}
    @@ -167,9 +153,8 @@ class Performance extends Component { userId={userId} blockStyle={blockStyle} headerStyle={headerStyle} - successMessageStyle={successMessageStyle} - errorMessageStyle={errorMessageStyle} - defaultMessageStyle={defaultMessageStyle} + loading={retrofits.loading} + error={retrofits.error} />
    -- GitLab From 522c304cdb81d2a3cb5a75617a2df9a91cce4494 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 14 Jun 2019 11:28:41 -0400 Subject: [PATCH 46/50] Change button style --- src/components/Performance/Occupants.js | 6 +++--- src/components/Performance/ThermalComfort.js | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index c634c1c4..d6c9f30c 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -134,7 +134,7 @@ class Occupants extends Component { let lastButton = null; const buttonStyle = { textAlign: 'center', - marginBottom: '30px', + marginBottom: '10px', marginLeft: '0px', cursor: 'pointer', }; @@ -142,14 +142,14 @@ class Occupants extends Component { if (this.state.showNextButton) { nextButton = ( ); } if (this.state.showLastButton) { lastButton = ( ); } diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index f5ba81ff..daa4a760 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -137,7 +137,7 @@ class ThermalComfort extends Component { let lastButton = null; const buttonStyle = { textAlign: 'center', - marginBottom: '30px', + marginBottom: '10px', marginLeft: '0px', cursor: 'pointer', }; @@ -145,14 +145,14 @@ class ThermalComfort extends Component { if (this.state.showNextButton) { nextButton = ( ); } if (this.state.showLastButton) { lastButton = ( ); } -- GitLab From 9346c97c6bce47fc54f6cd4b557ac139ab123895 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 14 Jun 2019 15:08:23 -0400 Subject: [PATCH 47/50] Fixing retrofits delete issue --- src/components/Performance/Retrofits.js | 31 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js index 9dbae3aa..b3c48c9c 100644 --- a/src/components/Performance/Retrofits.js +++ b/src/components/Performance/Retrofits.js @@ -120,13 +120,12 @@ class Retrofits extends Component { this.props.deleteRetrofit( this.props.buildingId, { id }, + () => { + this.setState({ + retrofits: this.state.retrofits.filter(retrofit => retrofit.id !== id), + }); + } ); - - const retrofitsCopy = this.state.retrofits.filter(retrofit => retrofit.id !== id); - this.setState({ - retrofits: retrofitsCopy, - action: 'deleted', - }); } } } @@ -150,8 +149,13 @@ class Retrofits extends Component { let retrofits = []; let historyButton = null; + console.log(this.state.retrofits); // eslint-disable-line + console.log(this.props.retrofits); // eslint-disable-line + console.log(this.state.retrofits); // eslint-disable-line + this.state.retrofits = this.props.retrofits; if (this.state.retrofits !== null && Object.keys(this.state.retrofits).length !== 0) { retrofits = this.state.retrofits.map((retrofit, index) => { + console.log(retrofit); // eslint-disable-line return ( Date: Fri, 14 Jun 2019 17:06:42 -0400 Subject: [PATCH 48/50] Fixed retrofit delete issue --- src/components/Performance/Retrofits.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js index b3c48c9c..c1a3c05e 100644 --- a/src/components/Performance/Retrofits.js +++ b/src/components/Performance/Retrofits.js @@ -120,12 +120,12 @@ class Retrofits extends Component { this.props.deleteRetrofit( this.props.buildingId, { id }, - () => { - this.setState({ - retrofits: this.state.retrofits.filter(retrofit => retrofit.id !== id), - }); - } ); + + this.setState({ + retrofits: this.state.retrofits.filter(retrofit => retrofit.id !== id), + action: 'deleted', + }); } } } @@ -149,16 +149,12 @@ class Retrofits extends Component { let retrofits = []; let historyButton = null; - console.log(this.state.retrofits); // eslint-disable-line - console.log(this.props.retrofits); // eslint-disable-line - console.log(this.state.retrofits); // eslint-disable-line this.state.retrofits = this.props.retrofits; if (this.state.retrofits !== null && Object.keys(this.state.retrofits).length !== 0) { - retrofits = this.state.retrofits.map((retrofit, index) => { - console.log(retrofit); // eslint-disable-line + retrofits = this.state.retrofits.map((retrofit) => { return ( Date: Fri, 14 Jun 2019 17:19:18 -0400 Subject: [PATCH 49/50] Update button size --- src/components/Performance/RetrofitRow.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js index 86cb1987..cc0804b6 100644 --- a/src/components/Performance/RetrofitRow.js +++ b/src/components/Performance/RetrofitRow.js @@ -202,6 +202,7 @@ class RetrofitRow extends Component { actionButton = (
    Saving Estimation -
    UtilityUtility Estimated Savings Used Before Retrofit Used After Retrofit
    - {this.props.utilityName} + + {this.props.utilityName.charAt(0).toUpperCase() + this.props.utilityName.slice(1)}
    diff --git a/src/components/Blocnote/PreliminaryFinance/SelectScenario.js b/src/components/Blocnote/PreliminaryFinance/SelectScenario.js index 44ac0af7..fed9fb54 100644 --- a/src/components/Blocnote/PreliminaryFinance/SelectScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/SelectScenario.js @@ -20,7 +20,6 @@ class SelectScenario extends Component { scenarioDropDownValue: 'Select Scenario', scenarioOptions: [ { id: 'Scenario1', key: 'Scenario1', name: 'Scenario 1' }, - { id: 'Scenario2', key: 'Scenario2', name: 'Scenario 2' }, ], }; } diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 398817c2..73b1596c 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -129,7 +129,7 @@ class FinancialInputs extends Component { fianceOverview.data.instance.financing_overview_data !== undefined; let cashBalanceData = []; let loanOptionsData = []; - let billsSummaryData = { + const billsSummaryData = { gas: [], oil: [], water: [], @@ -153,7 +153,9 @@ class FinancialInputs extends Component { } }); } else { - billsSummaryData = billsSummary.data.result.user_bill; + Object.keys(billsSummary.data.result.user_bill).forEach((billName) => { + billsSummaryData[billName] = billsSummary.data.result.user_bill[billName]; + }); } if (Object.keys(customerPreference.data).length !== 0) { customerPreferenceData = customerPreference.data.instance; -- GitLab From f4831efc7f78fd162bf6ae45bcecc4b16c449a6a Mon Sep 17 00:00:00 2001 From: akkking Date: Sat, 11 May 2019 00:06:46 -0400 Subject: [PATCH 08/50] Fix scenario saving issue --- src/components/Blocnote/PreliminaryFinance/InputScenario.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Blocnote/PreliminaryFinance/InputScenario.js b/src/components/Blocnote/PreliminaryFinance/InputScenario.js index a31f7c5a..a68406d2 100644 --- a/src/components/Blocnote/PreliminaryFinance/InputScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/InputScenario.js @@ -25,7 +25,9 @@ class InputScenario extends Component { const data = { scenario: this.state.scenarioName, cost: this.state.costs, - savings: Object.values(this.state.savings), + savings: Object.values(this.state.savings).map(saving => { + return Object.assign({}, saving, { estimated_savings: String(saving.estimated_savings) }); + }), }; console.log(data); // eslint-disable-line this.props.updateScenario( -- GitLab From aba14435f3ff2f3da4fbac304d868b7633a584dd Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 15 May 2019 10:45:24 -0400 Subject: [PATCH 09/50] Move css to separate file --- .../PreliminaryFinance/CostEstimation.js | 17 +++------- .../PreliminaryFinance/InputScenario.js | 31 ++++++++++++++----- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 9354b137..455cfbeb 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -4,6 +4,7 @@ import { Table, Button, } from 'reactstrap'; +import '../styles.css'; import CostEstimationRow from './CostEstimationRow'; @@ -121,18 +122,10 @@ class CostEstimation extends Component {
    -
    - Cost Estimation + +
    + Cost Estimation +
    { const data = { scenario: this.state.scenarioName, - cost: this.state.costs, + cost: this.state.costs + .filter(costItem => + costItem.item !== '' && costItem.item !== null && costItem.cost !== null && costItem.cost !== 'null') + .map(costItem => { + return Object.assign({}, costItem, { cost: String(costItem.cost) }); + }), savings: Object.values(this.state.savings).map(saving => { return Object.assign({}, saving, { estimated_savings: String(saving.estimated_savings) }); }), @@ -70,8 +75,18 @@ class InputScenario extends Component { if (!this.props.error && !this.props.loading && this.props.data !== null && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; + // messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); + // messageStyle = this.props.successMessageStyle; + messageContent = ( + + ✔  {'Saved and reloaded.'} + + ); + messageStyle = { + paddingRight: '25px', + color: '#336633', + fontWeight: 'bold', + }; } return ( @@ -141,11 +156,11 @@ InputScenario.propTypes = { textAlign: PropTypes.string, marginBottom: PropTypes.string, }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), + // successMessageStyle: PropTypes.shape({ + // color: PropTypes.string, + // paddingLeft: PropTypes.string, + // fontWeight: PropTypes.string, + // }), errorMessageStyle: PropTypes.shape({ color: PropTypes.string, paddingLeft: PropTypes.string, -- GitLab From 9a399fab7455ced870ba938d4239376b84fb06ef Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 15 May 2019 17:57:45 -0400 Subject: [PATCH 10/50] Add BlocLink reducers, sagas, contants, actions --- src/components/Performance/Occupants.js | 2 +- src/components/Performance/ThermalComfort.js | 2 +- src/containers/Performance/actions.js | 36 +++-- src/containers/Performance/constants.js | 18 ++- src/containers/Performance/reducer.js | 150 +++++++++++++++++++ src/containers/Performance/sagas.js | 128 ++++++++++++++++ src/reducers.js | 2 + 7 files changed, 318 insertions(+), 20 deletions(-) create mode 100644 src/containers/Performance/reducer.js create mode 100644 src/containers/Performance/sagas.js diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index fa3be3f9..9f04f771 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -93,7 +93,7 @@ class Occupants extends Component { - +
    + + + + + + + + + ); + } +} + +RetrofitRow.propTypes = { + id: PropTypes.number, + retrofitName: PropTypes.string, + installStartDate: PropTypes.string, + installEndDate: PropTypes.string, + primaryUtility: PropTypes.string, + secondUtility: PropTypes.string, + notes: PropTypes.string, + utilityNames: PropTypes.arrayOf, + retrofitNames: PropTypes.arrayOf, + onDelEvent: PropTypes.func, + onChangeEvent: PropTypes.func, +}; + +export default RetrofitRow; diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js new file mode 100644 index 00000000..89cf5d33 --- /dev/null +++ b/src/components/Performance/Retrofits.js @@ -0,0 +1,292 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { + Button, + Table, +} from 'reactstrap'; +import RetrofitRow from './RetrofitRow'; +import ResultMessage from './ResultMessage'; + + +class Retrofits extends Component { + constructor(props) { + super(props); + this.deleteRow = this.deleteRow.bind(this); + this.addRow = this.addRow.bind(this); + this.updateRow = this.updateRow.bind(this); + this.state = { + retrofitNames: props.retrofitNames, + utilityNames: props.utilityNames, + retrofits: props.retrofits, + retrofit_name: 'Waterstripping', + install_start_date: null, + install_end_date: null, + primary_utility: 'Natural Gas', + second_utility: 'Water', + notes: null, + }; + } + + validateInputs = () => { + const emptyFields = []; + if (this.state.retrofits.length > 0) { + Object.values(this.state.retrofits).forEach(retrofit => { + console.log(retrofit); // eslint-disable-line + if (retrofit.retrofit_name === null && + !emptyFields.includes('Retrofit Name')) { + emptyFields.push('Retrofit Name'); + } + if (retrofit.install_start_date === null && + !emptyFields.includes('Installation Start Date')) { + emptyFields.push('Installation Start Date'); + } + if (retrofit.install_end_date === null && + !emptyFields.includes('Installation End Date')) { + emptyFields.push('Installation End Date'); + } + if (retrofit.primary_utility === null && + !emptyFields.includes('Primary Influenced Utility')) { + emptyFields.push('Primary Influenced Utility'); + } + if (retrofit.second_utility === null && + !emptyFields.includes('Second Influenced Utility')) { + emptyFields.push('Second Influenced Utility'); + } + }); + } + + if (emptyFields.length > 0) { + alert(`Please fill in ${emptyFields.join(', ')} fields`); + return false; + } + return true; + } + + deleteRow = id => { + const retrofitsCopy = this.state.retrofits.filter((retrofit, index) => { + console.log(retrofit); // eslint-disable-line + return index !== id; + }); + this.setState({ retrofits: retrofitsCopy }, () => { + console.log('Retrofit deleted!'); // eslint-disable-line + }); + } + + addRow = () => { + if (this.validateInputs() === true) { + const retrofit = { + id: this.state.id, + retrofit_name: this.state.retrofit_name, + install_start_date: this.state.install_start_date, + install_end_date: this.state.install_end_date, + primary_utility: this.state.primary_utility, + second_utility: this.state.second_utility, + notes: this.state.notes, + }; + console.log(this.state.retrofits); // eslint-disable-line + const retrofits = this.state.retrofits; + retrofits.push(retrofit); + this.setState({ retrofits }, () => { + console.log(this.state.retrofits, 'New retrofit added!'); // eslint-disable-line + this.setState({ + id: this.state.id + 1, + retrofit_name: 'Waterstripping', + install_start_date: null, + install_end_date: null, + primary_utility: 'Natural Gas', + second_utility: 'Water', + notes: null, + }); + }); + } + } + + updateRow = (row) => { + const retrofits = this.state.retrofits.map((retrofit, id) => { + console.log(id); // eslint-disable-line + console.log(row.id); // eslint-disable-line + if (id === row.id) { + const tmp = { id }; + tmp.retrofit_name = row.retrofit_name; + tmp.install_start_date = row.install_start_date; + tmp.install_end_date = row.install_end_date; + tmp.primary_utility = row.primary_utility; + tmp.second_utility = row.second_utility; + tmp.notes = row.notes; + return tmp; + } + return retrofit; + }); + this.setState({ retrofits }, () => { + console.log(retrofits); // eslint-disable-line + }); + } + + handleUpdateRetrofits = () => { + if (this.validateInputs() === true) { + const formData = {}; + formData.instance = this.state.retrofits; + this.props.updateRetrofits( + this.props.buildingId, + formData, + ); + this.setState({ + loading: false, + action: 'updated', + }); + } + } + + render() { + const header = [ + 'Retrofit Name', + 'Installation Start Date', + 'Installation End Date', + 'Primary Influenced Utility', + 'Second Influenced Utility', + 'Notes', + ' ', + ].map((title, key) => { + return ( + + ); + }); + + let retrofits = []; + let saveButton = null; + if (Object.keys(this.state.retrofits).length !== 0) { + retrofits = this.state.retrofits.map((retrofit, index) => { + return ( + + ); + }); + saveButton = ( + + ); + } else { + retrofits = ( + + + + ); + } + + let messageStyle = {}; + let messageContent = null; + + if (this.props.loading) { + messageContent = 'Updating ...'; + messageStyle = this.props.defaultMessageStyle; + } + + if (this.props.error && typeof this.props.error === 'object') { + messageContent = this.props.error.response.statusText; + messageStyle = this.props.errorMessageStyle; + } + + if (!this.props.error && !this.props.loading + && this.props.data !== null + && this.state.updated) { + messageContent = 'Saved!'; + messageStyle = this.props.successMessageStyle; + } + + return ( +
    +

    + My Retrofits +

    +
    +
    +
    Number of Units diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index 154a2968..118ad184 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -66,7 +66,7 @@ class ThermalComfort extends Component { {' '} - +
    + + + + + + ); + }); + return (
    @@ -81,7 +102,7 @@ class Occupants extends Component { color="secondary" onClick={this.openModal} > - Action log + History {' '} -
    I am a modal
    -
    - - - - - - +
    +
    +

    Change History

    +
    +
    + +
    +
    +
    +
    Heating Set Point (Pre-retrofit) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 13e51833..8baa0e03 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -1,16 +1,28 @@ import { - LOAD_OCCUPANTS, - OCCUPANTS_SUCCESS, - OCCUPANTS_ERROR, - LOAD_THERMAL_COMFORT, - THERMAL_COMFORT_SUCCESS, - THERMAL_COMFORT_ERROR, + OCCUPANTS_REQUESTED, + OCCUPANTS_SUCCEEDED, + OCCUPANTS_FAILED, + OCCUPANTS_LOG_REQUESTED, + OCCUPANTS_LOG_SUCCEEDED, + OCCUPANTS_LOG_FAILED, + THERMAL_COMFORT_REQUESTED, + THERMAL_COMFORT_SUCCEEDED, + THERMAL_COMFORT_FAILED, + THERMAL_COMFORT_LOG_REQUESTED, + THERMAL_COMFORT_LOG_SUCCEEDED, + THERMAL_COMFORT_LOG_FAILED, } from './constants'; import { makeActionCreator } from '../../utils/reduxHelpers'; -export const loadOccupants = makeActionCreator(LOAD_OCCUPANTS, 'buildingId'); -export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCESS, 'payload'); -export const occupantsLoadingError = makeActionCreator(OCCUPANTS_ERROR, 'error'); -export const loadThermalComfort = makeActionCreator(LOAD_THERMAL_COMFORT, 'buildingId'); -export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCESS, 'payload'); -export const thermalComfortLoadingError = makeActionCreator(THERMAL_COMFORT_ERROR, 'error'); +export const loadOccupants = makeActionCreator(OCCUPANTS_REQUESTED, 'buildingId'); +export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCEEDED, 'payload'); +export const occupantsLoadingError = makeActionCreator(OCCUPANTS_FAILED, 'error'); +export const loadOccupantsLog = makeActionCreator(OCCUPANTS_LOG_REQUESTED, 'buildingId'); +export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'payload'); +export const occupantsLogLoadingError = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); +export const loadThermalComfort = makeActionCreator(THERMAL_COMFORT_REQUESTED, 'buildingId'); +export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'payload'); +export const thermalComfortLoadingError = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); +export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); +export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); +export const thermalComfortLogLoadingError = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index 059b46d5..f7081663 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -1,6 +1,12 @@ -export const LOAD_OCCUPANTS = 'LOAD_OCCUPANTS'; -export const OCCUPANTS_SUCCESS = 'OCCUPANTS_SUCCESS'; -export const OCCUPANTS_ERROR = 'OCCUPANTS_ERROR'; -export const LOAD_THERMAL_COMFORT = 'LOAD_THERMAL_COMFORT'; -export const THERMAL_COMFORT_SUCCESS = 'THERMAL_COMFORT_SUCCESS'; -export const THERMAL_COMFORT_ERROR = 'THERMAL_COMFORT_ERROR'; +export const OCCUPANTS_REQUESTED = 'OCCUPANTS_REQUESTED'; +export const OCCUPANTS_SUCCEEDED = 'OCCUPANTS_SUCCEEDED'; +export const OCCUPANTS_FAILED = 'OCCUPANTS_FAILED'; +export const OCCUPANTS_LOG_REQUESTED = 'OCCUPANTS_LOG_REQUESTED'; +export const OCCUPANTS_LOG_SUCCEEDED = 'OCCUPANTS_LOG_SUCCEEDED'; +export const OCCUPANTS_LOG_FAILED = 'OCCUPANTS_LOG_FAILED'; +export const THERMAL_COMFORT_REQUESTED = 'THERMAL_COMFORT_REQUESTED'; +export const THERMAL_COMFORT_SUCCEEDED = 'THERMAL_COMFORT_SUCCEEDED'; +export const THERMAL_COMFORT_FAILED = 'THERMAL_COMFORT_FAILED'; +export const THERMAL_COMFORT_LOG_REQUESTED = 'THERMAL_COMFORT_LOG_REQUESTED'; +export const THERMAL_COMFORT_LOG_SUCCEEDED = 'THERMAL_COMFORT_LOG_SUCCEEDED'; +export const THERMAL_COMFORT_LOG_FAILED = 'THERMAL_COMFORT_LOG_FAILED'; diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js new file mode 100644 index 00000000..e8e4f4bc --- /dev/null +++ b/src/containers/Performance/reducer.js @@ -0,0 +1,150 @@ +import { + OCCUPANTS_REQUESTED, + OCCUPANTS_SUCCEEDED, + OCCUPANTS_FAILED, + OCCUPANTS_LOG_REQUESTED, + OCCUPANTS_LOG_SUCCEEDED, + OCCUPANTS_LOG_FAILED, + THERMAL_COMFORT_REQUESTED, + THERMAL_COMFORT_SUCCEEDED, + THERMAL_COMFORT_FAILED, + THERMAL_COMFORT_LOG_REQUESTED, + THERMAL_COMFORT_LOG_SUCCEEDED, + THERMAL_COMFORT_LOG_FAILED, +} from './constants'; + +const PerformanceInitialState = { + occupants: { + loading: false, + error: false, + data: null, + }, + thermalComfort: { + loading: false, + error: false, + data: null, + }, +}; + +export default function (state = PerformanceInitialState, action) { + switch (action.type) { + case OCCUPANTS_REQUESTED: + return { + ...state, + occupants: { + ...state.occupants, + loading: true, + error: false, + }, + }; + + case OCCUPANTS_SUCCEEDED: + return { + ...state, + occupants: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case OCCUPANTS_FAILED: + return { + ...state, + occupants: { + loading: false, + error: action.error, + }, + }; + + case OCCUPANTS_LOG_REQUESTED: + return { + ...state, + occupantsLog: { + ...state.occupantsLog, + loading: true, + error: false, + }, + }; + + case OCCUPANTS_LOG_SUCCEEDED: + return { + ...state, + occupantsLog: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case OCCUPANTS_LOG_FAILED: + return { + ...state, + occupantsLog: { + loading: false, + error: action.error, + }, + }; + + case THERMAL_COMFORT_REQUESTED: + return { + ...state, + thermalComfort: { + ...state.thermalComfort, + loading: true, + error: false, + }, + }; + + case THERMAL_COMFORT_SUCCEEDED: + return { + ...state, + thermalComfort: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case THERMAL_COMFORT_FAILED: + return { + ...state, + thermalComfort: { + loading: false, + error: action.error, + }, + }; + + case THERMAL_COMFORT_LOG_REQUESTED: + return { + ...state, + thermalComfortLog: { + ...state.thermalComfortLog, + loading: true, + error: false, + }, + }; + + case THERMAL_COMFORT_LOG_SUCCEEDED: + return { + ...state, + thermalComfortLog: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case THERMAL_COMFORT_LOG_FAILED: + return { + ...state, + thermalComfortLog: { + loading: false, + error: action.error, + }, + }; + + default: + return state; + } +} diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js new file mode 100644 index 00000000..a1126eb4 --- /dev/null +++ b/src/containers/Performance/sagas.js @@ -0,0 +1,128 @@ +import { call, put, takeEvery } from 'redux-saga/effects'; +import SagaRequests from '../../utils/sagaRequests'; +import request from '../../utils/request'; +import { getHeaders } from '../../utils/restServices'; +import { + OCCUPANTS_REQUESTED, + OCCUPANTS_LOG_REQUESTED, + THERMAL_COMFORT_REQUESTED, + THERMAL_COMFORT_LOG_REQUESTED, +} from './constants'; + +import { + occupantsLoaded, occupantsFailed, + occupantsLogLoaded, occupantsLogFailed, + thermalComfortLoaded, thermalComfortFailed, + thermalComfortLogLoaded, thermalComfortLogFailed, + createThermalComfortLogSucceeded, createOccupantsLogFailed, + createThermalComfortLogSucceeded, createOccupantsLogFailed, +} from './actions'; + +function* loadOccupants(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants`; + yield SagaRequests.get(action, url, occupantsLoaded, occupantsFailed); +} + +function* loadOccupantsLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants-log`; + yield SagaRequests.get(action, url, occupantsLogLoaded, occupantsLogFailed); +} + +function* loadThermalComfort(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/thermal-comfort/`; + yield SagaRequests.get(action, url, thermalComfortLoaded, thermalComfortFailed); +} + +function* loadThermalComfortLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/thermal-comfort-log/`; + yield SagaRequests.get(action, url, thermalComfortLogLoaded, thermalComfortLogFailed); +} + +function* updateOccupants(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'PUT', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(updateOccupantsSucceeded(action.payload)); + } else { + yield put(updateOccupantsFailed(res.err)); + } +} + +function* updateThermalComfort(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/thermal-comfort/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'PUT', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(updateThermalComfortSucceeded(action.payload)); + } else { + yield put(updateThermalComfortFailed(res.err)); + } +} + +function* createOccupantsLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants-log/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(createOccupantsLogSucceeded(action.payload, res)); + } else { + yield put(createOccupantsLogFailed(res.err)); + } +} + +function* createThermalComfortLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/thermal-comfort-log/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'POST', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(createThermalComfortLogSucceeded(action.payload, res)); + } else { + yield put(createThermalComfortLogFailed(res.err)); + } +} + +function* bloclinkWatcher() { + yield takeEvery(OCCUPANTS_REQUESTED, loadOccupants); + yield takeEvery(OCCUPANTS_LOG_REQUESTED, loadOccupantsLog); + yield takeEvery(THERMAL_COMFORT_REQUESTED, loadThermalComfort); + yield takeEvery(THERMAL_COMFORT_LOG_REQUESTED, loadThermalComfortLog); + yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); + yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); + yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); + yield takeEvery(CREATE_THERMAL_COMFORT_LOG_REQUESTED, createThermalComfortLog); +} + +export default bloclinkWatcher; diff --git a/src/reducers.js b/src/reducers.js index 5bf5ae9a..0044eac8 100644 --- a/src/reducers.js +++ b/src/reducers.js @@ -17,6 +17,7 @@ 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'; export default combineReducers({ @@ -37,4 +38,5 @@ export default combineReducers({ weather, events, blocnote, + bloclink, }); -- GitLab From b9dc10e95d957743a6179ecb48e0b7b59d36f92b Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 16 May 2019 15:37:20 -0400 Subject: [PATCH 11/50] Add performance sidebar icon --- src/components/SideBarDetail/index.js | 3 ++- src/components/SideBarDetail/sidebarSVGs.js | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/SideBarDetail/index.js b/src/components/SideBarDetail/index.js index b90e6a55..ee470758 100644 --- a/src/components/SideBarDetail/index.js +++ b/src/components/SideBarDetail/index.js @@ -12,6 +12,7 @@ import { envelopeSVG, reportsSVG, blocnoteSVG, + performanceSVG, iotSVG, } from './sidebarSVGs'; import userPropType from '../../containers/User/propTypes'; @@ -212,7 +213,7 @@ export default function SideBarDetail({ building, children, contacts, user }) {
  • - {blocnoteSVG} + {performanceSVG} Performance
  • diff --git a/src/components/SideBarDetail/sidebarSVGs.js b/src/components/SideBarDetail/sidebarSVGs.js index cb06b34a..35a6ce3d 100644 --- a/src/components/SideBarDetail/sidebarSVGs.js +++ b/src/components/SideBarDetail/sidebarSVGs.js @@ -88,3 +88,11 @@ export const iotSVG = ( ); + +export const performanceSVG = ( + + + + + +); -- GitLab From 23e6955484083c1745f9a0341abd2f3ab0d7919a Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 16 May 2019 16:56:44 -0400 Subject: [PATCH 12/50] Add performance sagas --- src/containers/Performance/actions.js | 34 ++++++++++++++++++++++--- src/containers/Performance/constants.js | 14 ++++++++++ src/containers/Performance/index.js | 1 + src/containers/Performance/reducer.js | 1 + src/containers/Performance/sagas.js | 12 ++++++--- src/sagas.js | 2 ++ 6 files changed, 57 insertions(+), 7 deletions(-) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 8baa0e03..0d92d0eb 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -11,18 +11,44 @@ import { THERMAL_COMFORT_LOG_REQUESTED, THERMAL_COMFORT_LOG_SUCCEEDED, THERMAL_COMFORT_LOG_FAILED, + UPDATE_OCCUPANTS_REQUESTED, + UPDATE_OCCUPANTS_SUCCEEDED, + UPDATE_OCCUPANTS_FAILED, + UPDATE_THERMAL_COMFORT_REQUESTED, + UPDATE_THERMAL_COMFORT_SUCCEEDED, + UPDATE_THERMAL_COMFORT_FAILED, + CREATE_OCCUPANTS_LOG_REQUESTED, + CREATE_OCCUPANTS_LOG_SUCCEEDED, + CREATE_OCCUPANTS_LOG_FAILED, + CREATE_THERMAL_COMFORT_LOG_REQUESTED, + CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, + CREATE_THERMAL_COMFORT_LOG_FAILED, } from './constants'; import { makeActionCreator } from '../../utils/reduxHelpers'; export const loadOccupants = makeActionCreator(OCCUPANTS_REQUESTED, 'buildingId'); export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCEEDED, 'payload'); -export const occupantsLoadingError = makeActionCreator(OCCUPANTS_FAILED, 'error'); +export const occupantsFailed = makeActionCreator(OCCUPANTS_FAILED, 'error'); export const loadOccupantsLog = makeActionCreator(OCCUPANTS_LOG_REQUESTED, 'buildingId'); export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'payload'); -export const occupantsLogLoadingError = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); +export const occupantsLogFailed = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); export const loadThermalComfort = makeActionCreator(THERMAL_COMFORT_REQUESTED, 'buildingId'); export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'payload'); -export const thermalComfortLoadingError = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); +export const thermalComfortFailed = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); -export const thermalComfortLogLoadingError = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); +export const thermalComfortLogFailed = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); + +export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId'); +export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload'); +export const updateOccupantsFailed = makeActionCreator(UPDATE_OCCUPANTS_FAILED, 'error'); +export const updateThermalComfort = makeActionCreator(UPDATE_THERMAL_COMFORT_REQUESTED, 'buildingId'); +export const updateThermalComfortSucceeded = makeActionCreator(UPDATE_THERMAL_COMFORT_SUCCEEDED, 'payload'); +export const updateThermalComfortFailed = makeActionCreator(UPDATE_THERMAL_COMFORT_FAILED, 'error'); + +export const createOccupantsLog = makeActionCreator(CREATE_OCCUPANTS_LOG_REQUESTED, 'buildingId'); +export const createOccupantsLogSucceeded = makeActionCreator(CREATE_OCCUPANTS_LOG_SUCCEEDED, 'payload'); +export const createOccupantsLogFailed = makeActionCreator(CREATE_OCCUPANTS_LOG_FAILED, 'error'); +export const createThermalComfortLog = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); +export const createThermalComfortLogSucceeded = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); +export const createThermalComfortLogFailed = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_FAILED, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index f7081663..4aa464e5 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -10,3 +10,17 @@ export const THERMAL_COMFORT_FAILED = 'THERMAL_COMFORT_FAILED'; export const THERMAL_COMFORT_LOG_REQUESTED = 'THERMAL_COMFORT_LOG_REQUESTED'; export const THERMAL_COMFORT_LOG_SUCCEEDED = 'THERMAL_COMFORT_LOG_SUCCEEDED'; export const THERMAL_COMFORT_LOG_FAILED = 'THERMAL_COMFORT_LOG_FAILED'; + +export const UPDATE_OCCUPANTS_REQUESTED = 'UPDATE_OCCUPANTS_REQUESTED'; +export const UPDATE_OCCUPANTS_SUCCEEDED = 'UPDATE_OCCUPANTS_SUCCEEDED'; +export const UPDATE_OCCUPANTS_FAILED = 'UPDATE_OCCUPANTS_FAILED'; +export const UPDATE_THERMAL_COMFORT_REQUESTED = 'UPDATE_THERMAL_COMFORT_REQUESTED'; +export const UPDATE_THERMAL_COMFORT_SUCCEEDED = 'UPDATE_THERMAL_COMFORT_SUCCEEDED'; +export const UPDATE_THERMAL_COMFORT_FAILED = 'UPDATE_THERMAL_COMFORT_FAILED'; + +export const CREATE_OCCUPANTS_LOG_REQUESTED = 'CREATE_OCCUPANTS_LOG_REQUESTED'; +export const CREATE_OCCUPANTS_LOG_SUCCEEDED = 'CREATE_OCCUPANTS_LOG_SUCCEEDED'; +export const CREATE_OCCUPANTS_LOG_FAILED = 'CREATE_OCCUPANTS_LOG_FAILED'; +export const CREATE_THERMAL_COMFORT_LOG_REQUESTED = 'CREATE_THERMAL_COMFORT_LOG_REQUESTED'; +export const CREATE_THERMAL_COMFORT_LOG_SUCCEEDED = 'CREATE_THERMAL_COMFORT_LOG_SUCCEEDED'; +export const CREATE_THERMAL_COMFORT_LOG_FAILED = 'CREATE_THERMAL_COMFORT_LOG_FAILED'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index bae57c91..1009b1c7 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -22,6 +22,7 @@ class Performance extends Component { componentDidMount() { const buildingId = this.props.building.building_id; + console.log(buildingId); // eslint-disable-line this.props.loadOccupants(buildingId); this.props.loadThermalComfort(buildingId); } diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index e8e4f4bc..67373829 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -27,6 +27,7 @@ const PerformanceInitialState = { }; export default function (state = PerformanceInitialState, action) { + console.log(action); // eslint-disable-line switch (action.type) { case OCCUPANTS_REQUESTED: return { diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js index a1126eb4..34d8a268 100644 --- a/src/containers/Performance/sagas.js +++ b/src/containers/Performance/sagas.js @@ -7,6 +7,10 @@ import { OCCUPANTS_LOG_REQUESTED, THERMAL_COMFORT_REQUESTED, THERMAL_COMFORT_LOG_REQUESTED, + UPDATE_OCCUPANTS_REQUESTED, + UPDATE_THERMAL_COMFORT_REQUESTED, + CREATE_OCCUPANTS_LOG_REQUESTED, + CREATE_THERMAL_COMFORT_LOG_REQUESTED, } from './constants'; import { @@ -14,8 +18,10 @@ import { occupantsLogLoaded, occupantsLogFailed, thermalComfortLoaded, thermalComfortFailed, thermalComfortLogLoaded, thermalComfortLogFailed, - createThermalComfortLogSucceeded, createOccupantsLogFailed, - createThermalComfortLogSucceeded, createOccupantsLogFailed, + updateOccupantsSucceeded, updateOccupantsFailed, + updateThermalComfortSucceeded, updateThermalComfortFailed, + createOccupantsLogSucceeded, createOccupantsLogFailed, + createThermalComfortLogSucceeded, createThermalComfortLogFailed, } from './actions'; function* loadOccupants(action) { @@ -120,8 +126,8 @@ function* bloclinkWatcher() { yield takeEvery(THERMAL_COMFORT_REQUESTED, loadThermalComfort); yield takeEvery(THERMAL_COMFORT_LOG_REQUESTED, loadThermalComfortLog); yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); - yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); + yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); yield takeEvery(CREATE_THERMAL_COMFORT_LOG_REQUESTED, createThermalComfortLog); } diff --git a/src/sagas.js b/src/sagas.js index d880c23e..7d7ea267 100644 --- a/src/sagas.js +++ b/src/sagas.js @@ -14,6 +14,7 @@ import buildingAreaSaga from './containers/BuildingArea/sagas'; import weatherSaga from './containers/Weather/sagas'; import eventsSaga from './containers/Event/sagas'; import blocnoteSaga from './containers/Blocnote/sagas'; +import performanceSaga from './containers/Performance/sagas'; export default function* rootSaga() { @@ -34,5 +35,6 @@ export default function* rootSaga() { weatherSaga(), eventsSaga(), blocnoteSaga(), + performanceSaga(), ]; } -- GitLab From 366952b187da6e2ee0041ce974e61febce098fcd Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 21 May 2019 11:30:29 -0400 Subject: [PATCH 13/50] Add update events to actions and reducers --- src/components/Performance/Occupants.js | 35 +++++++++++++++++++++++-- src/containers/Performance/actions.js | 16 +++++------ src/containers/Performance/index.js | 10 +++++++ src/containers/Performance/reducer.js | 32 ++++++++++++++++++++++ 4 files changed, 83 insertions(+), 10 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 9f04f771..b6e747c3 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -25,6 +25,8 @@ Modal.setAppElement('body'); class Occupants extends Component { constructor(props) { super(props); + this.handleOnChange = this.handleOnChange.bind(this); + this.handleUpdateOccupants = this.handleUpdateOccupants.bind(this); this.state = { totalUnits: props.totalUnits, preVacantUnits: props.preVacantUnits, @@ -46,8 +48,22 @@ class Occupants extends Component { closeModal() { this.setState({ modalIsOpen: false }); } - handleOnChange = () => { - this.setState({ displayChart: !this.state.displayChart }); + + handleOnChange = (event) => { + this.setState({ [event.target.name]: event.target.value }); + } + + handleUpdateOccupants = () => { + console.log(this.state); // eslint-disable-line + this.props.updateOccupants( + this.props.buildingId, + { + totalUnits: this.state.totalUnits, + preVacantUnits: this.state.preVacantUnits, + postVacantUnits: this.state.postVacantUnits, + } + ); + this.setState({ action: 'updated' }); } render() { @@ -69,6 +85,7 @@ class Occupants extends Component { @@ -100,6 +117,10 @@ class Occupants extends Component {
    @@ -111,6 +132,10 @@ class Occupants extends Component { @@ -122,6 +147,10 @@ class Occupants extends Component { @@ -137,6 +166,8 @@ Occupants.propTypes = { totalUnits: PropTypes.number, preVacantUnits: PropTypes.number, postVacantUnits: PropTypes.number, + updateOccupants: PropTypes.func, + buildingId: PropTypes.number, }; Occupants.defaultProps = { diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 0d92d0eb..65d6a68d 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -39,16 +39,16 @@ export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUE export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); export const thermalComfortLogFailed = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); -export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId'); -export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload'); +export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId', 'payload'); +export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload', 'instance'); export const updateOccupantsFailed = makeActionCreator(UPDATE_OCCUPANTS_FAILED, 'error'); -export const updateThermalComfort = makeActionCreator(UPDATE_THERMAL_COMFORT_REQUESTED, 'buildingId'); -export const updateThermalComfortSucceeded = makeActionCreator(UPDATE_THERMAL_COMFORT_SUCCEEDED, 'payload'); +export const updateThermalComfort = makeActionCreator(UPDATE_THERMAL_COMFORT_REQUESTED, 'buildingId', 'payload'); +export const updateThermalComfortSucceeded = makeActionCreator(UPDATE_THERMAL_COMFORT_SUCCEEDED, 'instance'); export const updateThermalComfortFailed = makeActionCreator(UPDATE_THERMAL_COMFORT_FAILED, 'error'); -export const createOccupantsLog = makeActionCreator(CREATE_OCCUPANTS_LOG_REQUESTED, 'buildingId'); -export const createOccupantsLogSucceeded = makeActionCreator(CREATE_OCCUPANTS_LOG_SUCCEEDED, 'payload'); +export const createOccupantsLog = makeActionCreator(CREATE_OCCUPANTS_LOG_REQUESTED, 'buildingId', 'payload'); +export const createOccupantsLogSucceeded = makeActionCreator(CREATE_OCCUPANTS_LOG_SUCCEEDED, 'instance'); export const createOccupantsLogFailed = makeActionCreator(CREATE_OCCUPANTS_LOG_FAILED, 'error'); -export const createThermalComfortLog = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); -export const createThermalComfortLogSucceeded = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); +export const createThermalComfortLog = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_REQUESTED, 'buildingId', 'payload'); +export const createThermalComfortLogSucceeded = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_SUCCEEDED, 'instance'); export const createThermalComfortLogFailed = makeActionCreator(CREATE_THERMAL_COMFORT_LOG_FAILED, 'error'); diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 1009b1c7..f6683df1 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -5,6 +5,8 @@ import { bindActionCreators } from 'redux'; import { loadOccupants, loadThermalComfort, + updateOccupants, + updateThermalComfort, } from './actions'; import buildingDetailPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; @@ -54,17 +56,21 @@ class Performance extends Component {
    @@ -78,12 +84,16 @@ Performance.propTypes = { building: buildingDetailPropTypes, loadOccupants: PropTypes.func, loadThermalComfort: PropTypes.func, + updateOccupants: PropTypes.func, + updateThermalComfort: PropTypes.func, }; const mapDispatchToProps = dispatch => ( bindActionCreators({ loadOccupants, loadThermalComfort, + updateOccupants, + updateThermalComfort, }, dispatch) ); diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index 67373829..f4d12e09 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -11,6 +11,9 @@ import { THERMAL_COMFORT_LOG_REQUESTED, THERMAL_COMFORT_LOG_SUCCEEDED, THERMAL_COMFORT_LOG_FAILED, + UPDATE_OCCUPANTS_REQUESTED, + UPDATE_OCCUPANTS_SUCCEEDED, + UPDATE_OCCUPANTS_FAILED, } from './constants'; const PerformanceInitialState = { @@ -145,6 +148,35 @@ export default function (state = PerformanceInitialState, action) { }, }; + case UPDATE_OCCUPANTS_REQUESTED: + return { + ...state, + occupants: { + ...state.occupants, + loading: true, + error: false, + }, + }; + + case UPDATE_OCCUPANTS_SUCCEEDED: + return { + ...state, + occupants: { + ...state.occupants, + loading: false, + error: false, + }, + }; + + case UPDATE_OCCUPANTS_FAILED: + return { + ...state, + occupants: { + loading: false, + error: action.error, + }, + }; + default: return state; } -- GitLab From aaedac2346537289b7cba7cd0eae7e37c0d21ece Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 21 May 2019 18:29:08 -0400 Subject: [PATCH 14/50] Update Occupants and Thermal Comfort actions, index --- src/components/Performance/Occupants.js | 7 +- src/components/Performance/ThermalComfort.js | 29 ++++-- src/containers/Performance/actions.js | 8 +- src/containers/Performance/index.js | 98 +++++++++++++------- 4 files changed, 95 insertions(+), 47 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index b6e747c3..ea5a3998 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -58,9 +58,10 @@ class Occupants extends Component { this.props.updateOccupants( this.props.buildingId, { - totalUnits: this.state.totalUnits, - preVacantUnits: this.state.preVacantUnits, - postVacantUnits: this.state.postVacantUnits, + building_id: this.props.buildingId, + total_units: this.state.totalUnits, + pre_vacant_units: this.state.preVacantUnits, + post_vacant_units: this.state.postVacantUnits, } ); this.setState({ action: 'updated' }); diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index 118ad184..9514809d 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -26,20 +26,31 @@ class ThermalComfort extends Component { }; } - handleUpdateThermalComfort() { - console.log(this.props); // eslint-disable-line - if (confirm('Are you sure to save these updates?') === true) { - this.setState({ preHeatingSetPoint: !this.props.preHeatingSetPoint }); - alert('Confirmed!'); - } - } - toggle() { this.setState(prevState => ({ modal: !prevState.modal, })); } + handleOnChange = (event) => { + this.setState({ [event.target.name]: event.target.value }); + } + + handleUpdateThermalComfort = () => { + console.log(this.state); // eslint-disable-line + this.props.updateThermalComfort( + this.props.buildingId, + { + building_id: this.props.buildingId, + pre_heating_set_point: this.state.preHeatingSetPoint, + post_heating_set_point: this.state.postHeatingSetPoint, + pre_cooling_set_point: this.state.preCoolingSetPoint, + post_cooling_setPoint: this.state.postCoolingSetPoint, + } + ); + this.setState({ action: 'updated' }); + } + render() { return (
    @@ -172,6 +183,8 @@ ThermalComfort.propTypes = { postHeatingSetPoint: PropTypes.number, preCoolingSetPoint: PropTypes.number, postCoolingSetPoint: PropTypes.number, + updateThermalComfort: PropTypes.func, + buildingId: PropTypes.number, }; Modal.propTypes = { diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 65d6a68d..e87ba57b 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -27,16 +27,16 @@ import { import { makeActionCreator } from '../../utils/reduxHelpers'; export const loadOccupants = makeActionCreator(OCCUPANTS_REQUESTED, 'buildingId'); -export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCEEDED, 'payload'); +export const occupantsLoaded = makeActionCreator(OCCUPANTS_SUCCEEDED, 'instance'); export const occupantsFailed = makeActionCreator(OCCUPANTS_FAILED, 'error'); export const loadOccupantsLog = makeActionCreator(OCCUPANTS_LOG_REQUESTED, 'buildingId'); -export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'payload'); +export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'instance'); export const occupantsLogFailed = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); export const loadThermalComfort = makeActionCreator(THERMAL_COMFORT_REQUESTED, 'buildingId'); -export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'payload'); +export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'instance'); export const thermalComfortFailed = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUESTED, 'buildingId'); -export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'payload'); +export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'instance'); export const thermalComfortLogFailed = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId', 'payload'); diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index f6683df1..6edacc5b 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -2,6 +2,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; +import Loading from '../../components/Loading'; import { loadOccupants, loadThermalComfort, @@ -30,51 +31,81 @@ class Performance extends Component { } render() { - const occupants = { - totalUnits: null, - preVacantUnits: null, - postVacantUnits: null, - }; - const thermalComfort = { - preHeatingSetPoint: null, - postHeatingSetPoint: null, - preCoolingSetPoint: null, - postCoolingSetPoint: null, - }; - return ( -
    - + let mainContent = null; + console.log(this.props); // eslint-disable-line + + const { + performance, + } = this.props; + let { + occupants, thermalComfort, + } = performance; + + mainContent = ; + if (occupants.data !== undefined && thermalComfort.data !== undefined && + occupants.data !== null && thermalComfort.data !== null && + occupants.data.occupants !== undefined && thermalComfort.data.thermalComfort !== undefined) { + + if (occupants.data.occupants === null) { + occupants = { + total_units: 0, + pre_vacant_units: 0, + updateOccupants: 0, + }; + } else { + occupants = occupants.data.occupants; + } + + if (thermalComfort.data.thermalComfort === null) { + thermalComfort = { + pre_heating_set_point: 0, + post_heating_set_point: 0, + pre_cooling_set_point: 0, + post_cooling_set_point: 0, + }; + } else { + thermalComfort = thermalComfort.data.thermalComfort; + } + + mainContent = (
    -
    {/* Container */} +
    + ); + } + + return ( +
    + + {mainContent}
    ); } @@ -86,6 +117,7 @@ Performance.propTypes = { loadThermalComfort: PropTypes.func, updateOccupants: PropTypes.func, updateThermalComfort: PropTypes.func, + performance: PropTypes.objectOf, }; const mapDispatchToProps = dispatch => ( @@ -98,9 +130,11 @@ const mapDispatchToProps = dispatch => ( ); const mapStateToProps = state => ({ - occupants: state.occupants, - thermalComfort: state.thermalComfort, - eng: state.eng, + performance: state.bloclink, + occupants: state.bloclink.occupants, + thermalComfort: state.bloclink.thermalComfort, + // occupants: state.occupants, + // thermalComfort: state.thermalComfort, }); export default connect(mapStateToProps, mapDispatchToProps)(Performance); -- GitLab From c920500bf2332c82880ff448f6804169f4cc4dca Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 22 May 2019 17:32:49 -0400 Subject: [PATCH 15/50] Fix history modal --- src/components/Performance/Occupants.js | 104 ++++++---- src/components/Performance/ThermalComfort.js | 191 ++++++++++--------- src/containers/Performance/index.js | 36 +++- src/containers/Performance/reducer.js | 10 + 4 files changed, 209 insertions(+), 132 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index ea5a3998..a164f1e8 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -17,9 +17,10 @@ const customStyles = { bottom: 'auto', marginRight: '-50%', transform: 'translate(-50%, -50%)', + minWidth: '750px', }, }; -// Make sure to bind modal to your appElement (http://reactcommunity.org/react-modal/accessibility/) + Modal.setAppElement('body'); class Occupants extends Component { @@ -32,42 +33,62 @@ class Occupants extends Component { preVacantUnits: props.preVacantUnits, postVacantUnits: props.postVacantUnits, modalIsOpen: false, + action: null, }; - this.openModal = this.openModal.bind(this); - this.afterOpenModal = this.afterOpenModal.bind(this); this.closeModal = this.closeModal.bind(this); } openModal() { this.setState({ modalIsOpen: true }); } - afterOpenModal() { - // references are now sync'd and can be accessed. - this.subtitle.style.color = '#f00'; - } closeModal() { this.setState({ modalIsOpen: false }); } - handleOnChange = (event) => { this.setState({ [event.target.name]: event.target.value }); } - handleUpdateOccupants = () => { - console.log(this.state); // eslint-disable-line - this.props.updateOccupants( - this.props.buildingId, - { - building_id: this.props.buildingId, - total_units: this.state.totalUnits, - pre_vacant_units: this.state.preVacantUnits, - post_vacant_units: this.state.postVacantUnits, - } - ); - this.setState({ action: 'updated' }); + if (confirm('Are you sure to update?') === true) { + this.props.updateOccupants( + this.props.buildingId, + { + building_id: this.props.buildingId, + total_units: this.state.totalUnits, + pre_vacant_units: this.state.preVacantUnits, + post_vacant_units: this.state.postVacantUnits, + user_id: this.props.userId, + } + ); + this.setState({ action: 'updated' }, () => { + alert('Update successful.'); + }); + } } render() { + const rows = this.props.occupantsLog.map((occupant) => { + const delta = Object.entries(occupant.delta) + .filter(entry => entry[0] !== 'id' && entry[0] !== 'building_id') + .map(entry => { + return ( +
    + {entry[0]} : {entry[1]} +
    + ); + }); + let updatedTime = new Date(occupant.updated_time); + updatedTime = `${updatedTime.toLocaleDateString('en-US')} ${updatedTime.toLocaleTimeString('en-US')}`; + + return ( +
    {occupant.id}{delta}{occupant.user_id}{updatedTime}
    + + + + + + + + {rows} + +
    IDChangesUser IDUpdated Time
    + @@ -164,11 +200,13 @@ class Occupants extends Component { } Occupants.propTypes = { + userId: PropTypes.string, totalUnits: PropTypes.number, preVacantUnits: PropTypes.number, postVacantUnits: PropTypes.number, updateOccupants: PropTypes.func, buildingId: PropTypes.number, + occupantsLog: PropTypes.arrayOf, }; Occupants.defaultProps = { diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index 9514809d..82adbce8 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -1,4 +1,5 @@ import React, { Component } from 'react'; +import Modal from 'react-modal'; import PropTypes from 'prop-types'; import { Table, @@ -6,14 +7,24 @@ import { InputGroup, InputGroupAddon, Button, - Modal, - ModalBody, - ModalHeader, - ModalFooter, } from 'reactstrap'; import './styles.css'; +const customStyles = { + content: { + top: '50%', + left: '50%', + right: 'auto', + bottom: 'auto', + marginRight: '-50%', + transform: 'translate(-50%, -50%)', + minWidth: '750px', + }, +}; + +Modal.setAppElement('body'); + class ThermalComfort extends Component { constructor(props) { super(props); @@ -22,36 +33,64 @@ class ThermalComfort extends Component { postHeatingSetPoint: props.postHeatingSetPoint, preCoolingSetPoint: props.preCoolingSetPoint, postCoolingSetPoint: props.postCoolingSetPoint, - modal: false, + modalIsOpen: false, + action: null, }; + this.openModal = this.openModal.bind(this); + this.closeModal = this.closeModal.bind(this); } - - toggle() { - this.setState(prevState => ({ - modal: !prevState.modal, - })); + openModal() { + this.setState({ modalIsOpen: true }); + } + closeModal() { + this.setState({ modalIsOpen: false }); } - handleOnChange = (event) => { this.setState({ [event.target.name]: event.target.value }); } - handleUpdateThermalComfort = () => { - console.log(this.state); // eslint-disable-line - this.props.updateThermalComfort( - this.props.buildingId, - { - building_id: this.props.buildingId, - pre_heating_set_point: this.state.preHeatingSetPoint, - post_heating_set_point: this.state.postHeatingSetPoint, - pre_cooling_set_point: this.state.preCoolingSetPoint, - post_cooling_setPoint: this.state.postCoolingSetPoint, - } - ); - this.setState({ action: 'updated' }); + if (confirm('Are you sure to update?') === true) { + this.props.updateThermalComfort( + this.props.buildingId, + { + building_id: this.props.buildingId, + pre_heating_set_point: this.state.preHeatingSetPoint, + post_heating_set_point: this.state.postHeatingSetPoint, + pre_cooling_set_point: this.state.preCoolingSetPoint, + post_cooling_set_point: this.state.postCoolingSetPoint, + user_id: this.props.userId, + } + ); + this.setState({ action: 'updated' }, () => { + alert('Update successful.'); + }); + } } render() { + const rows = this.props.thermalComfortLog.map((thermalComfort) => { + const delta = Object.entries(thermalComfort.delta) + .filter(entry => entry[0] !== 'id' && entry[0] !== 'building_id') + .map(entry => { + return ( +
    + {entry[0]} : {entry[1]} +
    + ); + }); + let updatedTime = new Date(thermalComfort.updated_time); + updatedTime = `${updatedTime.toLocaleDateString('en-US')} ${updatedTime.toLocaleTimeString('en-US')}`; + + return ( + + + + + + + ); + }); + return (
    @@ -63,9 +102,9 @@ class ThermalComfort extends Component {
    {' '}
    + +
    +
    +

    Change History

    +
    +
    + +
    +
    +
    +
    {thermalComfort.id}{delta}{thermalComfort.user_id}{updatedTime}
    + + + + + + + + {rows} + +
    IDChangesUser IDUpdated Time
    + +
    @@ -163,83 +235,20 @@ class ThermalComfort extends Component {
    - - Modal title - - This is Modal body! - - - {' '} - - - ); } } ThermalComfort.propTypes = { + userId: PropTypes.string, preHeatingSetPoint: PropTypes.number, postHeatingSetPoint: PropTypes.number, preCoolingSetPoint: PropTypes.number, postCoolingSetPoint: PropTypes.number, updateThermalComfort: PropTypes.func, buildingId: PropTypes.number, -}; - -Modal.propTypes = { - // boolean to control the state of the popover - isOpen: PropTypes.bool, - autoFocus: PropTypes.bool, - // if modal should be centered vertically in viewport - centered: PropTypes.bool, - // corresponds to bootstrap's modal sizes, ie. 'lg' or 'sm' - size: PropTypes.string, - // callback for toggling isOpen in the controlling component - toggle: PropTypes.func, - role: PropTypes.string, // defaults to "dialog" - // used to reference the ID of the title element in the modal - labelledBy: PropTypes.string, - keyboard: PropTypes.bool, - // control backdrop, see http://v4-alpha.getbootstrap.com/components/modal/#options - backdrop: PropTypes.oneOfType([ - PropTypes.bool, - PropTypes.oneOf(['static']), - ]), - // if body of modal should be scrollable when content is long - scrollable: PropTypes.bool, - // external: PropTypes.node, - // called on componentDidMount - onEnter: PropTypes.func, - // called on componentWillUnmount - onExit: PropTypes.func, - // called when done transitioning in - onOpened: PropTypes.func, - // called when done transitioning out - onClosed: PropTypes.func, - className: PropTypes.string, - wrapClassName: PropTypes.string, - modalClassName: PropTypes.string, - backdropClassName: PropTypes.string, - contentClassName: PropTypes.string, - // boolean to control whether the fade transition occurs (default: true) - fade: PropTypes.bool, - cssModule: PropTypes.objectOf, - // zIndex defaults to 1000. - zIndex: PropTypes.oneOfType([ - PropTypes.number, - PropTypes.string, - ]), - // backdropTransition - controls backdrop transition - // timeout is 150ms by default to match bootstrap - // see Fade for more details - backdropTransition: PropTypes.shape, - // modalTransition - controls modal transition - // timeout is 300ms by default to match bootstrap - // see Fade for more details - innerRef: PropTypes.objectOf, - // if modal should be destructed/removed from DOM after closing - unmountOnClose: PropTypes.bool, // defaults to true + thermalComfortLog: PropTypes.arrayOf, }; export default ThermalComfort; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 6edacc5b..0674bd82 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -6,6 +6,8 @@ import Loading from '../../components/Loading'; import { loadOccupants, loadThermalComfort, + loadOccupantsLog, + loadThermalComfortLog, updateOccupants, updateThermalComfort, } from './actions'; @@ -27,7 +29,9 @@ class Performance extends Component { const buildingId = this.props.building.building_id; console.log(buildingId); // eslint-disable-line this.props.loadOccupants(buildingId); + this.props.loadOccupantsLog(buildingId); this.props.loadThermalComfort(buildingId); + this.props.loadThermalComfortLog(buildingId); } render() { @@ -35,17 +39,27 @@ class Performance extends Component { console.log(this.props); // eslint-disable-line const { - performance, + user, performance, } = this.props; let { - occupants, thermalComfort, + occupants, + thermalComfort, + } = performance; + const { + occupantsLog, + thermalComfortLog, } = performance; mainContent = ; - if (occupants.data !== undefined && thermalComfort.data !== undefined && + if (user !== undefined && user.user_id !== undefined && + occupants.data !== undefined && thermalComfort.data !== undefined && occupants.data !== null && thermalComfort.data !== null && - occupants.data.occupants !== undefined && thermalComfort.data.thermalComfort !== undefined) { + occupants.data.occupants !== undefined && thermalComfort.data.thermalComfort !== undefined && + occupantsLog.data !== null && thermalComfortLog.data !== null && + occupantsLog.data.data !== undefined && thermalComfortLog.data.data !== undefined) { + + const userId = user.user_id.split('|')[1]; if (occupants.data.occupants === null) { occupants = { @@ -78,6 +92,8 @@ class Performance extends Component { preVacantUnits={occupants.pre_vacant_units} postVacantUnits={occupants.post_vacant_units} updateOccupants={this.props.updateOccupants} + userId={userId} + occupantsLog={occupantsLog.data.data} />
    @@ -88,6 +104,8 @@ class Performance extends Component { preCoolingSetPoint={thermalComfort.pre_cooling_set_point} postCoolingSetPoint={thermalComfort.post_cooling_set_point} updateThermalComfort={this.props.updateThermalComfort} + userId={userId} + thermalComfortLog={thermalComfortLog.data.data} />
    @@ -115,8 +133,11 @@ Performance.propTypes = { building: buildingDetailPropTypes, loadOccupants: PropTypes.func, loadThermalComfort: PropTypes.func, + loadOccupantsLog: PropTypes.func, + loadThermalComfortLog: PropTypes.func, updateOccupants: PropTypes.func, updateThermalComfort: PropTypes.func, + user: PropTypes.objectOf, performance: PropTypes.objectOf, }; @@ -124,6 +145,8 @@ const mapDispatchToProps = dispatch => ( bindActionCreators({ loadOccupants, loadThermalComfort, + loadOccupantsLog, + loadThermalComfortLog, updateOccupants, updateThermalComfort, }, dispatch) @@ -131,10 +154,7 @@ const mapDispatchToProps = dispatch => ( const mapStateToProps = state => ({ performance: state.bloclink, - occupants: state.bloclink.occupants, - thermalComfort: state.bloclink.thermalComfort, - // occupants: state.occupants, - // thermalComfort: state.thermalComfort, + user: state.user, }); export default connect(mapStateToProps, mapDispatchToProps)(Performance); diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index f4d12e09..46da9491 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -27,6 +27,16 @@ const PerformanceInitialState = { error: false, data: null, }, + occupantsLog: { + loading: false, + error: false, + data: null, + }, + thermalComfortLog: { + loading: false, + error: false, + data: null, + }, }; export default function (state = PerformanceInitialState, action) { -- GitLab From afc0522dc71ee81a5397e02118149cf1a09cca9f Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 23 May 2019 12:21:10 -0400 Subject: [PATCH 16/50] Add react-modal library --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 5bf2fb11..67f057fc 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "react-highcharts": "^12.0.0", "react-json-tree": "^0.10.9", "react-leaflet": "^1.4.1", + "react-modal": "^3.8.1", "react-placeholder": "^1.0.6", "react-redux": "^4.4.5", "react-router": "^3.0.0", -- GitLab From 6d9904a8adec1b2defdc8e436b24d5bb7276eb8c Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 24 May 2019 16:17:40 -0400 Subject: [PATCH 17/50] Add Retrofit section --- src/components/Performance/ResultMessage.js | 22 ++ src/components/Performance/RetrofitRow.js | 227 +++++++++++++++ src/components/Performance/Retrofits.js | 292 ++++++++++++++++++++ src/containers/Performance/index.js | 61 ++++ 4 files changed, 602 insertions(+) create mode 100644 src/components/Performance/ResultMessage.js create mode 100644 src/components/Performance/RetrofitRow.js create mode 100644 src/components/Performance/Retrofits.js diff --git a/src/components/Performance/ResultMessage.js b/src/components/Performance/ResultMessage.js new file mode 100644 index 00000000..22e20eea --- /dev/null +++ b/src/components/Performance/ResultMessage.js @@ -0,0 +1,22 @@ +import React from 'react'; +import PropTypes from 'prop-types'; + + +const ResultMessage = (props) => { + return ( + + {props.messageContent} + + ); +}; + +ResultMessage.propTypes = { + messageStyle: PropTypes.shape({ + downpayment: PropTypes.string, + expected_net_noi_dscr: PropTypes.string, + expected_payback: PropTypes.string, + }), + messageContent: PropTypes.string, +}; + +export default ResultMessage; diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js new file mode 100644 index 00000000..20b622dc --- /dev/null +++ b/src/components/Performance/RetrofitRow.js @@ -0,0 +1,227 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import { + Input, + Button, + Dropdown, + DropdownToggle, + DropdownMenu, + DropdownItem, +} from 'reactstrap'; + + +class RetrofitRow extends Component { + constructor(props) { + super(props); + this.handleOnChange = this.handleOnChange.bind(this); + this.onDelEvent = this.onDelEvent.bind(this); + this.toggleRetrofit = this.toggleRetrofit.bind(this); + this.togglePrimaryUtility = this.togglePrimaryUtility.bind(this); + this.toggleSecondUtility = this.toggleSecondUtility.bind(this); + this.changeRetrofit = this.changeRetrofit.bind(this); + this.changePrimaryUtility = this.changePrimaryUtility.bind(this); + this.changeSecondUtility = this.changeSecondUtility.bind(this); + this.state = { + id: props.id, + retrofit_name: props.retrofitName, + install_start_date: props.installStartDate, + install_end_date: props.installEndDate, + primary_utility: props.primaryUtility, + second_utility: props.secondUtility, + notes: props.notes, + retrofitDropdownOpen: false, + retrofitDropDownValue: props.retrofitName, + retrofitNames: props.retrofitNames !== undefined ? + props.retrofitNames.map((retrofitName, id) => { + return { id, key: id, name: retrofitName }; + }) : [], + primaryUtilityDropdownOpen: false, + primaryUtilityDropDownValue: props.primaryUtility, + secondUtilityDropdownOpen: false, + secondUtilityDropDownValue: props.secondUtility, + utilityNames: props.utilityNames !== undefined ? props.utilityNames.map((utilityName, id) => { + return { id, key: id, name: utilityName }; + }) : [], + }; + } + + onDelEvent() { + this.props.onDelEvent(this.props.id); + } + + toggleRetrofit() { + this.setState({ + retrofitDropdownOpen: !this.state.retrofitDropdownOpen, + }); + } + + togglePrimaryUtility() { + this.setState({ + primaryUtilityDropdownOpen: !this.state.primaryUtilityDropdownOpen, + }); + } + + toggleSecondUtility() { + this.setState({ + secondUtilityDropdownOpen: !this.state.secondUtilityDropdownOpen, + }); + } + + changeRetrofit(e) { + this.setState({ retrofitDropDownValue: e.currentTarget.textContent }); + } + + changePrimaryUtility(e) { + this.setState({ primaryUtilityDropDownValue: e.currentTarget.textContent }); + } + + changeSecondUtility(e) { + this.setState({ secondUtilityDropDownValue: e.currentTarget.textContent }); + } + + handleOnChange = (event) => { + this.setState({ [event.target.name]: event.target.value }, + () => { + this.props.onChangeEvent(this.state); + }); + } + + render() { + const style = { textAlign: 'left' }; + const retrofitNames = this.state.retrofitNames.map(e => { + return ( + + {e.name} + + ); + }); + const primaryUtilityNames = this.state.utilityNames.map(e => { + return ( + + {e.name} + + ); + }); + const secondUtilityNames = this.state.utilityNames.map(e => { + return ( + + {e.name} + + ); + }); + const dropdownStyle = { + marginLeft: '0px', + }; + return ( +
    + + + {this.state.retrofitDropDownValue} + + + {retrofitNames} + + + + + + + + + + {this.state.primaryUtilityDropDownValue} + + + {primaryUtilityNames} + + + + + + {this.state.secondUtilityDropDownValue} + + + {secondUtilityNames} + + + + + + +
    + {title} +
    + Currently no retrofits. +
    + + {header} + + + {retrofits} + +
    + + +
    +
    +    +   + {saveButton} +
    +
    + + ); + } +} + +Retrofits.propTypes = { + blockStyle: PropTypes.shape({ + marginBottom: PropTypes.string, + }), + headerStyle: PropTypes.shape({ + textAlign: PropTypes.string, + marginBottom: PropTypes.string, + }), + retrofitNames: PropTypes.arrayOf, + utilityNames: PropTypes.arrayOf, + retrofits: PropTypes.arrayOf, + data: PropTypes.arrayOf( + PropTypes.shape({ + duration: PropTypes.string, + interest_rate: PropTypes.string, + lender: PropTypes.string, + max_loan_amount: PropTypes.string, + }), + ), + successMessageStyle: PropTypes.shape({ + color: PropTypes.string, + paddingLeft: PropTypes.string, + fontWeight: PropTypes.string, + }), + errorMessageStyle: PropTypes.shape({ + color: PropTypes.string, + paddingLeft: PropTypes.string, + fontWeight: PropTypes.string, + }), + defaultMessageStyle: PropTypes.shape({ + color: PropTypes.string, + paddingLeft: PropTypes.string, + fontWeight: PropTypes.string, + }), + buildingId: PropTypes.number, + updateRetrofits: PropTypes.func, + error: PropTypes.bool, + loading: PropTypes.bool, +}; + +export default Retrofits; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 0674bd82..00fdc7b9 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -15,6 +15,7 @@ import buildingDetailPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; import Occupants from '../../components/Performance/Occupants'; import ThermalComfort from '../../components/Performance/ThermalComfort'; +import Retrofits from '../../components/Performance/Retrofits'; class Performance extends Component { @@ -36,6 +37,29 @@ class Performance extends Component { render() { let mainContent = null; + + const blockStyle = { marginBottom: '40px', marginTop: '40px' }; + const headerStyle = { + textAlign: 'left', + marginBottom: '25px', + paddingLeft: '10px', + }; + const successMessageStyle = { + color: 'green', + paddingLeft: '25px', + fontWeight: 'bold', + }; + const errorMessageStyle = { + color: 'red', + paddingLeft: '25px', + fontWeight: 'bold', + }; + const defaultMessageStyle = { + color: 'black', + paddingLeft: '25px', + fontWeight: 'bold', + }; + console.log(this.props); // eslint-disable-line const { @@ -82,6 +106,25 @@ class Performance extends Component { thermalComfort = thermalComfort.data.thermalComfort; } + const retrofits = [ + { + retrofit_name: 'Weatherstripping', + install_start_date: '2019-04-20', + install_end_date: '2019-05-20', + primary_utility: 'Natural Gas', + second_utility: 'Oil', + notes: 'Test notes 1', + }, + { + retrofit_name: 'Toilet Replacement', + install_start_date: '2019-03-20', + install_end_date: '2019-04-12', + primary_utility: 'Water', + second_utility: 'Natural Gas', + notes: 'Test notes 2', + }, + ]; + mainContent = (
    @@ -109,6 +152,23 @@ class Performance extends Component { />
    +
    +
    + +
    +
    ); } @@ -137,6 +197,7 @@ Performance.propTypes = { loadThermalComfortLog: PropTypes.func, updateOccupants: PropTypes.func, updateThermalComfort: PropTypes.func, + updateRetrofits: PropTypes.func, user: PropTypes.objectOf, performance: PropTypes.objectOf, }; -- GitLab From 03a3218819257bf6b766f99ebae29264e07f8659 Mon Sep 17 00:00:00 2001 From: akkking Date: Fri, 24 May 2019 17:00:26 -0400 Subject: [PATCH 18/50] Add pagination to occupants --- src/components/Performance/Occupants.js | 78 ++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index a164f1e8..86d8776b 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -25,6 +25,7 @@ Modal.setAppElement('body'); class Occupants extends Component { constructor(props) { + global.expandNum = 5; super(props); this.handleOnChange = this.handleOnChange.bind(this); this.handleUpdateOccupants = this.handleUpdateOccupants.bind(this); @@ -34,10 +35,53 @@ class Occupants extends Component { postVacantUnits: props.postVacantUnits, modalIsOpen: false, action: null, + occupantsLog: (this.props.occupantsLog.length > global.expandNum) ? + this.props.occupantsLog.slice(0, global.expandNum) : this.props.occupantsLog, + showNextButton: (this.props.occupantsLog.length > global.expandNum) === true, + showlastButton: false, }; this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); } + nextRecords = () => { + console.log(this.props.occupantsLog.slice(0, this.state.occupantsLog.length + global.expandNum)); // eslint-disable-line + this.setState({ + occupantsLog: + this.props.occupantsLog.slice(this.state.occupantsLog.length, + this.state.occupantsLog.length + global.expandNum), + }, () => { + console.log('Expanded'); // eslint-disable-line + this.setState({ + showLastButton: true, + }); + console.log(this.state.occupantsLog.length); // eslint-disable-line + console.log(this.props.occupantsLog.length); // eslint-disable-line + if (this.state.occupantsLog.length === this.props.occupantsLog.length) { + console.log(this.props.occupantsLog.length); // eslint-disable-line + this.setState({ + showNextButton: false, + }); + } + }); + } + lastRecords = () => { + const collapeNum = this.state.occupantsLog.length === this.props.occupantsLog.length ? + this.state.occupantsLog.length % global.expandNum : global.expandNum; + this.setState({ + occupantsLog: this.props.occupantsLog.slice(this.state.occupantsLog.length, + this.state.occupantsLog.length - collapeNum), + }, () => { + console.log('Collapsed'); // eslint-disable-line + this.setState({ + showNextButton: true, + }); + if (this.state.occupantsLog.length <= global.expandNum) { + this.setState({ + showLastButton: false, + }); + } + }); + } openModal() { this.setState({ modalIsOpen: true }); } @@ -66,7 +110,7 @@ class Occupants extends Component { } render() { - const rows = this.props.occupantsLog.map((occupant) => { + const rows = this.state.occupantsLog.map((occupant) => { const delta = Object.entries(occupant.delta) .filter(entry => entry[0] !== 'id' && entry[0] !== 'building_id') .map(entry => { @@ -89,6 +133,30 @@ class Occupants extends Component { ); }); + let nextButton = null; + let lastButton = null; + const buttonStyle = { + textAlign: 'center', + marginBottom: '30px', + marginLeft: '0px', + cursor: 'pointer', + }; + + if (this.state.showNextButton) { + nextButton = ( + + ); + } + if (this.state.showLastButton) { + lastButton = ( + + ); + } + return (
    @@ -145,6 +213,14 @@ class Occupants extends Component { {rows}
    +
    +
    + {lastButton} +
    +
    + {nextButton} +
    +
    -- GitLab From bac5bbd4e2158fe50e59478d98e7349f81ead35b Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 28 May 2019 14:50:40 -0400 Subject: [PATCH 19/50] Apply modal pagination to both occupants and thermal comfort --- src/components/Performance/Occupants.js | 32 ++++----- src/components/Performance/RetrofitRow.js | 1 + src/components/Performance/Retrofits.js | 3 +- src/components/Performance/ThermalComfort.js | 75 +++++++++++++++++++- 4 files changed, 91 insertions(+), 20 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 86d8776b..414b9011 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -38,26 +38,25 @@ class Occupants extends Component { occupantsLog: (this.props.occupantsLog.length > global.expandNum) ? this.props.occupantsLog.slice(0, global.expandNum) : this.props.occupantsLog, showNextButton: (this.props.occupantsLog.length > global.expandNum) === true, + currentLogPos: 0, showlastButton: false, }; this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); } nextRecords = () => { - console.log(this.props.occupantsLog.slice(0, this.state.occupantsLog.length + global.expandNum)); // eslint-disable-line + // console.log(this.props.occupantsLog.slice(0, global.expandNum)); // eslint-disable-line this.setState({ - occupantsLog: - this.props.occupantsLog.slice(this.state.occupantsLog.length, - this.state.occupantsLog.length + global.expandNum), + currentLogPos: this.state.currentLogPos + global.expandNum, }, () => { - console.log('Expanded'); // eslint-disable-line this.setState({ + occupantsLog: + this.props.occupantsLog.slice(this.state.currentLogPos, + this.state.currentLogPos + global.expandNum), showLastButton: true, }); - console.log(this.state.occupantsLog.length); // eslint-disable-line - console.log(this.props.occupantsLog.length); // eslint-disable-line - if (this.state.occupantsLog.length === this.props.occupantsLog.length) { - console.log(this.props.occupantsLog.length); // eslint-disable-line + console.log(this.state.currentLogPos); // eslint-disable-line + if (this.state.currentLogPos + global.expandNum >= this.props.occupantsLog.length) { this.setState({ showNextButton: false, }); @@ -65,17 +64,14 @@ class Occupants extends Component { }); } lastRecords = () => { - const collapeNum = this.state.occupantsLog.length === this.props.occupantsLog.length ? - this.state.occupantsLog.length % global.expandNum : global.expandNum; this.setState({ - occupantsLog: this.props.occupantsLog.slice(this.state.occupantsLog.length, - this.state.occupantsLog.length - collapeNum), + occupantsLog: this.props.occupantsLog.slice(this.state.currentLogPos - global.expandNum, + this.state.currentLogPos), + currentLogPos: this.state.currentLogPos - global.expandNum, + showNextButton: true, }, () => { - console.log('Collapsed'); // eslint-disable-line - this.setState({ - showNextButton: true, - }); - if (this.state.occupantsLog.length <= global.expandNum) { + console.log(this.state.currentLogPos); // eslint-disable-line + if (this.state.currentLogPos === 0) { this.setState({ showLastButton: false, }); diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js index 20b622dc..1367ab0f 100644 --- a/src/components/Performance/RetrofitRow.js +++ b/src/components/Performance/RetrofitRow.js @@ -190,6 +190,7 @@ class RetrofitRow extends Component { @@ -169,7 +175,12 @@ class RetrofitRow extends Component { {this.state.primaryUtilityDropDownValue} - + {primaryUtilityNames} @@ -183,7 +194,12 @@ class RetrofitRow extends Component { {this.state.secondUtilityDropDownValue} - + {secondUtilityNames} @@ -213,6 +229,7 @@ class RetrofitRow extends Component { RetrofitRow.propTypes = { id: PropTypes.number, + retrofitId: PropTypes.number, retrofitName: PropTypes.string, installStartDate: PropTypes.string, installEndDate: PropTypes.string, @@ -220,7 +237,7 @@ RetrofitRow.propTypes = { secondUtility: PropTypes.string, notes: PropTypes.string, utilityNames: PropTypes.arrayOf, - retrofitNames: PropTypes.arrayOf, + retrofitMeta: PropTypes.arrayOf, onDelEvent: PropTypes.func, onChangeEvent: PropTypes.func, }; diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js index c6b96ce3..5d68a676 100644 --- a/src/components/Performance/Retrofits.js +++ b/src/components/Performance/Retrofits.js @@ -15,12 +15,13 @@ class Retrofits extends Component { this.addRow = this.addRow.bind(this); this.updateRow = this.updateRow.bind(this); this.state = { - retrofitNames: props.retrofitNames, utilityNames: props.utilityNames, retrofits: props.retrofits, - retrofit_name: 'Waterstripping', - install_start_date: null, - install_end_date: null, + retrofitsLog: props.retrofitsLog, + retrofit_id: 1, + retrofit_name: 'Water Stripping', + install_start_date: '2019-05-01', + install_end_date: '2019-06-01', primary_utility: 'Natural Gas', second_utility: 'Water', notes: null, @@ -29,7 +30,7 @@ class Retrofits extends Component { validateInputs = () => { const emptyFields = []; - if (this.state.retrofits.length > 0) { + if (this.state.retrofits !== null && this.state.retrofits.length > 0) { Object.values(this.state.retrofits).forEach(retrofit => { console.log(retrofit); // eslint-disable-line if (retrofit.retrofit_name === null && @@ -85,14 +86,16 @@ class Retrofits extends Component { }; console.log(this.state.retrofits); // eslint-disable-line const retrofits = this.state.retrofits; + console.log(retrofits); // eslint-disable-line retrofits.push(retrofit); + console.log(retrofits); // eslint-disable-line this.setState({ retrofits }, () => { console.log(this.state.retrofits, 'New retrofit added!'); // eslint-disable-line this.setState({ id: this.state.id + 1, - retrofit_name: 'Waterstripping', - install_start_date: null, - install_end_date: null, + retrofit_name: 'Water Stripping', + install_start_date: '2019-05-01', + install_end_date: '2019-06-01', primary_utility: 'Natural Gas', second_utility: 'Water', notes: null, @@ -107,6 +110,7 @@ class Retrofits extends Component { console.log(row.id); // eslint-disable-line if (id === row.id) { const tmp = { id }; + // tmp.retrofit_id = row.retrofit_id; tmp.retrofit_name = row.retrofit_name; tmp.install_start_date = row.install_start_date; tmp.install_end_date = row.install_end_date; @@ -155,16 +159,18 @@ class Retrofits extends Component { }); let retrofits = []; + let historyButton = null; let saveButton = null; - if (Object.keys(this.state.retrofits).length !== 0) { + if (this.state.retrofits !== null && Object.keys(this.state.retrofits).length !== 0) { retrofits = this.state.retrofits.map((retrofit, index) => { return ( Save @@ -193,6 +200,18 @@ class Retrofits extends Component { ); } + if (this.state.retrofitsLog !== null && Object.keys(this.state.retrofitsLog).length !== 0) { + historyButton = ( + + ); + } + let messageStyle = {}; let messageContent = null; @@ -231,7 +250,8 @@ class Retrofits extends Component { onClick={this.addRow} > + Retrofit -   +   + {historyButton} {saveButton} @@ -264,9 +284,10 @@ Retrofits.propTypes = { textAlign: PropTypes.string, marginBottom: PropTypes.string, }), - retrofitNames: PropTypes.arrayOf, + retrofitMeta: PropTypes.arrayOf, utilityNames: PropTypes.arrayOf, retrofits: PropTypes.arrayOf, + retrofitsLog: PropTypes.arrayOf, data: PropTypes.arrayOf( PropTypes.shape({ duration: PropTypes.string, -- GitLab From fd0b3deabae8072dc98d7e3c6f9723caacbe08d9 Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 29 May 2019 18:15:37 -0400 Subject: [PATCH 23/50] update retrofit and log --- src/containers/Performance/actions.js | 7 +++ src/containers/Performance/constants.js | 3 ++ src/containers/Performance/index.js | 63 ++++++++++++++++--------- src/containers/Performance/reducer.js | 2 +- src/containers/Performance/sagas.js | 22 +++++++++ 5 files changed, 74 insertions(+), 23 deletions(-) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index ca6d52c0..4f90cd91 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -26,6 +26,9 @@ import { UPDATE_THERMAL_COMFORT_REQUESTED, UPDATE_THERMAL_COMFORT_SUCCEEDED, UPDATE_THERMAL_COMFORT_FAILED, + UPDATE_RETROFITS_REQUESTED, + UPDATE_RETROFITS_SUCCEEDED, + UPDATE_RETROFITS_FAILED, CREATE_OCCUPANTS_LOG_REQUESTED, CREATE_OCCUPANTS_LOG_SUCCEEDED, CREATE_OCCUPANTS_LOG_FAILED, @@ -66,6 +69,10 @@ export const updateThermalComfort = makeActionCreator(UPDATE_THERMAL_COMFORT_REQ export const updateThermalComfortSucceeded = makeActionCreator(UPDATE_THERMAL_COMFORT_SUCCEEDED, 'instance'); export const updateThermalComfortFailed = makeActionCreator(UPDATE_THERMAL_COMFORT_FAILED, 'error'); +export const updateRetrofits = makeActionCreator(UPDATE_RETROFITS_REQUESTED, 'buildingId', 'payload'); +export const updateRetrofitsSucceeded = makeActionCreator(UPDATE_RETROFITS_SUCCEEDED, 'payload', 'instance'); +export const updateRetrofitsFailed = makeActionCreator(UPDATE_RETROFITS_FAILED, 'error'); + export const createOccupantsLog = makeActionCreator(CREATE_OCCUPANTS_LOG_REQUESTED, 'buildingId', 'payload'); export const createOccupantsLogSucceeded = makeActionCreator(CREATE_OCCUPANTS_LOG_SUCCEEDED, 'instance'); export const createOccupantsLogFailed = makeActionCreator(CREATE_OCCUPANTS_LOG_FAILED, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index c1b96178..37c7ccf3 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -28,6 +28,9 @@ export const UPDATE_OCCUPANTS_FAILED = 'UPDATE_OCCUPANTS_FAILED'; export const UPDATE_THERMAL_COMFORT_REQUESTED = 'UPDATE_THERMAL_COMFORT_REQUESTED'; export const UPDATE_THERMAL_COMFORT_SUCCEEDED = 'UPDATE_THERMAL_COMFORT_SUCCEEDED'; export const UPDATE_THERMAL_COMFORT_FAILED = 'UPDATE_THERMAL_COMFORT_FAILED'; +export const UPDATE_RETROFITS_REQUESTED = 'UPDATE_RETROFITS_REQUESTED'; +export const UPDATE_RETROFITS_SUCCEEDED = 'UPDATE_RETROFITS_SUCCEEDED'; +export const UPDATE_RETROFITS_FAILED = 'UPDATE_RETROFITS_FAILED'; export const CREATE_OCCUPANTS_LOG_REQUESTED = 'CREATE_OCCUPANTS_LOG_REQUESTED'; export const CREATE_OCCUPANTS_LOG_SUCCEEDED = 'CREATE_OCCUPANTS_LOG_SUCCEEDED'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 75c3cf11..aa9f8186 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -13,6 +13,7 @@ import { loadRetrofitMeta, updateOccupants, updateThermalComfort, + updateRetrofits, } from './actions'; import buildingDetailPropTypes from '../../containers/Building/propTypes'; import LinkBarDetail from '../../components/LinkBarDetail'; @@ -69,7 +70,8 @@ class Performance extends Component { console.log(this.props); // eslint-disable-line const { - user, performance, + user, + performance, } = this.props; let { occupants, @@ -79,6 +81,11 @@ class Performance extends Component { occupantsLog, thermalComfortLog, } = performance; + const { + retrofits, + retrofitsLog, + retrofitMeta, + } = performance; mainContent = ; @@ -87,7 +94,9 @@ class Performance extends Component { occupants.data !== null && thermalComfort.data !== null && occupants.data.occupants !== undefined && thermalComfort.data.thermalComfort !== undefined && occupantsLog.data !== null && thermalComfortLog.data !== null && - occupantsLog.data.data !== undefined && thermalComfortLog.data.data !== undefined) { + occupantsLog.data.data !== undefined && thermalComfortLog.data.data !== undefined && + retrofits.data !== null && retrofitsLog.data !== null && retrofitMeta.data !== null + ) { const userId = user.user_id.split('|')[1]; @@ -112,24 +121,32 @@ class Performance extends Component { thermalComfort = thermalComfort.data.thermalComfort; } - const retrofits = [ - { - retrofit_name: 'Weather Stripping', - install_start_date: '2019-04-20', - install_end_date: '2019-05-20', - primary_utility: 'Natural Gas', - second_utility: 'Oil', - notes: 'Test notes 1', - }, - { - retrofit_name: 'Toilet Replacement', - install_start_date: '2019-03-20', - install_end_date: '2019-04-12', - primary_utility: 'Water', - second_utility: 'Natural Gas', - notes: 'Test notes 2', - }, - ]; + const retrofitsData = retrofits.data.retrofits === null ? [] : retrofits.data.retrofits; + // let retrofitNames = []; + // if (retrofitMeta.data.data !== null) { + // retrofitNames = retrofitMeta.data.data.map(item => { + // return item.retrofit_name; + // }); + // } + + // const retrofits = [ + // { + // retrofit_name: 'Weather Stripping', + // install_start_date: '2019-04-20', + // install_end_date: '2019-05-20', + // primary_utility: 'Natural Gas', + // second_utility: 'Oil', + // notes: 'Test notes 1', + // }, + // { + // retrofit_name: 'Toilet Replacement', + // install_start_date: '2019-03-20', + // install_end_date: '2019-04-12', + // primary_utility: 'Water', + // second_utility: 'Natural Gas', + // notes: 'Test notes 2', + // }, + // ]; mainContent = (
    @@ -162,9 +179,10 @@ class Performance extends Component {
    ( loadRetrofitMeta, updateOccupants, updateThermalComfort, + updateRetrofits, }, dispatch) ); diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index 59efcf42..eca58f89 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -49,7 +49,7 @@ const PerformanceInitialState = { retrofits: { loading: false, error: false, - data: null, + data: [], }, retrofitsLog: { loading: false, diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js index b46d3410..adcde2a3 100644 --- a/src/containers/Performance/sagas.js +++ b/src/containers/Performance/sagas.js @@ -12,6 +12,7 @@ import { RETROFIT_META_REQUESTED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_THERMAL_COMFORT_REQUESTED, + UPDATE_RETROFITS_REQUESTED, CREATE_OCCUPANTS_LOG_REQUESTED, CREATE_THERMAL_COMFORT_LOG_REQUESTED, } from './constants'; @@ -26,6 +27,7 @@ import { retrofitMetaLoaded, retrofitMetaFailed, updateOccupantsSucceeded, updateOccupantsFailed, updateThermalComfortSucceeded, updateThermalComfortFailed, + updateRetrofitsSucceeded, updateRetrofitsFailed, createOccupantsLogSucceeded, createOccupantsLogFailed, createThermalComfortLogSucceeded, createThermalComfortLogFailed, } from './actions'; @@ -103,6 +105,25 @@ function* updateThermalComfort(action) { } } +function* updateRetrofits(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofits/`; + const res = yield call( + request, + SagaRequests.generateURL(url, action), + { + method: 'PUT', + headers: getHeaders(), + body: JSON.stringify(action.payload), + } + ); + + if (!res.err) { + yield put(updateRetrofitsSucceeded(action.payload)); + } else { + yield put(updateRetrofitsFailed(res.err)); + } +} + function* createOccupantsLog(action) { const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants-log/`; const res = yield call( @@ -151,6 +172,7 @@ function* bloclinkWatcher() { yield takeEvery(RETROFIT_META_REQUESTED, loadRetrofitMeta); yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); + yield takeEvery(UPDATE_RETROFITS_REQUESTED, updateRetrofits); yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); yield takeEvery(CREATE_THERMAL_COMFORT_LOG_REQUESTED, createThermalComfortLog); } -- GitLab From f940297ac0f7dfe7483333decb2d405cf4c2c493 Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 13:40:31 -0400 Subject: [PATCH 24/50] remove unused css file --- src/components/Blocnote/PreliminaryFinance/CostEstimation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 455cfbeb..7ac72966 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -4,7 +4,6 @@ import { Table, Button, } from 'reactstrap'; -import '../styles.css'; import CostEstimationRow from './CostEstimationRow'; -- GitLab From e1279deefceed5e9eca731cf8f2e41ba91b389ff Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 13:48:50 -0400 Subject: [PATCH 25/50] Update Cost Estimation header format --- .../Blocnote/PreliminaryFinance/CostEstimation.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index 7ac72966..ad5fa447 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -121,7 +121,17 @@ class CostEstimation extends Component {
    ); }); @@ -219,7 +220,7 @@ class Retrofits extends Component {
    - +
    {header} diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index 82adbce8..2856ed2a 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -35,10 +35,51 @@ class ThermalComfort extends Component { postCoolingSetPoint: props.postCoolingSetPoint, modalIsOpen: false, action: null, + thermalComfortLog: (this.props.thermalComfortLog.length > global.expandNum) ? + this.props.thermalComfortLog.slice(0, global.expandNum) : this.props.thermalComfortLog, + showNextButton: (this.props.thermalComfortLog.length > global.expandNum) === true, + currentLogPos: 0, + showlastButton: false, }; this.openModal = this.openModal.bind(this); this.closeModal = this.closeModal.bind(this); } + nextRecords = () => { + // console.log(this.props.occupantsLog.slice(0, global.expandNum)); // eslint-disable-line + this.setState({ + currentLogPos: this.state.currentLogPos + global.expandNum, + }, () => { + this.setState({ + thermalComfortLog: + this.props.thermalComfortLog.slice(this.state.currentLogPos, + this.state.currentLogPos + global.expandNum), + showLastButton: true, + }); + console.log(this.state.currentLogPos); // eslint-disable-line + if (this.state.currentLogPos + global.expandNum >= this.props.thermalComfortLog.length) { + this.setState({ + showNextButton: false, + }); + } + }); + } + lastRecords = () => { + this.setState({ + thermalComfortLog: this.props.thermalComfortLog.slice( + this.state.currentLogPos - global.expandNum, + this.state.currentLogPos + ), + currentLogPos: this.state.currentLogPos - global.expandNum, + showNextButton: true, + }, () => { + console.log(this.state.currentLogPos); // eslint-disable-line + if (this.state.currentLogPos === 0) { + this.setState({ + showLastButton: false, + }); + } + }); + } openModal() { this.setState({ modalIsOpen: true }); } @@ -68,7 +109,7 @@ class ThermalComfort extends Component { } render() { - const rows = this.props.thermalComfortLog.map((thermalComfort) => { + const rows = this.state.thermalComfortLog.map((thermalComfort) => { const delta = Object.entries(thermalComfort.delta) .filter(entry => entry[0] !== 'id' && entry[0] !== 'building_id') .map(entry => { @@ -91,6 +132,30 @@ class ThermalComfort extends Component { ); }); + let nextButton = null; + let lastButton = null; + const buttonStyle = { + textAlign: 'center', + marginBottom: '30px', + marginLeft: '0px', + cursor: 'pointer', + }; + + if (this.state.showNextButton) { + nextButton = ( + + ); + } + if (this.state.showLastButton) { + lastButton = ( + + ); + } + return (
    @@ -147,6 +212,14 @@ class ThermalComfort extends Component { {rows}
    +
    +
    + {lastButton} +
    +
    + {nextButton} +
    +
    -- GitLab From a9754a4b71887bc678dbd78853ed438ddc0ba164 Mon Sep 17 00:00:00 2001 From: akkking Date: Tue, 28 May 2019 17:59:22 -0400 Subject: [PATCH 20/50] Add retrofits component and container --- src/components/Performance/Retrofits.js | 36 +++++++----- src/containers/Performance/actions.js | 14 +++++ src/containers/Performance/constants.js | 8 +++ src/containers/Performance/index.js | 14 ++++- src/containers/Performance/reducer.js | 74 +++++++++++++++++++++++++ src/containers/Performance/sagas.js | 16 ++++++ 6 files changed, 144 insertions(+), 18 deletions(-) diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js index 89f69cd9..c6b96ce3 100644 --- a/src/components/Performance/Retrofits.js +++ b/src/components/Performance/Retrofits.js @@ -215,23 +215,13 @@ class Retrofits extends Component { return (
    -

    - My Retrofits -

    -
    -
    - - {header} - - - {retrofits} - -
    +
    +

    + My Retrofits +

    -
    -
    -
    +
    +
    +
    +
    +
    + + + {header} + + + {retrofits} + +
    +
    +
    +
    +
    ); } diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index e87ba57b..66d87cf0 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -11,6 +11,12 @@ import { THERMAL_COMFORT_LOG_REQUESTED, THERMAL_COMFORT_LOG_SUCCEEDED, THERMAL_COMFORT_LOG_FAILED, + RETROFITS_REQUESTED, + RETROFITS_SUCCEEDED, + RETROFITS_FAILED, + RETROFITS_LOG_REQUESTED, + RETROFITS_LOG_SUCCEEDED, + RETROFITS_LOG_FAILED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_OCCUPANTS_SUCCEEDED, UPDATE_OCCUPANTS_FAILED, @@ -32,6 +38,7 @@ export const occupantsFailed = makeActionCreator(OCCUPANTS_FAILED, 'error'); export const loadOccupantsLog = makeActionCreator(OCCUPANTS_LOG_REQUESTED, 'buildingId'); export const occupantsLogLoaded = makeActionCreator(OCCUPANTS_LOG_SUCCEEDED, 'instance'); export const occupantsLogFailed = makeActionCreator(OCCUPANTS_LOG_FAILED, 'error'); + export const loadThermalComfort = makeActionCreator(THERMAL_COMFORT_REQUESTED, 'buildingId'); export const thermalComfortLoaded = makeActionCreator(THERMAL_COMFORT_SUCCEEDED, 'instance'); export const thermalComfortFailed = makeActionCreator(THERMAL_COMFORT_FAILED, 'error'); @@ -39,6 +46,13 @@ export const loadThermalComfortLog = makeActionCreator(THERMAL_COMFORT_LOG_REQUE export const thermalComfortLogLoaded = makeActionCreator(THERMAL_COMFORT_LOG_SUCCEEDED, 'instance'); export const thermalComfortLogFailed = makeActionCreator(THERMAL_COMFORT_LOG_FAILED, 'error'); +export const loadRetrofits = makeActionCreator(RETROFITS_REQUESTED, 'buildingId'); +export const retrofitsLoaded = makeActionCreator(RETROFITS_SUCCEEDED, 'instance'); +export const retrofitsFailed = makeActionCreator(RETROFITS_FAILED, 'error'); +export const loadRetrofitsLog = makeActionCreator(RETROFITS_LOG_REQUESTED, 'buildingId'); +export const retrofitsLogLoaded = makeActionCreator(RETROFITS_LOG_SUCCEEDED, 'instance'); +export const retrofitsLogFailed = makeActionCreator(RETROFITS_LOG_FAILED, 'error'); + export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId', 'payload'); export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload', 'instance'); export const updateOccupantsFailed = makeActionCreator(UPDATE_OCCUPANTS_FAILED, 'error'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index 4aa464e5..0275300c 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -4,6 +4,7 @@ export const OCCUPANTS_FAILED = 'OCCUPANTS_FAILED'; export const OCCUPANTS_LOG_REQUESTED = 'OCCUPANTS_LOG_REQUESTED'; export const OCCUPANTS_LOG_SUCCEEDED = 'OCCUPANTS_LOG_SUCCEEDED'; export const OCCUPANTS_LOG_FAILED = 'OCCUPANTS_LOG_FAILED'; + export const THERMAL_COMFORT_REQUESTED = 'THERMAL_COMFORT_REQUESTED'; export const THERMAL_COMFORT_SUCCEEDED = 'THERMAL_COMFORT_SUCCEEDED'; export const THERMAL_COMFORT_FAILED = 'THERMAL_COMFORT_FAILED'; @@ -11,6 +12,13 @@ export const THERMAL_COMFORT_LOG_REQUESTED = 'THERMAL_COMFORT_LOG_REQUESTED'; export const THERMAL_COMFORT_LOG_SUCCEEDED = 'THERMAL_COMFORT_LOG_SUCCEEDED'; export const THERMAL_COMFORT_LOG_FAILED = 'THERMAL_COMFORT_LOG_FAILED'; +export const RETROFITS_REQUESTED = 'RETROFITS_REQUESTED'; +export const RETROFITS_SUCCEEDED = 'RETROFITS_SUCCEEDED'; +export const RETROFITS_FAILED = 'RETROFITS_FAILED'; +export const RETROFITS_LOG_REQUESTED = 'RETROFITS_LOG_REQUESTED'; +export const RETROFITS_LOG_SUCCEEDED = 'RETROFITS_LOG_SUCCEEDED'; +export const RETROFITS_LOG_FAILED = 'RETROFITS_LOG_FAILED'; + export const UPDATE_OCCUPANTS_REQUESTED = 'UPDATE_OCCUPANTS_REQUESTED'; export const UPDATE_OCCUPANTS_SUCCEEDED = 'UPDATE_OCCUPANTS_SUCCEEDED'; export const UPDATE_OCCUPANTS_FAILED = 'UPDATE_OCCUPANTS_FAILED'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 00fdc7b9..7ccbbedd 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -5,9 +5,11 @@ import { bindActionCreators } from 'redux'; import Loading from '../../components/Loading'; import { loadOccupants, - loadThermalComfort, loadOccupantsLog, + loadThermalComfort, loadThermalComfortLog, + loadRetrofits, + loadRetrofitsLog, updateOccupants, updateThermalComfort, } from './actions'; @@ -33,6 +35,8 @@ class Performance extends Component { this.props.loadOccupantsLog(buildingId); this.props.loadThermalComfort(buildingId); this.props.loadThermalComfortLog(buildingId); + this.props.loadRetrofits(buildingId); + this.props.loadRetrofitsLog(buildingId); } render() { @@ -192,9 +196,11 @@ class Performance extends Component { Performance.propTypes = { building: buildingDetailPropTypes, loadOccupants: PropTypes.func, - loadThermalComfort: PropTypes.func, loadOccupantsLog: PropTypes.func, + loadThermalComfort: PropTypes.func, loadThermalComfortLog: PropTypes.func, + loadRetrofits: PropTypes.func, + loadRetrofitsLog: PropTypes.func, updateOccupants: PropTypes.func, updateThermalComfort: PropTypes.func, updateRetrofits: PropTypes.func, @@ -205,9 +211,11 @@ Performance.propTypes = { const mapDispatchToProps = dispatch => ( bindActionCreators({ loadOccupants, - loadThermalComfort, loadOccupantsLog, + loadThermalComfort, loadThermalComfortLog, + loadRetrofits, + loadRetrofitsLog, updateOccupants, updateThermalComfort, }, dispatch) diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index 46da9491..4b88bc27 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -11,6 +11,12 @@ import { THERMAL_COMFORT_LOG_REQUESTED, THERMAL_COMFORT_LOG_SUCCEEDED, THERMAL_COMFORT_LOG_FAILED, + RETROFITS_REQUESTED, + RETROFITS_SUCCEEDED, + RETROFITS_FAILED, + RETROFITS_LOG_REQUESTED, + RETROFITS_LOG_SUCCEEDED, + RETROFITS_LOG_FAILED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_OCCUPANTS_SUCCEEDED, UPDATE_OCCUPANTS_FAILED, @@ -27,6 +33,11 @@ const PerformanceInitialState = { error: false, data: null, }, + retrofits: { + loading: false, + error: false, + data: null, + }, occupantsLog: { loading: false, error: false, @@ -37,6 +48,11 @@ const PerformanceInitialState = { error: false, data: null, }, + retrofitsLog: { + loading: false, + error: false, + data: null, + }, }; export default function (state = PerformanceInitialState, action) { @@ -158,6 +174,64 @@ export default function (state = PerformanceInitialState, action) { }, }; + case RETROFITS_REQUESTED: + return { + ...state, + retrofits: { + ...state.retrofits, + loading: true, + error: false, + }, + }; + + case RETROFITS_SUCCEEDED: + return { + ...state, + retrofits: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case RETROFITS_FAILED: + return { + ...state, + retrofits: { + loading: false, + error: action.error, + }, + }; + + case RETROFITS_LOG_REQUESTED: + return { + ...state, + retrofitsLog: { + ...state.retrofitsLog, + loading: true, + error: false, + }, + }; + + case RETROFITS_LOG_SUCCEEDED: + return { + ...state, + retrofitsLog: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case RETROFITS_LOG_FAILED: + return { + ...state, + retrofitsLog: { + loading: false, + error: action.error, + }, + }; + case UPDATE_OCCUPANTS_REQUESTED: return { ...state, diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js index 34d8a268..84684e7e 100644 --- a/src/containers/Performance/sagas.js +++ b/src/containers/Performance/sagas.js @@ -7,6 +7,8 @@ import { OCCUPANTS_LOG_REQUESTED, THERMAL_COMFORT_REQUESTED, THERMAL_COMFORT_LOG_REQUESTED, + RETROFITS_REQUESTED, + RETROFITS_LOG_REQUESTED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_THERMAL_COMFORT_REQUESTED, CREATE_OCCUPANTS_LOG_REQUESTED, @@ -18,6 +20,8 @@ import { occupantsLogLoaded, occupantsLogFailed, thermalComfortLoaded, thermalComfortFailed, thermalComfortLogLoaded, thermalComfortLogFailed, + retrofitsLoaded, retrofitsFailed, + retrofitsLogLoaded, retrofitsLogFailed, updateOccupantsSucceeded, updateOccupantsFailed, updateThermalComfortSucceeded, updateThermalComfortFailed, createOccupantsLogSucceeded, createOccupantsLogFailed, @@ -44,6 +48,16 @@ function* loadThermalComfortLog(action) { yield SagaRequests.get(action, url, thermalComfortLogLoaded, thermalComfortLogFailed); } +function* loadRetrofits(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofits/`; + yield SagaRequests.get(action, url, retrofitsLoaded, retrofitsFailed); +} + +function* loadRetrofitsLog(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofits-log/`; + yield SagaRequests.get(action, url, retrofitsLogLoaded, retrofitsLogFailed); +} + function* updateOccupants(action) { const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants/`; const res = yield call( @@ -125,6 +139,8 @@ function* bloclinkWatcher() { yield takeEvery(OCCUPANTS_LOG_REQUESTED, loadOccupantsLog); yield takeEvery(THERMAL_COMFORT_REQUESTED, loadThermalComfort); yield takeEvery(THERMAL_COMFORT_LOG_REQUESTED, loadThermalComfortLog); + yield takeEvery(RETROFITS_REQUESTED, loadRetrofits); + yield takeEvery(RETROFITS_LOG_REQUESTED, loadRetrofitsLog); yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); -- GitLab From 91f88f70229f61187af4c089ab99682b70c4f95e Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 29 May 2019 12:00:18 -0400 Subject: [PATCH 21/50] Add retrofit meta --- src/containers/Performance/actions.js | 6 ++++ src/containers/Performance/constants.js | 3 ++ src/containers/Performance/index.js | 8 +++-- src/containers/Performance/reducer.js | 45 ++++++++++++++++++++++--- src/containers/Performance/sagas.js | 8 +++++ 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/src/containers/Performance/actions.js b/src/containers/Performance/actions.js index 66d87cf0..ca6d52c0 100644 --- a/src/containers/Performance/actions.js +++ b/src/containers/Performance/actions.js @@ -17,6 +17,9 @@ import { RETROFITS_LOG_REQUESTED, RETROFITS_LOG_SUCCEEDED, RETROFITS_LOG_FAILED, + RETROFIT_META_REQUESTED, + RETROFIT_META_SUCCEEDED, + RETROFIT_META_FAILED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_OCCUPANTS_SUCCEEDED, UPDATE_OCCUPANTS_FAILED, @@ -52,6 +55,9 @@ export const retrofitsFailed = makeActionCreator(RETROFITS_FAILED, 'error'); export const loadRetrofitsLog = makeActionCreator(RETROFITS_LOG_REQUESTED, 'buildingId'); export const retrofitsLogLoaded = makeActionCreator(RETROFITS_LOG_SUCCEEDED, 'instance'); export const retrofitsLogFailed = makeActionCreator(RETROFITS_LOG_FAILED, 'error'); +export const loadRetrofitMeta = makeActionCreator(RETROFIT_META_REQUESTED, 'buildingId'); +export const retrofitMetaLoaded = makeActionCreator(RETROFIT_META_SUCCEEDED, 'instance'); +export const retrofitMetaFailed = makeActionCreator(RETROFIT_META_FAILED, 'error'); export const updateOccupants = makeActionCreator(UPDATE_OCCUPANTS_REQUESTED, 'buildingId', 'payload'); export const updateOccupantsSucceeded = makeActionCreator(UPDATE_OCCUPANTS_SUCCEEDED, 'payload', 'instance'); diff --git a/src/containers/Performance/constants.js b/src/containers/Performance/constants.js index 0275300c..c1b96178 100644 --- a/src/containers/Performance/constants.js +++ b/src/containers/Performance/constants.js @@ -18,6 +18,9 @@ export const RETROFITS_FAILED = 'RETROFITS_FAILED'; export const RETROFITS_LOG_REQUESTED = 'RETROFITS_LOG_REQUESTED'; export const RETROFITS_LOG_SUCCEEDED = 'RETROFITS_LOG_SUCCEEDED'; export const RETROFITS_LOG_FAILED = 'RETROFITS_LOG_FAILED'; +export const RETROFIT_META_REQUESTED = 'RETROFIT_META_REQUESTED'; +export const RETROFIT_META_SUCCEEDED = 'RETROFIT_META_SUCCEEDED'; +export const RETROFIT_META_FAILED = 'RETROFIT_META_FAILED'; export const UPDATE_OCCUPANTS_REQUESTED = 'UPDATE_OCCUPANTS_REQUESTED'; export const UPDATE_OCCUPANTS_SUCCEEDED = 'UPDATE_OCCUPANTS_SUCCEEDED'; diff --git a/src/containers/Performance/index.js b/src/containers/Performance/index.js index 7ccbbedd..75c3cf11 100644 --- a/src/containers/Performance/index.js +++ b/src/containers/Performance/index.js @@ -10,6 +10,7 @@ import { loadThermalComfortLog, loadRetrofits, loadRetrofitsLog, + loadRetrofitMeta, updateOccupants, updateThermalComfort, } from './actions'; @@ -37,6 +38,7 @@ class Performance extends Component { this.props.loadThermalComfortLog(buildingId); this.props.loadRetrofits(buildingId); this.props.loadRetrofitsLog(buildingId); + this.props.loadRetrofitMeta(buildingId); } render() { @@ -112,7 +114,7 @@ class Performance extends Component { const retrofits = [ { - retrofit_name: 'Weatherstripping', + retrofit_name: 'Weather Stripping', install_start_date: '2019-04-20', install_end_date: '2019-05-20', primary_utility: 'Natural Gas', @@ -160,7 +162,7 @@ class Performance extends Component {
    ( loadThermalComfortLog, loadRetrofits, loadRetrofitsLog, + loadRetrofitMeta, updateOccupants, updateThermalComfort, }, dispatch) diff --git a/src/containers/Performance/reducer.js b/src/containers/Performance/reducer.js index 4b88bc27..59efcf42 100644 --- a/src/containers/Performance/reducer.js +++ b/src/containers/Performance/reducer.js @@ -17,6 +17,9 @@ import { RETROFITS_LOG_REQUESTED, RETROFITS_LOG_SUCCEEDED, RETROFITS_LOG_FAILED, + RETROFIT_META_REQUESTED, + RETROFIT_META_SUCCEEDED, + RETROFIT_META_FAILED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_OCCUPANTS_SUCCEEDED, UPDATE_OCCUPANTS_FAILED, @@ -28,22 +31,22 @@ const PerformanceInitialState = { error: false, data: null, }, - thermalComfort: { + occupantsLog: { loading: false, error: false, data: null, }, - retrofits: { + thermalComfort: { loading: false, error: false, data: null, }, - occupantsLog: { + thermalComfortLog: { loading: false, error: false, data: null, }, - thermalComfortLog: { + retrofits: { loading: false, error: false, data: null, @@ -53,6 +56,11 @@ const PerformanceInitialState = { error: false, data: null, }, + retrofitMeta: { + loading: false, + error: false, + data: null, + }, }; export default function (state = PerformanceInitialState, action) { @@ -232,6 +240,35 @@ export default function (state = PerformanceInitialState, action) { }, }; + case RETROFIT_META_REQUESTED: + return { + ...state, + retrofitMeta: { + ...state.retrofitMeta, + loading: true, + error: false, + }, + }; + + case RETROFIT_META_SUCCEEDED: + return { + ...state, + retrofitMeta: { + data: action.instance, + loading: false, + error: false, + }, + }; + + case RETROFIT_META_FAILED: + return { + ...state, + retrofitMeta: { + loading: false, + error: action.error, + }, + }; + case UPDATE_OCCUPANTS_REQUESTED: return { ...state, diff --git a/src/containers/Performance/sagas.js b/src/containers/Performance/sagas.js index 84684e7e..b46d3410 100644 --- a/src/containers/Performance/sagas.js +++ b/src/containers/Performance/sagas.js @@ -9,6 +9,7 @@ import { THERMAL_COMFORT_LOG_REQUESTED, RETROFITS_REQUESTED, RETROFITS_LOG_REQUESTED, + RETROFIT_META_REQUESTED, UPDATE_OCCUPANTS_REQUESTED, UPDATE_THERMAL_COMFORT_REQUESTED, CREATE_OCCUPANTS_LOG_REQUESTED, @@ -22,6 +23,7 @@ import { thermalComfortLogLoaded, thermalComfortLogFailed, retrofitsLoaded, retrofitsFailed, retrofitsLogLoaded, retrofitsLogFailed, + retrofitMetaLoaded, retrofitMetaFailed, updateOccupantsSucceeded, updateOccupantsFailed, updateThermalComfortSucceeded, updateThermalComfortFailed, createOccupantsLogSucceeded, createOccupantsLogFailed, @@ -58,6 +60,11 @@ function* loadRetrofitsLog(action) { yield SagaRequests.get(action, url, retrofitsLogLoaded, retrofitsLogFailed); } +function* loadRetrofitMeta(action) { + const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/retrofit-meta/`; + yield SagaRequests.get(action, url, retrofitMetaLoaded, retrofitMetaFailed); +} + function* updateOccupants(action) { const url = `${process.env.REACT_APP_BLOCLINK_URL}/buildings/${action.buildingId}/performance/occupants/`; const res = yield call( @@ -141,6 +148,7 @@ function* bloclinkWatcher() { yield takeEvery(THERMAL_COMFORT_LOG_REQUESTED, loadThermalComfortLog); yield takeEvery(RETROFITS_REQUESTED, loadRetrofits); yield takeEvery(RETROFITS_LOG_REQUESTED, loadRetrofitsLog); + yield takeEvery(RETROFIT_META_REQUESTED, loadRetrofitMeta); yield takeEvery(UPDATE_OCCUPANTS_REQUESTED, updateOccupants); yield takeEvery(UPDATE_THERMAL_COMFORT_REQUESTED, updateThermalComfort); yield takeEvery(CREATE_OCCUPANTS_LOG_REQUESTED, createOccupantsLog); -- GitLab From 8ced681472762a53c0496b9f9661147952818321 Mon Sep 17 00:00:00 2001 From: akkking Date: Wed, 29 May 2019 18:15:09 -0400 Subject: [PATCH 22/50] add retrofit and log --- src/components/Performance/RetrofitRow.js | 37 +++++++++++++----- src/components/Performance/Retrofits.js | 47 ++++++++++++++++------- 2 files changed, 61 insertions(+), 23 deletions(-) diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js index 1367ab0f..c11f3a18 100644 --- a/src/components/Performance/RetrofitRow.js +++ b/src/components/Performance/RetrofitRow.js @@ -23,17 +23,18 @@ class RetrofitRow extends Component { this.changeSecondUtility = this.changeSecondUtility.bind(this); this.state = { id: props.id, - retrofit_name: props.retrofitName, + retrofit_id: props.retrofitId, install_start_date: props.installStartDate, install_end_date: props.installEndDate, primary_utility: props.primaryUtility, second_utility: props.secondUtility, notes: props.notes, + retrofit_name: props.retrofitName, retrofitDropdownOpen: false, retrofitDropDownValue: props.retrofitName, - retrofitNames: props.retrofitNames !== undefined ? - props.retrofitNames.map((retrofitName, id) => { - return { id, key: id, name: retrofitName }; + retrofitMeta: props.retrofitMeta !== undefined ? + props.retrofitMeta.map((retrofit, id) => { + return { id, key: retrofit.id, name: retrofit.retrofit_name }; }) : [], primaryUtilityDropdownOpen: false, primaryUtilityDropDownValue: props.primaryUtility, @@ -88,7 +89,7 @@ class RetrofitRow extends Component { render() { const style = { textAlign: 'left' }; - const retrofitNames = this.state.retrofitNames.map(e => { + const retrofitMeta = this.state.retrofitMeta.map(e => { return ( {this.state.retrofitDropDownValue} - - {retrofitNames} + + {retrofitMeta}
    - {rows} - + + ); }); props.data.shift(); @@ -57,8 +61,8 @@ const LoanSummary = (props) => { }; LoanSummary.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/LoanSummaryRow.js b/src/components/Blocnote/PreliminaryFinance/LoanSummaryRow.js index 2b3da2b2..d70eee41 100644 --- a/src/components/Blocnote/PreliminaryFinance/LoanSummaryRow.js +++ b/src/components/Blocnote/PreliminaryFinance/LoanSummaryRow.js @@ -29,11 +29,11 @@ const LoanSummaryRow = (props) => { LoanSummaryRow.propTypes = { lender: PropTypes.string, - amountBorrowed: PropTypes.number, - amountUpperLimit: PropTypes.number, - annualInterestRate: PropTypes.number, - duration: PropTypes.number, - monthlyDebtService: PropTypes.number, + amountBorrowed: PropTypes.string, + amountUpperLimit: PropTypes.string, + annualInterestRate: PropTypes.string, + duration: PropTypes.string, + monthlyDebtService: PropTypes.string, }; export default LoanSummaryRow; diff --git a/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js b/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js index e27c3f5f..f9c78059 100644 --- a/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js +++ b/src/components/Blocnote/PreliminaryFinance/PostRetrofitBalanceSheet.js @@ -10,9 +10,13 @@ const PostRetrofitBalanceSheet = (props) => { let header = []; if (props.data !== null) { - header = props.data[0].map((item) => { + header = props.data[0].map((item, index) => { return ( - + ); }); props.data.shift(); @@ -36,8 +40,8 @@ const PostRetrofitBalanceSheet = (props) => { }; PostRetrofitBalanceSheet.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js b/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js index c949d896..87c82bfc 100644 --- a/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js +++ b/src/components/Blocnote/PreliminaryFinance/PostRetrofitIncomeStatement.js @@ -10,9 +10,13 @@ const PostRetrofitIncomeStatement = (props) => { let header = []; if (props.data !== null) { - header = props.data[0].map((item) => { + header = props.data[0].map((item, index) => { return ( - + ); }); props.data.shift(); @@ -36,8 +40,8 @@ const PostRetrofitIncomeStatement = (props) => { }; PostRetrofitIncomeStatement.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js index cde94856..fbd4ccab 100644 --- a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js +++ b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitBalanceSheet.js @@ -10,9 +10,13 @@ const PriorRetrofitBalanceSheet = (props) => { let header = []; if (props.data !== null) { - header = props.data[0].map((item) => { + header = props.data[0].map((item, index) => { return ( - + ); }); props.data.shift(); @@ -36,8 +40,8 @@ const PriorRetrofitBalanceSheet = (props) => { }; PriorRetrofitBalanceSheet.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js index 0a038581..c8087960 100644 --- a/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js +++ b/src/components/Blocnote/PreliminaryFinance/PriorRetrofitIncomeStatement.js @@ -10,9 +10,13 @@ const PriorRetrofitIncomeStatement = (props) => { let header = []; if (props.data !== null) { - header = props.data[0].map((item) => { + header = props.data[0].map((item, index) => { return ( - + ); }); props.data.shift(); @@ -36,8 +40,8 @@ const PriorRetrofitIncomeStatement = (props) => { }; PriorRetrofitIncomeStatement.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js b/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js index 9332a32d..dd614088 100644 --- a/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js +++ b/src/components/Blocnote/PreliminaryFinance/ProjectEconomics.js @@ -19,9 +19,10 @@ class ProjectEconomics extends Component { return false; // skip } return true; - }).map((item) => { + }).map((item, index) => { return ( @@ -43,8 +44,8 @@ class ProjectEconomics extends Component { } ProjectEconomics.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, data: PropTypes.arrayOf, }; diff --git a/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js b/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js index 333d5865..9783c65f 100644 --- a/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js +++ b/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js @@ -28,7 +28,7 @@ class ProjectEconomicsRow extends Component { ProjectEconomicsRow.propTypes = { row_name: PropTypes.string, - amount: PropTypes.number, + amount: PropTypes.string, }; export default ProjectEconomicsRow; diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index 734e0852..0ce65263 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -34,9 +34,10 @@ class SavingEstimation extends Component { const rows = []; if (this.state.savingEstimation !== null) { - Object.entries(this.state.savingEstimation).forEach(([utilityName, utilityData]) => { + Object.entries(this.state.savingEstimation).forEach(([utilityName, utilityData], index) => { rows.push( {this.state.scenarioDropDownValue} - + {scenarioOptions} diff --git a/src/components/Blocnote/PreliminaryFinance/TableContent.js b/src/components/Blocnote/PreliminaryFinance/TableContent.js index 8d0c0b91..48c3b985 100644 --- a/src/components/Blocnote/PreliminaryFinance/TableContent.js +++ b/src/components/Blocnote/PreliminaryFinance/TableContent.js @@ -6,8 +6,8 @@ const TableContent = (props) => { let rows = []; if (props.rows !== null) { - rows = props.rows.map((items) => { - const cells = items.map((item) => { + rows = props.rows.map((items, index1) => { + const cells = items.map((item, index2) => { let cellValue = item; if (typeof (item) !== 'string') { cellValue = Math.round(item * 100) / 100; @@ -16,7 +16,9 @@ const TableContent = (props) => { } return ( - + {cells} ); }); diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 2e272d4f..1ff67135 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -90,6 +90,7 @@ class FinancialInputs extends Component { marginBottom: '25px', paddingLeft: '10px', }; + console.log(this.props); // eslint-disable-line const { blocnote } = this.props; const { fianceOverview, bills, billsOverview, billsSummary, cashBalance, @@ -108,7 +109,6 @@ class FinancialInputs extends Component { liabilities.data !== null && customerPreference.data !== null) { const foData = this.processFinanceOverview(fianceOverview.data); - const financeOverviewExist = fianceOverview.data.instance.financing_overview_data !== undefined; let cashBalanceData = []; @@ -145,6 +145,7 @@ class FinancialInputs extends Component { customerPreferenceData = customerPreference.data.instance; } + console.log(incomeStatement.data.instance); // eslint-disable-line mainContent = (
    Date: Wed, 5 Jun 2019 18:14:10 -0400 Subject: [PATCH 35/50] Fix Cash balance, Income Statement, Bills Overview issues --- .../Blocnote/FinancialInputs/BillsOverview.js | 27 ++++-- .../FinancialInputs/BillsSummaryTable.js | 6 +- .../Blocnote/FinancialInputs/CashBalance.js | 6 +- .../FinancialInputs/CustomerPreference.js | 6 +- .../FinancialInputs/IncomeStatements.js | 91 ++++++++++++------- .../Blocnote/FinancialInputs/LoanOptions.js | 6 +- .../FinancialInputs/MortgageLiabilities.js | 6 +- .../Blocnote/FinancialInputs/ResultMessage.js | 4 +- .../Blocnote/FinancialInputs/index.js | 1 - src/containers/Blocnote/reducer.js | 16 +++- src/containers/Blocnote/sagas.js | 2 +- 11 files changed, 110 insertions(+), 61 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index c01adf04..d2fc2f06 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -50,7 +50,11 @@ class BillsOverview extends Component { } changeEstimation(e) { - this.setState({ estimationDropDownValue: e.currentTarget.textContent }); + this.setState({ + estimationDropDownValue: e.currentTarget.textContent, + messageContent: null, + messageStyle: 'default', + }); } handleCreateBillsOverview = () => { @@ -176,9 +180,11 @@ class BillsOverview extends Component { ); } - if (this.state.loading) { + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Processing ...'; - this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { @@ -192,10 +198,17 @@ class BillsOverview extends Component { } if (!this.props.error && !this.props.loading - && this.props.data !== null - && this.state.action !== null) { - this.state.messageContent = 'Saved!'; - this.state.messageStyle = 'success'; + && this.props.data !== null) { + if (this.state.action === 'updated') { + this.state.messageStyle = 'success'; + this.state.messageContent = 'Projected successfully.'; + } else if (this.state.action === 'created') { + this.state.messageStyle = 'success'; + this.state.messageContent = 'Saved.'; + } else { + this.state.messageStyle = 'default'; + this.state.messageContent = null; + } } return ( diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js index b2a50bb8..941865d3 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js @@ -159,8 +159,10 @@ class BillsSummaryTable extends Component { ); } - if (this.props.loading) { - this.state.messageStyle = 'default'; + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Processing ...'; } diff --git a/src/components/Blocnote/FinancialInputs/CashBalance.js b/src/components/Blocnote/FinancialInputs/CashBalance.js index 5f478ab3..62c02d1a 100644 --- a/src/components/Blocnote/FinancialInputs/CashBalance.js +++ b/src/components/Blocnote/FinancialInputs/CashBalance.js @@ -161,8 +161,10 @@ class CashBalance extends Component { ); } - if (this.state.loading) { - this.state.messageStyle = 'default'; + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; } diff --git a/src/components/Blocnote/FinancialInputs/CustomerPreference.js b/src/components/Blocnote/FinancialInputs/CustomerPreference.js index 0ef52259..8cc17495 100644 --- a/src/components/Blocnote/FinancialInputs/CustomerPreference.js +++ b/src/components/Blocnote/FinancialInputs/CustomerPreference.js @@ -128,8 +128,10 @@ class CustomerPreference extends Component { ); } - if (this.state.loading) { - this.state.messageStyle = 'default'; + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; } diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index cf3f5da8..2b3a8cf8 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -22,30 +22,44 @@ class IncomeStatements extends Component { this.handleOnChange = this.handleOnChange.bind(this); // this.handleOnChangeNew = this.handleOnChangeNew.bind(this); + console.log(props.data.growth_rate); // eslint-disable-line + const GRDropdownId = props.data.growth_rate !== null ? props.data.growth_rate : 0; + let GRDropdownValue = props.data.growth_rate !== null ? `${String(parseInt(parseFloat(props.data.growth_rate).toFixed(2) * 100, 10))}%` : 'Select Growth Rate'; + const growthRateOptions = [ + { id: '-2', key: '-2', name: 'CAGR=221.23%' }, + { id: '-1', key: '-1', name: 'Average' }, + { id: '0', key: '0', name: '0%' }, + { id: '1', key: '1', name: '1%' }, + { id: '2', key: '2', name: '2%' }, + { id: '3', key: '3', name: '3%' }, + { id: '4', key: '4', name: '4%' }, + { id: '5', key: '5', name: '5%' }, + { id: '6', key: '6', name: '6%' }, + { id: '7', key: '7', name: '7%' }, + { id: '8', key: '8', name: '8%' }, + { id: '9', key: '9', name: '9%' }, + { id: '10', key: '10', name: '10%' }, + { id: '11', key: '11', name: '11%' }, + { id: '12', key: '12', name: '12%' }, + { id: '13', key: '13', name: '13%' }, + { id: '14', key: '14', name: '14%' }, + { id: '15', key: '15', name: '15%' }, + ]; + growthRateOptions.forEach(option => { + if (option.id === GRDropdownId) { + GRDropdownValue = option.name; + } + }); + if (GRDropdownValue === null) { + GRDropdownValue = props.data.growth_rate !== null ? props.data.growth_rate : 0; + } + + const obj = { GRDropdownOpen: false, - GRDropdownId: props.data.growth_rate !== null ? props.data.growth_rate : 0, - GRDropdownValue: props.data.growth_rate !== null ? `${String(props.data.growth_rate * 100)}%` : 'Select Growth Rate', - growthRateOptions: [ - { id: '-2', key: '-2', name: 'CAGR=1.58%' }, - { id: '-1', key: '-1', name: 'Average' }, - { id: '0', key: '0', name: '0%' }, - { id: '1', key: '1', name: '1%' }, - { id: '2', key: '2', name: '2%' }, - { id: '3', key: '3', name: '3%' }, - { id: '4', key: '4', name: '4%' }, - { id: '5', key: '5', name: '5%' }, - { id: '6', key: '6', name: '6%' }, - { id: '7', key: '7', name: '7%' }, - { id: '8', key: '8', name: '8%' }, - { id: '9', key: '9', name: '9%' }, - { id: '10', key: '10', name: '10%' }, - { id: '11', key: '11', name: '11%' }, - { id: '12', key: '12', name: '12%' }, - { id: '13', key: '13', name: '13%' }, - { id: '14', key: '14', name: '14%' }, - { id: '15', key: '15', name: '15%' }, - ], + GRDropdownId, + GRDropdownValue, + growthRateOptions, incomeStatements: props.data, incomeStatementsNew: null, error: false, @@ -55,7 +69,6 @@ class IncomeStatements extends Component { messageStyle: 'default', }; - console.log(props.data.hist); // eslint-disable-line const histYears = {}; const incomeStatementsNew = { incomeStatementsNew: [] }; if (props.data.hist !== null) { @@ -226,6 +239,8 @@ class IncomeStatements extends Component { const growthRate = {}; growthRate['growth-rate'] = String(this.state.GRDropdownId); hist.push(growthRate); + console.log(hist); // eslint-disable-line + this.props.updateIncomeStatements( this.props.buildingId, hist, @@ -292,8 +307,6 @@ class IncomeStatements extends Component { let header = []; let rows = []; let calculateSaveButton = null; - console.log(this.props.data.hist); // eslint-disable-line - console.log(this.state.incomeStatements.hist); // eslint-disable-line const columnKeys = [ 'revenue', @@ -340,15 +353,17 @@ class IncomeStatements extends Component { if (this.state.incomeStatements.hist !== null && this.state.incomeStatements.future !== null) { header = this.buildHeader(); - console.log(this.state.incomeStatements.hist); // eslint-disable-line - const histYears = Object.keys(this.state.incomeStatements.hist).sort(); + const incomeStatements = this.state.incomeStatements; + const histYears = Object.keys(incomeStatements.hist).sort(); rows = columnKeys.map((columnKey, id) => { const cells = [ ...[columnNames[columnKey]], ...histYears.map((histYear) => { - let cellValue = this.state.incomeStatements.hist[histYear][columnKey]; - cellValue = Math.round(cellValue * 100) / 100; + // let cellValue = incomeStatements.hist[histYear][columnKey]; + // cellValue = Math.round(cellValue * 100) / 100; if (['utility_expense', 'revenue', 'non_utility_expense'].includes(columnKey)) { + let cellValue = this.state.incomeStatements.hist[histYear][columnKey]; + cellValue = Math.round(cellValue * 100) / 100; return ( @@ -366,18 +381,20 @@ class IncomeStatements extends Component { ); } + let cellValue = this.props.data.hist[histYear][columnKey]; + cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); cellValue = `$${cellValue}`; return cellValue; }), - ...[this.state.incomeStatements.future[columnKey]].map((amount) => { + ...[incomeStatements.future[columnKey]].map((amount) => { let cellValue = amount; cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); cellValue = `$${cellValue}`; return cellValue; }), - ...Object.values([this.state.incomeStatements.average[columnKey]]).map((amount) => { + ...Object.values([incomeStatements.average[columnKey]]).map((amount) => { let cellValue = amount; cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); @@ -477,8 +494,10 @@ class IncomeStatements extends Component { ); } - if (this.state.loading) { - this.state.messageStyle = 'default'; + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; } @@ -491,9 +510,11 @@ class IncomeStatements extends Component { && this.state.incomeStatements !== null && this.state.action === 'updated') { this.state.messageStyle = 'success'; - this.state.messageContent = 'Saved!'; + this.state.messageContent = 'Saved and reloaded.'; } - + console.log(this.state.GRDropdownId); // eslint-disable-line + console.log(this.state.GRDropdownValue); // eslint-disable-line + console.log(this.props.data.growth_rate); // eslint-disable-line return (

    diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index 35db9d8f..ea9a17b0 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -203,9 +203,11 @@ class LoanOptions extends Component { ); } - if (this.state.loading) { + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; - this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { diff --git a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js index ce931eb7..ed5a8c72 100644 --- a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js +++ b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js @@ -178,9 +178,11 @@ class MortgageLiabilities extends Component { ); } - if (this.state.loading) { + this.state.messageStyle = 'default'; + this.state.messageContent = null; + + if (this.props.loading === true) { this.state.messageContent = 'Updating ...'; - this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { diff --git a/src/components/Blocnote/FinancialInputs/ResultMessage.js b/src/components/Blocnote/FinancialInputs/ResultMessage.js index d00d8c20..7a784917 100644 --- a/src/components/Blocnote/FinancialInputs/ResultMessage.js +++ b/src/components/Blocnote/FinancialInputs/ResultMessage.js @@ -11,7 +11,6 @@ const errorStyle = { color: 'red', padding: '10px 25px 10px 25px', fontWeight: 'bold', - background: '#EEEEEE', }; const defaultStyle = { color: 'black', @@ -29,7 +28,8 @@ const ResultMessage = (props) => { } else if (props.style === 'error') { return ( - ×  {props.content} + {/* ×  {props.content} */} +   {props.content} ); } diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 1ff67135..2d3005e6 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -145,7 +145,6 @@ class FinancialInputs extends Component { customerPreferenceData = customerPreference.data.instance; } - console.log(incomeStatement.data.instance); // eslint-disable-line mainContent = (
    Date: Thu, 6 Jun 2019 12:05:28 -0400 Subject: [PATCH 36/50] Fix income statement dropdown issue --- .../FinancialInputs/IncomeStatements.js | 37 ++++++++----------- src/containers/Blocnote/sagas.js | 1 - 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 2b3a8cf8..93d78c56 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -22,10 +22,8 @@ class IncomeStatements extends Component { this.handleOnChange = this.handleOnChange.bind(this); // this.handleOnChangeNew = this.handleOnChangeNew.bind(this); - console.log(props.data.growth_rate); // eslint-disable-line - const GRDropdownId = props.data.growth_rate !== null ? props.data.growth_rate : 0; - let GRDropdownValue = props.data.growth_rate !== null ? `${String(parseInt(parseFloat(props.data.growth_rate).toFixed(2) * 100, 10))}%` : 'Select Growth Rate'; - const growthRateOptions = [ + const GRDropdownId = props.data.growth_rate !== null ? props.data.growth_rate : -99; + this.growthRateOptions = [ { id: '-2', key: '-2', name: 'CAGR=221.23%' }, { id: '-1', key: '-1', name: 'Average' }, { id: '0', key: '0', name: '0%' }, @@ -45,21 +43,11 @@ class IncomeStatements extends Component { { id: '14', key: '14', name: '14%' }, { id: '15', key: '15', name: '15%' }, ]; - growthRateOptions.forEach(option => { - if (option.id === GRDropdownId) { - GRDropdownValue = option.name; - } - }); - if (GRDropdownValue === null) { - GRDropdownValue = props.data.growth_rate !== null ? props.data.growth_rate : 0; - } - const obj = { GRDropdownOpen: false, GRDropdownId, - GRDropdownValue, - growthRateOptions, + growthRateOptions: this.growthRateOptions, incomeStatements: props.data, incomeStatementsNew: null, error: false, @@ -143,7 +131,6 @@ class IncomeStatements extends Component { changeGrowthRate(e) { this.setState({ GRDropdownId: e.currentTarget.id }); - this.setState({ GRDropdownValue: e.currentTarget.textContent }); } buildHeader = () => { @@ -239,7 +226,6 @@ class IncomeStatements extends Component { const growthRate = {}; growthRate['growth-rate'] = String(this.state.GRDropdownId); hist.push(growthRate); - console.log(hist); // eslint-disable-line this.props.updateIncomeStatements( this.props.buildingId, @@ -280,7 +266,7 @@ class IncomeStatements extends Component { return newStatement; }); - if (this.state.GRDropdownValue === 'Select Growth Rate') { + if (this.state.GRDropdownId === -99) { emptyMessages.push('Growth Rate'); } @@ -512,9 +498,16 @@ class IncomeStatements extends Component { this.state.messageStyle = 'success'; this.state.messageContent = 'Saved and reloaded.'; } - console.log(this.state.GRDropdownId); // eslint-disable-line - console.log(this.state.GRDropdownValue); // eslint-disable-line - console.log(this.props.data.growth_rate); // eslint-disable-line + + let GRDropdownValue = 'Select Growth Rate'; + this.growthRateOptions.forEach(option => { + if (option.id === String(parseInt(parseFloat(this.state.GRDropdownId).toFixed(2) * 100, 10)) + || option.id === this.state.GRDropdownId + || parseInt(option.id, 10) === this.state.GRDropdownId) { + GRDropdownValue = option.name; + } + }); + return (

    @@ -528,7 +521,7 @@ class IncomeStatements extends Component { className="btn-block" > - {this.state.GRDropdownValue} + {GRDropdownValue} {growthRateOptions} diff --git a/src/containers/Blocnote/sagas.js b/src/containers/Blocnote/sagas.js index 49bff678..7cdd5b7d 100644 --- a/src/containers/Blocnote/sagas.js +++ b/src/containers/Blocnote/sagas.js @@ -215,7 +215,6 @@ function* updateIncomeStatements(action) { ); if (!res.err) { - console.log(action.payload.slice(-1)); // eslint-disable-line res.growth_rate = action.payload.slice(-1)[0]['growth-rate']; yield put(updateIncomeStatementsSucceeded(res)); } else { -- GitLab From 58f1714a55ac516ab775a15ac7cf047330c79ef4 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Thu, 6 Jun 2019 12:12:40 -0400 Subject: [PATCH 37/50] Remove console logs --- src/components/Blocnote/FinancialInputs/BillsSummaryRow.js | 1 - src/components/Blocnote/FinancialInputs/BillsSummaryTable.js | 1 - 2 files changed, 2 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js b/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js index 529a7488..5c765e57 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js @@ -60,7 +60,6 @@ class BillsSummaryRow extends Component { this.setState({ [event.target.name]: event.target.value }, () => { this.props.handleOnChange(this.state); - console.log(this.state); // eslint-disable-line }, ); } diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js index 941865d3..fb2e5a2b 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js @@ -103,7 +103,6 @@ class BillsSummaryTable extends Component { } handleOnChange = (billData) => { - console.log("billData"); // eslint-disable-line const billsSummary = this.state.billData.map(bill => { if (bill.id === billData.id) { return { -- GitLab From 59518029d0cf081d6bff336c355aefc34ae95233 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 7 Jun 2019 13:17:56 -0400 Subject: [PATCH 38/50] Fix Bill overview and income statement issues --- .../Blocnote/FinancialInputs/BillsOverview.js | 32 ++++++++++--------- .../FinancialInputs/IncomeStatements.js | 6 ++-- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index d2fc2f06..7d3fb7a3 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -16,33 +16,35 @@ class BillsOverview extends Component { super(props); this.toggleEstimation = this.toggleEstimation.bind(this); this.changeEstimation = this.changeEstimation.bind(this); - const data = {}; - let estimationDropDownValue = 'Select Estimation'; - if (Object.keys(this.props.data).length !== 0) { - estimationDropDownValue = this.props.data.estimation_algorithm; - ['electric', 'water', 'gas', 'oil'].forEach((billName) => { - Object.entries(this.props.data[billName]).forEach((bill) => { - const keyName = `${billName}-value-${bill[0]}`; - data[keyName] = bill[1]; - }); - }); - } - this.state = { estimationDropdownOpen: false, - estimationDropDownValue, + estimationDropDownValue: Object.keys(this.props.data).length !== 0 ? + this.props.data.estimation_algorithm : 'Select Estimation', estimationOptions: [ { id: 'RoughEstimation', key: 'RoughEstimation', name: 'Rough Estimation' }, { id: 'FancyEstimation', key: 'FancyEstimation', name: 'Fancy Estimation' }, ], loading: props.loading, action: null, - postBills: data, + postBills: this.processBillsData(), messageContent: null, messageStyle: 'default', }; } + processBillsData = () => { + const data = {}; + if (Object.keys(this.props.data).length !== 0) { + ['electric', 'water', 'gas', 'oil'].forEach((billName) => { + Object.entries(this.props.data[billName]).forEach((bill) => { + const keyName = `${billName}-value-${bill[0]}`; + data[keyName] = bill[1]; + }); + }); + } + return data; + } + toggleEstimation() { this.setState({ estimationDropdownOpen: !this.state.estimationDropdownOpen, @@ -60,7 +62,7 @@ class BillsOverview extends Component { handleCreateBillsOverview = () => { this.props.createBillsOverview( this.props.buildingId, - this.state.postBills, + this.processBillsData(), ); this.setState({ action: 'created' }); } diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 93d78c56..9b3e0c73 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -24,7 +24,7 @@ class IncomeStatements extends Component { const GRDropdownId = props.data.growth_rate !== null ? props.data.growth_rate : -99; this.growthRateOptions = [ - { id: '-2', key: '-2', name: 'CAGR=221.23%' }, + { id: '-2', key: '-2', name: `CAGR=${props.data.cagr}%` }, { id: '-1', key: '-1', name: 'Average' }, { id: '0', key: '0', name: '0%' }, { id: '1', key: '1', name: '1%' }, @@ -373,14 +373,14 @@ class IncomeStatements extends Component { cellValue = `$${cellValue}`; return cellValue; }), - ...[incomeStatements.future[columnKey]].map((amount) => { + ...[this.props.data.future[columnKey]].map((amount) => { let cellValue = amount; cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); cellValue = `$${cellValue}`; return cellValue; }), - ...Object.values([incomeStatements.average[columnKey]]).map((amount) => { + ...Object.values([this.props.data.average[columnKey]]).map((amount) => { let cellValue = amount; cellValue = Math.round(cellValue * 100) / 100; cellValue = cellValue.toLocaleString(); -- GitLab From 92c98c14aaaedd19f966618f6ae28157f8d26da9 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 7 Jun 2019 14:30:17 -0400 Subject: [PATCH 39/50] Remove not needed js file --- .../FinancialInputs/\bIncomeStatements.js" | 605 ------------------ 1 file changed, 605 deletions(-) delete mode 100644 "src/containers/Blocnote/FinancialInputs/\bIncomeStatements.js" diff --git "a/src/containers/Blocnote/FinancialInputs/\bIncomeStatements.js" "b/src/containers/Blocnote/FinancialInputs/\bIncomeStatements.js" deleted file mode 100644 index e8db5907..00000000 --- "a/src/containers/Blocnote/FinancialInputs/\bIncomeStatements.js" +++ /dev/null @@ -1,605 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { - Dropdown, - DropdownToggle, - DropdownMenu, - DropdownItem, - Button, - Input, - InputGroup, - InputGroupAddon, - Table, -} from 'reactstrap'; -import ResultMessage from './../../../components/Blocnote/FinancialInputs/ResultMessage'; - - -class IncomeStatements extends Component { - constructor(props) { - super(props); - this.toggleGrowthRate = this.toggleGrowthRate.bind(this); - this.changeGrowthRate = this.changeGrowthRate.bind(this); - this.handleOnChange = this.handleOnChange.bind(this); - // this.handleOnChangeNew = this.handleOnChangeNew.bind(this); - - const obj = { - GRDropdownOpen: false, - GRDropdownValue: 'Select Growth Rate', - selectedDropdownId: 0, - growthRateOptions: [ - { id: '-2', key: '-2', name: 'CAGR=1.58%' }, - { id: '-1', key: '-1', name: 'Average' }, - { id: '0', key: '0', name: '0%' }, - { id: '1', key: '1', name: '1%' }, - { id: '2', key: '2', name: '2%' }, - { id: '3', key: '3', name: '3%' }, - { id: '4', key: '4', name: '4%' }, - { id: '5', key: '5', name: '5%' }, - { id: '6', key: '6', name: '6%' }, - { id: '7', key: '7', name: '7%' }, - { id: '8', key: '8', name: '8%' }, - { id: '9', key: '9', name: '9%' }, - { id: '10', key: '10', name: '10%' }, - { id: '11', key: '11', name: '11%' }, - { id: '12', key: '12', name: '12%' }, - { id: '13', key: '13', name: '13%' }, - { id: '14', key: '14', name: '14%' }, - { id: '15', key: '15', name: '15%' }, - ], - incomeStatements: props.data, - incomeStatementsNew: null, - error: false, - loading: false, - action: null, - }; - - const histYears = {}; - const incomeStatementsNew = { incomeStatementsNew: [] }; - if (props.data.hist !== null) { - Object.keys(props.data.hist).forEach((year, id) => { - const histYear = `Year-${id + 1}`; - histYears[histYear] = parseInt(year, 10); - }); - } else { - [0, 1, 2].forEach(id => { - const histYear = `Year-${id + 1}`; - histYears[histYear] = null; - }); - - const growthRate = {}; - growthRate['growth-rate'] = props.data.cagr; - incomeStatementsNew.incomeStatementsNew.push(this.initIncomeStatement()); - incomeStatementsNew.incomeStatementsNew.push(this.initIncomeStatement()); - incomeStatementsNew.incomeStatementsNew.push(this.initIncomeStatement()); - incomeStatementsNew.incomeStatementsNew.push(growthRate); - } - - this.state = Object.assign(obj, histYears, incomeStatementsNew); - console.log(this.state); // eslint-disable-line - } - - initIncomeStatement = () => { - const statement = { - year: null, - revenue: null, - }; - statement['utility-expense'] = null; - statement['non-utility-operating-expense'] = null; - return statement; - } - - handleOnChange = (event) => { - const year = event.target.id; - const targetName = event.target.name; - const copyIS = this.state.incomeStatements; - Object.entries(copyIS.hist).forEach((incomeStatement) => { - if (incomeStatement[0] === year) { - copyIS.hist[year][targetName] = parseFloat(event.target.value); - } - }); - - this.setState({ incomeStatements: copyIS }, () => { - console.log(this.state.incomeStatements); // eslint-disable-line - }); - } - - handleOnChangeNew = (event) => { - const id = event.target.id; - const targetName = event.target.name.includes('Year') ? 'year' : event.target.name; - const targetValue = event.target.value; - const copyISNew = this.state.incomeStatementsNew.map((item, key) => { - if (parseInt(key, 10) === parseInt(id, 10)) { - const tmp = item; - tmp[targetName] = targetValue; - return tmp; - } - return item; - }); - this.setState({ incomeStatementsNew: copyISNew }, () => { - console.log(this.state.incomeStatementsNew); // eslint-disable-line - }); - } - - toggleGrowthRate() { - this.setState({ - GRDropdownOpen: !this.state.GRDropdownOpen, - }); - } - - changeGrowthRate(e) { - this.setState({ GRDropdownValue: e.currentTarget.textContent }); - this.setState({ selectedDropdownId: e.currentTarget.id }); - } - - buildHeader = () => { - const headers = []; - const year = 'year'; - headers.push( -

    - ); - - Object.entries(this.state).forEach((entry, key) => { - if (entry[0].includes('Year')) { - headers.push( - - ); - } - }); - const futureYear = this.state.incomeStatements.future.year; - headers.push( - - ); - const average = 'average'; - headers.push( - - ); - return headers; - } - - buildEmptyHeader = () => { - const headers = []; - const year = 'year'; - headers.push( - - ); - let id = 0; - Object.entries(this.state).forEach((entry, key) => { - if (entry[0].includes('Year')) { - headers.push( - - ); - id += 1; - } - }); - headers.push( - - ); - headers.push( - - ); - return headers; - } - - handleUpdateIncomeStatements = () => { - this.setState({ loading: true }); - const hist = []; - Object.entries(this.state.incomeStatements.hist).forEach(incomeStatement => { - const obj = { - year: String(incomeStatement[0]), - revenue: String(incomeStatement[1].revenue), - }; - obj['non-utility-operating-expense'] = String(incomeStatement[1].non_utility_expense); - obj['utility-expense'] = String(incomeStatement[1].utility_expense); - hist.push(obj); - }); - const growthRate = {}; - growthRate['growth-rate'] = String(this.state.selectedDropdownId); - hist.push(growthRate); - this.props.updateIncomeStatements( - this.props.buildingId, - hist, - ); - this.setState({ - loading: false, - action: 'updated', - }); - } - - handleCreateIncomeStatements = () => { - const emptyMessages = []; - const incomeStatementsNew = Object.values(this.state.incomeStatementsNew.slice(0, 3)) - .map(statement => { - if (statement.year === null && - !emptyMessages.includes('Year')) { - emptyMessages.push('Year'); - } - if (statement.revenue === null && - !emptyMessages.includes('Revenue')) { - emptyMessages.push('Revenue'); - } - if (statement['utility-expense'] === null && - !emptyMessages.includes('Utility Expense')) { - emptyMessages.push('Utility Expense'); - } - if (statement['non-utility-operating-expense'] === null && - !emptyMessages.includes('Non-Utility Operating Expense')) { - emptyMessages.push('Non-Utility Operating Expense'); - } - - const newStatement = {}; - newStatement.year = String(statement.year); - newStatement.revenue = String(statement.revenue); - newStatement['utility-expense'] = String(statement['utility-expense']); - newStatement['non-utility-operating-expense'] = String(statement['non-utility-operating-expense']); - return newStatement; - }); - - if (emptyMessages.length !== 0) { - const msg = `Please fill in ${emptyMessages.join(', ')} fields.`; - alert(msg); - } else { - const growthRate = {}; - growthRate['growth-rate'] = String(this.state.incomeStatementsNew[3]['growth-rate']); - incomeStatementsNew.push(growthRate); - this.setState({ loading: true }); - this.props.updateIncomeStatements( - this.props.buildingId, - incomeStatementsNew, - ); - this.setState({ - loading: false, - action: 'updated', - }); - } - } - - render() { - let header = []; - let rows = []; - let calculateSaveButton = null; - - const columnKeys = [ - 'revenue', - 'utility_expense', - 'energy_opex', - 'electric_opex', - 'gas_opex', - 'oil_opex', - 'water_opex', - 'other_utility', - 'non_utility_expense', - 'net_non_energy_opex', - 'total_opex', - 'noi', - ]; - - const columnNames = { - revenue: 'Revenue', - utility_expense: 'Utility Expense', - energy_opex: 'Energy Expense', - electric_opex: 'Electric Bill', - gas_opex: 'Gas Bill', - oil_opex: 'Oil Bill', - water_opex: 'Water Bill', - other_utility: 'Other Utility Expense', - non_utility_expense: 'Non-Utility Operating Expense', - net_non_energy_opex: 'Net Non-Energy Expense', - total_opex: 'Total Expense', - noi: 'Net Operating Income', - }; - - const growthRateOptions = this.state.growthRateOptions.map(e => { - return ( - - {e.name} - - ); - }); - - if (this.state.incomeStatements.hist !== null && - this.state.incomeStatements.future !== null) { - header = this.buildHeader(); - const histYears = Object.keys(this.state.incomeStatements.hist).sort(); - rows = columnKeys.map((columnKey, id) => { - const cells = [ - ...[columnNames[columnKey]], - ...histYears.map((histYear) => { - let cellValue = this.state.incomeStatements.hist[histYear][columnKey]; - cellValue = Math.round(cellValue * 100) / 100; - if (['utility_expense', 'revenue', 'non_utility_expense'].includes(columnKey)) { - return ( - - - $ - - - - ); - } - cellValue = cellValue.toLocaleString(); - cellValue = `$${cellValue}`; - return cellValue; - }), - ...[this.state.incomeStatements.future[columnKey]].map((amount) => { - let cellValue = amount; - cellValue = Math.round(cellValue * 100) / 100; - cellValue = cellValue.toLocaleString(); - cellValue = `$${cellValue}`; - return cellValue; - }), - ...Object.values([this.state.incomeStatements.average[columnKey]]).map((amount) => { - let cellValue = amount; - cellValue = Math.round(cellValue * 100) / 100; - cellValue = cellValue.toLocaleString(); - cellValue = `$${cellValue}`; - return cellValue; - }), - ]; - - const cellsData = Object.values(cells).map((celldata, key) => { - return ( - - ); - }); - - return ( - - {cellsData} - - ); - }); - - calculateSaveButton = ( - - ); - } else { - header = this.buildEmptyHeader(); - const ids = Object.keys(this.state.incomeStatementsNew).slice(0, 3).sort(); - console.log(this.state.incomeStatementsNew); // eslint-disable-line - rows = columnKeys.map((columnKey, id) => { - const cells = [ - ...[columnNames[columnKey]], - ...ids.map((index) => { - const keyMapping = { - revenue: 'revenue', - utility_expense: 'utility-expense', - non_utility_expense: 'non-utility-operating-expense', - }; - - if (['revenue', 'utility_expense', 'non_utility_expense'].includes(columnKey)) { - const newColumnKey = keyMapping[columnKey]; - return ( - - - $ - - - - ); - } - return null; - }), - ...['', ''], - ]; - - const cellsData = Object.values(cells).map((celldata, key) => { - return ( - - ); - }); - - return ( - - {cellsData} - - ); - }); - - calculateSaveButton = ( - - ); - } - - let messageStyle = {}; - let messageContent = null; - - if (this.state.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; - } - - if (this.state.error && typeof this.state.error === 'object') { - messageContent = this.state.error.response.statusText; - messageStyle = this.props.errorMessageStyle; - } - - if (!this.state.error && !this.state.loading - && this.state.incomeStatements !== null - && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; - } - - return ( -
    -

    - Income Statements (in $, End of Year) -

    -
    -
    - - - {this.state.GRDropdownValue} - - - {growthRateOptions} - - -
    -
    -    - {calculateSaveButton} -
    -
    -
    -
    -
    +
    Cost Estimation
    -- GitLab From 9cd0f3dd124f6412585b6b7311b7c7dbc7dbc9a0 Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 15:03:49 -0400 Subject: [PATCH 26/50] Fix Saving Estimation not updated issue --- .../PreliminaryFinance/SavingEstimation.js | 2 +- .../PreliminaryFinance/SavingEstimationRow.js | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index b7798b43..fc3ae4b2 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -18,7 +18,7 @@ class SavingEstimation extends Component { const newRow = row; const savingEstimation = this.state.savingEstimation; newRow.estimated_savings = String(row.estimated_savings); - savingEstimation[row.utilityType] = newRow; + savingEstimation[row.utility_type] = newRow; this.setState({ savingEstimation }, () => { this.props.updateSavingEstimation(this.state.savingEstimation); console.log(this.state.savingEstimation); // eslint-disable-line diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js index 2602bf5f..9b88a914 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js @@ -12,17 +12,17 @@ class SavingEstimationRow extends Component { super(props); this.handleOnChange = this.handleOnChange.bind(); this.state = { - estimatedSavings: props.estimatedSavings, - usedBeforeRetrofit: props.usedBeforeRetrofit, - usedAfterRetrofit: props.usedAfterRetrofit, - utilityType: props.utilityType, + estimated_savings: props.estimatedSavings, + used_before_retrofit: props.usedBeforeRetrofit, + used_after_retrofit: props.usedAfterRetrofit, + utility_type: props.utilityType, }; console.log(props); // eslint-disable-line } handleOnChange = (event) => { this.setState({ [event.target.name]: - ['usedBeforeRetrofit', 'usedAfterRetrofit'].includes(event.target.name) ? + ['used_before_retrofit', 'used_after_retrofit'].includes(event.target.name) ? event.target.checked : event.target.value }, () => { this.props.updateRow(this.state); @@ -45,8 +45,8 @@ class SavingEstimationRow extends Component { @@ -72,9 +72,9 @@ class SavingEstimationRow extends Component { -- GitLab From 1715276add456ef3d56883d5846c6ca8f674faeb Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 15:10:52 -0400 Subject: [PATCH 27/50] Move Cost estimation button down --- .../PreliminaryFinance/CostEstimation.js | 35 ++++++++++--------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index ad5fa447..d11fa83b 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -122,7 +122,7 @@ class CostEstimation extends Component { - @@ -159,6 +144,24 @@ class CostEstimation extends Component { {rows} + + +
    - -
    Item
    + +
    -- GitLab From 3464a5fbeba08e4e3ca6a06436b805a9d81aa6af Mon Sep 17 00:00:00 2001 From: akkking Date: Thu, 30 May 2019 15:56:01 -0400 Subject: [PATCH 28/50] Remove comments --- src/components/Blocnote/PreliminaryFinance/BudgetChart.js | 2 -- .../Blocnote/PreliminaryFinance/CostEstimation.js | 1 - src/components/Blocnote/PreliminaryFinance/DownPayment.js | 1 - .../Blocnote/PreliminaryFinance/InputScenario.js | 7 ------- .../Blocnote/PreliminaryFinance/ProjectEconomicsRow.js | 1 - .../Blocnote/PreliminaryFinance/SavingEstimation.js | 1 - .../Blocnote/PreliminaryFinance/SavingEstimationRow.js | 2 -- 7 files changed, 15 deletions(-) diff --git a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js index 53c0d600..c3346d21 100644 --- a/src/components/Blocnote/PreliminaryFinance/BudgetChart.js +++ b/src/components/Blocnote/PreliminaryFinance/BudgetChart.js @@ -15,7 +15,6 @@ import { class BudgetChart extends Component { constructor(props) { super(props); - this.state = { successMessages: [], error: false, @@ -38,7 +37,6 @@ class BudgetChart extends Component { const CustomizedLabel = React.createClass({ render() { const { x, y, stroke, value } = this.props; - return ( {value} diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index d11fa83b..fa43452a 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -64,7 +64,6 @@ class CostEstimation extends Component { delRow = id => { if (confirm('Are you sure to delete this estimation?') === true) { const costEstimation = this.state.costEstimation.filter((estimation, index) => { - console.log(estimation); // eslint-disable-line return index !== id; }); this.setState({ costEstimation }, () => { diff --git a/src/components/Blocnote/PreliminaryFinance/DownPayment.js b/src/components/Blocnote/PreliminaryFinance/DownPayment.js index 5443c29f..9d470f06 100644 --- a/src/components/Blocnote/PreliminaryFinance/DownPayment.js +++ b/src/components/Blocnote/PreliminaryFinance/DownPayment.js @@ -5,7 +5,6 @@ import PropTypes from 'prop-types'; class DownPayment extends Component { constructor(props) { super(props); - this.state = { successMessages: [], error: false, diff --git a/src/components/Blocnote/PreliminaryFinance/InputScenario.js b/src/components/Blocnote/PreliminaryFinance/InputScenario.js index db84fba9..658e7624 100644 --- a/src/components/Blocnote/PreliminaryFinance/InputScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/InputScenario.js @@ -75,8 +75,6 @@ class InputScenario extends Component { if (!this.props.error && !this.props.loading && this.props.data !== null && this.state.action !== null) { - // messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - // messageStyle = this.props.successMessageStyle; messageContent = ( ✔  {'Saved and reloaded.'} @@ -156,11 +154,6 @@ InputScenario.propTypes = { textAlign: PropTypes.string, marginBottom: PropTypes.string, }), - // successMessageStyle: PropTypes.shape({ - // color: PropTypes.string, - // paddingLeft: PropTypes.string, - // fontWeight: PropTypes.string, - // }), errorMessageStyle: PropTypes.shape({ color: PropTypes.string, paddingLeft: PropTypes.string, diff --git a/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js b/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js index 5315d9b9..333d5865 100644 --- a/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js +++ b/src/components/Blocnote/PreliminaryFinance/ProjectEconomicsRow.js @@ -5,7 +5,6 @@ import PropTypes from 'prop-types'; class ProjectEconomicsRow extends Component { constructor(props) { super(props); - this.state = { successMessages: [], error: false, diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js index fc3ae4b2..734e0852 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimation.js @@ -32,7 +32,6 @@ class SavingEstimation extends Component { fontSize: '13px', }; const rows = []; - console.log(this.state.savingEstimation); // eslint-disable-line if (this.state.savingEstimation !== null) { Object.entries(this.state.savingEstimation).forEach(([utilityName, utilityData]) => { diff --git a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js index 9b88a914..c0c46312 100644 --- a/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js +++ b/src/components/Blocnote/PreliminaryFinance/SavingEstimationRow.js @@ -17,7 +17,6 @@ class SavingEstimationRow extends Component { used_after_retrofit: props.usedAfterRetrofit, utility_type: props.utilityType, }; - console.log(props); // eslint-disable-line } handleOnChange = (event) => { @@ -30,7 +29,6 @@ class SavingEstimationRow extends Component { } render() { - console.log(this.state); // eslint-disable-line return (
    Date: Thu, 30 May 2019 16:54:10 -0400 Subject: [PATCH 29/50] Update scenario to refresh project economics data --- src/containers/Blocnote/PreliminaryFinance/index.js | 1 + src/containers/Blocnote/sagas.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/containers/Blocnote/PreliminaryFinance/index.js b/src/containers/Blocnote/PreliminaryFinance/index.js index 6c46344e..106d7daf 100644 --- a/src/containers/Blocnote/PreliminaryFinance/index.js +++ b/src/containers/Blocnote/PreliminaryFinance/index.js @@ -48,6 +48,7 @@ class PreliminaryFinance extends Component { fontWeight: 'bold', }; + console.log(this.props); // eslint-disable-line const { blocnote } = this.props; const { scenario } = blocnote; diff --git a/src/containers/Blocnote/sagas.js b/src/containers/Blocnote/sagas.js index 53768134..0389e0d9 100644 --- a/src/containers/Blocnote/sagas.js +++ b/src/containers/Blocnote/sagas.js @@ -315,7 +315,7 @@ function* updateScenario(action) { ); if (!res.err) { - yield put(updateScenarioSucceeded(action.payload)); + yield put(updateScenarioSucceeded(res)); } else { yield put(updateScenarioFailed(res.err)); } -- GitLab From 9025bfac325af589422cf0a221c75219dc83be60 Mon Sep 17 00:00:00 2001 From: akkking Date: Mon, 3 Jun 2019 11:17:24 -0400 Subject: [PATCH 30/50] Fix Bills Summary section issues --- .../Blocnote/FinancialInputs/Bills.js | 1 - .../FinancialInputs/BillsSummaryRow.js | 67 ++++++++- .../FinancialInputs/BillsSummaryTable.js | 139 +++++++++++------- .../FinancialInputs/MortgageLiabilities.js | 1 - .../Blocnote/FinancialInputs/index.js | 1 + src/containers/Blocnote/reducer.js | 41 ++++-- src/containers/Blocnote/sagas.js | 2 +- 7 files changed, 174 insertions(+), 78 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/Bills.js b/src/components/Blocnote/FinancialInputs/Bills.js index e37b1d6a..bb02de2c 100644 --- a/src/components/Blocnote/FinancialInputs/Bills.js +++ b/src/components/Blocnote/FinancialInputs/Bills.js @@ -16,7 +16,6 @@ const Bills = (props) => { }; if (props.data !== null) { - console.log(props.data); // eslint-disable-line Object.keys(props.data).forEach(billName => { BillsTables.push(
    diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js b/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js index b7479d8d..8ecec0c4 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryRow.js @@ -12,6 +12,7 @@ class BillsSummaryRow extends Component { constructor(props) { super(props); this.handleOnChange = this.handleOnChange.bind(this); + this.handleCreateBillsSummary = this.handleCreateBillsSummary.bind(this); this.handleUpdateBillsSummary = this.handleUpdateBillsSummary.bind(this); this.handleDeleteBillsSummary = this.handleDeleteBillsSummary.bind(this); this.state = { @@ -21,9 +22,34 @@ class BillsSummaryRow extends Component { }; } + validateInputs() { + const emptyFields = []; + if (this.state.year === null || isNaN(this.state.year) || this.state.year === '') { + emptyFields.push('Year'); + } + if (this.state.charge === null || isNaN(this.state.charge) || this.state.charge === '') { + emptyFields.push('Charge'); + } + if (emptyFields.length > 0) { + alert(`Please fill in ${emptyFields.join(', ')} field(s)`); + return false; + } + return true; + } + + handleCreateBillsSummary() { + if (this.validateInputs() === true) { + this.props.createBillsSummary({ + year: this.state.year, + charge: this.state.charge, + }); + } + } + handleUpdateBillsSummary() { - console.log(this.state); // eslint-disable-line - this.props.updateBillsSummary(this.state); + if (this.validateInputs() === true) { + this.props.updateBillsSummary(this.state); + } } handleDeleteBillsSummary() { @@ -31,10 +57,37 @@ class BillsSummaryRow extends Component { } handleOnChange = (event) => { - this.setState({ [event.target.name]: event.target.value }); + this.setState({ [event.target.name]: event.target.value }, + () => { + this.props.handleOnChange(this.state); + console.log(this.state); // eslint-disable-line + }, + ); } render() { + let actionButton = null; + + if (this.props.id === 0) { + actionButton = ( + + ); + } else { + actionButton = ( + + ); + } + return (
    @@ -70,10 +123,8 @@ class BillsSummaryRow extends Component { - {' '} + {actionButton} + {' '} diff --git a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js index 58d2c9b9..bad1c1a7 100644 --- a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js +++ b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js @@ -141,7 +141,6 @@ class MortgageLiabilities extends Component { let rows = []; let saveButton = null; if (this.state.liabilities.length !== 0) { - console.log(this.state.liabilities); // eslint-disable-line rows = this.state.liabilities.map((liability, index) => { return ( { + userBill[billName] = billData; + if (billName === action.instance.utility_type) { + const bill = userBill[billName].pop(); + bill.id = action.result.id; + bill.year = action.instance.year; + bill.charge = action.instance.charge; + userBill[billName].push(bill); + } + }); return { ...state, billsSummary: { data: { - result: - [ - ...state.billsSummary.data, - { - id: action.result.id, - utility_type: action.instance.utility_type, - year: action.instance.year, - charge: action.instance.charge, - }, - ], - + result: { + user_bill: userBill, + }, }, loading: false, error: false, }, }; + } case FinancialInputs.CREATE_BILLS_SUMMARY_FAILED: return { @@ -288,15 +292,24 @@ export default function (state = blocnoteInitialState, action) { }, }; - case FinancialInputs.DELETE_BILLS_SUMMARY_SUCCEEDED: + case FinancialInputs.DELETE_BILLS_SUMMARY_SUCCEEDED: { + const userBill = {}; + Object.entries(state.billsSummary.data.result.user_bill).forEach(([billName, billData]) => { + userBill[billName] = billData.filter(bill => bill.id !== action.instance.id); + }); return { ...state, billsSummary: { - ...state.billsSummary, + data: { + result: { + user_bill: userBill, + }, + }, loading: false, error: false, }, }; + } case FinancialInputs.DELETE_BILLS_SUMMARY_FAILED: return { diff --git a/src/containers/Blocnote/sagas.js b/src/containers/Blocnote/sagas.js index 0389e0d9..a44a0dd2 100644 --- a/src/containers/Blocnote/sagas.js +++ b/src/containers/Blocnote/sagas.js @@ -132,7 +132,7 @@ function* updateBillsSummary(action) { request, SagaRequests.generateURL(url, action), { - method: 'POST', + method: 'PUT', headers: getHeaders(), body: JSON.stringify(action.payload), } -- GitLab From a79cdc3cf32619d56ba127e9a5e21f2af9144c68 Mon Sep 17 00:00:00 2001 From: akkking Date: Mon, 3 Jun 2019 17:42:46 -0400 Subject: [PATCH 31/50] Fix Energy Bills Overview Estimation error --- src/components/Blocnote/FinancialInputs/BillsOverview.js | 8 +++++++- src/components/Blocnote/FinancialInputs/BillsSummary.js | 1 - src/containers/Blocnote/FinancialInputs/index.js | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index 0c7b04f4..5c7a6c78 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -37,6 +37,7 @@ class BillsOverview extends Component { ], action: null, postBills: data, + message: null, }; } @@ -177,7 +178,12 @@ class BillsOverview extends Component { } if (this.props.error && typeof this.props.error === 'object') { - messageContent = this.props.error.response.statusText; + if (this.state.estimationDropDownValue !== 'Rough Estimation') { + messageContent = 'Only Rough Estimation available at this point'; + } + // } else { + // messageContent = this.props.error.response.statusText; + // } messageStyle = this.props.errorMessageStyle; } diff --git a/src/components/Blocnote/FinancialInputs/BillsSummary.js b/src/components/Blocnote/FinancialInputs/BillsSummary.js index 05b6b1ba..9a5c9626 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummary.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummary.js @@ -18,7 +18,6 @@ class BillsSummary extends Component { const BillsSummaryTables = []; if (this.state.billsSummary !== null) { - console.log(this.state.billsSummary); // eslint-disable-line Object.keys(this.state.billsSummary).forEach(billName => { BillsSummaryTables.push(
    diff --git a/src/containers/Blocnote/FinancialInputs/index.js b/src/containers/Blocnote/FinancialInputs/index.js index 026dac08..4569ea05 100644 --- a/src/containers/Blocnote/FinancialInputs/index.js +++ b/src/containers/Blocnote/FinancialInputs/index.js @@ -106,7 +106,6 @@ class FinancialInputs extends Component { fontWeight: 'bold', }; - console.log(this.props); // eslint-disable-line const { blocnote } = this.props; const { fianceOverview, bills, billsOverview, billsSummary, cashBalance, @@ -205,6 +204,7 @@ class FinancialInputs extends Component { errorMessageStyle={errorMessageStyle} defaultMessageStyle={defaultMessageStyle} data={billsOverview.data.instance} + error={billsOverview.error} buildingId={this.props.building.building_id} loading={billsOverview.loading} createBillsOverview={this.props.createBillsOverview} -- GitLab From 7988355953745f680487404bf97fc11ac7fed51d Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Tue, 4 Jun 2019 12:57:18 -0400 Subject: [PATCH 32/50] Code refactoring for result message, fix loan options not saving issue --- .../Blocnote/FinancialInputs/BillsOverview.js | 37 ++++--------- .../Blocnote/FinancialInputs/BillsSummary.js | 18 ------ .../FinancialInputs/BillsSummaryTable.js | 39 ++++--------- .../Blocnote/FinancialInputs/BillsTable.js | 3 +- .../Blocnote/FinancialInputs/CashBalance.js | 40 ++++---------- .../FinancialInputs/CustomerPreference.js | 36 ++++-------- .../FinancialInputs/FinanceOverview.js | 55 ++++++++----------- .../FinancialInputs/IncomeStatements.js | 54 +++++++----------- .../Blocnote/FinancialInputs/LoanOptions.js | 54 +++++++----------- .../FinancialInputs/MortgageLiabilities.js | 43 +++++---------- .../Blocnote/FinancialInputs/ResultMessage.js | 44 ++++++++++++--- 11 files changed, 157 insertions(+), 266 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/BillsOverview.js b/src/components/Blocnote/FinancialInputs/BillsOverview.js index 5c7a6c78..5b915a67 100644 --- a/src/components/Blocnote/FinancialInputs/BillsOverview.js +++ b/src/components/Blocnote/FinancialInputs/BillsOverview.js @@ -37,7 +37,8 @@ class BillsOverview extends Component { ], action: null, postBills: data, - message: null, + messageContent: null, + messageStyle: 'default', }; } @@ -169,29 +170,26 @@ class BillsOverview extends Component { ); } - let messageStyle = {}; - let messageContent = null; - if (this.props.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; + this.state.messageContent = 'Processing ...'; + this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { if (this.state.estimationDropDownValue !== 'Rough Estimation') { - messageContent = 'Only Rough Estimation available at this point'; + this.state.messageContent = 'Only Rough Estimation available at this point'; } // } else { // messageContent = this.props.error.response.statusText; // } - messageStyle = this.props.errorMessageStyle; + this.state.messageStyle = 'error'; } if (!this.props.error && !this.props.loading && this.props.data !== null && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; + this.state.messageContent = 'Saved!'; + this.state.messageStyle = 'success'; } return ( @@ -216,8 +214,8 @@ class BillsOverview extends Component {
    @@ -262,21 +260,6 @@ BillsOverview.propTypes = { water_user: PropTypes.string, total_annual_charge: PropTypes.objectOf, }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - defaultMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), headerStyle: PropTypes.shape({ textAlign: PropTypes.string, paddingLeft: PropTypes.string, diff --git a/src/components/Blocnote/FinancialInputs/BillsSummary.js b/src/components/Blocnote/FinancialInputs/BillsSummary.js index 9a5c9626..c409fbf8 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummary.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummary.js @@ -28,9 +28,6 @@ class BillsSummary extends Component { createBillsSummary={this.props.createBillsSummary} updateBillsSummary={this.props.updateBillsSummary} deleteBillsSummary={this.props.deleteBillsSummary} - successMessageStyle={this.props.successMessageStyle} - errorMessageStyle={this.props.errorMessageStyle} - defaultMessageStyle={this.props.defaultMessageStyle} />
    ); @@ -81,21 +78,6 @@ BillsSummary.propTypes = { }) ), }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - defaultMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), headerStyle: PropTypes.shape({ textAlign: PropTypes.string, paddingLeft: PropTypes.string, diff --git a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js index 811139d3..b2a50bb8 100644 --- a/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js +++ b/src/components/Blocnote/FinancialInputs/BillsSummaryTable.js @@ -15,6 +15,8 @@ class BillsSummaryTable extends Component { billName: props.billName, billData: props.billData, action: null, + messageContent: null, + messageStyle: 'default', }; } @@ -63,7 +65,6 @@ class BillsSummaryTable extends Component { this.props.buildingId, billData, ); - console.log('saga done!'); // eslint-disable-line this.setState({ action: 'updated' }); } @@ -158,24 +159,21 @@ class BillsSummaryTable extends Component { ); } - let messageStyle = {}; - let messageContent = null; - if (this.props.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; + this.state.messageStyle = 'default'; + this.state.messageContent = 'Processing ...'; } if (this.props.error && typeof this.props.error === 'object') { - messageContent = this.props.error.response.statusText; - messageStyle = this.props.errorMessageStyle; + this.state.messageStyle = 'error'; + this.state.messageContent = this.props.error.response.statusText; } if (!this.props.error && !this.props.loading && this.props.billData !== null && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; + this.state.messageStyle = 'success'; + this.state.messageContent = 'Saved!'; } const billName = this.props.billName.charAt(0).toUpperCase() + this.props.billName.slice(1); @@ -204,9 +202,9 @@ class BillsSummaryTable extends Component { }} > {' '}{' '} + style={this.state.messageStyle} + content={this.state.messageContent} + />   - - - +
    +
    + + + +    + + + +
    +
    @@ -373,16 +372,6 @@ FinanceOverview.propTypes = { anticipatedCommissioningDate: PropTypes.string, anticipatedConstructionPeriod: PropTypes.number, baseURL: PropTypes.string, - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), headerStyle: PropTypes.shape({ textAlign: PropTypes.string, paddingLeft: PropTypes.string, diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 5a356dd3..0aaf7a4d 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -51,6 +51,8 @@ class IncomeStatements extends Component { error: false, loading: false, action: null, + messageContent: null, + messageStyle: 'default', }; const histYears = {}; @@ -472,24 +474,21 @@ class IncomeStatements extends Component { ); } - let messageStyle = {}; - let messageContent = null; - - if (this.state.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; + if (this.props.loading) { + this.state.messageStyle = 'default'; + this.state.messageContent = 'Updating ...'; } - if (this.state.error && typeof this.state.error === 'object') { - messageContent = this.state.error.response.statusText; - messageStyle = this.props.errorMessageStyle; + if (this.props.error && typeof this.props.error === 'object') { + this.state.messageStyle = 'error'; + this.state.messageContent = this.props.error.response.statusText; } - if (!this.state.error && !this.state.loading + if (!this.props.error && !this.props.loading && this.state.incomeStatements !== null - && this.state.action !== null) { - messageContent = this.state.action.charAt(0).toUpperCase() + this.state.action.slice(1); - messageStyle = this.props.successMessageStyle; + && this.state.action === 'updated') { + this.state.messageStyle = 'success'; + this.state.messageContent = 'Saved!'; } return ( @@ -498,7 +497,7 @@ class IncomeStatements extends Component { Income Statements (in $, End of Year)
    -
    +
    -
    +
       + style={this.state.messageStyle} + content={this.state.messageContent} + /> +
    +
    {calculateSaveButton}
    @@ -587,22 +588,9 @@ IncomeStatements.propTypes = { non_utility_operating_expense: PropTypes.string, })), }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - defaultMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), updateIncomeStatements: PropTypes.func, + error: PropTypes.bool, + loading: PropTypes.bool, }; export default IncomeStatements; diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index 3b40ddb1..c62a1075 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -28,6 +28,8 @@ class LoanOptions extends Component { duration: null, max_loan_amount: null, action: null, + messageContent: null, + messageStyle: 'default', }; } @@ -67,7 +69,6 @@ class LoanOptions extends Component { alert('Sorry, you need at least one loan option!'); } else if (confirm('Are you sure to delete this loan option?') === true) { const loanOptionsCopy = this.state.loanOptions.filter((loanOption, index) => { - console.log(loanOption); // eslint-disable-line return index !== id; }); this.setState({ loanOptions: loanOptionsCopy }, () => { @@ -86,7 +87,6 @@ class LoanOptions extends Component { duration: this.state.duration, max_loan_amount: this.state.max_loan_amount, }; - console.log(this.state.loanOptions); // eslint-disable-line const loanOptions = this.state.loanOptions; loanOptions.push(loanOption); this.setState({ loanOptions }, () => { @@ -107,8 +107,6 @@ class LoanOptions extends Component { updateRow = (row) => { const loanOptions = this.state.loanOptions.map((loanOption, id) => { - console.log(id); // eslint-disable-line - console.log(row.id); // eslint-disable-line if (id === row.id) { const tmp = { id }; tmp.lender = row.lender; @@ -125,7 +123,11 @@ class LoanOptions extends Component { } handleUpdateLoanOptions = () => { - if (this.validateInputs() === true) { + if (isNaN(this.state.noi) === true) { + alert('Please fill in NOI DSCR'); + } else if (isNaN(this.state.cash) === true) { + alert('Please fill in Cash DSCR'); + } else if (this.validateInputs() === true) { const formData = {}; formData['noi-dscr'] = parseFloat(this.state.noi).toFixed(2); formData['cash-dscr'] = parseFloat(this.state.cash).toFixed(2); @@ -141,6 +143,10 @@ class LoanOptions extends Component { } } + handleOnChange = (event) => { + this.setState({ [event.target.name]: event.target.value }); + } + render() { const header = [ 'Loan Options', @@ -192,24 +198,21 @@ class LoanOptions extends Component { ); } - let messageStyle = {}; - let messageContent = null; - if (this.props.loading) { - messageContent = 'Updating ...'; - messageStyle = this.props.defaultMessageStyle; + this.state.messageContent = 'Updating ...'; + this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { - messageContent = this.props.error.response.statusText; - messageStyle = this.props.errorMessageStyle; + this.state.messageContent = this.props.error.response.statusText; + this.state.messageStyle = 'error'; } if (!this.props.error && !this.props.loading && this.props.data !== null - && this.state.updated) { - messageContent = 'Saved!'; - messageStyle = this.props.successMessageStyle; + && this.state.action === 'updated') { + this.state.messageContent = 'Saved!'; + this.state.messageStyle = 'success'; } return ( @@ -270,9 +273,9 @@ class LoanOptions extends Component {
       + style={this.state.messageStyle} + content={this.state.messageContent} + /> {' '}{' '} ); } if (this.state.showCollapseButton) { collapseButton = ( - ); } diff --git a/src/components/Blocnote/FinancialInputs/CashBalance.js b/src/components/Blocnote/FinancialInputs/CashBalance.js index 64169a00..5f478ab3 100644 --- a/src/components/Blocnote/FinancialInputs/CashBalance.js +++ b/src/components/Blocnote/FinancialInputs/CashBalance.js @@ -19,6 +19,7 @@ class CashBalance extends Component { balance_amount: null, statement_date: null, is_from_balance_sheet: false, + loading: props.loading, action: null, messageContent: null, messageStyle: 'default', @@ -160,7 +161,7 @@ class CashBalance extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageStyle = 'default'; this.state.messageContent = 'Updating ...'; } diff --git a/src/components/Blocnote/FinancialInputs/CashBalanceRow.js b/src/components/Blocnote/FinancialInputs/CashBalanceRow.js index 332bbfc6..c8f1a13e 100644 --- a/src/components/Blocnote/FinancialInputs/CashBalanceRow.js +++ b/src/components/Blocnote/FinancialInputs/CashBalanceRow.js @@ -89,7 +89,7 @@ class CashBalanceRow extends Component { CashBalanceRow.propTypes = { id: PropTypes.number, - balanceAmount: PropTypes.number, + balanceAmount: PropTypes.string, statementDate: PropTypes.string, isFromBalanceSheet: PropTypes.bool, onDelEvent: PropTypes.func, diff --git a/src/components/Blocnote/FinancialInputs/CustomerPreference.js b/src/components/Blocnote/FinancialInputs/CustomerPreference.js index 1478a557..0ef52259 100644 --- a/src/components/Blocnote/FinancialInputs/CustomerPreference.js +++ b/src/components/Blocnote/FinancialInputs/CustomerPreference.js @@ -18,7 +18,8 @@ class CustomerPreference extends Component { downpayment: this.props.data.downpayment, expectedNetNoiDscr: this.props.data.expected_net_noi_dscr, expectedPayback: this.props.data.expected_payback, - updated: false, + loading: props.loading, + action: null, messageContent: null, messageStyle: 'default', }; @@ -29,15 +30,20 @@ class CustomerPreference extends Component { } handleUpdateCustomerPreference = () => { - this.props.updateCustomerPreference( - this.props.buildingId, - { - downpayment: parseFloat(this.state.downpayment).toFixed(2), - expected_net_noi_dscr: parseInt(this.state.expectedNetNoiDscr, 10), - expected_payback: this.state.expectedPayback, - }, - ); - this.setState({ updated: true }); + this.setState({ loading: true }, () => { + this.props.updateCustomerPreference( + this.props.buildingId, + { + downpayment: parseFloat(this.state.downpayment).toFixed(2), + expected_net_noi_dscr: parseInt(this.state.expectedNetNoiDscr, 10), + expected_payback: this.state.expectedPayback, + }, + ); + this.setState({ + loading: false, + action: 'updated', + }); + }); } render() { @@ -122,7 +128,7 @@ class CustomerPreference extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageStyle = 'default'; this.state.messageContent = 'Updating ...'; } @@ -134,7 +140,7 @@ class CustomerPreference extends Component { if (!this.props.error && !this.props.loading && this.props.data !== null - && this.state.updated) { + && this.state.action === 'updated') { this.state.messageStyle = 'success'; this.state.messageContent = 'Saved!'; } diff --git a/src/components/Blocnote/FinancialInputs/IncomeStatements.js b/src/components/Blocnote/FinancialInputs/IncomeStatements.js index 0aaf7a4d..cf3f5da8 100644 --- a/src/components/Blocnote/FinancialInputs/IncomeStatements.js +++ b/src/components/Blocnote/FinancialInputs/IncomeStatements.js @@ -49,12 +49,13 @@ class IncomeStatements extends Component { incomeStatements: props.data, incomeStatementsNew: null, error: false, - loading: false, + loading: props.loading, action: null, messageContent: null, messageStyle: 'default', }; + console.log(props.data.hist); // eslint-disable-line const histYears = {}; const incomeStatementsNew = { incomeStatementsNew: [] }; if (props.data.hist !== null) { @@ -77,7 +78,6 @@ class IncomeStatements extends Component { } this.state = Object.assign(obj, histYears, incomeStatementsNew); - console.log(this.state); // eslint-disable-line } initIncomeStatement = () => { @@ -292,6 +292,8 @@ class IncomeStatements extends Component { let header = []; let rows = []; let calculateSaveButton = null; + console.log(this.props.data.hist); // eslint-disable-line + console.log(this.state.incomeStatements.hist); // eslint-disable-line const columnKeys = [ 'revenue', @@ -338,6 +340,7 @@ class IncomeStatements extends Component { if (this.state.incomeStatements.hist !== null && this.state.incomeStatements.future !== null) { header = this.buildHeader(); + console.log(this.state.incomeStatements.hist); // eslint-disable-line const histYears = Object.keys(this.state.incomeStatements.hist).sort(); rows = columnKeys.map((columnKey, id) => { const cells = [ @@ -474,7 +477,7 @@ class IncomeStatements extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageStyle = 'default'; this.state.messageContent = 'Updating ...'; } diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index c62a1075..35db9d8f 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -17,6 +17,7 @@ class LoanOptions extends Component { this.deleteRow = this.deleteRow.bind(this); this.addRow = this.addRow.bind(this); this.updateRow = this.updateRow.bind(this); + this.handleUpdateLoanOptions = this.handleUpdateLoanOptions.bind(this); this.state = { loanOptions: props.data, lenders: props.lenders, @@ -27,6 +28,7 @@ class LoanOptions extends Component { interest_rate: null, duration: null, max_loan_amount: null, + loading: props.loading, action: null, messageContent: null, messageStyle: 'default', @@ -37,7 +39,6 @@ class LoanOptions extends Component { const emptyFields = []; if (this.state.loanOptions.length > 0) { Object.values(this.state.loanOptions).forEach(loanOption => { - console.log(loanOption); // eslint-disable-line if (loanOption.lender === null && !emptyFields.includes('Lender')) { emptyFields.push('Lender'); @@ -128,17 +129,20 @@ class LoanOptions extends Component { } else if (isNaN(this.state.cash) === true) { alert('Please fill in Cash DSCR'); } else if (this.validateInputs() === true) { - const formData = {}; - formData['noi-dscr'] = parseFloat(this.state.noi).toFixed(2); - formData['cash-dscr'] = parseFloat(this.state.cash).toFixed(2); - formData.instance = this.state.loanOptions; - this.props.updateLoanOptions( - this.props.buildingId, - formData, - ); - this.setState({ - loading: false, - action: 'updated', + this.setState({ loading: true }, () => { + const formData = {}; + formData['noi-dscr'] = parseFloat(this.state.noi).toFixed(2); + formData['cash-dscr'] = parseFloat(this.state.cash).toFixed(2); + formData.instance = this.state.loanOptions; + formData.lenders = this.state.lenders; + this.props.updateLoanOptions( + this.props.buildingId, + formData, + ); + this.setState({ + loading: false, + action: 'updated', + }); }); } } @@ -177,6 +181,7 @@ class LoanOptions extends Component { duration={loanOption.duration} maxLoanAmount={parseFloat(loanOption.max_loan_amount).toFixed(2)} onDelEvent={this.deleteRow} + onChangeEvent={this.handleOnChange} /> ); }); @@ -198,7 +203,7 @@ class LoanOptions extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageContent = 'Updating ...'; this.state.messageStyle = 'default'; } @@ -298,8 +303,8 @@ LoanOptions.propTypes = { textAlign: PropTypes.string, marginBottom: PropTypes.string, }), - cash: PropTypes.number, - noi: PropTypes.number, + cash: PropTypes.string, + noi: PropTypes.string, lenders: PropTypes.arrayOf, data: PropTypes.arrayOf( PropTypes.shape({ diff --git a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js index bf54384b..afc3052c 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js @@ -149,9 +149,9 @@ class LoanOptionsRow extends Component { LoanOptionsRow.propTypes = { id: PropTypes.number, lender: PropTypes.string, - interestRate: PropTypes.number, + interestRate: PropTypes.string, duration: PropTypes.string, - maxLoanAmount: PropTypes.number, + maxLoanAmount: PropTypes.string, onDelEvent: PropTypes.func, lenders: PropTypes.arrayOf, onChangeEvent: PropTypes.func, diff --git a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js index ef53a101..ce931eb7 100644 --- a/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js +++ b/src/components/Blocnote/FinancialInputs/MortgageLiabilities.js @@ -20,6 +20,7 @@ class MortgageLiabilities extends Component { input_date: null, monthly_service: null, remaining_term: null, + loading: props.loading, action: null, messageContent: null, messageStyle: 'default', @@ -112,13 +113,15 @@ class MortgageLiabilities extends Component { handleUpdateLiabilities = () => { if (this.validateInputs() === true) { - this.props.updateLiabilities( - this.props.buildingId, - this.state.liabilities, - ); - this.setState({ - loading: false, - action: 'updated', + this.setState({ loading: true }, () => { + this.props.updateLiabilities( + this.props.buildingId, + this.state.liabilities, + ); + this.setState({ + loading: false, + action: 'updated', + }); }); } } @@ -175,7 +178,7 @@ class MortgageLiabilities extends Component { ); } - if (this.props.loading) { + if (this.state.loading) { this.state.messageContent = 'Updating ...'; this.state.messageStyle = 'default'; } diff --git a/src/components/Blocnote/FinancialInputs/ResultMessage.js b/src/components/Blocnote/FinancialInputs/ResultMessage.js index ce744823..d00d8c20 100644 --- a/src/components/Blocnote/FinancialInputs/ResultMessage.js +++ b/src/components/Blocnote/FinancialInputs/ResultMessage.js @@ -4,9 +4,8 @@ import PropTypes from 'prop-types'; const successStyle = { color: '#336633', - padding: '10px 25px 10px 25px', + padding: '8px 25px 8px 25px', fontWeight: 'bold', - background: '#EEEEEE', }; const errorStyle = { color: 'red', @@ -24,13 +23,13 @@ const ResultMessage = (props) => { if (props.style === 'success') { return ( - ✓   {props.content} + ✓  {props.content} ); } else if (props.style === 'error') { return ( - {props.content} + ×  {props.content} ); } diff --git a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js index fa43452a..755a017e 100644 --- a/src/components/Blocnote/PreliminaryFinance/CostEstimation.js +++ b/src/components/Blocnote/PreliminaryFinance/CostEstimation.js @@ -143,19 +143,20 @@ class CostEstimation extends Component {
    @@ -169,7 +170,7 @@ class CostEstimation extends Component { } CostEstimation.propTypes = { - blockStyle: PropTypes.string, + blockStyle: PropTypes.objectOf, // headerStyle: PropTypes.string, data: PropTypes.arrayOf, updateCostEstimation: PropTypes.func, diff --git a/src/components/Blocnote/PreliminaryFinance/DownPayment.js b/src/components/Blocnote/PreliminaryFinance/DownPayment.js index 9d470f06..83180ca6 100644 --- a/src/components/Blocnote/PreliminaryFinance/DownPayment.js +++ b/src/components/Blocnote/PreliminaryFinance/DownPayment.js @@ -27,9 +27,9 @@ class DownPayment extends Component { } DownPayment.propTypes = { - blockStyle: PropTypes.string, - headerStyle: PropTypes.string, - paymentAmount: PropTypes.string, + blockStyle: PropTypes.objectOf, + headerStyle: PropTypes.objectOf, + paymentAmount: PropTypes.number, }; export default DownPayment; diff --git a/src/components/Blocnote/PreliminaryFinance/InputScenario.js b/src/components/Blocnote/PreliminaryFinance/InputScenario.js index 658e7624..396a746e 100644 --- a/src/components/Blocnote/PreliminaryFinance/InputScenario.js +++ b/src/components/Blocnote/PreliminaryFinance/InputScenario.js @@ -18,6 +18,8 @@ class InputScenario extends Component { savings: props.savings, loading: false, action: null, + messageContent: null, + messageStyle: 'default', }; } @@ -59,32 +61,21 @@ class InputScenario extends Component { } render() { - let messageStyle = {}; - let messageContent = null; - if (this.props.loading) { - messageContent = 'Processing ...'; - messageStyle = this.props.defaultMessageStyle; + this.state.messageContent = 'Processing ...'; + this.state.messageStyle = 'default'; } if (this.props.error && typeof this.props.error === 'object') { - messageContent = this.props.error.response.statusText; - messageStyle = this.props.errorMessageStyle; + this.state.messageContent = this.props.error.response.statusText; + this.state.messageStyle = 'error'; } if (!this.props.error && !this.props.loading && this.props.data !== null && this.state.action !== null) { - messageContent = ( - - ✔  {'Saved and reloaded.'} - - ); - messageStyle = { - paddingRight: '25px', - color: '#336633', - fontWeight: 'bold', - }; + this.state.messageContent = 'Saved and reloaded'; + this.state.messageStyle = 'success'; } return ( @@ -105,9 +96,9 @@ class InputScenario extends Component {
    {' '}{' '} + style={this.state.messageStyle} + content={this.state.messageContent} + />   
    {item} + {item} + {item} + {item} + {item} + {item} + {item} + {item} + {item} + {item} + + {cellValue} @@ -25,7 +27,9 @@ const TableContent = (props) => { }); return ( -
    - Year - - - - {futureYear} - - Average - - Year - - - - {' '}Next Year{' '} - - {' '}Average{' '} - - - {celldata} - -
    - - {celldata} - -
    - - {header} - - - {rows} - -
    -
    - - - ); - } -} - -IncomeStatements.propTypes = { - blockStyle: PropTypes.shape({ - marginBottom: PropTypes.string, - }), - headerStyle: PropTypes.shape({ - textAlign: PropTypes.string, - marginBottom: PropTypes.string, - }), - buildingId: PropTypes.number, - data: PropTypes.shape({ - average: PropTypes.shape({ - electric_opex: PropTypes.number, - energy_opex: PropTypes.number, - gas_opex: PropTypes.number, - net_non_energy_opex: PropTypes.number, - noi: PropTypes.number, - non_utility_expense: PropTypes.number, - oil_opex: PropTypes.number, - other_utility: PropTypes.number, - revenue: PropTypes.number, - total_opex: PropTypes.number, - utility_expense: PropTypes.number, - water_opex: PropTypes.number, - year: null, - }), - cagr: PropTypes.number, - future: PropTypes.shape({ - electric_opex: PropTypes.number, - energy_opex: PropTypes.number, - gas_opex: PropTypes.number, - net_non_energy_opex: PropTypes.number, - noi: PropTypes.number, - non_utility_expense: PropTypes.number, - oil_opex: PropTypes.number, - other_utility: PropTypes.number, - revenue: PropTypes.number, - total_opex: PropTypes.number, - utility_expense: PropTypes.number, - water_opex: PropTypes.number, - year: null, - }), - growth_rate: PropTypes.number, - hist: PropTypes.objectOf, - result: PropTypes.arrayOf(PropTypes.shape({ - year: PropTypes.string, - revenue: PropTypes.string, - utility_expense: PropTypes.string, - non_utility_operating_expense: PropTypes.string, - })), - }), - successMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - errorMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - defaultMessageStyle: PropTypes.shape({ - color: PropTypes.string, - paddingLeft: PropTypes.string, - fontWeight: PropTypes.string, - }), - updateIncomeStatements: PropTypes.func, -}; - -export default IncomeStatements; -- GitLab From e321beebeead57cd4a544f24cc6b9cba4d8e9357 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 7 Jun 2019 15:04:23 -0400 Subject: [PATCH 40/50] Fix loan options not saving issue --- .../Blocnote/FinancialInputs/LoanOptions.js | 13 ++++++++++--- .../Blocnote/FinancialInputs/LoanOptionsRow.js | 6 +++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/Blocnote/FinancialInputs/LoanOptions.js b/src/components/Blocnote/FinancialInputs/LoanOptions.js index ea9a17b0..a01e9c54 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptions.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptions.js @@ -110,7 +110,7 @@ class LoanOptions extends Component { const loanOptions = this.state.loanOptions.map((loanOption, id) => { if (id === row.id) { const tmp = { id }; - tmp.lender = row.lender; + tmp.lender = row.lenderDropDownValue; tmp.interest_rate = row.interest_rate; tmp.duration = row.duration; tmp.max_loan_amount = row.max_loan_amount; @@ -133,7 +133,14 @@ class LoanOptions extends Component { const formData = {}; formData['noi-dscr'] = parseFloat(this.state.noi).toFixed(2); formData['cash-dscr'] = parseFloat(this.state.cash).toFixed(2); - formData.instance = this.state.loanOptions; + formData.instance = this.state.loanOptions.map(loanOption => { + return { + lender: loanOption.lender, + interest_rate: loanOption.interest_rate, + duration: loanOption.duration, + max_loan_amount: loanOption.max_loan_amount, + }; + }); formData.lenders = this.state.lenders; this.props.updateLoanOptions( this.props.buildingId, @@ -181,7 +188,7 @@ class LoanOptions extends Component { duration={loanOption.duration} maxLoanAmount={parseFloat(loanOption.max_loan_amount).toFixed(2)} onDelEvent={this.deleteRow} - onChangeEvent={this.handleOnChange} + onChangeEvent={this.updateRow} /> ); }); diff --git a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js index afc3052c..f4eb6c8d 100644 --- a/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js +++ b/src/components/Blocnote/FinancialInputs/LoanOptionsRow.js @@ -53,7 +53,11 @@ class LoanOptionsRow extends Component { } changeLender(e) { - this.setState({ lenderDropDownValue: e.currentTarget.textContent }); + this.setState({ lenderDropDownValue: e.currentTarget.textContent }, + () => { + console.log(this.state); // eslint-disable-line + this.props.onChangeEvent(this.state); + }); } render() { -- GitLab From 58cbb516dc4e6bca96c12c493cccf68998de06e0 Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Fri, 7 Jun 2019 15:59:28 -0400 Subject: [PATCH 41/50] update button style --- src/components/Performance/Occupants.js | 8 ++++---- src/components/Performance/ThermalComfort.js | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/Performance/Occupants.js b/src/components/Performance/Occupants.js index 414b9011..668e4d3c 100644 --- a/src/components/Performance/Occupants.js +++ b/src/components/Performance/Occupants.js @@ -140,15 +140,15 @@ class Occupants extends Component { if (this.state.showNextButton) { nextButton = ( - ); } if (this.state.showLastButton) { lastButton = ( - ); } diff --git a/src/components/Performance/ThermalComfort.js b/src/components/Performance/ThermalComfort.js index 2856ed2a..bffc966b 100644 --- a/src/components/Performance/ThermalComfort.js +++ b/src/components/Performance/ThermalComfort.js @@ -143,15 +143,15 @@ class ThermalComfort extends Component { if (this.state.showNextButton) { nextButton = ( - ); } if (this.state.showLastButton) { lastButton = ( - ); } -- GitLab From e4712fdc8e41bd2dd03e39368df86bb8ce6b02be Mon Sep 17 00:00:00 2001 From: Aizizi Yigaimu Date: Thu, 13 Jun 2019 14:36:26 -0400 Subject: [PATCH 42/50] Updates on Retrofits --- src/components/Performance/RetrofitRow.js | 116 +++++++++++++-- src/components/Performance/Retrofits.js | 142 ++++++++----------- src/components/Performance/ThermalComfort.js | 4 +- 3 files changed, 166 insertions(+), 96 deletions(-) diff --git a/src/components/Performance/RetrofitRow.js b/src/components/Performance/RetrofitRow.js index c11f3a18..47b96497 100644 --- a/src/components/Performance/RetrofitRow.js +++ b/src/components/Performance/RetrofitRow.js @@ -14,13 +14,15 @@ class RetrofitRow extends Component { constructor(props) { super(props); this.handleOnChange = this.handleOnChange.bind(this); - this.onDelEvent = this.onDelEvent.bind(this); this.toggleRetrofit = this.toggleRetrofit.bind(this); this.togglePrimaryUtility = this.togglePrimaryUtility.bind(this); this.toggleSecondUtility = this.toggleSecondUtility.bind(this); this.changeRetrofit = this.changeRetrofit.bind(this); this.changePrimaryUtility = this.changePrimaryUtility.bind(this); this.changeSecondUtility = this.changeSecondUtility.bind(this); + this.handleCreateRetrofit = this.handleCreateRetrofit.bind(this); + this.handleUpdateRetrofit = this.handleUpdateRetrofit.bind(this); + this.handleDeleteRetrofit = this.handleDeleteRetrofit.bind(this); this.state = { id: props.id, retrofit_id: props.retrofitId, @@ -29,9 +31,8 @@ class RetrofitRow extends Component { primary_utility: props.primaryUtility, second_utility: props.secondUtility, notes: props.notes, - retrofit_name: props.retrofitName, retrofitDropdownOpen: false, - retrofitDropDownValue: props.retrofitName, + retrofitDropDownValue: this.getRetrofitName(), retrofitMeta: props.retrofitMeta !== undefined ? props.retrofitMeta.map((retrofit, id) => { return { id, key: retrofit.id, name: retrofit.retrofit_name }; @@ -46,9 +47,15 @@ class RetrofitRow extends Component { }; } - onDelEvent() { - this.props.onDelEvent(this.props.id); - } + getRetrofitName = () => { + let retrofitName = null; + this.props.retrofitMeta.forEach((retrofit) => { + if (retrofit.id === this.props.retrofitId) { + retrofitName = retrofit.retrofit_name; + } + }); + return retrofitName; + }; toggleRetrofit() { this.setState({ @@ -69,7 +76,10 @@ class RetrofitRow extends Component { } changeRetrofit(e) { - this.setState({ retrofitDropDownValue: e.currentTarget.textContent }); + this.setState({ + retrofit_id: e.currentTarget.id, + retrofitDropDownValue: e.currentTarget.textContent, + }); } changePrimaryUtility(e) { @@ -81,10 +91,64 @@ class RetrofitRow extends Component { } handleOnChange = (event) => { - this.setState({ [event.target.name]: event.target.value }, - () => { - this.props.onChangeEvent(this.state); + this.setState({ [event.target.name]: event.target.value }, () => { + console.log(this.state.notes); // eslint-disable-line + this.props.onChangeEvent({ + id: this.props.id, + retrofit_id: this.state.retrofit_id, + install_start_date: this.state.install_start_date, + install_end_date: this.state.install_end_date, + primary_utility: this.state.primary_utility, + second_utility: this.state.second_utility, + notes: this.state.notes, + }); + }); + } + + handleCreateRetrofit() { + if (this.validateInputs() === true) { + this.props.createRetrofit({ + retrofit_id: this.state.retrofit_id, + install_start_date: this.state.install_start_date, + install_end_date: this.state.install_end_date, + primary_utility: this.state.primary_utility, + second_utility: this.state.second_utility, + notes: this.state.notes, + }); + } + } + + handleUpdateRetrofit() { + if (this.validateInputs() === true) { + this.props.updateRetrofit({ + id: this.props.id, + retrofit_id: this.state.retrofit_id, + install_start_date: this.state.install_start_date, + install_end_date: this.state.install_end_date, + primary_utility: this.state.primary_utility, + second_utility: this.state.second_utility, + notes: this.state.notes, }); + } + } + + handleDeleteRetrofit() { + this.props.deleteRetrofit(this.props.id); + } + + validateInputs() { + const emptyFields = []; + if (this.state.install_start_date === null || this.state.install_start_date === '') { + emptyFields.push('Install start date'); + } + if (this.state.install_end_date === null || this.state.install_end_date === '') { + emptyFields.push('Install end date'); + } + if (emptyFields.length > 0) { + alert(`Please fill in ${emptyFields.join(', ')} field(s)`); + return false; + } + return true; } render() { @@ -125,6 +189,28 @@ class RetrofitRow extends Component { const dropdownStyle = { marginLeft: '0px', }; + + let actionButton = null; + + if (this.props.id === 0) { + actionButton = ( + + ); + } else { + actionButton = ( + + ); + } return (
    @@ -215,9 +301,11 @@ class RetrofitRow extends Component { /> + {actionButton} + {' '} @@ -230,7 +318,7 @@ class RetrofitRow extends Component { RetrofitRow.propTypes = { id: PropTypes.number, retrofitId: PropTypes.number, - retrofitName: PropTypes.string, + // retrofitName: PropTypes.string, installStartDate: PropTypes.string, installEndDate: PropTypes.string, primaryUtility: PropTypes.string, @@ -238,7 +326,9 @@ RetrofitRow.propTypes = { notes: PropTypes.string, utilityNames: PropTypes.arrayOf, retrofitMeta: PropTypes.arrayOf, - onDelEvent: PropTypes.func, + createRetrofit: PropTypes.func, + updateRetrofit: PropTypes.func, + deleteRetrofit: PropTypes.func, onChangeEvent: PropTypes.func, }; diff --git a/src/components/Performance/Retrofits.js b/src/components/Performance/Retrofits.js index 5d68a676..a46f3a93 100644 --- a/src/components/Performance/Retrofits.js +++ b/src/components/Performance/Retrofits.js @@ -11,20 +11,10 @@ import ResultMessage from './ResultMessage'; class Retrofits extends Component { constructor(props) { super(props); - this.deleteRow = this.deleteRow.bind(this); - this.addRow = this.addRow.bind(this); - this.updateRow = this.updateRow.bind(this); this.state = { utilityNames: props.utilityNames, retrofits: props.retrofits, retrofitsLog: props.retrofitsLog, - retrofit_id: 1, - retrofit_name: 'Water Stripping', - install_start_date: '2019-05-01', - install_end_date: '2019-06-01', - primary_utility: 'Natural Gas', - second_utility: 'Water', - notes: null, }; } @@ -32,16 +22,15 @@ class Retrofits extends Component { const emptyFields = []; if (this.state.retrofits !== null && this.state.retrofits.length > 0) { Object.values(this.state.retrofits).forEach(retrofit => { - console.log(retrofit); // eslint-disable-line if (retrofit.retrofit_name === null && !emptyFields.includes('Retrofit Name')) { emptyFields.push('Retrofit Name'); } - if (retrofit.install_start_date === null && + if (retrofit.install_start_date === '' && !emptyFields.includes('Installation Start Date')) { emptyFields.push('Installation Start Date'); } - if (retrofit.install_end_date === null && + if (retrofit.install_end_date === '' && !emptyFields.includes('Installation End Date')) { emptyFields.push('Installation End Date'); } @@ -63,55 +52,29 @@ class Retrofits extends Component { return true; } - deleteRow = id => { - const retrofitsCopy = this.state.retrofits.filter((retrofit, index) => { - console.log(retrofit); // eslint-disable-line - return index !== id; - }); - this.setState({ retrofits: retrofitsCopy }, () => { - console.log('Retrofit deleted!'); // eslint-disable-line - }); - } - addRow = () => { if (this.validateInputs() === true) { - const retrofit = { - id: this.state.id, - retrofit_name: this.state.retrofit_name, - install_start_date: this.state.install_start_date, - install_end_date: this.state.install_end_date, - primary_utility: this.state.primary_utility, - second_utility: this.state.second_utility, - notes: this.state.notes, - }; - console.log(this.state.retrofits); // eslint-disable-line const retrofits = this.state.retrofits; - console.log(retrofits); // eslint-disable-line - retrofits.push(retrofit); - console.log(retrofits); // eslint-disable-line + retrofits.push({ + id: 0, + retrofit_id: 1, + install_start_date: '', + install_end_date: '', + primary_utility: 'Natural Gas', + second_utility: 'Water', + notes: '', + }); this.setState({ retrofits }, () => { console.log(this.state.retrofits, 'New retrofit added!'); // eslint-disable-line - this.setState({ - id: this.state.id + 1, - retrofit_name: 'Water Stripping', - install_start_date: '2019-05-01', - install_end_date: '2019-06-01', - primary_utility: 'Natural Gas', - second_utility: 'Water', - notes: null, - }); }); } } - updateRow = (row) => { - const retrofits = this.state.retrofits.map((retrofit, id) => { - console.log(id); // eslint-disable-line - console.log(row.id); // eslint-disable-line - if (id === row.id) { - const tmp = { id }; - // tmp.retrofit_id = row.retrofit_id; - tmp.retrofit_name = row.retrofit_name; + handleOnChange = (row) => { + const retrofits = this.state.retrofits.map((retrofit) => { + if (retrofit.id === row.id) { + const tmp = { id: retrofit.id, building_id: retrofit.building_id }; + tmp.retrofit_id = row.retrofit_id; tmp.install_start_date = row.install_start_date; tmp.install_end_date = row.install_end_date; tmp.primary_utility = row.primary_utility; @@ -126,18 +89,40 @@ class Retrofits extends Component { }); } - handleUpdateRetrofits = () => { - if (this.validateInputs() === true) { - const formData = {}; - formData.instance = this.state.retrofits; - this.props.updateRetrofits( - this.props.buildingId, - formData, - ); - this.setState({ - loading: false, - action: 'updated', - }); + createRetrofit = (retrofit) => { + this.props.createRetrofit( + this.props.buildingId, + retrofit, + ); + console.log('saga done!'); // eslint-disable-line + this.setState({ action: 'created' }); + } + + updateRetrofit = (retrofit) => { + this.props.updateRetrofit( + this.props.buildingId, + retrofit, + ); + this.setState({ action: 'updated' }); + } + + deleteRetrofit = id => { + if (confirm('Are you sure to delete this retrofit?') === true) { + if (id === 0) { + this.setState({ + retrofits: this.state.retrofits.filter(retrofit => retrofit.id !== 0), + }); + } else { + this.props.deleteRetrofit( + this.props.buildingId, + { id }, + ); + const retrofitsCopy = this.state.retrofits.filter(retrofit => retrofit.id !== id); + this.setState({ + retrofits: retrofitsCopy, + action: 'deleted', + }); + } } } @@ -160,36 +145,28 @@ class Retrofits extends Component { let retrofits = []; let historyButton = null; - let saveButton = null; if (this.state.retrofits !== null && Object.keys(this.state.retrofits).length !== 0) { retrofits = this.state.retrofits.map((retrofit, index) => { return ( ); }); - saveButton = ( - - ); } else { retrofits = (