From 65f37b24b1c52cfdb28931dfe42f94c004f2bc64 Mon Sep 17 00:00:00 2001
From: Aaron Briggs <abriggs@contractor.usgs.gov>
Date: Fri, 1 Jul 2022 09:53:21 -0500
Subject: [PATCH] secondary method id is set in state correctly

---
 .../hydrograph/selectors/time-series-data.js        |  7 ++++---
 .../vue-components/parameter-selection.vue          |  2 +-
 .../vue-components/secondary-parameter-controls.vue | 13 ++++++++++---
 3 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js
index 760d8bd83..7b375e0b7 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/selectors/time-series-data.js
@@ -147,9 +147,10 @@ export const getPrimaryParameterUnitCode = createSelector(
  *      @prop {Array} methods - sorted
  * Array of objects with details about the sampling methods available for the primary parameter.
  */
-export const getSortedIVMethods = createSelector(
-    getIVData('primary'),
+export const getSortedIVMethods = dataKind => createSelector(
+    getIVData(dataKind),
     (ivData) => {
+        console.log('getSortedIVMethods with dataKind ', dataKind);
         if (!ivData || !Object.keys(ivData.values).length) {
             return null;
         }
@@ -182,7 +183,7 @@ export const getSortedIVMethods = createSelector(
  * @returns {Function} which returns {String} the preferred method ID.
  */
 export const getPreferredIVMethodID = createSelector(
-    getSortedIVMethods,
+    getSortedIVMethods('primary'),
     (sortedMethods) => {
         return sortedMethods && sortedMethods.methods.length ? sortedMethods.methods[0].methodID : null;
     }
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/parameter-selection.vue b/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/parameter-selection.vue
index 3c6f70336..bb6d0e3fb 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/parameter-selection.vue
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/parameter-selection.vue
@@ -135,7 +135,7 @@ export default {
 
     const state = useState({
       parameters: getAvailableParameterData,
-      sortedIvMethods: getSortedIVMethods,
+      sortedIvMethods: getSortedIVMethods('primary'),
       selectedParameterCode: getSelectedParameterCode,
       isSecondaryParameterSelected: isVisible('secondary')
     });
diff --git a/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/secondary-parameter-controls.vue b/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/secondary-parameter-controls.vue
index 1d580ca46..4136b21ad 100644
--- a/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/secondary-parameter-controls.vue
+++ b/assets/src/scripts/monitoring-location/components/hydrograph/vue-components/secondary-parameter-controls.vue
@@ -22,11 +22,12 @@
 <script>
 import {ref, inject} from 'vue';
 
-import {useActions} from 'redux-connect-vue';
+import {useActions, useState} from 'redux-connect-vue';
 import {setSecondaryIVDataVisibility, setCompareDataVisibility, setMedianDataVisibility, setSelectedSecondaryIVMethodID} from 'ml/store/hydrograph-state';
 import {retrieveSecondParameterIVData} from 'ml/store/hydrograph-data';
 import {getTimeRange} from 'ml/selectors/hydrograph-data-selector';
 import {showDataIndicators} from '../data-indicator';
+import {getSortedIVMethods} from '../selectors/time-series-data';
 
 import USWDSCheckbox from 'ui/uswds-components/checkbox.vue';
 import USWDSRadioButtonSet from 'ui/uswds-components/radio-button-set.vue';
@@ -51,6 +52,10 @@ export default {
     const reduxStore = inject('store');
     const siteNumber = inject('siteno');
 
+    const state = useState({
+      sortedIvMethods: getSortedIVMethods('secondary')
+    });
+
     const actions = useActions({
       setSecondaryIVDataVisibility,
       setCompareDataVisibility,
@@ -97,8 +102,10 @@ export default {
            endTime: currentTimeRange.end
          }
       ).then(() => {
-        const sortedMethods = 'new method id';
-        actions.setSelectedSecondaryIVMethodID(sortedMethods);
+        const sortedMethods = state.sortedIvMethods.value;
+        if (sortedMethods && sortedMethods.methods.length) {
+          actions.setSelectedSecondaryIVMethodID(sortedMethods.methods[0].methodID);
+        }
         showDataIndicators(false, reduxStore);
       });
     };
-- 
GitLab