@@ -2,15 +2,16 @@ import {
22 getRowName ,
33 getTranslatedRowLabel ,
44 getSurveyFlatPaths ,
5- isRowSpecialLabelHolder
5+ isRowSpecialLabelHolder ,
66} from 'js/assetUtils' ;
77import {
88 FORM_VERSION_NAME ,
99 SCORE_ROW_TYPE ,
1010 RANK_LEVEL_TYPE ,
1111 MATRIX_PAIR_PROPS ,
1212 GROUP_TYPES_BEGIN ,
13- QUESTION_TYPES
13+ QUESTION_TYPES ,
14+ CHOICE_LISTS ,
1415} from 'js/constants' ;
1516
1617export const DISPLAY_GROUP_TYPES = new Map ( ) ;
@@ -19,7 +20,7 @@ new Set([
1920 'group_repeat' ,
2021 'group_regular' ,
2122 'group_matrix' ,
22- 'group_matrix_row'
23+ 'group_matrix_row' ,
2324] ) . forEach ( ( codename ) => { DISPLAY_GROUP_TYPES . set ( codename , codename ) ; } ) ;
2425
2526/**
@@ -50,14 +51,20 @@ class DisplayGroup {
5051 * @property {string } type - One of QUESTION_TYPES
5152 * @property {string } label - Localized display label
5253 * @property {string } name - Unique identifier
54+ * @property {string|undefined } listName - Unique identifier of a choices list,
55+ * only applicable for question types
56+ * that uses choices lists
5357 * @property {string|null } data - User response, `null` for no response
5458 */
5559class DisplayResponse {
56- constructor ( type , label , name , data = null ) {
60+ constructor ( type , label , name , listName , data = null ) {
5761 this . type = type ;
5862 this . label = label ;
5963 this . name = name ;
6064 this . data = data ;
65+ if ( listName ) {
66+ this . listName = listName ;
67+ }
6168 }
6269}
6370
@@ -85,6 +92,7 @@ export function getSubmissionDisplayData(survey, choices, translationIndex, subm
8592 const row = survey [ rowIndex ] ;
8693
8794 const rowName = getRowName ( row ) ;
95+ let rowListName = getRowListName ( row ) ;
8896 const rowLabel = getTranslatedRowLabel ( rowName , survey , translationIndex ) ;
8997
9098 let parentGroupPath = null ;
@@ -194,10 +202,20 @@ export function getSubmissionDisplayData(survey, choices, translationIndex, subm
194202 rowData = rowData [ repeatIndex ] ;
195203 }
196204
205+ // score and rank don't have list name on them and they need to use
206+ // the one of their parent
207+ if ( row . type === SCORE_ROW_TYPE || row . type === RANK_LEVEL_TYPE ) {
208+ const parentGroupRow = survey . find ( ( row ) => {
209+ return getRowName ( row ) === parentGroup . name ;
210+ } ) ;
211+ rowListName = getRowListName ( parentGroupRow ) ;
212+ }
213+
197214 let rowObj = new DisplayResponse (
198215 row . type ,
199216 rowLabel ,
200217 rowName ,
218+ rowListName ,
201219 rowData
202220 ) ;
203221 parentGroup . addChild ( rowObj ) ;
@@ -276,6 +294,7 @@ function populateMatrixData(
276294 questionSurveyObj . type ,
277295 getTranslatedRowLabel ( questionName , survey , translationIndex ) ,
278296 questionName ,
297+ getRowListName ( questionSurveyObj ) ,
279298 questionData
280299 ) ;
281300 matrixRowGroupObj . addChild ( questionObj ) ;
@@ -379,8 +398,21 @@ function getRegularGroupAnswers(data, targetKey) {
379398 return answers ;
380399}
381400
401+ /**
402+ * @param {object } row
403+ * @returns {string|undefiend }
404+ */
405+ function getRowListName ( row ) {
406+ return (
407+ row [ CHOICE_LISTS . SELECT ] ||
408+ row [ CHOICE_LISTS . MATRIX ] ||
409+ row [ CHOICE_LISTS . SCORE ] ||
410+ row [ CHOICE_LISTS . RANK ]
411+ ) ;
412+ }
413+
382414export default {
383415 DISPLAY_GROUP_TYPES ,
384416 getSubmissionDisplayData,
385- getRepeatGroupAnswers
417+ getRepeatGroupAnswers,
386418} ;
0 commit comments