-
Notifications
You must be signed in to change notification settings - Fork 85
fix: summary2 - reset override config when user reselects component #14619
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
Conversation
…eckbox nor multiple
📝 WalkthroughWalkthroughThis pull request updates the Summary2 override functionality. It adds a new test case in the corresponding test file to verify that the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #14619 +/- ##
=======================================
Coverage 95.75% 95.75%
=======================================
Files 1912 1912
Lines 24922 24922
Branches 2851 2851
=======================================
Hits 23863 23863
Misses 799 799
Partials 260 260 ☔ View full report in Codecov by Sentry. |
displayType
prop if user reselects component that doesn't support it
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx (1)
33-39
: LGTM! Consider extracting the condition for better readability.The logic for removing the
displayType
prop is correct and well-placed inside the unsupported component check.Consider extracting the condition into a descriptive variable for better readability:
+ const shouldRemoveDisplayType = !checkboxOrMultipleselect && override?.displayType; - if (!checkboxOrMultipleselect) { - if (override?.displayType) { + if (shouldRemoveDisplayType) { const { displayType, ...rest } = override; onChange(rest); } return null; }frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.test.tsx (1)
170-175
: Consider enhancing test coverage with additional scenarios.While the test correctly verifies the basic functionality, consider adding more test cases to ensure robust coverage.
Add test cases for:
- Switching between supported and unsupported components
- Multiple component switches
- Different initial displayType values
Example addition:
it('should handle switching between supported and unsupported components', async () => { const user = userEvent.setup(); render({ overrides: [{ componentId: checkBoxId, displayType: 'string' }] }); // Switch to unsupported component await user.click(overrideCollapsedButton(1)); await user.click(overrideComponentSelect()); await user.click(screen.getByRole('option', { name: /component1IdMock/ })); expect(defaultProps.onChange).toHaveBeenCalledWith([{ componentId: component1IdMock }]); // Switch back to supported component await user.click(overrideComponentSelect()); await user.click(screen.getByRole('option', { name: /checkBoxId/ })); expect(defaultProps.onChange).toHaveBeenCalledWith([{ componentId: checkBoxId }]); });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx
(1 hunks)frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.test.tsx
(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx (2)
Learnt from: lassopicasso
PR: Altinn/altinn-studio#14575
File: frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx:47-58
Timestamp: 2025-02-07T09:50:33.290Z
Learning: Avoid suggesting StudioCombobox component in future PRs for the Altinn Studio repository. A new replacement component will be introduced later.
Learnt from: Jondyr
PR: Altinn/altinn-studio#14379
File: frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/ShowEmptyFieldsSwitch.tsx:17-24
Timestamp: 2025-01-13T12:46:32.116Z
Learning: In the Summary2 component's override configuration, the `hideEmptyFields` and `forceShow` properties are intentionally controlled by the same switch, where `hideEmptyFields` is set to the inverse of `forceShow`.
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2Override.test.tsx (1)
Learnt from: lassopicasso
PR: Altinn/altinn-studio#14575
File: frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx:47-58
Timestamp: 2025-02-07T09:50:33.290Z
Learning: Avoid suggesting StudioCombobox component in future PRs for the Altinn Studio repository. A new replacement component will be introduced later.
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.
Nice catch! 💯
displayType
prop if user reselects component that doesn't support itThere 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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx (1)
78-82
: Consider documenting the property reset behavior.The interaction between component selection and property reset (like
displayType
) is an important behavior that affects multiple child components. Consider adding a code comment or updating the component's documentation to explain that selecting a new component resets all override properties.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx
(1 hunks)
🧰 Additional context used
🧠 Learnings (1)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx (2)
Learnt from: lassopicasso
PR: Altinn/altinn-studio#14575
File: frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx:47-58
Timestamp: 2025-02-07T09:50:33.290Z
Learning: Avoid suggesting StudioCombobox component in future PRs for the Altinn Studio repository. A new replacement component will be introduced later.
Learnt from: Jondyr
PR: Altinn/altinn-studio#14379
File: frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx:63-70
Timestamp: 2025-01-13T12:44:45.751Z
Learning: In the Altinn Studio codebase, when using StudioProperty.Button component, it's expected to pass `false` as the value prop when no meaningful value is available (e.g., when componentNameType is undefined). This is the intended behavior and should not be changed to handle undefined cases differently.
🔇 Additional comments (1)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/Summary2OverrideEntry.tsx (1)
66-66
: LGTM! The change effectively removes unsupported properties.The modification to only pass
componentId
in theonValueChange
handler is a clean solution that ensures properties likedisplayType
are automatically removed when reselecting components. This aligns well with the PR's objective of removing unsupported properties.
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.
Nice work! 🚀
Tested OK! 💯 |
Description
This PR adds logic to remove thedisplayType
prop if the selected component does not support itI encountered this issue in the summary2 overrides. If user selects a checkbox and set thedisplayType
prop, and then reselects a component that doesn't support this prop, it isn't removed in config.Only Checkbox and Multiple Select supports this prop (while RepeatingGroup and Subform supports
display
, and is not implemented yet, but will have similar behavior).Edit: this PR reset config for override when reselecting component.
Before
After
First image - checkbox selected with `displayType` as stringSecond image - user reselects to a different component, i.e. input, and

displayType
is auto deleted.Related Issue(s)
Verification
Documentation
Summary by CodeRabbit
Refactor
Tests