Skip to content

segments: add a separate validateButtonAction for next section#1385

Merged
tahini merged 1 commit intochairemobilite:mainfrom
tahini:fixSegmentsButton
Feb 6, 2026
Merged

segments: add a separate validateButtonAction for next section#1385
tahini merged 1 commit intochairemobilite:mainfrom
tahini:fixSegmentsButton

Conversation

@tahini
Copy link
Contributor

@tahini tahini commented Feb 6, 2026

This fixes a regression with commit
f2ade4d where it was not possible to confirm a segment group because it tried to navigate to the next section, but it is not possible.

It adds a separate validateButtonActionWithCompleteSection button action to the buttonActions part of the WidgetFactoryOptions. Thus each button can choose the appropriate action to call depending on its need.

Summary by CodeRabbit

  • Refactor

    • Centralized widget factory configuration (button actions and icon mappings) for consistent use across the survey UI
    • Added a second button validation action to support both section-completing navigation and standard validation flows
  • Tests

    • Updated test suites to use the new centralized widget factory configuration and its mocked helpers

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 17 files

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Walkthrough

This PR centralizes widget factory configuration by introducing a shared widgetFactoryOptions: WidgetFactoryOptions and wiring it through the demo survey and common widget factories. widgetFactoryOptions (containing getFormattedDate, buttonActions with both validateButtonActionWithCompleteSection and validateButtonAction, and iconMapper) is exported from the demo helper and imported where needed. Functions that construct button widgets now accept WidgetFactoryOptions instead of ad-hoc option objects. Tests were updated to import and use the shared widgetFactoryOptions test helper.

Possibly related PRs

Suggested reviewers

  • kaligrafy
  • samuel-duhaime
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: introducing a separate validateButtonAction for handling section navigation, which directly addresses the PR's core objective of fixing the segments button regression.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/evolution-common/src/services/questionnaire/sections/segments/buttonSaveTripSegments.ts (1)

31-36: 🧹 Nitpick | 🔵 Trivial

Minor: direct mutation of response object on line 33 is unnecessary.

segment._isNew = false mutates the interview response in-place. Since the actual update is done via updateValuesbyPath on line 35, this direct mutation is a no-op side effect. Pre-existing, so no action needed now, but worth cleaning up if you're ever back in this area.

Proposed cleanup
             for (const segmentUuid in segments) {
                 const segment = segments[segmentUuid];
-                segment._isNew = false;
                 const segmentPath = `${segmentsPath}.${segmentUuid}`;
                 updateValuesbyPath[`response.${segmentPath}._isNew`] = false;
             }
🤖 Fix all issues with AI agents
In `@example/demo_survey/src/survey/widgets.ts`:
- Around line 137-139: Remove the stray extra semicolon after the exported
widget constants so each export ends with a single semicolon; specifically
update the lines that declare buttonSaveNextSection and buttonSaveNextSection2
(which call getButtonValidateAndGotoNextSection with widgetFactoryOptions) to
remove the trailing double semicolon.

In
`@packages/evolution-common/src/services/questionnaire/sections/common/buttonValidateAndGotoNextSection.ts`:
- Line 12: Update the JSDoc that currently mentions `validateButtonAction` to
reference the actual action used, `validateButtonActionWithCompleteSection`;
locate the JSDoc block above the `buttonValidateAndGotoNextSection` (or the
corresponding exported function) and change the description and any
`@see`/`@returns` text to mention `validateButtonActionWithCompleteSection` so
the doc matches the implementation.

This fixes a regression with commit
f2ade4d where it was not possible to
confirm a segment group because it tried to navigate to the next
section, but it is not possible.

It adds a separate `validateButtonActionWithCompleteSection` button
action to the `buttonActions` part of the `WidgetFactoryOptions`. Thus
each button can choose the appropriate action to call depending on its
need.
@tahini tahini force-pushed the fixSegmentsButton branch from 64856da to 6073ef4 Compare February 6, 2026 00:53
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
packages/evolution-common/src/services/questionnaire/sections/segments/buttonSaveTripSegments.ts (1)

25-40: 🧹 Nitpick | 🔵 Trivial

Minor: segment._isNew = false mutates the response object in-place.

Line 33 directly mutates segment._isNew on the interview response object, in addition to setting it via updateValuesbyPath on line 35. The mutation is redundant since the update path handles it. This is pre-existing, but worth noting if you revisit this area.

example/demo_survey/src/survey/widgets.ts (1)

136-158: 🧹 Nitpick | 🔵 Trivial

Five factory buttons now use shared options — consistent and clean.

One small inconsistency: buttonStartNextSection (line 140-152) still references validateButtonActionWithCompleteSection directly instead of going through widgetFactoryOptions.buttonActions.validateButtonActionWithCompleteSection. Not a big deal — especially since this demo survey is slated for replacement — but worth noting for consistency.

Optional: align buttonStartNextSection with the others
 export const buttonStartNextSection: any = {
   type: "button",
   path: "buttonStartNextSection",
   color: "green",
   label: {
     fr: "Débuter",
     en: "Start"
   },
   hideWhenRefreshing: true,
   icon: faPlay,
   align: 'center',
-  action: validateButtonActionWithCompleteSection
+  action: widgetFactoryOptions.buttonActions.validateButtonActionWithCompleteSection
 }

This would also allow removing the direct validateButtonActionWithCompleteSection import on line 9.

🤖 Fix all issues with AI agents
In `@example/demo_survey/src/survey/helper.ts`:
- Around line 62-69: Use JavaScript/TypeScript object property shorthand in the
widgetFactoryOptions declaration: replace explicit longhand assignments like
getFormattedDate: getFormattedDate and validateButtonAction:
validateButtonAction with their shorthand forms, and similarly for
validateButtonActionWithCompleteSection and faCheckCircle inside iconMapper, so
the object reads more concisely while keeping the same identifiers
(widgetFactoryOptions, getFormattedDate,
validateButtonActionWithCompleteSection, validateButtonAction, iconMapper,
faCheckCircle).

Comment on lines +62 to +69
export const widgetFactoryOptions: WidgetFactoryOptions = {
getFormattedDate: getFormattedDate,
buttonActions: {
validateButtonActionWithCompleteSection: validateButtonActionWithCompleteSection,
validateButtonAction: validateButtonAction
},
iconMapper: { 'check-circle': faCheckCircle }
};
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Nit: consider using property shorthand.

Since the variable names match the property names, shorthand would be slightly cleaner.

✏️ Suggested shorthand
 export const widgetFactoryOptions: WidgetFactoryOptions = {
-    getFormattedDate: getFormattedDate,
+    getFormattedDate,
     buttonActions: { 
-        validateButtonActionWithCompleteSection: validateButtonActionWithCompleteSection,
-        validateButtonAction: validateButtonAction
+        validateButtonActionWithCompleteSection,
+        validateButtonAction
     },
     iconMapper: { 'check-circle': faCheckCircle }
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export const widgetFactoryOptions: WidgetFactoryOptions = {
getFormattedDate: getFormattedDate,
buttonActions: {
validateButtonActionWithCompleteSection: validateButtonActionWithCompleteSection,
validateButtonAction: validateButtonAction
},
iconMapper: { 'check-circle': faCheckCircle }
};
export const widgetFactoryOptions: WidgetFactoryOptions = {
getFormattedDate,
buttonActions: {
validateButtonActionWithCompleteSection,
validateButtonAction
},
iconMapper: { 'check-circle': faCheckCircle }
};
🤖 Prompt for AI Agents
In `@example/demo_survey/src/survey/helper.ts` around lines 62 - 69, Use
JavaScript/TypeScript object property shorthand in the widgetFactoryOptions
declaration: replace explicit longhand assignments like getFormattedDate:
getFormattedDate and validateButtonAction: validateButtonAction with their
shorthand forms, and similarly for validateButtonActionWithCompleteSection and
faCheckCircle inside iconMapper, so the object reads more concisely while
keeping the same identifiers (widgetFactoryOptions, getFormattedDate,
validateButtonActionWithCompleteSection, validateButtonAction, iconMapper,
faCheckCircle).

@tahini tahini merged commit 52660e1 into chairemobilite:main Feb 6, 2026
6 checks passed
@tahini tahini deleted the fixSegmentsButton branch February 6, 2026 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants