-
Notifications
You must be signed in to change notification settings - Fork 9
Fix demo generator #1034
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
Fix demo generator #1034
Conversation
The functions do not require the `UserRuntimeInterviewAttributes` and some functions, like the `enableConditional` and `completionConditional`, which could call them, receive a `UserInterviewAttributes` object.
by a call to the isSectionCompleted in the navigation helpers
fixes chairemobilite#1032 Since the enableConditional depend on the completion of the current section, when we navigate forward from a completed section, we need to set the section as completed, otherwise it won't be possible to navigate to the next section. The actual section completion is currently done on the section _after_ the section navigation. We'll need to revisit the section changes, when implementing chairemobilite#969.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Updates the demo generator to use the renamed section-completion helper, aligns interview attribute types, and adds runtime state-setting for completed sections.
- Swapped out
isSectionComplete
for the newisSectionCompleted
helper in the generator script - Updated type references from
UserRuntimeInterviewAttributes
toUserInterviewAttributes
in navigation helpers - Introduced a private
setSectionCompleted
method inNavigationService
usinglodash/set
to mark sections complete
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
packages/evolution-generator/src/scripts/generate_section_configs.py | Changed import and calls from isSectionComplete to isSectionCompleted |
packages/evolution-common/src/services/questionnaire/sections/navigationHelpers.ts | Switched interview type in imports and JSDoc to UserInterviewAttributes |
packages/evolution-common/src/services/questionnaire/sections/NavigationService.ts | Added _set import and setSectionCompleted method; inserted call after navigation |
Comments suppressed due to low confidence (3)
packages/evolution-generator/src/scripts/generate_section_configs.py:55
- Ensure the new import path correctly matches the published API and update any documentation or downstream consumers still referencing
isSectionComplete
.
ts_code += f"import { isSectionCompleted } from 'evolution-common/lib/services/questionnaire/sections/navigationHelpers';\n"
packages/evolution-common/src/services/questionnaire/sections/navigationHelpers.ts:19
- The JSDoc
@param
annotations have been updated, but verify that descriptions remain accurate and reflect any new assumptions inUserInterviewAttributes
.
* @param {UserInterviewAttributes} options.interview The interview object
packages/evolution-common/src/services/questionnaire/sections/NavigationService.ts:509
- The new
setSectionCompleted
method lacks associated unit tests. Adding tests here will help prevent regressions in navigation logic.
private setSectionCompleted({
@@ -6,6 +6,7 @@ | |||
*/ | |||
import _isEqual from 'lodash/isEqual'; | |||
import _shuffle from 'lodash/shuffle'; | |||
import _set from 'lodash/set'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Directly mutating nested interview state with lodash/set
can be error-prone; consider encapsulating this in a higher-level helper or service to maintain consistency and ease testing.
Copilot uses AI. Check for mistakes.
// FIXME Not sure this is the place to set this, but since some enable | ||
// conditional may depend on preceding section's completion status, we | ||
// need to know that a section is completed. Using _set directly is not | ||
// the best way, see if we should add a helper for this is we need to | ||
// set completion of a section more generally. The backend also has | ||
// similar code. Eventually, when implementing | ||
// https://github.com/chairemobilite/evolution/issues/969, the section | ||
// navigation history and completion won't be stored in the responses | ||
// anymore and we'll have a better way to set it, so we can go for the | ||
// easy fix for now. | ||
_set( | ||
interview, | ||
`response._sections.${section.sectionShortname}${section.iterationContext ? '.' + section.iterationContext.join('/') : ''}._isCompleted`, | ||
true | ||
); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FIXME
highlights technical debt—consider tracking a ticket or refactoring soon to avoid leaving this workaround in production.
// FIXME Not sure this is the place to set this, but since some enable | |
// conditional may depend on preceding section's completion status, we | |
// need to know that a section is completed. Using _set directly is not | |
// the best way, see if we should add a helper for this is we need to | |
// set completion of a section more generally. The backend also has | |
// similar code. Eventually, when implementing | |
// https://github.com/chairemobilite/evolution/issues/969, the section | |
// navigation history and completion won't be stored in the responses | |
// anymore and we'll have a better way to set it, so we can go for the | |
// easy fix for now. | |
_set( | |
interview, | |
`response._sections.${section.sectionShortname}${section.iterationContext ? '.' + section.iterationContext.join('/') : ''}._isCompleted`, | |
true | |
); | |
} | |
this.markSectionAsCompleted(interview, section); | |
} | |
/** | |
* Helper method to mark a section as completed in the interview responses. | |
* | |
* @param {UserRuntimeInterviewAttributes} interview The interview object | |
* @param {NavigationSection} section The section to mark as completed | |
*/ | |
private markSectionAsCompleted( | |
interview: UserRuntimeInterviewAttributes, | |
section: NavigationSection | |
): void { | |
const path = `response._sections.${section.sectionShortname}${ | |
section.iterationContext ? '.' + section.iterationContext.join('/') : '' | |
}._isCompleted`; | |
_set(interview, path, true); | |
} |
Copilot uses AI. Check for mistakes.
Make sure to remove the double click that I had to insert in the next button test in #1010, so we can test this. |
See individual commits for details