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: Account for invalid text resource ids in code list editor #14797

Merged
merged 9 commits into from
Feb 27, 2025

Conversation

TomasEng
Copy link
Contributor

@TomasEng TomasEng commented Feb 25, 2025

Description

This pull request makes the text resource selector account for text resource ID's that does not exist. In this case, no values will be selected in the search combobox. The invalid ID will remain as the current value until the user selects something.

There may be better ways to deal with this case, but we have a separate issue for that. This is relevant not only in code lists, but everywhere where we have text references. Therefore I have chosen the safest and most straightforward solution for now.

Spiller.inn.2025-02-25.103250.mp4

Note

When testing this in the app content library, there will still appear an error message when unsetting the text resource on the label field. That's another issue, which is due to the label property being required.

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)

Summary by CodeRabbit

  • New Features

    • The text resource selection component now displays an empty selection when an invalid resource identifier is provided, ensuring clearer user interaction.
  • Tests

    • Additional quality checks have been implemented to verify the component behaves correctly in scenarios with both valid and invalid resource identifiers.
    • A new test suite has been added for the utility function that retrieves selected values based on provided resource identifiers.

# Conflicts:
#	frontend/app-development/features/appContentLibrary/test-data/optionListDataList.ts
#	frontend/app-development/features/appContentLibrary/test-data/textResources.ts
Copy link
Contributor

coderabbitai bot commented Feb 25, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a new utility function, retrieveSelectedValues, to determine the selected values in the StudioTextResourcePicker component based on the existence of provided IDs in the text resources. Additionally, it adds a test case for the component to handle scenarios where a non-existent ID is provided, as well as a new test suite for the utility function, validating its behavior across various input scenarios.

Changes

Files Change Summary
frontend/.../StudioTextResourcePicker.tsx
frontend/.../StudioTextResourcePicker.test.tsx
Added a new test case for handling non-existent IDs in the StudioTextResourcePicker component and updated the component to use retrieveSelectedValues for determining selected values.
frontend/.../utils.ts
frontend/.../utils.test.ts
Introduced the retrieveSelectedValues and doesTextResourceExist utility functions, along with a test suite covering various scenarios for the retrieveSelectedValues function.

Possibly related PRs

Suggested labels

area/ui-editor, skip-manual-testing

Suggested reviewers

  • github-actions
  • ErlingHauan

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-storybook".

(The package "eslint-plugin-storybook" was not found when loaded as a Node module from the directory "/frontend/libs/studio-components".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-storybook@latest --save-dev

The plugin "eslint-plugin-storybook" was referenced from the config file in "frontend/libs/studio-components/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-storybook".

(The package "eslint-plugin-storybook" was not found when loaded as a Node module from the directory "/frontend/libs/studio-components".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-storybook@latest --save-dev

The plugin "eslint-plugin-storybook" was referenced from the config file in "frontend/libs/studio-components/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

frontend/libs/studio-components/src/components/StudioTextResourcePicker/utils.test.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-storybook".

(The package "eslint-plugin-storybook" was not found when loaded as a Node module from the directory "/frontend/libs/studio-components".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-storybook@latest --save-dev

The plugin "eslint-plugin-storybook" was referenced from the config file in "frontend/libs/studio-components/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

  • 1 others

Tip

CodeRabbit's docstrings feature is now available as part of our Pro Plan! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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 solution/studio/designer Issues related to the Altinn Studio Designer solution. frontend labels Feb 25, 2025
@TomasEng TomasEng changed the title Account for invalid text resource ids fix: Account for invalid text resource ids in code list editor Feb 25, 2025
Copy link

codecov bot commented Feb 25, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.77%. Comparing base (6722766) to head (2031211).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14797   +/-   ##
=======================================
  Coverage   95.77%   95.77%           
=======================================
  Files        1922     1923    +1     
  Lines       25077    25082    +5     
  Branches     2867     2867           
=======================================
+ Hits        24018    24023    +5     
  Misses        799      799           
  Partials      260      260           

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

@TomasEng TomasEng added skip-releasenotes Issues that do not make sense to list in our release notes team/studio-domain1 skip-documentation Issues where updating documentation is not relevant labels Feb 25, 2025
@TomasEng TomasEng marked this pull request as ready for review February 25, 2025 10:34
Copy link
Contributor

@wrt95 wrt95 left a comment

Choose a reason for hiding this comment

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

One comment added 😄

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/libs/studio-components/src/components/StudioTextResourcePicker/utils.test.ts (1)

8-9: Consider making the test more maintainable

Using a hardcoded index (129) makes the test brittle if the mock data changes. Consider using a more descriptive approach to find a text resource for testing, such as finding by a specific ID or using the first item in the array.

- const arbitraryTextResourceIndex = 129;
- const textResource = textResources[arbitraryTextResourceIndex];
+ // Use a specific text resource that we know exists in the mock data
+ const textResource = textResources.find(resource => resource.id !== undefined) || textResources[0];
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c86ae77 and 2d771f7.

📒 Files selected for processing (4)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx (1 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx (2 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/utils.test.ts (1 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: CodeQL
  • GitHub Check: Typechecking and linting
  • GitHub Check: Testing
🔇 Additional comments (5)
frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx (2)

41-44: Great implementation, addressing previous feedback!

Good job extracting the logic to a separate utility function and using useMemo to optimize the computation of selectedValues. This implementation efficiently handles the case where text resource IDs don't exist in the available resources.


50-50: Correct implementation of component value prop

The updated implementation ensures that the combobox only selects values that exist in the text resources, addressing the issue mentioned in the PR objectives where invalid IDs would result in empty selections.

frontend/libs/studio-components/src/components/StudioTextResourcePicker/utils.test.ts (1)

4-22: Comprehensive test suite covering all edge cases

The test cases effectively validate the behavior of retrieveSelectedValues:

  1. When a text resource exists
  2. When a text resource doesn't exist
  3. When the value is null or undefined

Good use of parameterized testing with it.each for null and undefined values.

frontend/libs/studio-components/src/components/StudioTextResourcePicker/utils.ts (2)

3-5: Clean implementation of retrieveSelectedValues

The function clearly fulfills its purpose by returning an array with the ID if the text resource exists, or an empty array if it doesn't. The implementation is concise and follows the single responsibility principle.


7-9: Efficient implementation of doesTextResourceExist

Good use of the some() method for an efficient search without unnecessary iteration through the entire array. The function handles the optional id parameter correctly.

@wrt95 wrt95 removed their assignment Feb 26, 2025
Copy link
Contributor

@Konrad-Simso Konrad-Simso 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!

After testing a bit I found this bug, it's not directly related to this PR, but made possible by it.

Skjermopptak.2025-02-26.154345.mp4

The errorcode i get is 400, here is the response from the backend:

{
    "errors": {
        "[0].Label": [
            "The field is required."
        ]
    },
    "type": "https://tools.ietf.org/html/rfc9110#section-15.5.1",
    "title": "One or more validation errors occurred.",
    "status": 400,
    "traceId": "00-c8a037410aff4b63b66bed2f43042ea0-5306a91dec31cfbf-01"
}

@Konrad-Simso Konrad-Simso removed their assignment Feb 26, 2025
@TomasEng
Copy link
Contributor Author

TomasEng commented Feb 27, 2025

Thanks for testing, @Konrad-Simso. This is the error that I mentioned in the description. I'm working on another pull request that will fix it: #14826

@TomasEng TomasEng merged commit 21f546a into main Feb 27, 2025
11 checks passed
@TomasEng TomasEng deleted the account-for-invalid-text-resource-ids branch February 27, 2025 07:43
@coderabbitai coderabbitai bot mentioned this pull request Feb 27, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend skip-documentation Issues where updating documentation is not relevant skip-releasenotes Issues that do not make sense to list in our release notes solution/studio/designer Issues related to the Altinn Studio Designer solution. team/studio-domain1
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants