-
Notifications
You must be signed in to change notification settings - Fork 75
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: summary2 override combobox crash #14512
Conversation
📝 WalkthroughWalkthroughThe pull request introduces changes to two TypeScript files in the frontend UX editor package. The modifications involve adding optional chaining to component ID checks in 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 #14512 +/- ##
=======================================
Coverage 95.69% 95.69%
=======================================
Files 1902 1902
Lines 24715 24715
Branches 2829 2829
=======================================
Hits 23652 23652
Misses 802 802
Partials 261 261 ☔ View full report in Codecov by Sentry. |
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 (3)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2ComponentReferenceSelector.tsx (1)
27-29
: Consider adding explicit type safety for single selection.Since this component is designed for single selection (as evident from
onValueChange((v) => onValueChange(v[0]))
), consider adding runtime validation to ensure the array never contains multiple values.<StudioCombobox size='small' label={label} value={value ? [value] : []} - onValueChange={(v) => onValueChange(v[0])} + onValueChange={(v) => { + if (v.length > 1) { + console.warn('Multiple values selected in single-select Summary2ComponentReferenceSelector'); + } + onValueChange(v[0]); + }} error={errorMessage} >frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx (2)
30-31
: LGTM! Good defensive programming with optional chaining.The addition of optional chaining operators (
?.
) helps prevent crashes whenoverride.componentId
is undefined or null.However, consider adding a type guard for additional safety:
+ const isValidComponentId = (id: string | undefined): boolean => { + return Boolean(id?.includes(ComponentType.MultipleSelect) || + id?.includes(ComponentType.Checkboxes)); + }; const checkboxOrMultipleselect = - override.componentId?.includes(ComponentType.MultipleSelect) || - override.componentId?.includes(ComponentType.Checkboxes); + isValidComponentId(override.componentId);
Line range hint
33-35
: Consider adding error boundary for additional crash protection.While the optional chaining prevents crashes from undefined values, consider wrapping the component in an error boundary to catch any other potential runtime errors.
class Summary2ErrorBoundary extends React.Component { // Implementation of error boundary } // Usage: <Summary2ErrorBoundary> <Summary2OverrideDisplayType override={override} onChange={onChange} /> </Summary2ErrorBoundary>
📜 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/Summary2ComponentReferenceSelector.tsx
(1 hunks)
🧰 Additional context used
📓 Learnings (1)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx (1)
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`.
🔇 Additional comments (1)
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2ComponentReferenceSelector.tsx (1)
Line range hint
24-41
: Verify if removingmultiple={false}
resolves the backspace crash.While removing the
multiple={false}
prop might help with the backspace handling, we should ensure this doesn't introduce unintended side effects since the component still processes single values.Let's verify the StudioCombobox's default behavior and if this change actually fixes the crash:
✅ Verification successful
Removing
multiple={false}
appears to be a valid fixThe change aligns with other StudioCombobox implementations in the codebase, which also handle single selection without explicitly setting
multiple={false}
. The component maintains correct single-selection behavior through array wrapping and value handling.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for other usages of StudioCombobox to understand the default behavior rg -t typescript "StudioCombobox" frontend/packages/ux-editor/src # Check if there are any related test files or documentation fd -t f -e test.tsx -e test.ts -e md "StudioCombobox" frontend/packagesLength of output: 172
Script:
#!/bin/bash # Search for StudioCombobox usages in TypeScript files rg -t ts -t tsx "StudioCombobox" frontend/packages/ux-editor/src # Look for test files related to Summary2ComponentReferenceSelector rg -t ts -t tsx "Summary2ComponentReferenceSelector" frontend/packages/ux-editor/src # Search for similar selector components rg -t ts -t tsx "ComponentReferenceSelector|ReferenceSelector" frontend/packages/ux-editor/srcLength of output: 330
Script:
#!/bin/bash # Search for StudioCombobox usages rg "StudioCombobox" --type-add 'ts:*.{ts,tsx}' -t ts frontend/packages/ux-editor/src # Find test files and implementation fd -e ts -e tsx . frontend/packages/ux-editor/src | rg "Summary2ComponentReference|StudioCombobox" # Search for similar selector components ast-grep --pattern 'const $_ = ({ $$$_ }) => { $$$ return ( <StudioCombobox $$$ > $$$ </StudioCombobox> ) }'Length of output: 3396
Script:
#!/bin/bash # Get implementation context of other StudioCombobox components rg -A 10 -B 5 "<StudioCombobox" --type-add 'ts:*.{ts,tsx}' -t ts frontend/packages/ux-editor/src/components/Elements/LayoutSetsContainer.tsx frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/ColumnElement/EditColumnElement/EditColumnElement.tsxLength of output: 6984
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.
LGTM ✅
Description
Sidenote: The combobox behavior when using backspace is not ideal. Since the combobox returns a value of undefined, it removes the entire text. I couldn't find a better solution without refactoring and introducing states. For now, I think this behavior is acceptable, but I’m open to addressing this as well. What do you think?
Related Issue(s)
Verification
Documentation
Summary by CodeRabbit