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: prevent adding components from a different data model to the subform table #14442

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

lassopicasso
Copy link
Contributor

@lassopicasso lassopicasso commented Jan 16, 2025

Description

Updated the filter logic for the component selector in the subform table to only allow components that are part of the same data model as the subform.

subform-default-datamodel.mp4

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

Release Notes

  • New Features

    • Enhanced subform table column selection with improved data model handling
    • Added dynamic default data model retrieval for more accurate component selection
  • Improvements

    • Updated component filtering logic to better match data model requirements
    • Introduced more robust data binding validation for subform components
  • Technical Updates

    • Expanded utility functions to support more complex data model scenarios

Copy link

coderabbitai bot commented Jan 16, 2025

📝 Walkthrough

Walkthrough

The pull request introduces enhancements to the subform table column editing functionality in the UX editor. The changes focus on improving the component selection logic by adding a new getDefaultDataModel utility function and updating the getComponentsForSubformTable method to incorporate a default data model. This modification allows for more precise component filtering based on layout sets and subform layouts, with updates spanning multiple files in the frontend package.

Changes

File Change Summary
frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/EditColumnElement/EditColumnElement.tsx Added useLayoutSetsQuery hook and integrated new getDefaultDataModel utility
frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/utils/editSubformTableColumnsUtils.ts - Updated getComponentsForSubformTable function signature to include defaultDataModel
- Added new getDefaultDataModel function
- Introduced componentsWithTitleAndDefaultDataModel filtering logic
frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/utils/editSubformTableColumnsUtils.test.ts - Updated test cases to accommodate new defaultDataModel parameter
- Added new component to test data

Possibly related PRs

Suggested labels

team/studio-domain1, skip-documentation, added-to-sprint

Suggested reviewers

  • mlqn
  • JamalAlabdullah

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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 16, 2025
@lassopicasso lassopicasso marked this pull request as ready for review January 16, 2025 16:35
@lassopicasso lassopicasso changed the title Prevent Adding Components from a Different Data Model to the Subform Table fix: prevent adding components from a different data model to the subform table Jan 16, 2025
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: 0

🧹 Nitpick comments (4)
frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/utils/editSubformTableColumnsUtils.ts (2)

40-51: Consider adding documentation for componentsWithTitleAndDefaultDataModel

Adding JSDoc comments or inline documentation to the componentsWithTitleAndDefaultDataModel function can improve readability and maintainability by clearly explaining its purpose and logic.


53-56: Consider adding documentation for getDefaultDataModel

Providing a brief explanation of the getDefaultDataModel function, including its parameters and return value, can enhance understandability for future contributors.

frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/ColumnElement/EditColumnElement/EditColumnElement.tsx (1)

88-89: Ensure data availability before using formLayouts and subformDefaultDataModel

Consider adding checks to ensure that formLayouts and subformDefaultDataModel are defined before they are used. This can prevent potential runtime errors if the data is not yet loaded.

Apply this diff to add conditional rendering based on data availability:

 const { data: formLayouts } = useFormLayoutsQuery(org, app, subformLayout);
 const { data: layoutSets } = useLayoutSetsQuery(org, app);

+ if (!formLayouts || !layoutSets) {
+   return null; // or a loading indicator if preferred
+ }

 const subformDefaultDataModel = getDefaultDataModel(layoutSets, subformLayout);
 const availableComponents = getComponentsForSubformTable(formLayouts, subformDefaultDataModel);
frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/utils/editSubformTableColumnsUtils.test.ts (1)

51-52: Address the use of as any in the test code

Using as any can bypass type safety provided by TypeScript. Since there's a TODO comment referencing issue #14441, consider implementing a temporary type or interface to avoid casting to any, enhancing type safety until the issue is resolved.

Do you want me to help create a temporary type definition to replace as any, or assist in resolving the underlying type issue?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9b7bba9 and d9e3a2f.

📒 Files selected for processing (3)
  • frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/ColumnElement/EditColumnElement/EditColumnElement.tsx (3 hunks)
  • frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/utils/editSubformTableColumnsUtils.test.ts (3 hunks)
  • frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/utils/editSubformTableColumnsUtils.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
🔇 Additional comments (7)
frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/utils/editSubformTableColumnsUtils.ts (2)

9-10: Import statements added appropriately

The new imports of LayoutSets and convertDataBindingToInternalFormat are necessary for the added functionalities and are correctly included.


29-32: Updated getComponentsForSubformTable function signature

The inclusion of the defaultDataModel parameter enhances the function's ability to filter components based on the specific data model, improving accuracy in component selection.

frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/ColumnElement/EditColumnElement/EditColumnElement.tsx (3)

22-22: Imported getDefaultDataModel function correctly

The addition of getDefaultDataModel to the imports ensures that the default data model can be retrieved for component filtering.


27-27: Imported useLayoutSetsQuery hook appropriately

Including useLayoutSetsQuery enables fetching of layout sets necessary for determining the default data model.


61-61: Fetch layoutSets using useLayoutSetsQuery

The use of useLayoutSetsQuery to retrieve layoutSets is appropriate for accessing layout set data within the component.

frontend/packages/ux-editor/src/components/Properties/EditSubformTableColumns/utils/editSubformTableColumnsUtils.test.ts (2)

131-135: Updated tests to include defaultDataModel parameter

The tests for getComponentsForSubformTable now correctly include the defaultDataModel argument, ensuring that the new logic is adequately tested.


153-156: Ensure test coverage for components without data model bindings

The test case appropriately checks that components without data model bindings are excluded when the defaultDataModel is provided, confirming the function's filtering logic.

Copy link

codecov bot commented Jan 16, 2025

Codecov Report

Attention: Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.65%. Comparing base (5c1b2b9) to head (79c151e).

Files with missing lines Patch % Lines
...TableColumns/utils/editSubformTableColumnsUtils.ts 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14442      +/-   ##
==========================================
- Coverage   95.65%   95.65%   -0.01%     
==========================================
  Files        1886     1886              
  Lines       24546    24556      +10     
  Branches     2817     2819       +2     
==========================================
+ Hits        23479    23488       +9     
  Misses        805      805              
- Partials      262      263       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 solution/studio/designer Issues related to the Altinn Studio Designer solution.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

subform: filter tablecolumns components/databindings to only show bindings using subform's default datamodel
1 participant