From beefeed92d54ebd39cc168833301ad3eab5f842f Mon Sep 17 00:00:00 2001 From: Conrad Date: Tue, 29 May 2018 12:23:45 -0400 Subject: [PATCH] Add event location for events that have locations --- .../BuildingEvents/BuildingEventsTable.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/containers/BuildingEvents/BuildingEventsTable.js b/src/containers/BuildingEvents/BuildingEventsTable.js index ba278892..58a58f8f 100644 --- a/src/containers/BuildingEvents/BuildingEventsTable.js +++ b/src/containers/BuildingEvents/BuildingEventsTable.js @@ -17,6 +17,7 @@ class BuildingEventsTable extends Component { eventsOpen: false, // The ARN for the email emailSubArn: null, + spaceIdToDescription: {}, } componentDidMount() { @@ -34,6 +35,34 @@ class BuildingEventsTable extends Component { if (nextProps === this.props) { return; } + if ( + nextProps.buildingArea.apartments.length > 0 || + nextProps.buildingArea.commonAreas.length > 0 || + nextProps.buildingArea.serviceAreas.length > 0 + ) { + let spaceIdToDescription = nextProps.buildingArea.apartments.reduce((acc, apartment) => { + apartment.spaces.map((space) => { + acc[space.id] = `Apartment ${apartment.number} ${space.description}`; + return space; + }); + return acc; + }, {}); + spaceIdToDescription = nextProps.buildingArea.commonAreas.reduce((acc, commonArea) => { + commonArea.spaces.map((space) => { + acc[space.id] = `Common Area ${space.description}`; + return space; + }); + return acc; + }, spaceIdToDescription); + spaceIdToDescription = nextProps.buildingArea.serviceAreas.reduce((acc, serviceArea) => { + serviceArea.spaces.map((space) => { + acc[space.id] = `Service Area ${space.description}`; + return space; + }); + return acc; + }, spaceIdToDescription); + this.setState({ spaceIdToDescription }); + } /* eslint-disable no-param-reassign */ if ( nextProps.events.alertSubscribersData !== @@ -150,6 +179,10 @@ class BuildingEventsTable extends Component { Timestamp Event Name + {Object.keys(this.state.spaceIdToDescription).length > 0 ? + Event Location : + null + } Indoor Temperature Outdoor Temperature @@ -159,6 +192,10 @@ class BuildingEventsTable extends Component { {event.ts} {event.type_description} + {Object.keys(this.state.spaceIdToDescription).length > 0 ? + {this.state.spaceIdToDescription[event.space_id]} : + null + } {event.event_specific.indoor_temperature.toFixed(2)} °F {event.event_specific.outdoor_temperature.toFixed(2)} °F @@ -215,6 +252,7 @@ BuildingEventsTable.propTypes = { loadAlertSubscribers: PropTypes.func, events: PropTypes.object, // eslint-disable-line limit: PropTypes.number, + buildingArea: PropTypes.object, // eslint-disable-line }; BuildingEventsTable.defaultProps = { @@ -223,6 +261,7 @@ BuildingEventsTable.defaultProps = { const mapStateToProps = state => ({ events: state.events, + buildingArea: state.buildingArea, }); const mapDispatchToProps = dispatch => ( -- GitLab