Skip to content

Commit

Permalink
fix processed trip survey responses not matching
Browse files Browse the repository at this point in the history
Processed responses for user input surveys were not being matched because they were being looked up under "manual/trip_user_input", while it should have just been "trip_user_input".
This is because we were only invoking a function to trim off "manual/" for MULTILABEL user input matching, and it was neglected for ENKETO.

Revise the functions in confirmHelper (keeping 2 versions, `removeManualPrefix` which just trims the key, and `inputType2retKey` which looks up the key and then trims), and use `removeManualPrefix` in inputMatcher appropriately

Some day we can unify the data model (e-mission/e-mission-docs#1045) and not keep 2 versions of so many things
  • Loading branch information
JGreenlee committed Feb 2, 2024
1 parent 48633c3 commit 539924c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 3 additions & 2 deletions www/js/survey/inputMatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { logDebug, displayErrorMsg } from '../plugin/logger';
import { DateTime } from 'luxon';
import { CompositeTrip, ConfirmedPlace, TimelineEntry, UserInputEntry } from '../types/diaryTypes';
import { keysForLabelInputs, unprocessedLabels, unprocessedNotes } from '../diary/timelineHelper';
import { getLabelInputDetails, inputType2retKey } from './multilabel/confirmHelper';
import { getLabelInputDetails, inputType2retKey, removeManualPrefix } from './multilabel/confirmHelper';
import { TimelineLabelMap, TimelineNotesMap } from '../diary/LabelTabContext';
import { MultilabelKey } from '../types/labelTypes';
import { EnketoUserInputEntry } from './enketo/enketoHelper';
Expand Down Expand Up @@ -281,7 +281,8 @@ export function mapInputsToTimelineEntries(
timelineLabelMap[tlEntry._id.$oid] = { SURVEY: userInputForTrip };
} else {
let processedSurveyResponse;
for (const key of keysForLabelInputs(appConfig)) {
for (const dataKey of keysForLabelInputs(appConfig)) {
const key = removeManualPrefix(dataKey);
if (tlEntry.user_input?.[key]) {
processedSurveyResponse = tlEntry.user_input[key];
break;
Expand Down
7 changes: 5 additions & 2 deletions www/js/survey/multilabel/confirmHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ export const getFakeEntry = (otherValue): Partial<LabelOption> | undefined => {
export const labelKeyToRichMode = (labelKey: string) =>
labelOptionByValue(labelKey, 'MODE')?.text || labelKeyToReadable(labelKey);

/* manual/mode_confirm becomes mode_confirm */
export const inputType2retKey = (inputType) => getLabelInputDetails()[inputType].key.split('/')[1];
/** @description e.g. manual/mode_confirm becomes mode_confirm */
export const removeManualPrefix = (key: string) => key.split('/')[1];
/** @description e.g. 'MODE' gets looked up, its key is 'manual/mode_confirm'. Returns without prefix as 'mode_confirm' */
export const inputType2retKey = (inputType: string) =>
removeManualPrefix(getLabelInputDetails()[inputType].key);

export function verifiabilityForTrip(trip: CompositeTrip, userInputForTrip?: UserInputMap) {
let allConfirmed = true;
Expand Down

0 comments on commit 539924c

Please sign in to comment.