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

feat: Remove featureflag multiple data models per task #14171

Merged
merged 17 commits into from
Jan 16, 2025

Conversation

lassopicasso
Copy link
Contributor

@lassopicasso lassopicasso commented Nov 26, 2024

Description

This PR removes the feature flag: 'multipleDataModelsPerTask and the code related to this + updates tests.

What should be tested before merging this to main

Pre-Test Setup

  1. Navigate to the Datamodell page
  2. Create and generate several data models with distinct data model fields
  3. Navigate to the Prosesser page
  4. Create a new layoutset and bind it to a data model so it has a default data model

Test cases

  1. Default data model binding for layout set
    a. Create a new layout set i prosesser
    b. Bind the layout set to a default data model
    c. Go to “Utforming” section and add a component
    d. Verify that the default data model is selected in the data model bindings for the component.

  2. Select an Alternative Data Model in Data Model Bindings
    a. Confirm that you can select a data model other than the default in the data model bindings for a component.

  3. Switch between data models in data model bindings
    a. Test switching between different data models in the data model bindings for a component
    b. Ensure the related data model fields are displayed correctly in the dropdown list for each selection.

  4. Preview Functionality with non-default data models
    a. Verify that the preview functionality works as expected when a data model other than the default is selected.
    b. See releated issue: Preview Fails When Linking Component to Non-Default Data Model #14104

  5. Layout configuration – correct bindings displayed
    a. In the layout configuration in “se siste endringer”:
    i. Check that the correct bindings are displayed when selecting data model fields for the default data model
    ii. Check that the correct bindings are displayed when selecting a non-default data model and one of its data model fields

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

  • Refactor

    • Removed feature flag for multiple data models per task
    • Simplified component configuration and data model binding logic
  • Tests

    • Updated test cases for data model binding components
    • Improved element selection and test specificity in UI editor tests
  • Chores

    • Streamlined code for form item generation
    • Removed conditional rendering based on feature flags

@lassopicasso lassopicasso linked an issue Nov 26, 2024 that may be closed by this pull request
8 tasks
@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. quality/testing Tests that are missing, needs to be created or could be improved. frontend labels Nov 26, 2024
@lassopicasso lassopicasso changed the title Remove featureflag multiple data models per task feat: Remove featureflag multiple data models per task Nov 26, 2024
@lassopicasso lassopicasso marked this pull request as ready for review November 26, 2024 15:18
@lassopicasso
Copy link
Contributor Author

lassopicasso commented Nov 26, 2024

This may need to be set to blocked after review until this is solved #14104, to make sure that number 4 works,Preview Functionality with non-default data models.

Copy link

codecov bot commented Nov 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.63%. Comparing base (e33453d) to head (cd8f7cd).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14171      +/-   ##
==========================================
- Coverage   95.65%   95.63%   -0.02%     
==========================================
  Files        1884     1884              
  Lines       24473    24470       -3     
  Branches     2811     2810       -1     
==========================================
- Hits        23409    23403       -6     
- Misses        804      805       +1     
- Partials      260      262       +2     

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

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! 🚀 I just left suggestions to remove some console.log.

frontend/packages/ux-editor/src/utils/component.ts Outdated Show resolved Hide resolved
@lassopicasso
Copy link
Contributor Author

lassopicasso commented Dec 12, 2024

Nice work! 🚀 I just left suggestions to remove some console.log.

Thx! :)

@mlqn
Copy link
Contributor

mlqn commented Jan 8, 2025

Tested OK in dev! 🙂🚀 but I didn’t realize I had already done the CR, so I can’t add the second approval on this one 🫤

@Annikenkbrathen
Copy link

Hi! just tested doing the 5 five test cases ☺️ it looks good overall, but I have some comments!

case 1: tested OK!✅

case 2: It worked to switch between different data models in the data model bindings for a component, but when I switched to a data model that is used in another task/layoutset, the preview crashed. When I switched to an unused datamodel, it worked perfectly fine! If that is something we can't/won't fix, maybe we should explain what's happening?

case 3: tested OK!✅ I have one thought about the data model bindings select. It might seem a bit odd that it looks like a data model binding field named "choose data model field" is already selected when switching between data models. Wouldn't it be better to have an empty select with a validation message indicating that you need to choose a data model field instead?
Skjermbilde 2025-01-09 kl  15 23 02

case 4: Commented on this in case 2

case 5: Tested OK (as far as I understood it 😅)

@lassopicasso
Copy link
Contributor Author

lassopicasso commented Jan 10, 2025

Thx for testing, @Annikenkbrathen! I will investigate case 2 and your other comments 🙂

@Jondyr
Copy link
Member

Jondyr commented Jan 13, 2025

case 2: It worked to switch between different data models in the data model bindings for a component, but when I switched to a data model that is used in another task/layoutset, the preview crashed. When I switched to an unused datamodel, it worked perfectly fine! If that is something we can't/won't fix, maybe we should explain what's happening?

@Annikenkbrathen

I am unable to reproduce this as described. Do you remember the app name used in dev? Here is what i did, in case i did something different:

  1. created new app
  2. added two components to layout and bound to default datamodel
  3. created a new datamodel and process task, set datamodel as default on new task
  4. went back into ux-editor/preview and changed one component's datamodel from default to the new task's datamodel
  5. preview works as expected

@Annikenkbrathen
Copy link

Annikenkbrathen commented Jan 13, 2025

case 2: It worked to switch between different data models in the data model bindings for a component, but when I switched to a data model that is used in another task/layoutset, the preview crashed. When I switched to an unused datamodel, it worked perfectly fine! If that is something we can't/won't fix, maybe we should explain what's happening?

@Annikenkbrathen

I am unable to reproduce this as described. Do you remember the app name used in dev? Here is what i did, in case i did something different:

  1. created new app
  2. added two components to layout and bound to default datamodel
  3. created a new datamodel and process task, set datamodel as default on new task
  4. went back into ux-editor/preview and changed one component's datamodel from default to the new task's datamodel
  5. preview works as expected

@Jondyr I used an app I made called Arbeidsflate and Still get this view when I switch to the data model called "model", the two other data models work perfectly.

https://dev.altinn.studio/editor/ttd/arbeidsflate/ui-editor?layout=Side1

@Jondyr
Copy link
Member

Jondyr commented Jan 14, 2025

@Annikenkbrathen

It looks to me like the issue here is that the datamodel is incorrectly defined. The preview throws this error:
Error: schema is invalid: data/$defs/name3/anyOf must NOT have fewer than 1 items

I am unable to edit this datamodel without getting errors so i'm not sure how to properly test it with this specific app.

@Annikenkbrathen
Copy link

@Annikenkbrathen

It looks to me like the issue here is that the datamodel is incorrectly defined. The preview throws this error: Error: schema is invalid: data/$defs/name3/anyOf must NOT have fewer than 1 items

I am unable to edit this datamodel without getting errors so i'm not sure how to properly test it with this specific app.

oh okay, my bad😰 Thanks for checking it out! Then all is good

@lassopicasso
Copy link
Contributor Author

@Annikenkbrathen or @Jondyr - if i understand correctly that testing went ok, could one of you approve this PR? I will solve the merge conflicts now.

Copy link

coderabbitai bot commented Jan 16, 2025

📝 Walkthrough

Walkthrough

This pull request involves modifications across multiple frontend files, primarily focusing on removing the MultipleDataModelsPerTask feature flag and updating type definitions related to data model bindings. The changes simplify the codebase by eliminating conditional rendering and feature flag checks, particularly in components and tests related to data model binding configurations. The modifications affect type definitions, utility functions, and test suites in the UX editor and shared packages.

Changes

File Change Summary
frontend/packages/shared/src/types/ComponentSpecificConfig.ts - Added type import for InternalBindingFormat
- Updated type signatures for DataModelBindingsOptionsSimple and DataModelBindingsSimple to support string | InternalBindingFormat
frontend/packages/shared/src/utils/featureToggleUtils.ts - Removed MultipleDataModelsPerTask enum entry
frontend/packages/ux-editor/src/components/Properties/DataModelBindings.test.tsx - Updated defaultModel from 'testModel' to 'testModelField'
frontend/packages/ux-editor/src/components/config/editModal/... - Removed feature flag checks in EditBinding, SelectDataModelBinding components
- Updated test cases to remove feature flag dependencies
frontend/packages/ux-editor/src/utils/component.ts - Simplified destructuring of formItemConfigs
- Modified generateFormItem function to streamline componentRef retrieval
frontend/testing/playwright/tests/ui-editor/... - Removed featureFlag parameter from setupAndVerifyUiEditorPage function calls

Possibly related PRs

Suggested labels

area/process, skip-releasenotes, team/studio-domain1, skip-documentation

Suggested reviewers

  • mlqn

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.

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

🔭 Outside diff range comments (1)
frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditDataModelBinding.test.tsx (1)

Add test coverage for data model switching scenarios

The current test suite lacks coverage for data model switching functionality, despite having the infrastructure in place. Consider adding the following test cases to EditDataModelBinding.test.tsx:

  • Test switching between defaultDataModel and secondDataModel
  • Verify bindings remain correct after switching data models
  • Test preview functionality with non-default data models

The test file already has the necessary setup with both data models defined and queryClient configured, making it straightforward to add these test cases.

🔗 Analysis chain

Line range hint 1-180: Consider adding test coverage for data model switching scenarios.

Given that this PR removes the multipleDataModelsPerTask feature flag and the PR objectives mention testing data model switching functionality, consider adding test cases for:

  • Switching between default and alternative data models
  • Verifying preview functionality with non-default data models
  • Testing layout configuration displays correct bindings after switches

This would help ensure the removal of the feature flag doesn't introduce regressions.

Let's verify if there are any existing tests for these scenarios:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for tests related to data model switching
rg -A 5 "test.*data.*model.*switch|test.*switch.*data.*model" frontend/packages/ux-editor/src

Length of output: 95


Script:

#!/bin/bash
# Search for data model related tests more broadly
echo "=== Searching for data model related tests ==="
rg -l "describe.*Data.*Model|test.*data.*model|it.*data.*model" frontend/packages/ux-editor/src/

echo -e "\n=== Checking EditDataModelBinding test content ==="
cat frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditDataModelBinding.test.tsx

echo -e "\n=== Searching for dataType tests ==="
rg "test.*dataType|it.*dataType" frontend/packages/ux-editor/src/

Length of output: 10736

🧹 Nitpick comments (3)
frontend/testing/playwright/tests/ui-editor/ui-editor-data-model-binding-and-gitea.spec.ts (1)

Line range hint 32-45: Clean up unused feature flag logic in setup function.

Since the feature flag functionality is being removed, the setupAndVerifyUiEditorPage function should be simplified by removing the unused feature flag parameter and its associated logic.

 const setupAndVerifyUiEditorPage = async (
   page: Page,
-  testAppName: string,
-  featureFlag?: string[],
+  testAppName: string
 ): Promise<UiEditorPage> => {
   const uiEditorPage = new UiEditorPage(page, { app: testAppName });
   await uiEditorPage.loadUiEditorPage();
   await uiEditorPage.verifyUiEditorPage();
-  if (featureFlag) {
-    await page.evaluate((flag) => {
-      localStorage.setItem('featureFlags', JSON.stringify(flag));
-    }, featureFlag);
-  }

   await uiEditorPage.clickOnPageAccordion(pageName);
   await uiEditorPage.verifyUiEditorPage(pageName);

   return uiEditorPage;
 };
frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.test.tsx (2)

46-50: Improve type safety in component change handler.

The type casting of dataModelBindings[defaultBindingKey] to InternalBindingFormat could be risky.

Consider adding a type guard:

-const fieldBinding = formItem.dataModelBindings[defaultBindingKey] as InternalBindingFormat;
+const binding = formItem.dataModelBindings[defaultBindingKey];
+const fieldBinding = typeof binding === 'object' && binding !== null ? binding : { field: binding };

Line range hint 326-355: Add test coverage for window.confirm.

The test mocks window.confirm but doesn't verify it was called.

Add an assertion to verify the confirmation dialog:

expect(window.confirm).toHaveBeenCalledWith(
  expect.stringContaining('delete')
);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e33453d and cd8f7cd.

📒 Files selected for processing (9)
  • frontend/packages/shared/src/types/ComponentSpecificConfig.ts (2 hunks)
  • frontend/packages/shared/src/utils/featureToggleUtils.ts (0 hunks)
  • frontend/packages/ux-editor/src/components/Properties/DataModelBindings.test.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.test.tsx (13 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/SelectDataModelBinding.tsx (2 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditDataModelBinding.test.tsx (1 hunks)
  • frontend/packages/ux-editor/src/utils/component.ts (1 hunks)
  • frontend/testing/playwright/tests/ui-editor/ui-editor-data-model-binding-and-gitea.spec.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • frontend/packages/shared/src/utils/featureToggleUtils.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Testing
  • GitHub Check: Build environment and run e2e test
🔇 Additional comments (10)
frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/SelectDataModelBinding.tsx (1)

4-4: LGTM! Code simplification improves maintainability.

The removal of feature flag checks and consistent use of FormField with StudioNativeSelect makes the code more maintainable and easier to understand.

Also applies to: 43-69

frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.tsx (1)

50-52: LGTM! Simplified value assignment logic.

The removal of feature flag checks simplifies the code while maintaining the same functionality.

frontend/packages/ux-editor/src/utils/component.ts (1)

144-146: LGTM! Improved code readability.

The changes enhance readability by:

  1. Destructuring all required properties in a single statement
  2. Simplifying the componentType assignment logic
frontend/testing/playwright/tests/ui-editor/ui-editor-data-model-binding-and-gitea.spec.ts (1)

156-156: LGTM! Removed feature flag parameters.

The removal of feature flag parameters from setupAndVerifyUiEditorPage calls aligns with the PR objectives.

Also applies to: 168-168

frontend/packages/shared/src/types/ComponentSpecificConfig.ts (1)

10-10: LGTM! Type definitions updated to support internal binding format.

The changes properly extend the type system to handle both string and InternalBindingFormat for data model bindings, which is a good preparation for removing the feature flag.

Also applies to: 42-42, 47-47

frontend/packages/ux-editor/src/components/Properties/DataModelBindings.test.tsx (1)

20-20: Verify the impact of renaming defaultModel.

The variable has been renamed from 'testModel' to 'testModelField', which seems to better reflect its purpose as a field name. However, this variable is used in multiple test assertions.

Let's verify all usages to ensure the rename doesn't change test semantics:

✅ Verification successful

Rename of defaultModel improves code clarity

The rename from 'testModel' to 'testModelField' better reflects its purpose as a field identifier, while 'testModel' is correctly preserved in the separate defaultDataModel variable. All usages are consistent and contained within the test file.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all occurrences of defaultModel in test files
rg "defaultModel" "frontend/packages/ux-editor/src/components/Properties/DataModelBindings.test.tsx" -A 2 -B 2

Length of output: 818

frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditBinding/EditBinding.test.tsx (3)

20-20: LGTM! Added constant for second data model field.

Good practice to define the test data as constants at the top of the file.


Line range hint 124-144: LGTM! Improved test descriptions and assertions.

The test cases are now more specific and better structured:

  • Clear test descriptions that explain what's being tested
  • Separate assertions for data model and field selectors
  • Proper use of ARIA roles for selector identification

Also applies to: 166-169


Line range hint 238-270: LGTM! Comprehensive test coverage for data model changes.

Good test coverage for both field and model changes:

  • Tests the correct structure of the binding format
  • Verifies the callback parameters
  • Checks both field and data type updates

Also applies to: 282-314

frontend/packages/ux-editor/src/components/config/editModal/EditDataModelBinding/EditDataModelBinding.test.tsx (1)

65-67: LGTM! More specific selector improves test robustness.

The addition of the name parameter using the i18n key makes the combobox selector more specific and maintainable.

@Jondyr
Copy link
Member

Jondyr commented Jan 16, 2025

if i understand correctly that testing went ok, could one of you approve this PR? I will solve the merge conflicts now.

I haven't done any testing here, so I think it's more appropriate for @Annikenkbrathen to approve/object to the changes.

@Annikenkbrathen Annikenkbrathen self-requested a review January 16, 2025 14:45
@lassopicasso lassopicasso merged commit 0ba2d73 into main Jan 16, 2025
9 checks passed
@lassopicasso lassopicasso deleted the remove-featureflag-multipleDataModelsPerTask branch January 16, 2025 15:03
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 quality/testing Tests that are missing, needs to be created or could be improved. solution/studio/designer Issues related to the Altinn Studio Designer solution.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove featureflag for multiple data models
4 participants