From 52b0087809647eac3f7b57b8ab54ac1dd6ef543d Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 1 Feb 2018 13:30:17 -0500 Subject: [PATCH 01/12] Increase max number of entries in the table to 50 --- src/containers/BGroup/BGroup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 8d70fc58..990d5dae 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -583,7 +583,7 @@ class BGroup extends Component { filterable data={bGroupBuildings} columns={columns} - defaultPageSize={10} + defaultPageSize={50} noDataText={this.props.bGroup.bGroupDetailLoading ? 'Loading...' : 'No data'} SubComponent={row => { const addresses = bGroupBuildings -- GitLab From 1ec09cd5c156eddc0f73db196bc66962a8987138 Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 1 Feb 2018 13:36:00 -0500 Subject: [PATCH 02/12] Change account to owner and account parent to parent company --- src/containers/BGroup/BGroup.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 990d5dae..271b0b6d 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -356,11 +356,11 @@ class BGroup extends Component { ), columns: [ { - Header: 'Account', + Header: 'Owner', filterMethod: genericFilterMethod, accessor: 'contact_account', }, { - Header: 'Parent Account', + Header: 'Parent Company', filterMethod: genericFilterMethod, accessor: 'contact_parent_account', }, { -- GitLab From 15eb3f47e5c6c86ac8419d7b35853675f16bc7e2 Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 1 Feb 2018 15:05:04 -0500 Subject: [PATCH 03/12] Show number of rows at the top of the bgroup table --- src/containers/BGroup/BGroup.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 271b0b6d..75027542 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -49,6 +49,7 @@ class BGroup extends Component { contactNames: {}, contactLoading: false, contactError: false, + numRows: -1, } componentDidMount() { @@ -65,6 +66,7 @@ class BGroup extends Component { val.building_id )); if (buildingIds.length > 0) { + this.setState({ numRows: buildingIds.length }); this.props.loadProjects({ 'building_id[]': buildingIds }); this.getUtilityAccounts(buildingIds); this.getGatewayDates(buildingIds); @@ -90,6 +92,10 @@ class BGroup extends Component { } } + componentWillUnmount() { + clearTimeout(this.updateNumRows); + } + getContacts = (projects) => { // A function to get all of the contact information for buildings this.setState({ contactLoading: true }); @@ -577,6 +583,11 @@ class BGroup extends Component { /> +
= 0 ? '' : 'none' }}> +
+
{this.state.numRows} rows
+
+
{ this.reactTable = reactTable; }} + onFilteredChange={() => { + // Create a bounce function so as to not decrease the speed of the filter. + clearTimeout(this.updateNumRows); + this.updateNumRows = setTimeout( + () => { this.setState({ numRows: this.reactTable.state.sortedData.length }); }, + 100, + ); + }} noDataText={this.props.bGroup.bGroupDetailLoading ? 'Loading...' : 'No data'} SubComponent={row => { const addresses = bGroupBuildings -- GitLab From f4277a3cd860a448a0bf9255321c4a0a224ee78e Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 1 Feb 2018 15:06:55 -0500 Subject: [PATCH 04/12] Change filter label for gas and electric columns to received and not received --- src/containers/BGroup/BGroup.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 75027542..7694becd 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -298,7 +298,7 @@ class BGroup extends Component { if (filter.value === 'all') { return true; } - if (filter.value === 'submitted') { + if (filter.value === 'received') { return row[filter.id]; } return !row[filter.id]; @@ -311,8 +311,8 @@ class BGroup extends Component { value={filter ? filter.value : 'all'} > - - + + ); const columns = [{ -- GitLab From 389f412ef00382d4d232289cd04e3026b50203fb Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 1 Feb 2018 15:08:59 -0500 Subject: [PATCH 05/12] Change filter text for energy simulation on bgroup --- src/containers/BGroup/BGroup.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 7694becd..8f645816 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -424,7 +424,7 @@ class BGroup extends Component { if (filter.value === 'all') { return true; } - if (filter.value === 'ran') { + if (filter.value === 'complete') { return row[filter.id]; } return !row[filter.id]; @@ -436,8 +436,8 @@ class BGroup extends Component { value={filter ? filter.value : 'all'} > - - + + ), accessor: 'building_simulation', -- GitLab From de4bf0d57cbef9d4988de59fbd221f0fa2b8e835 Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 1 Feb 2018 16:04:10 -0500 Subject: [PATCH 06/12] Remove edit buttons if user doesn't have the correct permissions --- src/containers/BGroup/BGroup.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 8f645816..2f96d732 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -246,6 +246,9 @@ class BGroup extends Component { } renderEditButton = () => { + if (!this.props.user.permissions['delete::BGroup'] && !this.props.user.permissions['update:BGroup']) { + return null; + } if (this.state.edit) { return (
@@ -535,6 +538,7 @@ class BGroup extends Component { if (this.state.edit) { columns.push({ Header: '', + filterable: false, accessor: 'delete', maxWidth: 35, Cell: row => this.renderDeleteBuildingButton(row.original.id), -- GitLab From 3ed98e68612d7ee0c69e5a0b8b2925f81063a02e Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 1 Feb 2018 16:17:37 -0500 Subject: [PATCH 07/12] Only show sensor install column if the user has the correct permissions --- src/components/AddressSearch/AddressSearch.js | 2 +- src/containers/BGroup/BGroup.js | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/AddressSearch/AddressSearch.js b/src/components/AddressSearch/AddressSearch.js index 43f1f857..d61339cb 100644 --- a/src/components/AddressSearch/AddressSearch.js +++ b/src/components/AddressSearch/AddressSearch.js @@ -93,7 +93,7 @@ class AddressSearch extends Component { )} renderInput={props => ( - + {this.state.isFetching ? : null} diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 2f96d732..e811e712 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -69,7 +69,9 @@ class BGroup extends Component { this.setState({ numRows: buildingIds.length }); this.props.loadProjects({ 'building_id[]': buildingIds }); this.getUtilityAccounts(buildingIds); - this.getGatewayDates(buildingIds); + if (this.props.user.permissions['read::Gateway']) { + this.getGatewayDates(buildingIds); + } this.getSimulationDates(buildingIds); } } @@ -460,7 +462,8 @@ class BGroup extends Component { ), columns: [ - { + // Only show the sensor install column if the user has the correct permission + ...(!this.props.user.permissions['read::Gateway']) ? [] : [{ Header: 'Sensor Install', filterMethod: (filter, row) => { if (filter.value === 'all') { @@ -505,7 +508,7 @@ class BGroup extends Component { ))} ) : null), - }, { + }], { Header: '# Projects', filterable: false, style: { textAlign: 'center' }, -- GitLab From 91be35027e5392da3645784e5af2651a7f4a1ceb Mon Sep 17 00:00:00 2001 From: Conrad Date: Thu, 1 Feb 2018 17:22:22 -0500 Subject: [PATCH 08/12] Add project breakdown for MOS users --- src/containers/BGroup/BGroup.js | 67 ++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index e811e712..b158d379 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -44,6 +44,7 @@ class BGroup extends Component { simulationLoading: false, simulationError: false, buildingIdProject: {}, + projectBreakdown: {}, contactAccounts: {}, contactParentAccounts: {}, contactNames: {}, @@ -79,6 +80,7 @@ class BGroup extends Component { nextProps.projects.projects.length > 0 && nextProps.projects.projects !== this.props.projects.project ) { + const projectBreakdown = {}; const buildingIdProject = nextProps.projects.projects.reduce( (acc, val) => { if (acc[val.building_id]) { @@ -86,10 +88,17 @@ class BGroup extends Component { } else { acc[val.building_id] = [val]; } + if (!(val.project_type in projectBreakdown)) { + projectBreakdown[val.project_type] = 0; + } + projectBreakdown[val.project_type] += 1; return acc; }, {} ); - this.setState({ buildingIdProject }); + this.setState({ + buildingIdProject, + projectBreakdown, + }); this.getContacts(nextProps.projects.projects); } } @@ -271,6 +280,58 @@ class BGroup extends Component { ); } + renderProjectTypeSummary = () => { + if ( + !this.props.user.permissions['view::bgroupProjectsSummary'] || + Object.keys(this.state.projectBreakdown).length === 0 + ) { + return null; + } + let numProjects = 0; + return ( +
= 0 ? '' : 'none', + marginRight: '20%', + marginLeft: '20%', + }} + > +
+

Project Type Summary

+ + + + + + + + + { + Object.keys(this.state.projectBreakdown).sort().map((key) => { + if (key === 'null') { + return null; + } + numProjects += this.state.projectBreakdown[key]; + return ( + + + + + ); + }) + } + + + + + +
Project TypeCount
{key}{this.state.projectBreakdown[key]}
Total{numProjects}
+
+
+ ); + } + renderDeleteBuildingButton = (id) => { if (this.props.bGroup.deleteBGroupBuildingLoading[id]) { return ( @@ -590,9 +651,11 @@ class BGroup extends Component { />
+
+ {this.renderProjectTypeSummary()}
= 0 ? '' : 'none' }}>
-
{this.state.numRows} rows
+
{this.state.numRows} buildings
-- GitLab From dc9d2348f9a92a15142778fe5a2b61fe75847ad4 Mon Sep 17 00:00:00 2001 From: Conrad Date: Fri, 2 Feb 2018 11:52:22 -0500 Subject: [PATCH 09/12] Tab the projects overview and buildings overview sections --- src/containers/BGroup/BGroup.js | 357 ++++++++++++++++++++------------ 1 file changed, 224 insertions(+), 133 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index b158d379..cb82d044 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -3,11 +3,12 @@ import { connect } from 'react-redux'; import { Link, browserHistory } from 'react-router'; import { bindActionCreators } from 'redux'; import PropTypes from 'prop-types'; -import { Button } from 'reactstrap'; +import { Button, Nav, NavItem, NavLink } from 'reactstrap'; import ReactTable from 'react-table'; import 'react-table/react-table.css'; import { Icon } from 'react-fa'; import ReactTooltip from 'react-tooltip'; +import Loading from '../../components/Loading'; import NavBar from '../../components/NavBar'; import { loadBGroupBuildings, @@ -44,13 +45,15 @@ class BGroup extends Component { simulationLoading: false, simulationError: false, buildingIdProject: {}, - projectBreakdown: {}, + projectTypeBreakdown: {}, + projectStatusBreakdown: {}, contactAccounts: {}, contactParentAccounts: {}, contactNames: {}, contactLoading: false, contactError: false, numRows: -1, + overviewTab: this.props.user.permissions['view::bgroupProjectsSummary'] ? 'projects' : 'buildings', } componentDidMount() { @@ -80,7 +83,8 @@ class BGroup extends Component { nextProps.projects.projects.length > 0 && nextProps.projects.projects !== this.props.projects.project ) { - const projectBreakdown = {}; + const projectTypeBreakdown = {}; + const projectStatusBreakdown = {}; const buildingIdProject = nextProps.projects.projects.reduce( (acc, val) => { if (acc[val.building_id]) { @@ -88,16 +92,21 @@ class BGroup extends Component { } else { acc[val.building_id] = [val]; } - if (!(val.project_type in projectBreakdown)) { - projectBreakdown[val.project_type] = 0; + if (!(val.project_type in projectTypeBreakdown)) { + projectTypeBreakdown[val.project_type] = 0; } - projectBreakdown[val.project_type] += 1; + if (!(val.state in projectStatusBreakdown)) { + projectStatusBreakdown[val.state] = 0; + } + projectTypeBreakdown[val.project_type] += 1; + projectStatusBreakdown[val.state] += 1; return acc; }, {} ); this.setState({ buildingIdProject, - projectBreakdown, + projectTypeBreakdown, + projectStatusBreakdown, }); this.getContacts(nextProps.projects.projects); } @@ -280,53 +289,80 @@ class BGroup extends Component { ); } - renderProjectTypeSummary = () => { + renderProjectSummary = () => { if ( !this.props.user.permissions['view::bgroupProjectsSummary'] || - Object.keys(this.state.projectBreakdown).length === 0 + Object.keys(this.state.projectTypeBreakdown).length === 0 ) { return null; } let numProjects = 0; return ( -
= 0 ? '' : 'none', - marginRight: '20%', - marginLeft: '20%', - }} - > -
-

Project Type Summary

- - - - - - - - - { - Object.keys(this.state.projectBreakdown).sort().map((key) => { - if (key === 'null') { - return null; - } - numProjects += this.state.projectBreakdown[key]; - return ( - - - - - ); - }) - } - - - - - -
Project TypeCount
{key}{this.state.projectBreakdown[key]}
Total{numProjects}
+
+
= 0 ? '' : 'none', + }} + > +
+

Project Type Summary

+ + + + + + + + + { + Object.keys(this.state.projectTypeBreakdown).sort().map((key) => { + if (key === 'null') { + return null; + } + numProjects += this.state.projectTypeBreakdown[key]; + return ( + + + + + ); + }) + } + + + + + +
Project TypeCount
{key}{this.state.projectTypeBreakdown[key]}
Total{numProjects}
+
+
+

Project Status Summary

+ + + + + + + + + { + Object.keys(this.state.projectStatusBreakdown).sort().map((key) => { + if (key === 'null') { + return null; + } + numProjects += this.state.projectStatusBreakdown[key]; + return ( + + + + + ); + }) + } + +
Project StatusCount
{key}{this.state.projectStatusBreakdown[key]}
+
); @@ -349,7 +385,7 @@ class BGroup extends Component { ); } - render() { + renderBuildingGroup = () => { let { bGroupBuildings } = this.props.bGroup; // A generic filter method that ensures that empty rows return false const genericFilterMethod = (filter, row) => ( @@ -629,103 +665,158 @@ class BGroup extends Component { val.contact_names = this.state.contactNames[val.building_id]; return val; }); - return ( -
- -
- View all groups -
-
-

{this.props.bGroup.bGroupDetail.name}

- {this.renderEditButton()} -
-
-
-
- - -
+
+
+
+ +
-
- {this.renderProjectTypeSummary()} -
= 0 ? '' : 'none' }}> -
-
{this.state.numRows} buildings
-
+
+
= 0 ? '' : 'none' }}> +
+
{this.state.numRows} buildings
-
-
- { this.reactTable = reactTable; }} - onFilteredChange={() => { - // Create a bounce function so as to not decrease the speed of the filter. - clearTimeout(this.updateNumRows); - this.updateNumRows = setTimeout( - () => { this.setState({ numRows: this.reactTable.state.sortedData.length }); }, - 100, - ); - }} - noDataText={this.props.bGroup.bGroupDetailLoading ? 'Loading...' : 'No data'} - SubComponent={row => { - const addresses = bGroupBuildings - .filter(i => i.building_id === row.original.building_id) - .reduce((acc, val) => val.address_list, '') - .split(','); - return ( -
- -
+
+
+
+ { this.reactTable = reactTable; }} + onFilteredChange={() => { + // Create a bounce function so as to not decrease the speed of the filter. + clearTimeout(this.updateNumRows); + this.updateNumRows = setTimeout( + () => { + this.setState({ + numRows: this.reactTable.state.sortedData.length, + }); + }, + 100, + ); + }} + noDataText={this.props.bGroup.bGroupDetailLoading ? 'Loading...' : 'No data'} + SubComponent={row => { + const addresses = bGroupBuildings + .filter(i => i.building_id === row.original.building_id) + .reduce((acc, val) => val.address_list, '') + .split(','); + return ( +
+ +
+
+

+ Address list{' '} + + + +

+
    + {addresses.map(i =>
  • {i}
  • )} +
+
+ {this.state.buildingIdProject[row.original.building_id] ? (

- Address list{' '} - - - + Project list

    - {addresses.map(i =>
  • {i}
  • )} + {this.state.buildingIdProject[row.original.building_id].map((i) => { + let spanStatus = 'pending'; + if (i.state === 'constructed') { + spanStatus = 'claimed'; + } else if (i.state === 'cancelled') { + spanStatus = 'rejected'; + } + return ( +
  • + { i.state } + {' '} - { i.project_type } + {' '} - {i.name} +
  • + ); + })}
- {this.state.buildingIdProject[row.original.building_id] ? ( -
-

- Project list -

-
    - {this.state.buildingIdProject[row.original.building_id].map((i) => { - let spanStatus = 'pending'; - if (i.state === 'constructed') { - spanStatus = 'claimed'; - } else if (i.state === 'cancelled') { - spanStatus = 'rejected'; - } - return ( -
  • - { i.state } - {' '} - { i.project_type } - {' '} - {i.name} -
  • - ); - })} -
-
- ) : null} -
+ ) : null}
- ); - }} - /> +
+ ); + }} + /> +
+
+
+ ); + } + + render() { + let content = ( + + ); + if (!this.props.bGroup.bGroupDetailLoading) { + switch (this.state.overviewTab) { + case 'projects': + if (!this.props.projects.loading) { + content = this.renderProjectSummary(); + } + break; + case 'buildings': + content = this.renderBuildingGroup(); + break; + default: + content = 'There was an error'; + } + } + + return ( +
+ +
+
+
+
+ View all groups + {' '} +

+ {this.props.bGroup.bGroupDetail.name} +

+
+ {this.renderEditButton()}
+ + {content}
); -- GitLab From f1ea8aaf5d646988cd9fdbe20fc66ac8c83226e4 Mon Sep 17 00:00:00 2001 From: Conrad Date: Fri, 2 Feb 2018 12:26:34 -0500 Subject: [PATCH 10/12] Switch to project stage --- src/containers/BGroup/BGroup.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index cb82d044..afcd3f9c 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -95,11 +95,11 @@ class BGroup extends Component { if (!(val.project_type in projectTypeBreakdown)) { projectTypeBreakdown[val.project_type] = 0; } - if (!(val.state in projectStatusBreakdown)) { - projectStatusBreakdown[val.state] = 0; + if (!(val.project_stage in projectStatusBreakdown)) { + projectStatusBreakdown[val.project_stage] = 0; } projectTypeBreakdown[val.project_type] += 1; - projectStatusBreakdown[val.state] += 1; + projectStatusBreakdown[val.project_stage] += 1; return acc; }, {} ); @@ -297,6 +297,7 @@ class BGroup extends Component { return null; } let numProjects = 0; + const stageOrder = ['Engaged', 'Out to Bid', 'In Construction', 'Complete', 'HPD Pipeline']; return (
-

Project Status Summary

+

Project Stage Summary

- + { - Object.keys(this.state.projectStatusBreakdown).sort().map((key) => { - if (key === 'null') { - return null; - } - numProjects += this.state.projectStatusBreakdown[key]; + stageOrder.map((key) => { return ( -- GitLab From fea2d17633e236a88b42e82f79405a0b8499f1f1 Mon Sep 17 00:00:00 2001 From: Conrad Date: Tue, 6 Feb 2018 12:24:28 -0500 Subject: [PATCH 11/12] Add test to BGroup --- src/containers/BGroup/BGroup.js | 2 +- src/containers/BGroup/BGroup.test.js | 45 ++++++++++++++++++++++++++++ src/containers/BGroup/reducer.js | 2 +- src/containers/Project/reducer.js | 2 +- src/containers/User/reducer.js | 2 +- 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/containers/BGroup/BGroup.test.js diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index afcd3f9c..417598aa 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -32,7 +32,7 @@ const UTILITY_TYPES = { }; /* eslint-disable no-param-reassign */ -class BGroup extends Component { +export class BGroup extends Component { state = { edit: false, utilityAccountsStatus: {}, diff --git a/src/containers/BGroup/BGroup.test.js b/src/containers/BGroup/BGroup.test.js new file mode 100644 index 00000000..1c1cb8e6 --- /dev/null +++ b/src/containers/BGroup/BGroup.test.js @@ -0,0 +1,45 @@ +import React from 'react'; +import ReactDOM from 'react-dom'; +import { BGroup } from './BGroup'; +import { initState as bGroupState } from './reducer'; +import { initState as projectState } from '../Project/reducer'; +import { initState as userState } from '../User/reducer'; + +class LocalStorageMock { + constructor() { + this.store = {}; + } + + clear() { + this.store = {}; + } + + getItem(key) { + return this.store[key] || null; + } + + setItem(key, value) { + this.store[key] = value.toString(); + } + + removeItem(key) { + delete this.store[key]; + } +} + +global.localStorage = new LocalStorageMock; // eslint-disable-line + +it('renders without crashing', () => { + const div = document.createElement('div'); + ReactDOM.render( + {}} + loadBGroupDetail={() => {}} + params={{ bGroupId: '' }} + />, + div, + ); +}); diff --git a/src/containers/BGroup/reducer.js b/src/containers/BGroup/reducer.js index 30dc95dc..7bf81845 100644 --- a/src/containers/BGroup/reducer.js +++ b/src/containers/BGroup/reducer.js @@ -22,7 +22,7 @@ import { DELETE_BGROUP_BUILDING_FAILED, } from './constants'; -const initState = { +export const initState = { // bgroup bGroupLoading: false, bGroupError: false, diff --git a/src/containers/Project/reducer.js b/src/containers/Project/reducer.js index 875ca7c8..10ee4934 100644 --- a/src/containers/Project/reducer.js +++ b/src/containers/Project/reducer.js @@ -11,7 +11,7 @@ import { FILTER_PROJECTS_FAILURE, } from './constants'; -const initState = { +export const initState = { type: 'name', term: '', projects: [], diff --git a/src/containers/User/reducer.js b/src/containers/User/reducer.js index 9bb411fb..7715ba03 100644 --- a/src/containers/User/reducer.js +++ b/src/containers/User/reducer.js @@ -19,7 +19,7 @@ const initUser = { permissions: {}, }; -const initState = { +export const initState = { ...initUser, loading: false, error: false, -- GitLab From ee98a25eab7c5a6076473216504ae7d482e9f376 Mon Sep 17 00:00:00 2001 From: Conrad Date: Tue, 6 Feb 2018 13:11:31 -0500 Subject: [PATCH 12/12] Seperate the bgroup project overview into a different component --- src/containers/BGroup/BGroup.js | 85 ++-------------- .../BGroup/BGroupProjectOverview.js | 96 +++++++++++++++++++ 2 files changed, 105 insertions(+), 76 deletions(-) create mode 100644 src/containers/BGroup/BGroupProjectOverview.js diff --git a/src/containers/BGroup/BGroup.js b/src/containers/BGroup/BGroup.js index 417598aa..5a0df2ea 100644 --- a/src/containers/BGroup/BGroup.js +++ b/src/containers/BGroup/BGroup.js @@ -17,6 +17,7 @@ import { deleteBuildingFromBGroup, deleteBGroup, } from './actions'; +import BGroupProjectOverview from './BGroupProjectOverview'; import completeProjectPropTypes from '../Project/propTypes'; import { loadProjects } from '../Project/actions'; import AddressSearch from '../../components/AddressSearch/AddressSearch'; @@ -290,79 +291,6 @@ export class BGroup extends Component { } renderProjectSummary = () => { - if ( - !this.props.user.permissions['view::bgroupProjectsSummary'] || - Object.keys(this.state.projectTypeBreakdown).length === 0 - ) { - return null; - } - let numProjects = 0; - const stageOrder = ['Engaged', 'Out to Bid', 'In Construction', 'Complete', 'HPD Pipeline']; - return ( -
-
= 0 ? '' : 'none', - }} - > -
-

Project Type Summary

-
Project StatusProject Stage Count
{key}
- - - - - - - - { - Object.keys(this.state.projectTypeBreakdown).sort().map((key) => { - if (key === 'null') { - return null; - } - numProjects += this.state.projectTypeBreakdown[key]; - return ( - - - - - ); - }) - } - - - - - -
Project TypeCount
{key}{this.state.projectTypeBreakdown[key]}
Total{numProjects}
-
-
-

Project Stage Summary

- - - - - - - - - { - stageOrder.map((key) => { - return ( - - - - - ); - }) - } - -
Project StageCount
{key}{this.state.projectStatusBreakdown[key]}
-
-
-
- ); } renderDeleteBuildingButton = (id) => { @@ -762,9 +690,14 @@ export class BGroup extends Component { if (!this.props.bGroup.bGroupDetailLoading) { switch (this.state.overviewTab) { case 'projects': - if (!this.props.projects.loading) { - content = this.renderProjectSummary(); - } + content = ( + + ); break; case 'buildings': content = this.renderBuildingGroup(); diff --git a/src/containers/BGroup/BGroupProjectOverview.js b/src/containers/BGroup/BGroupProjectOverview.js new file mode 100644 index 00000000..eccb35e9 --- /dev/null +++ b/src/containers/BGroup/BGroupProjectOverview.js @@ -0,0 +1,96 @@ +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; +import userPropTypes from '../User/propTypes'; +import completeProjectPropTypes from '../Project/propTypes'; +import Loading from '../../components/Loading'; + +export default class BGroupProjectOverview extends Component { + state = { }; + + render() { + const { + user, projects, + projectStatusBreakdown, + projectTypeBreakdown, + } = this.props; + if (projects.loading) { + return ; + } + if ( + !user.permissions['view::bgroupProjectsSummary'] || + Object.keys(projectTypeBreakdown).length === 0 + ) { + return null; + } + let numProjects = 0; + const stageOrder = ['Engaged', 'Out to Bid', 'In Construction', 'Complete', 'HPD Pipeline']; + return ( +
+
+
+

Project Type Summary

+ + + + + + + + + { + Object.keys(projectTypeBreakdown).sort().map((key) => { + if (key === 'null') { + return null; + } + numProjects += projectTypeBreakdown[key]; + return ( + + + + + ); + }) + } + + + + + +
Project TypeCount
{key}{projectTypeBreakdown[key]}
Total{numProjects}
+
+
+

Project Stage Summary

+ + + + + + + + + { + stageOrder.map((key) => { + return ( + + + + + ); + }) + } + +
Project StageCount
{key}{projectStatusBreakdown[key]}
+
+
+
+ ); + } +} + +BGroupProjectOverview.propTypes = { + user: userPropTypes, + projects: completeProjectPropTypes, + projectTypeBreakdown: PropTypes.object, // eslint-disable-line + projectStatusBreakdown: PropTypes.object, // eslint-disable-line +}; + -- GitLab