-
Notifications
You must be signed in to change notification settings - Fork 75
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 undefined text resource in text resource selector #14495
Conversation
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
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.stories.tsxOops! 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:
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/StudioTextResourceInput/StudioTextResourceInput.test.tsxOops! 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:
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/StudioTextResourceInput/utils.test.tsOops! 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:
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.
📝 WalkthroughWalkthroughThe pull request focuses on enhancing the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #14495 +/- ##
=======================================
Coverage 95.71% 95.71%
=======================================
Files 1902 1903 +1
Lines 24788 24797 +9
Branches 2839 2841 +2
=======================================
+ Hits 23726 23735 +9
Misses 801 801
Partials 261 261 ☔ View full report in Codecov by Sentry. |
…t-resource-id # Conflicts: # frontend/language/src/nb.json # frontend/libs/studio-components/src/components/StudioCodelistEditor/test-data/texts.ts # frontend/libs/studio-components/src/components/StudioInputTable/test-data/testTableData.ts # frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.stories.tsx # frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.test.tsx # frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.tsx # frontend/libs/studio-components/src/components/StudioTextResourceInput/types/TextResourceInputTexts.ts # frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.stories.tsx # frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx # frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx # frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/hooks/useCodeListEditorTexts.ts # frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/hooks/useOptionListEditorTexts.ts
There was a problem hiding this 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/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.tsx (1)
53-53
: Consider adding type conversion safety.The currentId state management could benefit from explicit type handling.
-const [currentId, setCurrentId] = usePropState<string | null | undefined>(givenCurrentId); +const [currentId, setCurrentId] = usePropState<string | null | undefined>( + givenCurrentId === '' ? null : givenCurrentId +);Also applies to: 55-55
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.test.tsx (1)
93-104
: Consider adding error case tests.While the happy path is well tested, consider adding tests for error scenarios:
- Invalid text resource format
- Network errors in resource loading
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.stories.tsx (1)
49-54
: Consider adding more edge case stories.While the basic cases are covered, consider adding stories for:
- Error states
- Loading states
- Invalid text resource format
frontend/libs/studio-components/src/components/StudioTextResourceInput/utils.test.ts (1)
59-73
: Well-structured test suite with room for additional edge cases.The test suite effectively covers the basic scenarios including empty string, null, and undefined values. Consider adding tests for these edge cases:
- Whitespace-only strings (e.g., ' ', '\t', '\n')
- Very long IDs
- IDs with special characters
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.stories.tsx
(2 hunks)frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.test.tsx
(5 hunks)frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.tsx
(4 hunks)frontend/libs/studio-components/src/components/StudioTextResourceInput/utils.test.ts
(2 hunks)frontend/libs/studio-components/src/components/StudioTextResourceInput/utils.ts
(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
- GitHub Check: Build environment and run e2e test
- GitHub Check: Testing
- GitHub Check: CodeQL
🔇 Additional comments (8)
frontend/libs/studio-components/src/components/StudioTextResourceInput/utils.ts (2)
5-8
: LGTM! Good type safety improvement.The updated return type
TextResource | undefined
better reflects the function's behavior when no matching resource is found.
30-32
: LGTM! Clean implementation of mode determination.The function is well-focused and handles null/undefined cases appropriately.
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.tsx (2)
26-26
: LGTM! Type definitions align with requirements.The updated types properly support undefined/null text resources.
Also applies to: 29-29
161-172
: LGTM! Good component separation.Clean separation of enabled/disabled states improves code organization and maintainability.
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.test.tsx (1)
38-42
: LGTM! Comprehensive test cases for edge scenarios.Good coverage of different null/undefined cases using test.each.
frontend/libs/studio-components/src/components/StudioTextResourceInput/StudioTextResourceInput.stories.tsx (1)
34-34
: LGTM! Clear story naming.Renaming to WithId provides better clarity about the story's purpose.
Also applies to: 48-48
frontend/libs/studio-components/src/components/StudioTextResourceInput/utils.test.ts (2)
1-6
: LGTM! Clean import addition.The new
determineDefaultMode
import is properly added alongside related utility functions.
59-73
: Verify component behavior alignment.Let's verify that the test cases align with how
determineDefaultMode
is used in the component:✅ Verification successful
✓ Component behavior is correctly aligned
The test cases perfectly match how
determineDefaultMode
is used in the component, covering all possible input scenarios (valid ID, empty string, null, undefined) and their expected behavior (EditValue/Search modes).🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for usage of determineDefaultMode in the component echo "Searching for determineDefaultMode usage in StudioTextResourceInput component..." rg -A 5 "determineDefaultMode" frontend/libs/studio-components/src/components/StudioTextResourceInput/Length of output: 4441
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally in Storybook.
StudioTextResourceInput
, spesifically it's child component StudioTextResourcePicker
has 2 unexpected behaviours when removing the text resource key.
Removing the text resouce key results in "ikke oppgitt" being selected automatically when the first letter is removed, or if the user pauses while removing the line and continues to hold down backspace
afterwords.
Here is an example:
Skjermopptak.2025-02-03.101207.mp4
I know this issue is not directly related to this PR as i've tested this on both this branch and main, it exists in both. However thought i should mention it here as it's an issue with removing the key and that is part of the goal with this PR.
Great testing, @Konrad-Simso! I'll have a look at the problem you found, but since it is not caused by this pull request, I suggest we merge it and create another one for fixing the bug. What do you think? |
Sounds good |
Description
Added support for undefined text resources in the text resource input component. This includes the following:
null
andundefined
values for thecurrentId
proponChangeCurrentId
callnull
when the user deconnects a text resourceDefault mode with no text resource:

Edit mode with no text resource:

Related Issue(s)
Verification
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests
The updates provide more flexible text resource input functionality with better error handling and mode selection.