From 2a93e96766e08f4f0dde85457c74ae589620e074 Mon Sep 17 00:00:00 2001
From: Aaron Briggs <abriggs@contractor.usgs.gov>
Date: Wed, 18 Nov 2020 18:28:33 -0600
Subject: [PATCH] fixed all, but still working on adding parm code

---
 .../components/hydrograph/download-links.js   |  8 +--
 .../hydrograph/download-links.spec.js         | 18 ++---
 .../components/hydrograph/index.js            | 68 +++++++++----------
 .../components/hydrograph/index.spec.js       |  1 +
 4 files changed, 48 insertions(+), 47 deletions(-)

diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js
index 7557308e9..a899be35b 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.js
@@ -9,18 +9,18 @@ import config from 'ui/config.js';
  * @param {String} currentIVDateRange
  * @param {Object} queryInformation - from the application state under ivTimeSeriesData>queryInfo; contains
  * URL queries for WaterServices - but they require reformatting to use
+ * @param {String} parameterCode - a five digit number indicating the type of data
+ * @param {String} timeSeriesType - one of two options, 'current' or 'compare'
  * @return {String} a URL usable to retrieve station data from WaterServices
  */
 export const createHrefForDownloadLinks = function(currentIVDateRange, queryInformation, parameterCode, timeSeriesType) {
-
     let url = '';
     const key = currentIVDateRange === 'P7D' ? `${timeSeriesType}:${currentIVDateRange}` : `${timeSeriesType}:${currentIVDateRange}:${parameterCode}`;
-    console.log('key ', key)
-    console.log('queryInformation[key] ', queryInformation[key])
+
     if (queryInformation[key]) {
         url =  queryInformation[key];
         url = url.queryURL;
-       const splitUrl = url.split('http://nwis.waterservices.usgs.gov/nwis/iv/');
+        const splitUrl = url.split('/nwis/iv/');
         url = splitUrl[1];
         url = url.replace('json', 'rdb');
         url = `${config.SERVICE_ROOT}/iv/?${url}`;
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.spec.js b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.spec.js
index b1df85741..e57b612ad 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/download-links.spec.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/download-links.spec.js
@@ -3,31 +3,31 @@ import {createHrefForDownloadLinks} from 'ivhydrograph/download-links';
 describe('createHrefForDownloadOfCompareData', () => {
     const queryInformation = {
         'current:P7D': {
-            'queryURL': 'http://nwis.waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&&period=P7D&siteStatus=all&format=json'
+            'queryURL': 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&&period=P7D&siteStatus=all&format=json'
         },
         'compare:P7D': {
-            'queryURL': 'http://nwis.waterservices.usgs.gov/nwis/iv/sites=05370000&startDT=2019-11-10T19:33Z&endDT=2019-11-17T19:33Z&siteStatus=all&format=json'
+            'queryURL': 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&startDT=2019-11-10T19:33Z&endDT=2019-11-17T19:33Z&siteStatus=all&format=json'
         },
         'current:custom:00060': {
-            'queryURL': 'http://nwis.waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&startDT=2020-11-01T05:00Z&endDT=2020-11-03T05:59Z&siteStatus=all&format=json'
+            'queryURL': 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&startDT=2020-11-01T05:00Z&endDT=2020-11-03T05:59Z&siteStatus=all&format=json'
         },
         'current:P30D:00060': {
-            'queryURL': 'http://nwis.waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&startDT=2020-10-18T18:33Z&endDT=2020-11-17T19:33Z&siteStatus=all&format=json'
+            'queryURL': 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&startDT=2020-10-18T18:33Z&endDT=2020-11-17T19:33Z&siteStatus=all&format=json'
         },
         'compare:P30D:00060': {
-            'queryURL': 'http://nwis.waterservices.usgs.gov/nwis/iv/sites=05370000&startDT=2019-10-18T18:33Z&endDT=2019-11-17T19:33Z&siteStatus=all&format=json'
+            'queryURL': 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&startDT=2019-10-18T18:33Z&endDT=2019-11-17T19:33Z&siteStatus=all&format=json'
         },
         'current:P1Y:00060': {
-            'queryURL': 'http://nwis.waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&startDT=2019-11-17T19:33Z&endDT=2020-11-17T19:33Z&siteStatus=all&format=json'
+            'queryURL': 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&startDT=2019-11-17T19:33Z&endDT=2020-11-17T19:33Z&siteStatus=all&format=json'
         },
         'compare:P1Y:00060': {
-            'queryURL': 'http://nwis.waterservices.usgs.gov/nwis/iv/sites=05370000&startDT=2018-11-17T19:33Z&endDT=2019-11-17T19:33Z&siteStatus=all&format=json'
+            'queryURL': 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&startDT=2018-11-17T19:33Z&endDT=2019-11-17T19:33Z&siteStatus=all&format=json'
         },
         'current:P1Y:00065': {
-            'queryURL': 'http://nwis.waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&startDT=2019-11-17T19:33Z&endDT=2020-11-17T19:33Z&siteStatus=all&format=json'
+            'queryURL': 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&parameterCd=00060&startDT=2019-11-17T19:33Z&endDT=2020-11-17T19:33Z&siteStatus=all&format=json'
         },
         'compare:P1Y:00065': {
-            'queryURL': 'http://nwis.waterservices.usgs.gov/nwis/iv/sites=05370000&startDT=2018-11-17T19:33Z&endDT=2019-11-17T19:33Z&siteStatus=all&format=json'
+            'queryURL': 'http://waterservices.usgs.gov/nwis/iv/sites=05370000&startDT=2018-11-17T19:33Z&endDT=2019-11-17T19:33Z&siteStatus=all&format=json'
         }
     };
 
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.js
index af1d64a3f..677169f63 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/index.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.js
@@ -164,40 +164,40 @@ export const attachToNode = function(store,
                 nodeElem.select('.ts-legend-controls-container')
                     .call(drawGraphControls, store);
                 // Construct and add the hrefs needed so users can download the data corresponding to the currently displayed hydrograph with the 'download data' links
-                // nodeElem.select('#iv-download-container').call(link(store, (container, {currentIVDateRange, parameterCode, showIVTimeSeries, queryInformation}) => {
-                //     // The 'compare' and 'median' links are only available if those options are selected, so remove and replace if needed
-                //     nodeElem.select('#station-compare-data-download-link').text('').attr('href', '');
-                //     nodeElem.select('#median-data-download-link').text('').attr('href', '');
-                //
-                //     const href = createHrefForDownloadLinks(currentIVDateRange, queryInformation, parameterCode, 'current');
-                //     nodeElem.select('#station-data-download-link')
-                //         .attr('href', href);
-                //
-                //     if (showIVTimeSeries.compare) {
-                //         const href = createHrefForDownloadLinks(currentIVDateRange, queryInformation, parameterCode, 'compare');
-                //         nodeElem.select('#station-compare-data-download-link')
-                //             .text('Data from last year for current timespan')
-                //             .attr('href', href);
-                //     }
-                //
-                //     if (showIVTimeSeries.median && parameterCode === '00060') {
-                //         const href = `${config.SERVICE_ROOT}/stat/?format=rdb&sites=${siteno}&statReportType=daily&statTypeCd=median&parameterCd=00060`;
-                //         nodeElem.select('#median-data-download-link')
-                //             .text('Median data')
-                //             .attr('href', href);
-                //     }
-                //     const hrefMetadata = `${config.SERVICE_ROOT}/site/?format=rdb&sites=${siteno}&siteStatus=all`;
-                //     const hrefMetadataExpanded = `${config.SERVICE_ROOT}/site/?format=rdb&sites=${siteno}&siteOutput=expanded&siteStatus=all`;
-                //     nodeElem.select('#metadata-download-link')
-                //         .attr('href', hrefMetadata);
-                //     nodeElem.select('#metadata-expanded-download-link')
-                //         .attr('href', hrefMetadataExpanded);
-                // },  createStructuredSelector({
-                //     currentIVDateRange: getCurrentDateRange,
-                //     parameterCode: getCurrentParmCd,
-                //     showIVTimeSeries: getShowIVTimeSeries,
-                //     queryInformation: getQueryInformation
-                // })));
+                nodeElem.select('#iv-download-container').call(link(store, (container, {currentIVDateRange, parameterCode, showIVTimeSeries, queryInformation}) => {
+                    // The 'compare' and 'median' links are only available if those options are selected, so remove and replace if needed
+                    nodeElem.select('#station-compare-data-download-link').text('').attr('href', '');
+                    nodeElem.select('#median-data-download-link').text('').attr('href', '');
+
+                    const href = createHrefForDownloadLinks(currentIVDateRange, queryInformation, parameterCode, 'current');
+                    nodeElem.select('#station-data-download-link')
+                        .attr('href', href);
+
+                    if (showIVTimeSeries.compare) {
+                        const href = createHrefForDownloadLinks(currentIVDateRange, queryInformation, parameterCode, 'compare');
+                        nodeElem.select('#station-compare-data-download-link')
+                            .text('Data from last year for current timespan')
+                            .attr('href', href);
+                    }
+
+                    if (showIVTimeSeries.median && parameterCode === '00060') {
+                        const href = `${config.SERVICE_ROOT}/stat/?format=rdb&sites=${siteno}&statReportType=daily&statTypeCd=median&parameterCd=00060`;
+                        nodeElem.select('#median-data-download-link')
+                            .text('Median data')
+                            .attr('href', href);
+                    }
+                    const hrefMetadata = `${config.SERVICE_ROOT}/site/?format=rdb&sites=${siteno}&siteStatus=all`;
+                    const hrefMetadataExpanded = `${config.SERVICE_ROOT}/site/?format=rdb&sites=${siteno}&siteOutput=expanded&siteStatus=all`;
+                    nodeElem.select('#metadata-download-link')
+                        .attr('href', hrefMetadata);
+                    nodeElem.select('#metadata-expanded-download-link')
+                        .attr('href', hrefMetadataExpanded);
+                },  createStructuredSelector({
+                    currentIVDateRange: getCurrentDateRange,
+                    parameterCode: getCurrentParmCd,
+                    showIVTimeSeries: getShowIVTimeSeries,
+                    queryInformation: getQueryInformation
+                })));
 
                 nodeElem.select('#iv-data-table-container')
                     .call(drawDataTable, store);
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/index.spec.js b/assets/src/scripts/monitoring-location/components/hydrograph/index.spec.js
index 28c3a03b0..73e6ed8b6 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/index.spec.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/index.spec.js
@@ -62,6 +62,7 @@ const TEST_STATE = {
         },
         queryInfo: {
             'current:P7D': {
+                queryURL: 'http://waterservices.usgs.gov/nwis/iv/sites=05413500&period=P7D&siteStatus=all&format=json',
                 notes: {
                     'filter:timeRange':  {
                         mode: 'PERIOD',
-- 
GitLab