Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Bugfixes + Refactoring relating to User Inputs #1155

Merged
merged 4 commits into from
May 11, 2024

Conversation

JGreenlee
Copy link
Collaborator

@JGreenlee JGreenlee commented May 9, 2024

refactor ENKETO userinputs to use survey name as key instead of 'SURVEY'

Part of the initiative described in e-mission/e-mission-docs#1045
This implements the "proposed" structure on the phone for Enketo user inputs.
When unprocessed user inputs are read and stored into unprocessedLabels in timelineHelper, responses will now be sorted by survey name instead of all being kept in one slot 'SURVEY'.

Also implement a new function, enketoHelper > resolveSurveyButtonConfig, which reads the config and determines what survey(s) are available for a button (like 'trip label', 'trip addition', 'place label', 'place addition').
Includes backwards compat so old configs (which don't have those fields) will just use the default 'TripConfirmSurvey'.
Including the translations for TripConfirmSurvey's 'not-filled-in-label' directly in the backwards compat to be consistent with new-style surveys where the translations are directly in the config.

This new function is used by , simplifying the code that was there previously. It now stores the returned SurveyButtonConfig object as 'survey' rather than keeping 'surveyName' and 'notFilledInLabel' separately.
This allows conditionalSurveys > getSurveyForTimelineEntry to be simplified too.
The new function is also used in timelineHelper > updateUnprocessedInputs. Instead of calling filterByNameAndVersion only for 'TripConfirmSurvey' and then storing those under the key of 'SURVEY', it first calls resolveSurveyButtonConfig to get all possible 'trip-label' surveys, iterates over those surveys calling filterByNameAndVersion for each, and stores unprocessed responses using the name of the survey as the key.

See types updated in LabelTabContext.ts.
appConfigTypes.ts updated to reflect that showsIf is optional (if not present, that survey shows unconditionally)


don't filter deleted additions twice

I found an edge case where if an old addition (ie one that was already processed) was edited, there would be duplicates; both the old and new version would show up (until the new one got processed).

This is because we were first applying the 'not deleted' filter to unprocessed entries. Then after they are merged with processed entreis we applied it to the merged copy. This didn't work for the edge case because the DELETED entry was already filtered out the first time, so the processed original entry just sticks around.

This fix ensures that the 'not deleted' filter ONLY happens once processed+unprocessed are merged together, this way the filter considers all entries at once

JGreenlee added 4 commits May 9, 2024 15:25
Part of the initiative described in e-mission/e-mission-docs#1045
This implements the "proposed" structure on the phone for Enketo user inputs.
When unprocessed user inputs are read and stored into unprocessedLabels in timelineHelper, responses will now be sorted by survey name instead of all being kept in one slot 'SURVEY'.

Also implement a new function, enketoHelper > resolveSurveyButtonConfig, which reads the config and determines what survey(s) are available for a button (like 'trip label', 'trip addition', 'place label', 'place addition').
Includes backwards compat so old configs (which don't have those fields) will just use the default 'TripConfirmSurvey'.
Including the translations for TripConfirmSurvey's 'not-filled-in-label' directly in the backwards compat to be consistent with new-style surveys where the translations are directly in the config.

This new function is used by <UserInputButton>, simplifying the code that was there previously. It now stores the returned SurveyButtonConfig object as 'survey' rather than keeping 'surveyName' and 'notFilledInLabel' separately.
This allows conditionalSurveys > getSurveyForTimelineEntry to be simplified too.
The new function is also used in timelineHelper > updateUnprocessedInputs. Instead of calling filterByNameAndVersion only for 'TripConfirmSurvey' and then storing those under the key of 'SURVEY', it first calls `resolveSurveyButtonConfig` to get *all* possible 'trip-label' surveys, iterates over those surveys calling filterByNameAndVersion for each, and stores unprocessed responses using the name of the survey as the key.

See types updated in LabelTabContext.ts.
appConfigTypes.ts updated to reflect that showsIf is optional (if not present, that survey shows unconditionally)
I found an edge case where if an old addition (ie one that was already processed) was edited, there would be duplicates; both the old and new version would show up (until the new one got processed).

This is because we were first applying the 'not deleted' filter to unprocessed entries. Then after they are merged with processed entreis we applied it to the merged copy. This didn't work for the edge case because the DELETED entry was already filtered out the first time, so the processed original entry just sticks around.

This fix ensures that the 'not deleted' filter ONLY happens once processed+unprocessed are merged together, this way the filter considers all entries at once
02655ba changed from using 'SURVEY' as the key for unprocessed user inputs to using the name of the survey
These tests still expected 'SURVEY'; replaced with the survey name. The existing test only had 'TripConfirmSurvey'; I also changed one to 'MyCustomSurvey' to highlight that they will be stored under separate fields now.

inputMatcher.test.ts tests on both MULTILABEL and ENKETO configurations.
It is necessary to call updateUnprocessedInputs after testing MULTILABEL and before testing ENKETO so that unprocessed MULTILABEL inputs are not kept it memory.
It is also necessary for updateUnprocessedInputs to clear unprocessedLabels before re-filling it; otherwise survey responses could linger from a previous time the function was called.
Previously all responses were kept in SURVEY, so SURVEY would always get reassigned. but now each survey's responses are kept under the survey name as a key
Trip and place surveys give their own button text in the config now, so this text + translations relocated to the backwards-compat in enketoHelper > resolveSurveyButtonConfig
@JGreenlee
Copy link
Collaborator Author

JGreenlee commented May 9, 2024

This fixes 2 bugs relating to unprocessed inputs:

  1. On trip surveys other than "TripConfirmSurvey", recording a survey response and refreshing before the response is processed causes it to temporarily disappear
    • This was due to line ~118 in timelineHelper; fixed by 02655ba
    • testing done: On dfc-fermata, record a GasTripSurvey response. It shows "Answered". Click the refresh button. Before applying patch, it showed "Gas Car Survey". After applying the patch, it still shows "Answered" as expected.
  2. Processed additions that were edited/deleted still showed the original version until the edit/deletion was processed
    • fixed by cb1e45b
    • Testing done: On stage-timeuse, I had an old activity that was "2 Recreation/Leisure". I edited it to be "3 Recreation/Leisure" and saved. Then, before applying the patch, both "2 Reaction/Leisure" and "3 Recreation/Leisure" show on the same place. After applying the patch, only "3 Recreation/Leisure" shows.

@JGreenlee JGreenlee marked this pull request as ready for review May 9, 2024 23:42
@JGreenlee JGreenlee marked this pull request as draft May 10, 2024 00:12
@JGreenlee JGreenlee marked this pull request as ready for review May 10, 2024 00:12
Copy link

codecov bot commented May 10, 2024

Codecov Report

Attention: Patch coverage is 44.00000% with 28 lines in your changes are missing coverage. Please review.

Project coverage is 26.57%. Comparing base (f504f68) to head (2761e19).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1155      +/-   ##
==========================================
+ Coverage   26.40%   26.57%   +0.16%     
==========================================
  Files         114      114              
  Lines        4983     4993      +10     
  Branches     1064     1033      -31     
==========================================
+ Hits         1316     1327      +11     
- Misses       3665     3666       +1     
+ Partials        2        0       -2     
Flag Coverage Δ
unit 26.57% <44.00%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
www/js/diary/timelineHelper.ts 92.11% <100.00%> (+0.23%) ⬆️
www/js/survey/inputMatcher.ts 63.18% <100.00%> (ø)
www/js/survey/enketo/enketoHelper.ts 68.29% <80.00%> (+0.49%) ⬆️
www/js/survey/enketo/infinite_scroll_filters.ts 0.00% <0.00%> (ø)
www/js/diary/LabelTab.tsx 0.00% <0.00%> (ø)
www/js/diary/diaryHelper.ts 69.23% <0.00%> (-4.24%) ⬇️
www/js/survey/enketo/conditionalSurveys.ts 0.00% <0.00%> (ø)
www/js/survey/enketo/UserInputButton.tsx 0.00% <0.00%> (ø)

... and 2 files with indirect coverage changes

@shankari shankari changed the base branch from master to add_labeling_screen May 11, 2024 03:37
@shankari shankari changed the base branch from add_labeling_screen to master May 11, 2024 03:37
Copy link
Contributor

@shankari shankari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting! It always felt hacky to have a hardcoded value for the survey configuration SURVEY, so I am glad to see that the structure was actually prescient and forwards compatible!

@shankari shankari merged commit 4ea0f35 into e-mission:master May 11, 2024
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants