Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

set showAll as part of setFilter action

Jason Kent3821e25ce29b
diff --git a/web/js/components/sidebar/events-filter.js b/web/js/components/sidebar/events-filter.js
index cfb38bc8b..108943c61 100644
--- a/web/js/components/sidebar/events-filter.js
+++ b/web/js/components/sidebar/events-filter.js
@@ -8,7 +8,6 @@ import Switch from '../util/switch';
import Checkbox from '../util/checkbox';
import {
setEventsFilter as setEventsFilterAction,
- toggleListAll as toggleListAllAction,
} from '../../modules/natural-events/actions';
import util from '../../util/util';
import DateRangeSelector from '../date-selector/date-range-selector';
@@ -21,20 +20,18 @@ function EventsFilter (props) {
selectedEndDate,
setFilter,
closeModal,
- toggleListAll,
showAll,
} = props;
const [allNone, setAllNone] = useState(!!selectedCategories.length);
const [categories, setCategories] = useState(selectedCategories);
+ const [listAll, setListAll] = useState(showAll);
const parsedStartDate = selectedStartDate && new Date(moment(selectedStartDate).valueOf());
const parsedEndDate = selectedEndDate && new Date(moment(selectedEndDate).valueOf());
const [dateRange, setDateRange] = useState([parsedStartDate, parsedEndDate]);
const [startDate, endDate] = dateRange || [];
- const [listAll, setListAll] = useState(showAll);
-
const toggleCategory = (category) => {
const isActive = categories.some(({ id }) => id === category.id);
let newCategories;
@@ -49,10 +46,9 @@ function EventsFilter (props) {
const applyFilter = () => {
const start = startDate && util.toISOStringDate(startDate);
const end = endDate && util.toISOStringDate(endDate);
- setFilter(categories, start, end);
+ setFilter(categories, start, end, listAll);
if (showAll !== listAll) {
- toggleListAll();
- const event = showAll ? 'natural_events_show_all' : 'natural_events_current_view_only';
+ const event = listAll ? 'natural_events_show_all' : 'natural_events_current_view_only';
googleTagManager.pushEvent({ event });
}
closeModal();
@@ -66,9 +62,7 @@ function EventsFilter (props) {
}
setAllNone(!allNone);
};
-
const disableApply = !categories.length || !!(!startDate && endDate) || !!(!endDate && startDate);
-
const getDisableApplyMsg = () => {
let msg = '';
if (!startDate || !endDate) {
@@ -79,7 +73,6 @@ function EventsFilter (props) {
}
return msg;
};
-
const minDate = new Date('01-01-2000');
const maxDate = new Date();
@@ -161,7 +154,6 @@ EventsFilter.propTypes = {
selectedEndDate: PropTypes.string,
setFilter: PropTypes.func,
showAll: PropTypes.bool,
- toggleListAll: PropTypes.func,
};
const mapStateToProps = (state) => {
@@ -179,18 +171,16 @@ const mapStateToProps = (state) => {
};
const mapDispatchToProps = (dispatch) => ({
- setFilter: (categories, startDate, endDate) => {
+ setFilter: (categories, startDate, endDate, showAll) => {
dispatch(
setEventsFilterAction(
categories,
startDate,
endDate,
+ showAll,
),
);
},
- toggleListAll: () => {
- dispatch(toggleListAllAction());
- },
});
export default connect(mapStateToProps, mapDispatchToProps)(EventsFilter);
diff --git a/web/js/containers/sidebar/events.js b/web/js/containers/sidebar/events.js
index f62f8ece4..173b1b374 100644
--- a/web/js/containers/sidebar/events.js
+++ b/web/js/containers/sidebar/events.js
@@ -143,24 +143,28 @@ function Events(props) {
</div>
</Scrollbars>
- {eventLimitReach && (
- <div className="event-count">
- Showing the first
- {` ${eventsData ? eventsData.length : ''} `}
- events
- <FontAwesomeIcon id="filter-info-icon" icon="info-circle" />
- <UncontrolledTooltip
- placement="right"
- target="filter-info-icon"
- >
- <div>
- More than
- {` ${LIMIT_EVENT_REQUEST_COUNT} `}
- events matched the current filter criteria.
- </div>
- </UncontrolledTooltip>
- </div>
- )}
+ <div className="event-count">
+ {eventLimitReach && (
+ <>
+ <span>
+ Showing the first
+ {` ${eventsData ? eventsData.length : ''} `}
+ events
+ </span>
+ <FontAwesomeIcon id="filter-info-icon" icon="info-circle" />
+ <UncontrolledTooltip
+ placement="right"
+ target="filter-info-icon"
+ >
+ <div>
+ More than
+ {` ${LIMIT_EVENT_REQUEST_COUNT} `}
+ events matched the current filter criteria.
+ </div>
+ </UncontrolledTooltip>
+ </>
+ )}
+ </div>
{showInactiveEventAlert && (
<AlertUtil
diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.js
index 1cac163b9..791091609 100644
--- a/web/js/modules/natural-events/actions.js
+++ b/web/js/modules/natural-events/actions.js
@@ -8,10 +8,7 @@ import {
REQUEST_SOURCES,
SELECT_EVENT,
DESELECT_EVENT,
- SHOW_ALL_EVENTS,
SET_EVENTS_FILTER,
- ONLY_SHOW_VISIBLE,
- TOGGLE_SHOW_ALL,
FINISHED_ANIMATING_TO_EVENT,
} from './constants';
import { requestAction } from '../core/actions';
@@ -49,13 +46,7 @@ export function deselectEvent(id, date) {
};
}
-export function showAll() {
- return {
- type: SHOW_ALL_EVENTS,
- };
-}
-
-export function setEventsFilter(categories, startDate, endDate) {
+export function setEventsFilter(categories, startDate, endDate, showAll) {
return (dispatch, getState) => {
const { config, proj, events } = getState();
const { selectedCategories, selectedDates } = events;
@@ -63,31 +54,20 @@ export function setEventsFilter(categories, startDate, endDate) {
const requestUrl = getEventsRequestURL(baseUrl, startDate, endDate, categories, proj);
const sameCategories = lodashEqual(selectedCategories, categories);
const sameDates = lodashEqual(selectedDates, { start: startDate, end: endDate });
- if (sameCategories && sameDates) {
- return;
+ if (!sameCategories || !sameDates) {
+ dispatch(requestEvents(requestUrl));
}
- dispatch(requestEvents(requestUrl));
+
dispatch({
type: SET_EVENTS_FILTER,
categories,
startDate,
endDate,
+ showAll,
});
};
}
-export function toggleListAll() {
- return {
- type: TOGGLE_SHOW_ALL,
- };
-}
-
-export function onlyShowVisible() {
- return {
- type: ONLY_SHOW_VISIBLE,
- };
-}
-
export function selected() {
return {
type: FINISHED_ANIMATING_TO_EVENT,
diff --git a/web/js/modules/natural-events/constants.js b/web/js/modules/natural-events/constants.js
index c135c0e8f..36e4d8bfa 100644
--- a/web/js/modules/natural-events/constants.js
+++ b/web/js/modules/natural-events/constants.js
@@ -11,11 +11,8 @@ export const REQUEST_SOURCES_SUCCESS = 'EVENTS/REQUEST_SOURCES_SUCCESS';
export const SET_EVENTS_FILTER = 'EVENTS/SET_FILTER';
export const DESELECT_EVENT = 'EVENTS/DESELECT_EVENT';
export const SELECT_EVENT = 'EVENTS/SELECT_EVENT';
-export const SHOW_ALL_EVENTS = 'EVENTS/SHOW_ALL_EVENTS';
export const ADD_CATEGORY = 'EVENTS/ADD_CATEGORY';
export const REMOVE_CATEGORY = 'EVENTS/REMOVE_CATEGORY';
-export const ONLY_SHOW_VISIBLE = 'EVENTS/ONLY_SHOW_VISIBLE';
-export const TOGGLE_SHOW_ALL = 'EVENTS/TOGGLE_SHOW_ALL';
export const FINISHED_ANIMATING_TO_EVENT = 'EVENTS/FINISHED_ANIMATING_TO_EVENT';
export const LIMIT_EVENT_REQUEST_COUNT = 50;
diff --git a/web/js/modules/natural-events/reducers.js b/web/js/modules/natural-events/reducers.js
index 847ab1f9e..e442032d3 100644
--- a/web/js/modules/natural-events/reducers.js
+++ b/web/js/modules/natural-events/reducers.js
@@ -9,9 +9,6 @@ import {
SELECT_EVENT,
DESELECT_EVENT,
SET_EVENTS_FILTER,
- SHOW_ALL_EVENTS,
- ONLY_SHOW_VISIBLE,
- TOGGLE_SHOW_ALL,
FINISHED_ANIMATING_TO_EVENT,
} from './constants';
import { CHANGE_TAB as CHANGE_SIDEBAR_TAB } from '../sidebar/constants';
@@ -92,27 +89,13 @@ export function eventsReducer(state = eventsReducerState, action) {
case SET_EVENTS_FILTER:
return {
...state,
+ showAll: action.showAll,
selectedCategories: action.categories,
selectedDates: {
start: action.startDate,
end: action.endDate,
},
};
- case SHOW_ALL_EVENTS:
- return {
- ...state,
- showAll: true,
- };
- case TOGGLE_SHOW_ALL:
- return {
- ...state,
- showAll: !state.showAll,
- };
- case ONLY_SHOW_VISIBLE:
- return {
- ...state,
- showAll: false,
- };
case CHANGE_SIDEBAR_TAB: {
const isActive = action.activeTab === 'events';
if (isActive === state.active) return state;