diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.js index b9d68e99eb969e41241e11e5553840c240cab33f..3957098a2199d65ca244d176543ee607e7b07e28 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.js @@ -30,6 +30,9 @@ import {drawSelectionTable} from './parameters'; import {drawTimeSeriesGraph} from './time-series-graph'; import {drawTooltipCursorSlider} from './tooltip'; +import {getPreferredIVMethodID} from './selectors/time-series-data'; + + /* * Renders the hydrograph on the node element using the Redux store for state information. The siteno, latitude, and @@ -93,7 +96,6 @@ export const attachToNode = function(store, } else { store.dispatch(setSelectedDateRange('P7D')); } - store.dispatch(setSelectedIVMethodID(timeSeriesId)); } // Fetch waterwatch flood levels @@ -106,6 +108,9 @@ export const attachToNode = function(store, } Promise.all(fetchDataPromises).then(() => { showDataLoadingIndicator(false); + // selectedIVMethodID should be set regardless of whether we are showing only the graph but the preferred method ID + // can not be determined until the data is fetched so that is done here. + store.dispatch(setSelectedIVMethodID(timeSeriesId) || getPreferredIVMethodID(store.getState())); let graphContainer = nodeElem.select('.graph-container'); graphContainer.call(drawTimeSeriesGraph, store, siteno, agencyCode, sitename, showMLName, !showOnlyGraph); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js index 5e16f4269fdc7af2d503220a0adccc366f6d4c1a..a784d7f34806e9dbc16e733c0aad94b8cfed0b7f 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.test.js @@ -199,27 +199,6 @@ describe('monitoring-location/components/hydrograph module', () => { selectedIVMethodID: undefined }); }); - - it('With timeSeriesId set', () => { - attachToNode(store, graphNode, { - ...INITIAL_PARAMETERS, - timeSeriesId: '90649' - }); - expect(retrieveHydrographDataSpy).toHaveBeenCalledWith('11112222', { - parameterCode: '72019', - period: 'P7D', - startTime: null, - endTime: null, - loadCompare: undefined, - loadMedian: false - }); - expect(store.getState().hydrographState).toEqual({ - selectedParameterCode: '72019', - selectedDateRange: 'P7D', - showCompareIVData: undefined, - selectedIVMethodID: '90649' - }); - }); }); it('Should fetch the hydrograph parameters', () => {