Skip to content

Commit 28f84fe

Browse files
authored
Merge pull request #1144 from PADAS/ERA-9940
[ERA-9940] Exclude empty patrols for the web client
2 parents 3ad558e + 23fd55b commit 28f84fe

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is the web interface for EarthRanger. It is built with React (whose bootstr
44
### Licensing
55
This repository is open-sourced under the Apache 2.0 license. However, Mapbox GL, a required dependency, is closed-source. It is provided here in a "bring your own token" capacity; you may use and modify all EarthRanger-authored code herein, but will need to provide your own Mapbox access token, tied to your own Mapbox account.
66

7-
------------------
7+
-------------------
88

99
## Setting up for development
1010
To start developing within this repo, you need to have [Docker](https://www.docker.com/get-started), [Node](https://nodejs.org/), and [Yarn](https://yarnpkg.com/) installed. Once docker is up and running, `cd` into the root of this project repository and run the following command: `docker compose up --build`.

src/utils/patrol-filter.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@ export const calcPatrolFilterForRequest = (options = {}) => {
1212
const { data: { patrolFilter } } = store.getState();
1313
const { filter: { patrols_overlap_daterange } } = patrolFilter;
1414
const { params, format = 'string' } = options;
15-
const filterParams = merge({}, patrolFilter, params);
15+
16+
const filterParams = merge(
17+
{
18+
exclude_empty_patrols: true,
19+
},
20+
patrolFilter,
21+
params
22+
);
1623
delete filterParams._persist;
1724
// only apply current filter settings if it is modified, otherwise allow overlap
1825
filterParams.filter.patrols_overlap_daterange = isDateFilterModified(patrolFilter) ? patrols_overlap_daterange : true;
@@ -23,7 +30,7 @@ export const calcPatrolFilterForRequest = (options = {}) => {
2330

2431
export const isFilterModified = ({ status, filter: { patrol_type, text, tracked_by } }) => (
2532
!isEqual(INITIAL_FILTER_STATE.status, status)
26-
|| !isEqual(INITIAL_FILTER_STATE.filter.patrol_type, patrol_type)
27-
|| !isEqual(INITIAL_FILTER_STATE.filter.text, text)
28-
|| !isEqual(INITIAL_FILTER_STATE.filter.tracked_by, tracked_by)
33+
|| !isEqual(INITIAL_FILTER_STATE.filter.patrol_type, patrol_type)
34+
|| !isEqual(INITIAL_FILTER_STATE.filter.text, text)
35+
|| !isEqual(INITIAL_FILTER_STATE.filter.tracked_by, tracked_by)
2936
);

src/utils/patrol-filter.test.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import { INITIAL_FILTER_STATE } from '../ducks/patrol-filter';
2-
import { isFilterModified } from './patrol-filter';
2+
import { isFilterModified, calcPatrolFilterForRequest } from './patrol-filter';
33

44
describe('Patrol filter utils', () => {
5+
describe('calcPatrolFilterForRequest', () => {
6+
test('adds a constant exclude_empty_patrols=true param to all patrols API requests', () => {
7+
const value = calcPatrolFilterForRequest({ hello: false });
8+
9+
expect(value).toContain('exclude_empty_patrols=true');
10+
});
11+
});
12+
513
describe('isFilterModified', () => {
614
test('returns false if the filter has the default values', () => {
715
expect(isFilterModified(INITIAL_FILTER_STATE)).toBe(false);

0 commit comments

Comments
 (0)