@@ -34,7 +40,8 @@ export class MapPanel extends React.Component {
const mapStateToProps = state => ( {
error: state.map.error,
- isLoading: state.map.isLoading
+ isLoading: state.map.isLoading,
+ showWarning: hasFiltersEnabled( state.query )
} )
export default connect( mapStateToProps )( MapPanel )
diff --git a/src/PerCapita.jsx b/src/PerCapita.jsx
index e1a7983ec..ad7b3026b 100644
--- a/src/PerCapita.jsx
+++ b/src/PerCapita.jsx
@@ -1,7 +1,8 @@
import './PerCapita.less'
-import { GEO_NORM_NONE, GEO_NORM_PER1000, knownFilters } from './constants'
+import { GEO_NORM_NONE, GEO_NORM_PER1000 } from './constants'
import { connect } from 'react-redux'
import { dataNormalizationChanged } from './actions/map';
+import { hasFiltersEnabled } from './utils'
import React from 'react'
@@ -45,26 +46,9 @@ export class PerCapita extends React.Component {
}
}
-/**
- * helper function to determine if we have any filters selected so we can
- * disable the Per 1000 Complaints button
- * @param {object} query contains values for the filters, etc
- * @returns {boolean} are we enabling the perCap
- */
-export const validatePerCapFilters = query => {
- const keys = []
- for ( let i = 0; i < knownFilters.length; i++ ) {
- const filter = knownFilters[i]
- if ( query[filter] && query[filter].length ) {
- keys.push( filter )
- }
- }
- return keys.length === 0
-}
-
export const mapStateToProps = state => ( {
dataNormalization: state.map.dataNormalization,
- enablePer1000: validatePerCapFilters( state.query )
+ enablePer1000: !hasFiltersEnabled( state.query )
} );
export const mapDispatchToProps = dispatch => ( {
diff --git a/src/__tests__/PerCapita.spec.jsx b/src/__tests__/PerCapita.spec.jsx
index 3b089af05..0f0fe0429 100644
--- a/src/__tests__/PerCapita.spec.jsx
+++ b/src/__tests__/PerCapita.spec.jsx
@@ -90,29 +90,5 @@ describe( 'component: PerCapita', () => {
enablePer1000: true
} )
} )
- } )
-
- describe( 'validatePerCapFilters', () => {
- it( 'handles no filters', () => {
- const query = {
- date: {},
- bogus: {},
- product: []
- }
-
- expect( validatePerCapFilters( query ) ).toBeTruthy()
- } )
-
- it( 'handles some filters', () => {
- const query = {
- date: {},
- bogus: {},
- product: [ { name: 'foo', value: 123 } ]
- }
-
- expect( validatePerCapFilters( query ) ).toBeFalsy()
- } )
- } )
-
-
+ }
} )
diff --git a/src/__tests__/utils.spec.jsx b/src/__tests__/utils.spec.jsx
index 0a1fff05f..767fef73c 100644
--- a/src/__tests__/utils.spec.jsx
+++ b/src/__tests__/utils.spec.jsx
@@ -1,10 +1,11 @@
import {
ariaReadoutNumbers, calculateDateInterval, clamp, coalesce, debounce,
- getFullUrl, hashCode, shortIsoFormat
+ getFullUrl, hasFiltersEnabled, hashCode, shortIsoFormat
} from '../utils'
import { DATE_RANGE_MIN } from '../constants'
import React from 'react'
import moment from 'moment'
+import { validatePerCapFilters } from '../PerCapita'
describe('module::utils', () => {
describe( 'ariaReadoutNumbers', () => {
@@ -149,5 +150,27 @@ describe('module::utils', () => {
expect( actual ).toEqual( uri )
} );
} );
+
+ describe( 'hasFiltersEnabled', () => {
+ it( 'handles no filters', () => {
+ const query = {
+ date: {},
+ bogus: {},
+ product: []
+ }
+
+ expect( hasFiltersEnabled( query ) ).toBeFalsy()
+ } )
+
+ it( 'handles some filters', () => {
+ const query = {
+ date: {},
+ bogus: {},
+ product: [ { name: 'foo', value: 123 } ]
+ }
+
+ expect( hasFiltersEnabled( query ) ).toBeTruthy()
+ } )
+ } )
})
diff --git a/src/utils.jsx b/src/utils.jsx
index 679834175..f45b96e31 100644
--- a/src/utils.jsx
+++ b/src/utils.jsx
@@ -1,4 +1,4 @@
-import { DATE_RANGE_MIN, SLUG_SEPARATOR } from './constants'
+import { DATE_RANGE_MIN, knownFilters, SLUG_SEPARATOR } from './constants'
import moment from 'moment'
/**
@@ -107,6 +107,23 @@ export function hashCode( someString ) {
return hash
}
+/**
+ * helper function to determine if we have any filters selected so we can
+ * disable the Per 1000 Complaints button
+ * @param {object} query contains values for the filters, etc
+ * @returns {boolean} are we enabling the perCap
+ */
+export function hasFiltersEnabled( query ) {
+ const keys = []
+ for ( let i = 0; i < knownFilters.length; i++ ) {
+ const filter = knownFilters[i]
+ if ( query[filter] && query[filter].length ) {
+ keys.push( filter )
+ }
+ }
+ return keys.length > 0
+}
+
/**
* Creates a hash from an object
*
From aaa3a1960d9f205e9b6161212f767991a13f00ba Mon Sep 17 00:00:00 2001
From: Richard Dinh
Date: Thu, 26 Mar 2020 12:46:48 -0400
Subject: [PATCH 07/11] update test coverage
---
src/__tests__/MapPanel.spec.jsx | 6 ++-
src/__tests__/PerCapita.spec.jsx | 2 +-
.../__snapshots__/MapPanel.spec.jsx.snap | 48 ++++++++++++++++++-
3 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/src/__tests__/MapPanel.spec.jsx b/src/__tests__/MapPanel.spec.jsx
index 468fe2f93..939413386 100644
--- a/src/__tests__/MapPanel.spec.jsx
+++ b/src/__tests__/MapPanel.spec.jsx
@@ -21,12 +21,16 @@ function setupSnapshot( printMode ) {
total: items.length
},
map: {
+ product: [],
state: []
},
query: {
from: 0,
size: 10,
- tab: MODE_MAP
+ tab: MODE_MAP,
+ product: [
+ { name: 'foo' }
+ ]
},
results: {
items
diff --git a/src/__tests__/PerCapita.spec.jsx b/src/__tests__/PerCapita.spec.jsx
index 0f0fe0429..2273893fa 100644
--- a/src/__tests__/PerCapita.spec.jsx
+++ b/src/__tests__/PerCapita.spec.jsx
@@ -90,5 +90,5 @@ describe( 'component: PerCapita', () => {
enablePer1000: true
} )
} )
- }
+ } )
} )
diff --git a/src/__tests__/__snapshots__/MapPanel.spec.jsx.snap b/src/__tests__/__snapshots__/MapPanel.spec.jsx.snap
index 69435fe23..7402af954 100644
--- a/src/__tests__/__snapshots__/MapPanel.spec.jsx.snap
+++ b/src/__tests__/__snapshots__/MapPanel.spec.jsx.snap
@@ -37,6 +37,28 @@ exports[`component:MapPanel renders Print without crashing 1`] = `
+
+
+
+
+ Due to your filter selections, the "Complaints per 1,000" option has been disabled
+
+
+
@@ -99,7 +121,7 @@ exports[`component:MapPanel renders Print without crashing 1`] = `
Complaints
Complaints per 1,000 population
@@ -192,6 +214,28 @@ exports[`component:MapPanel renders without crashing 1`] = `
+
+
+
+
+ Due to your filter selections, the "Complaints per 1,000" option has been disabled
+
+
+
@@ -254,7 +298,7 @@ exports[`component:MapPanel renders without crashing 1`] = `
Complaints
Complaints per 1,000 population
From 425d6a02281ba201b3fe0f15e29704a3f42e24b6 Mon Sep 17 00:00:00 2001
From: Richard Dinh
Date: Thu, 26 Mar 2020 13:05:38 -0400
Subject: [PATCH 08/11] update text to use smart quotes
---
src/MapPanel.jsx | 4 ++--
src/__tests__/__snapshots__/MapPanel.spec.jsx.snap | 4 ++--
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/MapPanel.jsx b/src/MapPanel.jsx
index 3747ebb99..441b54bcb 100644
--- a/src/MapPanel.jsx
+++ b/src/MapPanel.jsx
@@ -12,8 +12,8 @@ import RowChart from './RowChart'
import TileChartMap from './TileChartMap'
import Warning from './Warning'
-const WARNING_MESSAGE = 'Due to your filter selections, the "Complaints per ' +
- '1,000" option has been disabled'
+const WARNING_MESSAGE = 'Due to your filter selections, the “Complaints per' +
+ ' 1,000” option has been disabled'
export class MapPanel extends React.Component {
render() {
diff --git a/src/__tests__/__snapshots__/MapPanel.spec.jsx.snap b/src/__tests__/__snapshots__/MapPanel.spec.jsx.snap
index 7402af954..9eda88e70 100644
--- a/src/__tests__/__snapshots__/MapPanel.spec.jsx.snap
+++ b/src/__tests__/__snapshots__/MapPanel.spec.jsx.snap
@@ -55,7 +55,7 @@ exports[`component:MapPanel renders Print without crashing 1`] = `
- Due to your filter selections, the "Complaints per 1,000" option has been disabled
+ Due to your filter selections, the “Complaints per 1,000” option has been disabled
- Due to your filter selections, the "Complaints per 1,000" option has been disabled
+ Due to your filter selections, the “Complaints per 1,000” option has been disabled