Skip to content
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

Merged
merged 3 commits into from
Jan 28, 2025
Merged

Conversation

lassopicasso
Copy link
Contributor

@lassopicasso lassopicasso commented Jan 27, 2025

Description

  • Prevent studio crash when pressing backspace in Summary2 override combobox.

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

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • Improvements
    • Enhanced error handling by adding optional chaining in component configuration checks
    • Modified component reference selector to potentially support multiple selections

Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

📝 Walkthrough

Walkthrough

The 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 Summary2OverrideDisplayType component and removing the multiple={false} prop from the StudioCombobox component in the Summary2ComponentReferenceSelector. These changes aim to improve the flexibility of component rendering and selection handling.

Changes

File Change Summary
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Override/OverrideFields/Summary2OverrideDisplayType.tsx Added optional chaining (?.) to override.componentId property checks to safely handle undefined or null values
frontend/packages/ux-editor/src/components/config/componentSpecificContent/Summary2/Summary2ComponentReferenceSelector.tsx Removed multiple={false} prop from StudioCombobox, potentially allowing multiple selections

Possibly related PRs

Suggested labels

kind/bug, team/studio-domain1, quality/testing, skip-documentation

Suggested reviewers

  • Jondyr

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. solution/studio/designer Issues related to the Altinn Studio Designer solution. frontend labels Jan 27, 2025
@lassopicasso lassopicasso changed the title Fix/summary2 combobox crash fix: summary2 combobox crash Jan 27, 2025
Copy link

codecov bot commented Jan 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.69%. Comparing base (3a133e6) to head (1d35c7d).
Report is 11 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

@lassopicasso lassopicasso changed the title fix: summary2 combobox crash fix: summary2 override combobox crash Jan 27, 2025
@lassopicasso lassopicasso marked this pull request as ready for review January 27, 2025 07:03
Copy link
Contributor

@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: 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 when override.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

📥 Commits

Reviewing files that changed from the base of the PR and between bed2631 and 1d35c7d.

📒 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 removing multiple={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 fix

The 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/packages

Length 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/src

Length 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.tsx

Length of output: 6984

Copy link
Member

@Jondyr Jondyr left a comment

Choose a reason for hiding this comment

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

LGTM ✅

@Jondyr Jondyr added the skip-manual-testing PRs that do not need to be tested manually label Jan 28, 2025
@Jondyr Jondyr enabled auto-merge (squash) January 28, 2025 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. frontend skip-manual-testing PRs that do not need to be tested manually solution/studio/designer Issues related to the Altinn Studio Designer solution.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pressing backspace to remove a selected component in Summary2 causes Studio to crash
2 participants