Skip to content

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

Merged
merged 6 commits into from
Feb 11, 2025

Conversation

lassopicasso
Copy link
Contributor

@lassopicasso lassopicasso commented Feb 10, 2025

Description

This PR adds logic to remove the displayType prop if the selected component does not support it

I encountered this issue in the summary2 overrides. If user selects a checkbox and set the displayType 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

image

After First image - checkbox selected with `displayType` as string

image

Second image - user reselects to a different component, i.e. input, and displayType is auto deleted.
image

Related Issue(s)

  • itself

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

  • Refactor

    • Improved component configuration by automatically removing unsupported display settings when a user selects a component type that doesn’t support them.
  • Tests

    • Added a new test case to verify that the configuration updates as expected, ensuring only applicable properties are retained.

Copy link
Contributor

coderabbitai bot commented Feb 10, 2025

📝 Walkthrough

Walkthrough

This pull request updates the Summary2 override functionality. It adds a new test case in the corresponding test file to verify that the displayType property is removed when a non-multiple select or non-checkbox component is reselected. Simultaneously, the onValueChange method in the Summary2 override component is modified to pass only the componentId, omitting all other properties. No changes were made to any exported entities.

Changes

File(s) Change Summary
frontend/.../Summary2Override.test.tsx, frontend/.../Summary2OverrideEntry.tsx Added a test case verifying the removal of displayType when a non-multiple select/checkbox is reselected. Updated the onValueChange handler to pass only componentId, dropping other override properties.

Possibly related PRs

Suggested labels

skip-manual-testing

Suggested reviewers

  • mlqn
  • Jondyr
  • github-actions

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 Feb 10, 2025
Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.75%. Comparing base (ecd1df9) to head (a90652c).
Report is 1 commits behind head on main.

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

@lassopicasso lassopicasso self-assigned this Feb 10, 2025
@lassopicasso lassopicasso changed the title fix: remove displayType prop user reselects component that doesn't have this fix: summary2 - remove displayType prop if user reselects component that doesn't support it Feb 10, 2025
@lassopicasso lassopicasso marked this pull request as ready for review February 10, 2025 13:32
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 (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:

  1. Switching between supported and unsupported components
  2. Multiple component switches
  3. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 418d09f and c99a414.

📒 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.

Copy link
Contributor

@mlqn mlqn left a comment

Choose a reason for hiding this comment

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

Nice catch! 💯

@mlqn mlqn self-assigned this Feb 11, 2025
@lassopicasso lassopicasso assigned lassopicasso and unassigned mlqn Feb 11, 2025
@lassopicasso lassopicasso changed the title fix: summary2 - remove displayType prop if user reselects component that doesn't support it fix: summary2 - reset override config when user reselects component Feb 11, 2025
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 (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

📥 Commits

Reviewing files that changed from the base of the PR and between c99a414 and 2011cd3.

📒 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 the onValueChange handler is a clean solution that ensures properties like displayType are automatically removed when reselecting components. This aligns well with the PR's objective of removing unsupported properties.

Copy link
Contributor

@mlqn mlqn left a comment

Choose a reason for hiding this comment

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

Nice work! 🚀

@mlqn mlqn added the skip-manual-testing PRs that do not need to be tested manually label Feb 11, 2025
@mlqn
Copy link
Contributor

mlqn commented Feb 11, 2025

Tested OK! 💯

@lassopicasso lassopicasso merged commit c1627ac into main Feb 11, 2025
9 checks passed
@lassopicasso lassopicasso deleted the remove-displayType-is-reselect-component branch February 11, 2025 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
added-to-sprint 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. team/studio-domain2
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants