diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.js index 2802aeb8be2bd8c868b0a506024aafd3ec0ec387..7ee637b1d3e4249cb028fc7b11946be32e098708 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/index.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.js @@ -3,14 +3,11 @@ */ import {select} from 'd3-selection'; import {DateTime} from 'luxon'; -import {createStructuredSelector} from 'reselect'; import config from 'ui/config.js'; -import {link} from 'ui/lib/d3-redux'; -import {sortedParameters} from 'ui/utils'; -import {drawWarningAlert, drawInfoAlert} from 'd3render/alerts'; +import {drawInfoAlert} from 'd3render/alerts'; import {drawLoadingIndicator} from 'd3render/loading-indicator'; //import {isPeriodWithinAcceptableRange, isPeriodCustom} from 'ml/iv-data-utils'; @@ -19,6 +16,7 @@ import {drawLoadingIndicator} from 'd3render/loading-indicator'; //import {hasAnyVariables, getCurrentVariableID, getCurrentParmCd, getVariables} from 'ml/selectors/time-series-selector'; import {retrieveHydrographData} from 'ml/store/hydrograph-data'; +import {retrieveHydrographParameters} from 'ml/store/hydrograph-parameters'; import {setSelectedParameterCode} from 'ml/store/hydrograph-state'; //import {Actions as ivTimeSeriesDataActions} from 'ml/store/instantaneous-value-time-series-data'; @@ -34,7 +32,7 @@ import {drawGraphBrush} from './graph-brush'; //import {drawGraphControls} from './graph-controls'; import {drawTimeSeriesLegend} from './legend'; import {drawMethodPicker} from './method-picker'; -//import {plotSeriesSelectTable} from './parameters'; +import {drawSelectionTable} from './parameters'; import {drawTimeSeriesGraph} from './time-series-graph'; import {drawTooltipCursorSlider} from './tooltip'; @@ -83,10 +81,15 @@ export const attachToNode = function(store, period: startDT && endDT ? null : period || 'P7D', startTime: DateTime.fromISO(startDT, {zone: config.locationTimeZone}), endTime: DateTime.fromISO(endDT, {zone: config.locationTimeZone}), - loadCompare: false, + loadCompare: compare, loadMedian: false })); + // if showing the controls, fetch the parameters + let fetchParameters; + if (!showOnlyGraph) { + fetchParameters = store.dispatch(retrieveHydrographParameters(siteno)); + } // Fetch waterwatch flood levels - TODO: consider only fetching when gage height is requested store.dispatch(floodDataActions.retrieveWaterwatchData(siteno)); @@ -129,16 +132,13 @@ export const attachToNode = function(store, */ // Set the parameter code explictly. We may eventually set this within the parameter selection table store.dispatch(setSelectedParameterCode(parameterCode)); - /* - //TODO: Find out why putting this before drawDataTable causes the tests to not work correctly - nodeElem.select('.select-time-series-container') - .call(link(store, plotSeriesSelectTable, createStructuredSelector({ - siteno: () => siteno, - availableParameterCodes: getAvailableParameterCodes, - lineSegmentsByParmCd: getLineSegmentsByParmCd('current', 'P7D'), - timeSeriesScalesByParmCd: getTimeSeriesScalesByParmCd('current', 'P7D', SPARK_LINE_DIM) - }), store)); + fetchParameters.then(() => { + nodeElem.select('.select-time-series-container') + .call(drawSelectionTable, store, siteno); + }); + + /* renderTimeSeriesUrlParams(store); */ } diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.js b/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.js index eba088b5a4c4ffacd82cf30851d00e42e7d342ea..afa8a3bd5f13a00d1ce157ca29c722399cab09c8 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/method-picker.js @@ -31,6 +31,9 @@ export const drawMethodPicker = function(elem, store, initialTimeSeriesId) { .call(link(store, function(elem, {methods}) { let selectedMethodID = getSelectedIVMethodID(store.getState()); elem.selectAll('option').remove(); + if (!methods) { + return; + } if (methods.length && (!selectedMethodID || !methods.find(method => method.methodID === selectedMethodID))) { // Set the selected method ID to the first one in the list diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.js b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.js index 430a97a4f68dd99fbe6fb4cf69a684cd8b0d0918..1b3d5c4e9935149b84313970da7a79b538265ebe 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/parameters.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/parameters.js @@ -1,116 +1,34 @@ // Required to initialize USWDS components after page load (WaterAlert ToolTips) import components from 'uswds/src/js/components'; -import {line} from 'd3-shape'; import {select} from 'd3-selection'; import config from 'ui/config'; +import {link} from 'ui/lib/d3-redux'; import {appendInfoTooltip} from 'd3render/info-tooltip'; -import {Actions} from 'ml/store/instantaneous-value-time-series-data'; +import {getInputsForRetrieval, getSelectedParameterCode} from 'ml/selectors/hydrograph-state-selector'; -import {MASK_DESC} from './selectors/drawing-data'; -import {SPARK_LINE_DIM, CIRCLE_RADIUS_SINGLE_PT} from './selectors/layout'; +import {setSelectedParameterCode} from 'ml/store/hydrograph-state'; +import {retrieveHydrographData} from 'ml/store/hydrograph-data'; -/** - * Draw a sparkline in a selected SVG element - * - * @param {Object} svgSelection - * @param {Array} of line segment Objects - seriesLineSegments - * @param {Object} scales - has x property for x scale and y property for y scale - */ -export const addSparkLine = function(svgSelection, {seriesLineSegments, scales}) { - if (seriesLineSegments.length === 0) { - return; - } - let spark = line() - .x(function(d) { - return scales.x(d.dateTime); - }) - .y(function(d) { - return scales.y(d.value); - }); - const seriesDataMasks = seriesLineSegments.map(x => x.classes.dataMask); - if (seriesDataMasks.includes(null)) { - for (const lineSegment of seriesLineSegments) { - if (lineSegment.classes.dataMask === null) { - if (lineSegment.points.length === 1) { - svgSelection.append('circle') - .data(lineSegment.points) - .classed('spark-point', true) - .attr('r', CIRCLE_RADIUS_SINGLE_PT/2) - .attr('cx', d => scales.x(d.dateTime)) - .attr('cy', d => scales.y(d.value)); - } else { - svgSelection.append('path') - .attr('d', spark(lineSegment.points)) - .classed('spark-line', true); - } - } - } - } else { - const centerElement = function(svgElement) { - const elementWidth = svgElement.node().getBoundingClientRect().width; - const xLocation = (SPARK_LINE_DIM.width - elementWidth) / 2; - svgElement.attr('x', xLocation); - }; - let svgText = svgSelection.append('text') - .attr('x', 0) - .attr('y', 0) - .classed('sparkline-text', true); - const maskDescs = seriesDataMasks.map(x => MASK_DESC[x.toLowerCase()]); - const maskDesc = maskDescs.length === 1 ? maskDescs[0] : 'Masked'; - const maskDescWords = maskDesc.split(' '); - - if (maskDescWords.length > 1) { - Array.from(maskDescWords.entries()).forEach(x => { - const yPosition = 15 + x[0]*12; - const maskText = x[1]; - let tspan = svgText.append('tspan') - .attr('x', 0) - .attr('y', yPosition) - .text(maskText); - centerElement(svgText); - centerElement(tspan); - }); - } else { - svgText.text(maskDesc) - .attr('y', '20'); - centerElement(svgText); - } - } -}; +import {getAvailableParameterCodes} from './selectors/parameter-data'; /** * Draws a table with clickable rows of time series parameter codes. Selecting * a row changes the active parameter code. - * @param {Object} elem d3 selection - * @param {String} siteno - * @param {Object} availableParameterCodes parameter metadata to display - * @param {Object} lineSegmentsByParmCd line segments for each parameter code - * @param {Object} timeSeriesScalesByParmCd scales for each parameter code */ -export const plotSeriesSelectTable = function(elem, - { - siteno, - availableParameterCodes, - lineSegmentsByParmCd, - timeSeriesScalesByParmCd - }, store) { - // Get the position of the scrolled window before removing it so it can be set to the same value. - const lastTable = elem.select('#select-time-series table'); - const scrollTop = lastTable.size() ? lastTable.property('scrollTop') : null; - - elem.select('#select-time-series').remove(); +export const drawSelectionTable = function(container, store, siteno) { + const parameterCodes = getAvailableParameterCodes(store.getState()); - if (!availableParameterCodes.length) { + if (!Object.keys(parameterCodes).length) { return; } - const columnHeaders = [' ', 'Parameter', 'Preview', '#', 'Period of Record', 'WaterAlert']; - const tableContainer = elem.append('div') + const columnHeaders = [' ', 'Parameter', 'Period of Record', 'WaterAlert']; + const tableContainer = container.append('div') .attr('id', 'select-time-series'); tableContainer.append('label') @@ -133,18 +51,23 @@ export const plotSeriesSelectTable = function(elem, table.append('tbody') .attr('class', 'usa-fieldset') .selectAll('tr') - .data(availableParameterCodes) + .data(Object.values(parameterCodes)) .enter().append('tr') .attr('id', d => `time-series-select-table-row-${d.parameterCode}`) .attr('ga-on', 'click') .attr('ga-event-category', 'selectTimeSeries') .attr('ga-event-action', (d) => `time-series-parmcd-${d.parameterCode}`) .attr('role', 'option') - .classed('selected', d => d.selected) - .attr('aria-selected', d => d.selected) + .call(link(store, (trElem, selectedParameterCode) => { + trElem + .classed('selected', d => d.parameterCode === selectedParameterCode) + .attr('aria-selected', d => d.parameterCode === selectedParameterCode); + }, getSelectedParameterCode)) .on('click', function(event, d) { - if (!d.selected) { - store.dispatch(Actions.updateIVCurrentVariableAndRetrieveTimeSeries(siteno, d.variableID)); + const thisClass = select(this).attr('class'); + if (!thisClass || !thisClass.includes('selected')) { + store.dispatch(setSelectedParameterCode(d.parameterCode)); + store.dispatch(retrieveHydrographData(siteno, getInputsForRetrieval(store.getState()))); } }) .call(tr => { @@ -154,8 +77,10 @@ export const plotSeriesSelectTable = function(elem, .attr('type', 'radio') .attr('name', 'param-select-radio-input') .attr('class', 'usa-radio__input') - .attr('value', d => `${d.variableID}`) - .property('checked', d => d.selected ? true : null); + .attr('value', d => `${d.parameterCode}`) + .call(link(store, (inputElem, selectedParameterCode) => { + inputElem.property('checked', d => d.parameterCode === selectedParameterCode ? true : null); + }, getSelectedParameterCode)); paramSelectCol.append('label') .attr('class', 'usa-radio__label'); const paramCdCol = tr.append('th') @@ -165,12 +90,6 @@ export const plotSeriesSelectTable = function(elem, .each(function(d) { appendInfoTooltip(select(this), `Parameter code: ${d.parameterCode}`); }); - tr.append('td') - .append('svg') - .attr('width', SPARK_LINE_DIM.width.toString()) - .attr('height', SPARK_LINE_DIM.height.toString()); - tr.append('td') - .text(param => param.timeSeriesCount); tr.append('td') .style('white-space', 'nowrap') .text(d => d.periodOfRecord ? @@ -199,19 +118,5 @@ export const plotSeriesSelectTable = function(elem, }); // Activate the USWDS toolTips for WaterAlert subscriptions - components.tooltip.on(elem.node()); - - table.property('scrollTop', scrollTop); - - table.selectAll('tbody svg').each(function(d) { - let selection = select(this); - const paramCd = d.parameterCode; - const lineSegments = lineSegmentsByParmCd[paramCd] ? lineSegmentsByParmCd[paramCd] : []; - for (const seriesLineSegments of lineSegments) { - selection.call(addSparkLine, { - seriesLineSegments: seriesLineSegments, - scales: timeSeriesScalesByParmCd[paramCd] - }); - } - }); + components.tooltip.on(container.node()); }; \ No newline at end of file diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/axes.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/axes.js index 4ce430b497239c7ee30eb0c86c0e02c8dab314cd..a4a59e06ff7f20fbf8d6fd579e0884552907b165 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/axes.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/axes.js @@ -74,7 +74,7 @@ export const getAxes = memoize(graphKind => createSelector( -layout.width + layout.margin.right ), layout: layout, - yTitle: parameter.unit + yTitle: parameter ? parameter.unit : '' }; } )); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.js index 201e03d5b94dc799028b3d6b796ac3dff5a05187..38585757a12bd72d73b675e9442c394a1bccd3c0 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/parameter-data.js @@ -4,8 +4,6 @@ import {createSelector} from 'reselect'; import config from 'ui/config'; import {sortedParameters} from 'ui/utils'; -import {getCurrentVariableID, getTimeSeries, getVariables} from 'ml/selectors/time-series-selector'; - /** * Returns a Redux selector function which returns an sorted array of metadata * for each available parameter code. Each object has the following properties: @@ -16,18 +14,15 @@ import {getCurrentVariableID, getTimeSeries, getVariables} from 'ml/selectors/ti * @prop {Number} timeSeriesCount - count of unique time series for this parameter */ export const getAvailableParameterCodes = createSelector( - getVariables, - getTimeSeries, - getCurrentVariableID, - (allVariables, timeSeries, currentVariableID) => { - if (!allVariables) { + (state) => state.hydrographParameters, + allParameters => { + if (!Object.keys(allParameters).length) { return []; } - const seriesList = Object.values(timeSeries); - return sortedParameters(allVariables) - .map((variable) => { - const parameterCode = variable.variableCode.value; + return sortedParameters(allParameters) + .map((parameter) => { + const parameterCode = parameter.parameterCode; const measuredParameterCode = parameterCode.replace(config.CALCULATED_TEMPERATURE_VARIABLE_CODE, ''); const isIVParameterCode = config.ivPeriodOfRecord && measuredParameterCode in config.ivPeriodOfRecord; const isGWParameterCode = config.gwPeriodOfRecord && measuredParameterCode in config.gwPeriodOfRecord; @@ -67,21 +62,14 @@ export const getAvailableParameterCodes = createSelector( } return { - variableID: variable.oid, - parameterCode: parameterCode, - description: variable.variableDescription, - selected: currentVariableID === variable.oid, - timeSeriesCount: seriesList.filter(ts => { - return ts.tsKey === 'current:P7D' && ts.variable === variable.oid; - }).length, - periodOfRecord: periodOfRecord, + ...parameter, + periodOfRecord, waterAlert: { hasWaterAlert, subscriptionParameterCode: hasWaterAlert ? measuredParameterCode : '', displayText: waterAlertDisplayText, tooltipText: waterAlertTooltipText } - }; }); } diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js index 0a481480afc58b7c745ebf46b059864547b3c35a..a67cbab7079fb4a99d351afe5aaa3e9bfe7676f3 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/scales.js @@ -121,7 +121,7 @@ export const getYScale = memoize(graphKind => createSelector( getPrimaryValueRange, getPrimaryParameter, (layout, yDomain, parameter) => { - return createYScale(parameter.parameterCode, yDomain, layout.height - (layout.margin.top + layout.margin.bottom)); + return createYScale(parameter ? parameter.parameterCode : '', yDomain, layout.height - (layout.margin.top + layout.margin.bottom)); } )); diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-lines.js b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-lines.js index d4bf180668cebf61ad3acabf1520a46c37e5d91e..b13ca1f4319abc3351c069898a8dd61951714ea9 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/time-series-lines.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/time-series-lines.js @@ -99,7 +99,7 @@ export const drawDataSegments = function(elem, {visible, currentMethodID, tsSegm }; container.selectAll(`#${elemId}`).remove(); - if (!visible) { + if (!visible || !tsSegmentsMap) { return; } const tsLineGroup = container diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js b/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js index 11f52e9ebe11d7174930605d40eba0d6bcc420f6..dee1d255db132a23309285f218ecdaff72376b7d 100644 --- a/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js +++ b/assets/src/scripts/monitoring-location/components/hydrograph/tooltip.js @@ -46,7 +46,7 @@ const createTooltipTextGroup = function(elem, { currentPoints, comparePoints, gwLevelPoint, - unitCode, + parameter, layout }, textGroup) { const adjustMarginOfTooltips = function(elem) { @@ -59,6 +59,7 @@ const createTooltipTextGroup = function(elem, { .attr('class', 'tooltip-text-group') .call(adjustMarginOfTooltips); } + const unitCode = parameter ? parameter.unit : ''; const currentTooltipData = Object.values(currentPoints).map((tsPoint) => { return getIVDataTooltipTextInfo(tsPoint, 'primary', unitCode); }); @@ -102,7 +103,7 @@ export const drawTooltipText = function(elem, store) { currentPoints: getIVDataCursorPoints('primary', 'current'), comparePoints: getIVDataCursorPoints('compare', 'prioryear'), gwLevelPoint: getGroundwaterLevelCursorPoint, - unitCode: state => getPrimaryParameter(state).unit, + parameter: getPrimaryParameter, layout: getMainLayout }))); }; diff --git a/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js b/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js index 8fbccf8b36d1a7d99b11d6136da855b47e3be5d6..177836eb77072423f354154c724d176ad6f17fb6 100644 --- a/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js +++ b/assets/src/scripts/monitoring-location/selectors/hydrograph-data-selector.js @@ -65,7 +65,7 @@ export const getPrimaryMethods = createSelector( getIVData('primary'), ivData => { if (!ivData) { - return null; + return []; } return Object.values(ivData.values).map(value => value.method); } diff --git a/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js b/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js index d2a978953734eb8249102cea8d693ff0b21a1964..81b3aebc722364374336615eff780ea1b8fb8c75 100644 --- a/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js +++ b/assets/src/scripts/monitoring-location/selectors/hydrograph-state-selector.js @@ -7,7 +7,7 @@ export const isMedianDataVisible = state => state.hydrographState.showMedianData export const getSelectedDateRange = state => state.hydrographState.selectedDateRange || null; export const getSelectedCustomTimeRange = state => state.hydrographState.selectedCustomTimeRange || null; -export const getSelectedParameterCode = state => state.hydrographState.selectedParameterCOde || null; +export const getSelectedParameterCode = state => state.hydrographState.selectedParameterCode || null; export const getSelectedIVMethodID = state => state.hydrographState.selectedIVMethodID || null; export const getGraphCursorOffset = state => state.hydrographState.graphCursorOffset || null; export const getGraphBrushOffset = state => state.hydrographState.graphBrushOffset || null; diff --git a/assets/src/scripts/monitoring-location/store/hydrograph-parameters.js b/assets/src/scripts/monitoring-location/store/hydrograph-parameters.js index 2e56098d7db72a0628e93bc4fc973fe8b849ed0e..1b990d69d0cb5ab4c98c60235d2c17e1dfc88a6a 100644 --- a/assets/src/scripts/monitoring-location/store/hydrograph-parameters.js +++ b/assets/src/scripts/monitoring-location/store/hydrograph-parameters.js @@ -4,8 +4,7 @@ import merge from 'lodash/merge'; import config from 'ui/config'; import {fetchGroundwaterLevels} from 'ui/web-services/groundwater-levels'; -import {fetchIVTimeSeries} from 'ui/web-services/instantaneous-values'; -import {fetchSiteStatistics} from 'ui/web-services/statistics-data'; +import {fetchTimeSeries} from 'ui/web-services/instantaneous-values'; import {getConvertedTemperatureParameter} from 'ml/iv-data-utils'; @@ -14,7 +13,7 @@ import {getConvertedTemperatureParameter} from 'ml/iv-data-utils'; * @param {Object} variables - keys are parameter codes. * @return {Object} - Redux action */ -export const updateHydrographParameters = function(parameters) { +const updateHydrographParameters = function(parameters) { return { type: 'UPDATE_HYDROGRAPH_PARAMETERS', parameters @@ -27,9 +26,9 @@ export const updateHydrographParameters = function(parameters) { */ export const retrieveHydrographParameters = function(siteno) { return function(dispatch) { - const fetchIVParameters = fetchIVTimeSeries({sites: [siteno]}).then(series => { + const fetchIVParameters = fetchTimeSeries({sites: [siteno]}).then(series => { return series.value.timeSeries.reduce((varsByPCode, ts) => { - const parameterCode = ts.variable.variableCode.value; + const parameterCode = ts.variable.variableCode[0].value; varsByPCode[parameterCode] = { parameterCode: parameterCode, name: ts.variable.variableName, @@ -44,15 +43,16 @@ export const retrieveHydrographParameters = function(siteno) { }) }; // If it is a celsius parameterCode, add a variable for calculated Fahrenheit. - if (parameterCode in config.TEMPERATURE_PARAMETERS.celsius) { + if (config.TEMPERATURE_PARAMETERS.celsius.includes(parameterCode)) { const fahrenheitParameter = getConvertedTemperatureParameter(varsByPCode[parameterCode]); varsByPCode[fahrenheitParameter.parameterCode] = fahrenheitParameter; } + return varsByPCode; }, {}); }); const fetchGWLevelParameters = fetchGroundwaterLevels({site: siteno}).then(series => { return series.value.timeSeries.reduce((varsByPCode, ts) => { - const parameterCode = ts.variable.variableCode.value; + const parameterCode = ts.variable.variableCode[0].value; varsByPCode[parameterCode] = { parameterCode: parameterCode, name: ts.variable.variableName, @@ -60,16 +60,17 @@ export const retrieveHydrographParameters = function(siteno) { unit: ts.variable.unit.unitCode, hasGWLevelsData: true }; + return varsByPCode; }, {}); }); - return Promise.all([fetchIVParameters, fetchGWLevelParameters]).then((ivVars, gwVars) => { + return Promise.all([fetchIVParameters, fetchGWLevelParameters]).then(([ivVars, gwVars]) => { const mergedVars = merge({}, gwVars, ivVars); dispatch(updateHydrographParameters(mergedVars)); }); }; }; -export const hydrographVariablesReducer = function(hydrographParameters={}, action) { +export const hydrographParametersReducer = function(hydrographParameters={}, action) { switch(action.type) { case 'UPDATE_HYDROGRAPH_PARAMETERS': { return { diff --git a/assets/src/scripts/monitoring-location/store/index.js b/assets/src/scripts/monitoring-location/store/index.js index 2050e1796059398a441c0da904d9e4de27f22937..8e169d5b5e1dad11f49a2e75426c6de935c02df6 100644 --- a/assets/src/scripts/monitoring-location/store/index.js +++ b/assets/src/scripts/monitoring-location/store/index.js @@ -7,6 +7,7 @@ import { floodDataReducer as floodData, floodStateReducer as floodState} from './flood-inundation'; import {hydrographDataReducer as hydrographData} from './hydrograph-data'; +import {hydrographParametersReducer as hydrographParameters} from './hydrograph-parameters'; import {hydrographStateReducer as hydrographState, INITIAL_STATE as HYDROGRAPH_INITIAL_STATE } from './hydrograph-state'; @@ -16,6 +17,7 @@ import {uiReducer as ui} from './ui-state'; const appReducer = combineReducers({ hydrographData, + hydrographParameters, hydrographState, dailyValueTimeSeriesData, floodData, @@ -32,6 +34,7 @@ const MIDDLEWARES = [thunk]; export const configureStore = function(initialState) { initialState = { hydrographData: {}, + hydrographParameters: {}, hydrographState: HYDROGRAPH_INITIAL_STATE, dailyValueTimeSeriesData: {}, floodData: { diff --git a/assets/src/scripts/utils.js b/assets/src/scripts/utils.js index 0405c1aa3f65cf4cc0e0b00b780484c7acbff3fd..d4917636f31befb1d50576cb95c2b1e3e0c0fb33 100644 --- a/assets/src/scripts/utils.js +++ b/assets/src/scripts/utils.js @@ -233,28 +233,28 @@ export const convertCelsiusToFahrenheit = function(celsius) { * @param {Array of variable Object} * @return {Array of variable Object} */ -export const sortedParameters = function(variables) { +export const sortedParameters = function(parameters) { const PARAM_PERTINENCE = { '00065': 0, '00060': 1, '72019': 2 }; - const dataVars = variables ? Object.values(variables) : []; + const allParameters = parameters ? Object.values(parameters) : []; const pertinentParmCds = Object.keys(PARAM_PERTINENCE); - const highPertinenceVars = dataVars.filter(x => pertinentParmCds.includes(x.variableCode.value)) + const highPertinenceVars = allParameters.filter(x => pertinentParmCds.includes(x.parameterCode)) .sort((a, b) => { - const aPertinence = PARAM_PERTINENCE[a.variableCode.value]; - const bPertinence = PARAM_PERTINENCE[b.variableCode.value]; + const aPertinence = PARAM_PERTINENCE[a.parameterCode]; + const bPertinence = PARAM_PERTINENCE[b.parameterCode]; if (aPertinence < bPertinence) { return -1; } else { return 1; } }); - const lowPertinenceVars = dataVars.filter(x => !pertinentParmCds.includes(x.variableCode.value)) + const lowPertinenceVars = allParameters.filter(x => !pertinentParmCds.includes(x.parameterCode)) .sort((a, b) => { - const aDesc = a.variableDescription.toLowerCase(); - const bDesc = b.variableDescription.toLowerCase(); + const aDesc = a.description.toLowerCase(); + const bDesc = b.description.toLowerCase(); if (aDesc < bDesc) { return -1; } else {