1
- import { keyBy , mapValues , toString } from 'lodash' ;
1
+ import { keyBy , mapValues , pick , toString } from 'lodash' ;
2
2
import { Seq } from '../Utils/IterableUtils' ;
3
3
import {
4
4
combineEpics ,
@@ -57,6 +57,7 @@ import {
57
57
QuestionWithParameters ,
58
58
RecordClass ,
59
59
ParameterValues ,
60
+ Question ,
60
61
} from '../Utils/WdkModel' ;
61
62
62
63
import {
@@ -1022,22 +1023,21 @@ async function loadQuestion(
1022
1023
initialParamData ?: ParameterValues ,
1023
1024
submissionMetadata ?: SubmissionMetadata
1024
1025
) {
1025
- const step = stepId ? await wdkService . findStep ( stepId ) : undefined ;
1026
- const initialParams = await fetchInitialParams (
1027
- searchName ,
1028
- step ,
1029
- initialParamData ,
1030
- prepopulateWithLastParamValues ,
1031
- paramValueStore
1032
- ) ;
1033
-
1034
- const atLeastOneInitialParamValueProvided =
1035
- Object . keys ( initialParams ) . length > 0 ;
1036
-
1037
1026
try {
1027
+ const step = stepId ? await wdkService . findStep ( stepId ) : undefined ;
1038
1028
const defaultQuestion = await wdkService . getQuestionAndParameters (
1039
1029
searchName
1040
1030
) ;
1031
+ const initialParams = await fetchInitialParams (
1032
+ defaultQuestion ,
1033
+ step ,
1034
+ initialParamData ,
1035
+ prepopulateWithLastParamValues ,
1036
+ paramValueStore
1037
+ ) ;
1038
+
1039
+ const atLeastOneInitialParamValueProvided =
1040
+ Object . keys ( initialParams ) . length > 0 ;
1041
1041
1042
1042
const question = atLeastOneInitialParamValueProvided
1043
1043
? await wdkService . getQuestionGivenParameters ( searchName , initialParams )
@@ -1084,7 +1084,7 @@ async function loadQuestion(
1084
1084
}
1085
1085
1086
1086
async function fetchInitialParams (
1087
- searchName : string ,
1087
+ question : Question ,
1088
1088
step : Step | undefined ,
1089
1089
initialParamData : ParameterValues | undefined ,
1090
1090
prepopulateWithLastParamValues : boolean ,
@@ -1093,9 +1093,11 @@ async function fetchInitialParams(
1093
1093
if ( step != null ) {
1094
1094
return initialParamDataFromStep ( step ) ;
1095
1095
} else if ( initialParamData != null ) {
1096
- return initialParamDataWithDatasetParamSpecialCase ( initialParamData ) ;
1096
+ return extracParamValues ( initialParamData , question . paramNames ) ;
1097
1097
} else if ( prepopulateWithLastParamValues ) {
1098
- return ( await fetchLastParamValues ( paramValueStore , searchName ) ) ?? { } ;
1098
+ return (
1099
+ ( await fetchLastParamValues ( paramValueStore , question . urlSegment ) ) ?? { }
1100
+ ) ;
1099
1101
} else {
1100
1102
return { } ;
1101
1103
}
@@ -1114,18 +1116,12 @@ function initialParamDataFromStep(step: Step): ParameterValues {
1114
1116
} , { } ) ;
1115
1117
}
1116
1118
1117
- function initialParamDataWithDatasetParamSpecialCase (
1118
- initialParamData : ParameterValues
1119
- ) {
1120
- return Object . keys ( initialParamData ) . reduce ( function ( result , paramName ) {
1121
- if ( paramName . endsWith ( '.idList' ) || paramName . endsWith ( '.url' ) ) {
1122
- return result ;
1123
- }
1124
-
1125
- return Object . assign ( result , {
1126
- [ paramName ] : initialParamData [ paramName ] ,
1127
- } ) ;
1128
- } , { } ) ;
1119
+ /** Pick items from `initialParamData` that correspond to parameter names */
1120
+ function extracParamValues (
1121
+ initialParamData : Record < string , string > ,
1122
+ paramNames : string [ ]
1123
+ ) : ParameterValues {
1124
+ return pick ( initialParamData , paramNames ) ;
1129
1125
}
1130
1126
1131
1127
function updateLastParamValues (
0 commit comments