Skip to content

segments: support adding custom widgets in segment group#1386

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

segments: support adding custom widgets in segment group#1386
tahini merged 1 commit intochairemobilite:mainfrom
tahini:builtinSectionSegments

Conversation

@tahini
Copy link
Contributor

@tahini tahini commented Feb 6, 2026

completes #1345

This adds the additionalSegmentWidgetNames configuration option to the SegmentSectionConfiguration type. It contains a list of widget names to add after the mode question and before the has next mode question.

These widgets need to be defined in the survey itself.

Summary by CodeRabbit

  • New Features

    • Survey segments can now include additional custom widgets via a new configurable list, allowing more flexible segment layouts.
  • Tests

    • Added coverage verifying additional widgets are correctly included and ordered in segment configurations.
  • Chores

    • Removed unused imports and cleaned up legacy commented code for clarity.

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 5 files

@coderabbitai
Copy link

coderabbitai bot commented Feb 6, 2026

Walkthrough

Adds support for configuring extra segment widgets via a new optional field additionalSegmentWidgetNames?: string[] on SegmentSectionConfiguration. The demo survey segmentSectionConfig is now explicitly typed and lists additional widget names. The segments group factory spreads any configured additional widget names into its widgets array. Tests were added to verify the extra widgets are included. Minor cleanup removed unused imports and a deprecated commented block in the demo widgets file.

Possibly related PRs

Suggested reviewers

  • samuel-duhaime
  • kaligrafy
🚥 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 describes the main change: adding support for custom widgets in segment groups via the new additionalSegmentWidgetNames configuration option.
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

🤖 Fix all issues with AI agents
In
`@packages/evolution-common/src/services/questionnaire/sections/segments/__tests__/groupSegments.test.ts`:
- Around line 200-223: The new test 'SegmentsGroupConfigFactory segments
GroupConfig widget with additional widget names' should be moved inside the
existing describe block titled 'SegmentsGroupConfigFactory segments GroupConfig
widget' in groupSegments.test.ts so it follows the same test grouping and setup;
locate the standalone test and cut/paste it into that describe block (keeping
the test name, assertions, and any required setup like segmentSectionConfig and
widgetFactoryOptions), and ensure indentation and imports remain correct after
relocation.

In `@packages/evolution-common/src/services/questionnaire/types/SectionConfig.ts`:
- Around line 508-514: Fix the JSDoc typo for the additionalSegmentWidgetNames
field in SectionConfig by changing "The will be added after the mode question,
before the hasNextMode question." to "They will be added after the mode
question, before the hasNextMode question." so the plural pronoun matches
"widgets"; update the comment block for additionalSegmentWidgetNames in
SectionConfig.ts accordingly.

Comment on lines +200 to +223
test('SegmentsGroupConfigFactory segments GroupConfig widget with additional widget names', () => {
const segmentSectionConfigWithWidgets: SegmentSectionConfiguration = _cloneDeep(segmentSectionConfig);
segmentSectionConfigWithWidgets.additionalSegmentWidgetNames = ['customWidget1', 'customWidget2'];
const widgetConfig = new SegmentsGroupConfigFactory(segmentSectionConfigWithWidgets, widgetFactoryOptions).getWidgetConfigs()['segments'] as GroupConfig;
expect(widgetConfig).toEqual({
type: 'group',
path: 'segments',
title: expect.any(Function),
name: expect.any(Function),
showTitle: false,
showGroupedObjectDeleteButton: expect.any(Function),
showGroupedObjectAddButton: expect.any(Function),
groupedObjectAddButtonLabel: expect.any(Function),
addButtonLocation: 'bottom' as const,
widgets: [
'segmentSameModeAsReverseTrip',
'segmentModePre',
'segmentMode',
'customWidget1',
'customWidget2',
'segmentHasNextMode'
]
});
});
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Good test coverage for the new feature.

The test correctly validates widget insertion order. One small nit: this test sits outside the existing describe blocks. Consider nesting it under 'SegmentsGroupConfigFactory segments GroupConfig widget' for consistency.

🤖 Prompt for AI Agents
In
`@packages/evolution-common/src/services/questionnaire/sections/segments/__tests__/groupSegments.test.ts`
around lines 200 - 223, The new test 'SegmentsGroupConfigFactory segments
GroupConfig widget with additional widget names' should be moved inside the
existing describe block titled 'SegmentsGroupConfigFactory segments GroupConfig
widget' in groupSegments.test.ts so it follows the same test grouping and setup;
locate the standalone test and cut/paste it into that describe block (keeping
the test name, assertions, and any required setup like segmentSectionConfig and
widgetFactoryOptions), and ensure indentation and imports remain correct after
relocation.

completes chairemobilite#1345

This adds the `additionalSegmentWidgetNames` configuration option to the
`SegmentSectionConfiguration` type. It contains a list of widget names
to add after the mode question and before the has next mode question.

These widgets need to be defined in the survey itself.
@tahini tahini force-pushed the builtinSectionSegments branch from bd7ccf3 to cf7df52 Compare February 6, 2026 13:48
Copy link
Collaborator

@samuel-duhaime samuel-duhaime left a comment

Choose a reason for hiding this comment

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

Any reason why we don't have more control over the widget placement order?

What if I want to put an introduction at the start of the segment section?

'segmentModePre',
'segmentMode',
// Additional widgets are added here
...additionalWidgetNames,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Will the additionalWidgetNames will always be exactly there or we have more control over the placement?

@tahini
Copy link
Contributor Author

tahini commented Feb 6, 2026

The reason is that for the segment group, there is no real need for it. It would complicate how we configure it, I'd rather deal with that problem when it's required. Now, for the group segment, it goes there. For other sections, configurations may be different.

@tahini tahini merged commit afdbfee into chairemobilite:main Feb 6, 2026
6 checks passed
@tahini tahini deleted the builtinSectionSegments branch February 6, 2026 18:26
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.

3 participants