@@ -6,6 +6,7 @@ import { connect } from 'react-redux';
66import { withStyles } from '@material-ui/core/styles' ;
77import axios from 'axios' ;
88import { getDataRequest , getDataRequestSuccess , updateDateRanges } from '@reducers/data' ;
9+ import { updateStartDate , updateEndDate , updateNcId , updateRequestTypes } from '@reducers/filters'
910import { updateMapPosition } from '@reducers/ui' ;
1011import { trackMapExport } from '@reducers/analytics' ;
1112import { INTERNAL_DATE_SPEC } from '../common/CONSTANTS' ;
@@ -41,9 +42,12 @@ class MapContainer extends React.Component {
4142 // converted and stored in the Redux store.
4243 this . rawRequests = [ ] ;
4344 this . isSubscribed = null ;
45+
46+ this . initialState = props . initialState
4447 }
4548
46- componentDidMount ( ) {
49+ componentDidMount ( props ) {
50+ this . processSearchParams ( )
4751 this . isSubscribed = true ;
4852 this . setData ( ) ;
4953 }
@@ -65,6 +69,31 @@ class MapContainer extends React.Component {
6569 this . isSubscribed = false ;
6670 }
6771
72+
73+ processSearchParams = ( ) => {
74+ // Dispatch to edit Redux store with url search params
75+ const { dispatchUpdateStartDate, dispatchUpdateEndDate, dispatchUpdateTypesFilter } = this . props ;
76+
77+ // Filter requests on time
78+ const dateFormat = 'YYYY-MM-DD' ;
79+ // TODO: Check if endDate > startDate
80+ if ( moment ( this . initialState . startDate , 'YYYY-MM-DD' , true ) . isValid ( ) && moment ( this . initialState . endDate , 'YYYY-MM-DD' , true ) . isValid ( ) ) {
81+ const formattedStart = moment ( this . initialState . startDate ) . format ( dateFormat ) ;
82+ const formattedEnd = moment ( this . initialState . endDate ) . format ( dateFormat ) ;
83+ if ( formattedStart <= formattedEnd ) {
84+ dispatchUpdateStartDate ( formattedStart ) ;
85+ dispatchUpdateEndDate ( formattedEnd ) ;
86+ }
87+ }
88+
89+ for ( let request_id = 1 ; request_id < 13 ; request_id ++ ) {
90+ if ( this . initialState [ `rtId${ request_id } ` ] == 'false' ) {
91+ dispatchUpdateTypesFilter ( request_id ) ;
92+ }
93+ }
94+
95+ }
96+
6897 /**
6998 * Returns the non-overlapping date ranges of A before and after B.
7099 * @param {string } startA The start date of range A in INTERNAL_DATE_SPEC format.
@@ -301,6 +330,7 @@ class MapContainer extends React.Component {
301330 updatePosition = { updatePosition }
302331 exportMap = { exportMap }
303332 selectedTypes = { selectedTypes }
333+ initialState = { this . initialState }
304334 />
305335 < CookieNotice />
306336 { isMapLoading && < img style = { { width :window . innerWidth , height : 16 , position :'absolute' } } src = { gif } /> }
@@ -328,6 +358,10 @@ const mapDispatchToProps = dispatch => ({
328358 getDataRedux : ( ) => dispatch ( getDataRequest ( ) ) ,
329359 getDataSuccess : data => dispatch ( getDataRequestSuccess ( data ) ) ,
330360 updateDateRangesWithRequests : dateRanges => dispatch ( updateDateRanges ( dateRanges ) ) ,
361+ dispatchUpdateStartDate : startDate => dispatch ( updateStartDate ( startDate ) ) ,
362+ dispatchUpdateEndDate : endDate => dispatch ( updateEndDate ( endDate ) ) ,
363+ dispatchUpdateNcId : id => dispatch ( updateNcId ( id ) ) ,
364+ dispatchUpdateTypesFilter : type => dispatch ( updateRequestTypes ( type ) )
331365} ) ;
332366
333367MapContainer . propTypes = { } ;
0 commit comments