diff --git a/assets/src/scripts/components/hydrograph/index.js b/assets/src/scripts/components/hydrograph/index.js index be14dec2aeafd128c0c623ed10e2211412377ba5..1a05008a8cfd34b6665b8d3917cd9e8b1ef5eafc 100644 --- a/assets/src/scripts/components/hydrograph/index.js +++ b/assets/src/scripts/components/hydrograph/index.js @@ -31,7 +31,7 @@ const { const {createTooltipFocus, createTooltipText} = require('./tooltip'); const {coerceStatisticalSeries} = require('./statistics'); -const {getCurrentDateRange, getTimeSeriesCollections, isLoadingTS} = require('../../selectors/timeSeriesSelector'); +const {getCurrentDateRange, getTimeSeriesCollection, isLoadingTS} = require('../../selectors/timeSeriesSelector'); const drawMessage = function (elem, message) { @@ -385,9 +385,8 @@ const dateRangeControls = function (elem, siteno) { const container = elem.insert('div', ':nth-child(2)') .attr('id', 'ts-daterange-select-container') - .attr('hidden', true) - .call(link(function(div, showControls) { - div.attr('hidden', showControls ? null : true); + .call(link(function(container, showControls) { + container.attr('hidden', showControls ? null : true); }, hasTimeSeriesWithPoints('current', 'P7D'))); const listContainer = container.append('ul') .attr('class', 'usa-fieldset-inputs usa-unstyled-list'); @@ -444,7 +443,7 @@ const attachToNode = function (store, node, {siteno, parameter, compare, cursorO select(node) .call(provide(store)); select(node) - .call(link(noDataAlert, getTimeSeriesCollections('current', 'P7D'))); + .call(link(noDataAlert, getTimeSeriesCollection('current', 'P7D'))); select(node).select('.loading-indicator-container') .call(link(loadingIndicator, createStructuredSelector({ showLoadingIndicator: isLoadingTS('current', 'P7D'), diff --git a/assets/src/scripts/selectors/timeSeriesSelector.js b/assets/src/scripts/selectors/timeSeriesSelector.js index cc5009c6e3caddcb834cb5fa8517cab1a22afa2c..d16228817b62649044b60d956d08830424b63f39 100644 --- a/assets/src/scripts/selectors/timeSeriesSelector.js +++ b/assets/src/scripts/selectors/timeSeriesSelector.js @@ -10,6 +10,8 @@ export const getMethods = state => state.series.methods ? state.series.methods : export const getQueryInfo = state => state.series.queryInfo || {}; +export const getRequests = state => state.series.requests || {}; + export const getCurrentVariableID = state => state.timeSeriesState.currentVariableID; @@ -47,7 +49,7 @@ export const getCurrentParmCd = createSelector( /* * @param {String} - Time series key: current, compre or median * @param {String} or null period = date range of interest as an ISO-8601 duration. If null the currentDateRange is used - * @param {String} or null parmCD - if null the parmCd of the current variable is used. + * @param {String} or null parmCd - if null the parmCd of the current variable is used. * @return {String} or null - Return the the request key for the request object * selected variable. */ @@ -70,7 +72,7 @@ export const getTsRequestKey = memoize((tsKey, period, parmCd) => createSelector /* * @param {String} tsKey - current, compare, or median * @param {String} or null period - date range of interest specified as an ISO-8601 duration. If null, P7D is assumed - * @param {String} or null parmCD - Only need to specify if period is something other than P7D or null + * @param {String} or null parmCd - Only need to specify if period is something other than P7D or null * @return {Boolean} - True if the time series with key, period, and parmCd has already been requested * */ @@ -84,7 +86,7 @@ export const hasTimeSeries = memoize((tsKey, period, parmCd) => createSelector( /* * @param {String} tsKey - current, compare, or median * @param {String} or null period - date range of interest specified as an ISO-8601 duration. If null, P7D is assumed - * @param {String} or null parmCD - Only need to specify if period is something other than P7D or null + * @param {String} or null parmCd - Only need to specify if period is something other than P7D or null * @return {Object} containing the queryInfo for a specific timeseries request or the empty object if that request * is not in the state * */ @@ -97,7 +99,7 @@ export const getTsQueryInfo = memoize((tsKey, period, parmCd) => createSelector /* * @param {String} tsKey - current, compare, or median * @param {String} or null period - date range of interest specified as an ISO-8601 duration. If null, P7D is assumed - * @param {String} or null parmCD - Only need to specify if period is something other than P7D or null + * @param {String} or null parmCd - Only need to specify if period is something other than P7D or null * @return {Object} with start and end {Date} properties that contain the range of the data requested or null * if the store does not contain a query for the tsKey request * */ @@ -128,20 +130,40 @@ export const getRequestTimeRange = memoize((tsKey, period, parmCd) => createSele } )); +/* + * @param {String} tsKey - current, compare, or median + * @param {String} or null period - date range of interest specified as an ISO-8601 duration. If null, P7D is assumed + * @param {String} or null parmCd - Only need to specify if period is something other than P7D or null + * @return {Boolean} - True if the tsRequestKey for tsKey, period, and parmCD is being loaded. + * */ export const isLoadingTS = memoize((tsKey, period, parmCd) => createSelector( getLoadingTsKeys, getTsRequestKey(tsKey, period, parmCd), (loadingTSKeys, tsRequestKey) => loadingTSKeys.includes(tsRequestKey) )); -export const getTimeSeriesCollections = memoize((tsKey, period, parmCd) => createSelector( + +/* + * @param {String} tsKey - current, compare, or median + * @param {String} or null period - date range of interest specified as an ISO-8601 duration. If null, P7D is assumed + * @param {String} or null parmCd - Only need to specify if period is something other than P7D or null + * @return {Object} the requests object for the time series identified by tsKey, period, and parmCd or the empty object + * if none exists + */ +export const getTsRequest = memoize((tsKey, period, parmCd) => createSelector( + getRequests, getTsRequestKey(tsKey, period, parmCd), - state => state.series, - (tsRequestKey, series) => { - if (series && series.requests && series.requests[tsRequestKey]) { - return series.requests[tsRequestKey].timeSeriesCollections; - } else { - return null; - } - } -)) + (requests, tsRequestKey) => requests[tsRequestKey] || {} +)); + +/* + * @param {String} tsKey - current, compare, or median + * @param {String} or null period - date range of interest specified as an ISO-8601 duration. If null, P7D is assumed + * @param {String} or null parmCd - Only need to specify if period is something other than P7D or null + * @return {Object} the timeSeriesCollection for the time series identified by tsKey, period, and parmCd or null if + * none exists + */ +export const getTimeSeriesCollection = memoize((tsKey, period, parmCd) => createSelector( + getTsRequest(tsKey, period, parmCd), + (tsRequest) => tsRequest.timeSeriesCollection || null +)); diff --git a/assets/src/scripts/selectors/timeSeriesSelector.spec.js b/assets/src/scripts/selectors/timeSeriesSelector.spec.js index 0e2ffc8f0adf25b5fe0e6d896ba2d21e3f6d97b3..1036fcf62185d94c345b11ef5b830b93db01f5bc 100644 --- a/assets/src/scripts/selectors/timeSeriesSelector.spec.js +++ b/assets/src/scripts/selectors/timeSeriesSelector.spec.js @@ -1,7 +1,8 @@ -const { getVariables, getCurrentVariableID, getCurrentDateRange, getCurrentVariable, getQueryInfo, getCurrentParmCd, - hasTimeSeries, getTsRequestKey, getTsQueryInfo, getRequestTimeRange } = require('./timeSeriesSelector'); +const { getVariables, getCurrentVariableID, getCurrentDateRange, getCurrentVariable, getQueryInfo, getRequests, + getCurrentParmCd, hasTimeSeries, getTsRequestKey, getTsQueryInfo, getRequestTimeRange, isLoadingTs, getTsRequest, + getTimeSeriesCollection } = require('./timeSeriesSelector'); -describe('timeSeriesSelector', () => { +fdescribe('timeSeriesSelector', () => { const TEST_VARS = { '45807042': { variableCode: { @@ -55,6 +56,18 @@ describe('timeSeriesSelector', () => { }); }); + describe('getRequests', () => { + it('Empty object if series is empty', () => { + expect(getRequests({ + series: {} + })).toEqual({}); + }); + + it('Requests object if in state', () => { + + }) + }); + describe('getCurrentVariableID', () => { it('Return the current variable ID', () => { expect(getCurrentVariableID({