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: Support unsetting the text resource in the text resource picker #14496

Merged
merged 5 commits into from
Jan 27, 2025

Conversation

TomasEng
Copy link
Contributor

@TomasEng TomasEng commented Jan 23, 2025

Description

In order to support undefined text resources in code lists, we need to support it in the text resource picker. This pull request adds an option for unsetting the text resource. Since this option is always present, the option list is never empty, som I have also removed the use of the StudioCombobox.Empty component.

The updated component calls the onChangeValue callback with null when the user chooses to unset the text resource.

image

I have added the skip-manual-testing label since it makes more sense to test it together with my next pull request, which will extend this functionality to the TextResourceInput component.

Related Issue

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

    • Added an "Unset Option" label for text resources with the value "Ikke oppgitt" (Not specified)
    • Introduced a new mode enumeration for text resource input
  • Style

    • Added italic styling for unset option labels
  • Refactor

    • Updated text resource picker to handle null values
    • Modified how empty/unset states are managed in text resource components
    • Adjusted translations for text resource handling in various components and hooks
  • Bug Fixes

    • Removed outdated messages regarding empty text resources from various components and tests.

Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Warning

Rate limit exceeded

@standeren has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 12 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 07fbbef and bfc2852.

📒 Files selected for processing (1)
  • frontend/language/src/nb.json (1 hunks)
📝 Walkthrough

Walkthrough

This pull request introduces changes to the text resource handling in the frontend components, specifically focusing on adding an "unset option" label and removing the empty resource list text. The modifications span multiple files across the studio components, affecting how text resources are displayed and managed. The changes primarily involve updating type definitions, test files, and component implementations to support a new way of representing unset or empty options.

Changes

File Change Summary
frontend/language/src/nb.json Added unset_option_label key, removed empty_list key
frontend/libs/studio-components/src/components/StudioCodelistEditor/test-data/texts.ts Removed emptyResourceList, added noTextResourceOptionLabel
frontend/libs/studio-components/src/components/StudioInputTable/test-data/testTableData.ts Removed emptyResourceList, added noTextResourceOptionLabel, updated import statement
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.stories.tsx Removed emptyResourceList, added noTextResourceOptionLabel
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.test.tsx Removed emptyResourceList, added noTextResourceOptionLabel
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.tsx Removed emptyListText, added noTextResourceOptionLabel
frontend/libs/studio-components/src/components/StudioTextResourceInput/types/Mode.ts Added Mode enum with EditValue and Search
frontend/libs/studio-components/src/components/StudioTextResourceInput/types/TextResourceInputTexts.ts Removed emptyResourceList, added noTextResourceOptionLabel
frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.module.css Added .noTextResourceOption label CSS rule for italic styling
frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.stories.tsx Removed emptyListText, added noTextResourceOptionLabel
frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx Removed emptyListText, added noTextResourceOptionLabel, updated tests
frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx Updated onValueChange to accept `string
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/hooks/useCodeListEditorTexts.ts Removed retrieval of emptyResourceList, added retrieval for noTextResourceOptionLabel
frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/hooks/useOptionListEditorTexts.ts Added noTextResourceOptionLabel to return object

Possibly related PRs

Suggested labels

quality/code

Suggested reviewers

  • Jondyr
  • Ildest

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 23, 2025
@TomasEng TomasEng force-pushed the suppurt-unset-text-resource branch from 4c63325 to 4056bcb Compare January 23, 2025 11:47
Copy link

codecov bot commented Jan 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.70%. Comparing base (165fcf1) to head (bfc2852).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14496   +/-   ##
=======================================
  Coverage   95.70%   95.70%           
=======================================
  Files        1901     1901           
  Lines       24730    24733    +3     
  Branches     2831     2831           
=======================================
+ Hits        23667    23670    +3     
  Misses        802      802           
  Partials      261      261           

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

@TomasEng TomasEng force-pushed the suppurt-unset-text-resource branch from 4056bcb to 5b32fcf Compare January 23, 2025 12:03
@TomasEng TomasEng added team/studio-domain1 skip-releasenotes Issues that do not make sense to list in our release notes skip-manual-testing PRs that do not need to be tested manually skip-documentation Issues where updating documentation is not relevant labels Jan 23, 2025
@TomasEng TomasEng marked this pull request as ready for review January 23, 2025 12:21
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/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.stories.tsx (1)

18-18: Consider using i18n keys in Storybook stories.

While the Norwegian text "Ikke oppgitt" works, consider using translation keys for consistency across the application. This would make the stories more maintainable and aligned with the application's internationalization approach.

frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.stories.tsx (1)

43-43: Maintain consistency with StudioTextResourcePicker stories.

The implementation looks good, but consider standardizing the approach to internationalization across all component stories. This could involve either:

  1. Using translation keys consistently across all stories
  2. Using English placeholder text for all stories
frontend/libs/studio-components/src/components/StudioInputTable/test-data/testTableData.ts (1)

41-41: Consider using English in test data.

The unset option label is in Norwegian ('Ikke oppgitt'). Consider using English for test data consistency unless specifically testing localization.

-  unsetOptionLabel: 'Ikke oppgitt',
+  unsetOptionLabel: 'Not specified',
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd014a5 and 5b32fcf.

📒 Files selected for processing (14)
  • frontend/language/src/nb.json (1 hunks)
  • frontend/libs/studio-components/src/components/StudioCodelistEditor/test-data/texts.ts (1 hunks)
  • frontend/libs/studio-components/src/components/StudioInputTable/test-data/testTableData.ts (2 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.stories.tsx (1 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.test.tsx (1 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.tsx (1 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourceInput/types/Mode.ts (1 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourceInput/types/TextResourceInputTexts.ts (1 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.module.css (1 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.stories.tsx (1 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx (2 hunks)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx (1 hunks)
  • frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/hooks/useCodeListEditorTexts.ts (1 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/hooks/useOptionListEditorTexts.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.module.css
  • frontend/libs/studio-components/src/components/StudioTextResourceInput/types/Mode.ts
🔇 Additional comments (15)
frontend/libs/studio-components/src/components/StudioTextResourceInput/types/TextResourceInputTexts.ts (1)

7-7: LGTM! Type definition updated to support unsetting text resources.

The addition of unsetOptionLabel and removal of emptyResourceList aligns well with the PR objective to support undefined text resources.

frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/hooks/useCodeListEditorTexts.ts (1)

45-45: LGTM! Proper implementation of i18n for the unset option.

The implementation correctly uses the translation system and maintains type safety. The translation key structure follows the established pattern.

frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/hooks/useOptionListEditorTexts.ts (1)

46-46: LGTM! Clean addition of unset option label.

The addition of unsetOptionLabel follows the existing translation pattern and integrates well with the i18n system.

frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx (4)

11-14: LGTM! Type changes align with feature requirements.

The updated type signature for onValueChange and addition of required unsetOptionLabel prop properly support the unsetting feature.


41-48: Good documentation of component structure requirement.

The comment explaining why this can't be a component function is valuable for maintainability.


29-31: Consider handling undefined value case.

The current implementation handles null/empty values by defaulting to ['']. Consider if undefined should be handled differently.

-        value={value ? [value] : ['']}
+        value={value != null ? [value] : ['']}

20-24: Verify the null handling behavior.

The handleValueChange callback converts empty string to null. Ensure this behavior is consistent with other form components in the codebase.

✅ Verification successful

Empty string to null conversion is correct and consistent

The null handling in StudioTextResourcePicker is intentional and well-tested. The conversion of empty string to null aligns with the component's unset option behavior, which is explicitly verified in the test suite. This pattern ensures consistent handling of unset values.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar form value handling patterns
rg -l "onValueChange.*null" frontend/libs/studio-components/src/components/

Length of output: 284


Script:

#!/bin/bash
# Search for form components and their value handling
rg -l "onChange.*value" frontend/libs/studio-components/src/components/

# Get the content of the test file to understand expected behavior
cat frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx

# Use ast-grep to find similar array destructuring patterns in value handling
ast-grep --pattern 'const $_ = useCallback(($_: $_[]) => $_($_), [$_])'

Length of output: 9862


Script:

#!/bin/bash
# Check implementation of similar components
rg -A 3 "onValueChange.*null" frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.tsx
rg -A 3 "onValueChange.*null" frontend/libs/studio-components/src/components/StudioStatusRadioGroup/StudioStatusRadioGroup.tsx

# Look for similar picker/select components
fd "Studio.*Picker.tsx|Studio.*Select.tsx" frontend/libs/studio-components/src/components/

Length of output: 542


Script:

#!/bin/bash
# Check StudioNativeSelect implementation
cat frontend/libs/studio-components/src/components/StudioNativeSelect/StudioNativeSelect.tsx

# Look for its tests as well
cat frontend/libs/studio-components/src/components/StudioNativeSelect/StudioNativeSelect.test.tsx

Length of output: 1054

frontend/libs/studio-components/src/components/StudioInputTable/test-data/testTableData.ts (1)

2-2: LGTM! Import path updated correctly.

The import path change reflects proper module organization.

frontend/libs/studio-components/src/components/StudioCodelistEditor/test-data/texts.ts (1)

37-37: LGTM! Test data properly updated.

The addition of unsetOptionLabel with English text 'None' is consistent with test data best practices.

frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx (3)

17-17: LGTM! Good test setup.

The addition of unsetOptionLabel to defaultProps ensures consistent test behavior.

Also applies to: 21-21


25-25: LGTM! Good test hygiene.

Adding beforeEach(jest.clearAllMocks) ensures clean test state between runs.


69-90: LGTM! Comprehensive test coverage for the new unset feature.

The new test cases thoroughly verify the unset option functionality:

  1. Displays the unset option
  2. Shows unset option as default selection
  3. Triggers callback with null when unset is selected
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.test.tsx (1)

24-24: LGTM! Good localization.

Added Norwegian translation 'Ikke oppgitt' for the unset option label.

frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.tsx (1)

135-136: LGTM! Clean prop passing.

Good prop organization and proper forwarding of unsetOptionLabel to StudioTextResourcePicker.

frontend/language/src/nb.json (1)

160-160: LGTM! Consistent localization.

Added Norwegian translation key and value following the established naming pattern.

@standeren standeren self-assigned this Jan 24, 2025
Copy link
Contributor

@standeren standeren left a comment

Choose a reason for hiding this comment

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

As usual, not much to comment 🌟

@standeren standeren assigned TomasEng and unassigned standeren Jan 24, 2025
@TomasEng TomasEng requested a review from standeren January 27, 2025 06:04
@TomasEng TomasEng assigned standeren and unassigned TomasEng Jan 27, 2025
@standeren standeren assigned TomasEng and unassigned standeren Jan 27, 2025
@TomasEng TomasEng merged commit 0dca765 into main Jan 27, 2025
11 checks passed
@TomasEng TomasEng deleted the suppurt-unset-text-resource branch January 27, 2025 11:44
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-documentation Issues where updating documentation is not relevant skip-manual-testing PRs that do not need to be tested manually 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.

2 participants