Skip to content

feat: show code list title as readOnly displayTile if in use #14400

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

Merged
merged 6 commits into from
Jan 20, 2025

Conversation

standeren
Copy link
Contributor

@standeren standeren commented Jan 10, 2025

Description

Show title as readOnly displayTile if in use.

Skjermbilde 2025-01-10 kl  14 06 26

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

Release Notes

  • New Features

    • Added a new error message for code list editing restrictions.
  • Bug Fixes

    • Improved user feedback regarding code list editing states.
  • Refactor

    • Restructured code list editing component to enhance modularity.
    • Simplified component logic for code list title management.
    • Enhanced data handling by adding code list sources to the editing component.
  • Tests

    • Added test coverage for scenarios where the code list is in use.

@standeren standeren added skip-releasenotes Issues that do not make sense to list in our release notes area/content-library Area: Related to library for shared resources frontend team/studio-domain1 skip-documentation Issues where updating documentation is not relevant labels Jan 10, 2025
@github-actions github-actions bot added the solution/studio/designer Issues related to the Altinn Studio Designer solution. label Jan 10, 2025
Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.66%. Comparing base (026ec9d) to head (8ec1219).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14400   +/-   ##
=======================================
  Coverage   95.66%   95.66%           
=======================================
  Files        1891     1891           
  Lines       24581    24583    +2     
  Branches     2822     2823    +1     
=======================================
+ Hits        23515    23517    +2     
  Misses        805      805           
  Partials      261      261           

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

@standeren standeren changed the title feat: show title as readOnly displayTile if in use feat: show code list title as readOnly displayTile if in use Jan 13, 2025
Copy link
Contributor

coderabbitai bot commented Jan 13, 2025

📝 Walkthrough

Walkthrough

This pull request introduces changes to the code list editing functionality in a frontend application. Modifications include adding a Norwegian error message for disabled code list editing, updating a test case to verify the rendering behavior of the CodeLists component when a code list is in use, and refactoring the EditCodeList component to improve code modularity. The changes focus on enhancing user feedback and component structure when managing code lists.

Changes

File Change Summary
frontend/language/src/nb.json Added Norwegian error message for disabled code list editing
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/CodeLists.test.tsx Added test case to verify rendering when code list is in use
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/EditCodeList/EditCodeList.tsx - Created new EditCodeListTitle component
- Simplified EditCodeList component
- Updated method signature for updateCodeListWithMetadata
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/CodeLists.tsx Updated CodeListAccordionContent to include codeListSources prop in EditCodeList

Possibly related PRs

Suggested labels

area/ui-editor, text/content, added-to-sprint

Suggested reviewers

  • Jondyr

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 91b0915 and 8ec1219.

📒 Files selected for processing (1)
  • frontend/language/src/nb.json (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/language/src/nb.json
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
  • GitHub Check: CodeQL
  • GitHub Check: Typechecking and linting

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.

@standeren standeren force-pushed the disallow-code-list-id-change-when-in-use branch from b8dbe82 to fd9b3c8 Compare January 13, 2025 14:55
@standeren standeren marked this pull request as ready for review January 15, 2025 14:12
@Konrad-Simso Konrad-Simso self-assigned this Jan 16, 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, i just have 1 suggestion

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: 1

🧹 Nitpick comments (1)
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/EditCodeList/EditCodeList.tsx (1)

68-124: Well-implemented component with clean conditional rendering!

The component handles both editable and non-editable states elegantly. Good use of StudioToggleableTextfield and StudioDisplayTile components.

Consider extracting validation error messages to a separate utility function for better reusability:

+const getCodeListValidationError = (newCodeListId: string, invalidCodeListNames: string[]) => {
+  const fileNameError = FileNameUtils.findFileNameError(newCodeListId, invalidCodeListNames);
+  return getInvalidInputFileNameErrorMessage(fileNameError);
+};

 const handleValidateCodeListId = (newCodeListId: string) => {
   const invalidCodeListNames = ArrayUtils.removeItemByValue(codeListNames, codeListTitle);
-  const fileNameError = FileNameUtils.findFileNameError(newCodeListId, invalidCodeListNames);
-  return getInvalidInputFileNameErrorMessage(fileNameError);
+  return getCodeListValidationError(newCodeListId, invalidCodeListNames);
 };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 60ea6c6 and 71da4b0.

📒 Files selected for processing (3)
  • frontend/language/src/nb.json (1 hunks)
  • frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/CodeLists.test.tsx (1 hunks)
  • frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/EditCodeList/EditCodeList.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
  • GitHub Check: Typechecking and linting
  • GitHub Check: CodeQL
🔇 Additional comments (4)
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/EditCodeList/EditCodeList.tsx (3)

47-47: LGTM! Clean variable extraction.

The boolean variable clearly expresses the editability state based on code list usage, following the suggested extraction from previous reviews.


51-56: Well-structured component extraction!

The EditCodeListTitle component extraction improves code organization and follows the single responsibility principle. Props interface is clean and focused.


125-130: LGTM! Clean type update.

The type change from StudioComponentsCodeList to CodeList aligns with the import consolidation without affecting functionality.

frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/CodeLists.test.tsx (1)

179-193: Well-written test case covering the new functionality!

The test properly verifies that a display tile is rendered instead of an edit button when the code list is in use. Good assertions checking both presence and role attributes.

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.

Good work 🚀

@Konrad-Simso Konrad-Simso removed their assignment Jan 16, 2025
@standeren standeren force-pushed the disallow-code-list-id-change-when-in-use branch from 719df4a to d5b5374 Compare January 16, 2025 14:00
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 (2)
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/EditCodeList/EditCodeList.tsx (1)

100-102: Consider adding error handling for the onBlur event.

The onBlur handler should consider handling potential errors from the validation before updating the ID.

  const handleUpdateCodeListId = (newCodeListId: string) => {
-   if (newCodeListId !== codeListTitle) onUpdateCodeListId(codeListTitle, newCodeListId);
+   const validationError = handleValidateCodeListId(newCodeListId);
+   if (!validationError && newCodeListId !== codeListTitle) {
+     onUpdateCodeListId(codeListTitle, newCodeListId);
+   }
  };

Also applies to: 120-120

frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/CodeLists.tsx (1)

Line range hint 119-125: Consider extracting error state into a separate component.

For improved modularity, consider extracting the error state rendering into a separate component. This would make the code more maintainable and reusable.

+const CodeListError: React.FC = () => {
+  const { t } = useTranslation();
+  return (
+    <StudioAlert size='small' severity='danger'>
+      {t('app_content_library.code_lists.fetch_error')}
+    </StudioAlert>
+  );
+};

 function CodeListAccordionContent({
   codeListData,
   codeListSources,
   ...rest
 }: CodeListAccordionContentProps): React.ReactElement {
-  const { t } = useTranslation();
   return (
     <Accordion.Content>
-      {codeListData.hasError ? (
-        <StudioAlert size='small' severity='danger'>
-          {t('app_content_library.code_lists.fetch_error')}
-        </StudioAlert>
-      ) : (
+      {codeListData.hasError ? <CodeListError /> : (
         <EditCodeList
           codeList={codeListData.data}
           codeListTitle={codeListData.title}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 719df4a and d5b5374.

📒 Files selected for processing (4)
  • frontend/language/src/nb.json (1 hunks)
  • frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/CodeLists.test.tsx (1 hunks)
  • frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/CodeLists.tsx (2 hunks)
  • frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/EditCodeList/EditCodeList.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/CodeLists.test.tsx
  • frontend/language/src/nb.json
⏰ 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 (7)
frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/EditCodeList/EditCodeList.tsx (5)

5-5: LGTM!

The StudioDisplayTile import is correctly placed and properly utilized in the new component.


52-52: Consider renaming the variable to match the previous review suggestion.

For consistency with the previous review suggestion and better clarity, consider renaming isCodeListEditable to isCodeListIdEditable as it specifically controls the ID field's editability.


56-61: LGTM! Clean component extraction.

The EditCodeListTitle component extraction improves code organization and maintainability. All necessary props are correctly passed.


84-89: LGTM! Well-defined props interface.

The EditCodeListTitleProps type is clear and properly typed.


110-139: LGTM! Clean conditional rendering implementation.

The component appropriately switches between editable and read-only views based on the isCodeListEditable flag. The translation keys and props are handled correctly in both cases.

frontend/libs/studio-content-library/src/ContentLibrary/LibraryBody/pages/CodeListPage/CodeLists/CodeLists.tsx (2)

114-114: LGTM! Prop addition is well-structured.

The addition of codeListSources prop is properly typed and aligns with the PR's objective to handle code lists that are in use.


126-131: LGTM! Component refactoring improves readability.

The EditCodeList component changes maintain proper prop passing while improving code readability through multi-line formatting. The error handling remains intact, and the new codeListSources prop is correctly forwarded.

@ErlingHauan ErlingHauan self-assigned this Jan 17, 2025
Copy link
Contributor

@ErlingHauan ErlingHauan left a comment

Choose a reason for hiding this comment

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

Test OK 🙂

I noticed two things that are not directly related to this PR, but I can create issues for them if you agree:

  1. StudioToggleableTextfield does not save on enter
  2. Styling for StudioToggleableTextfield and StudioDisplayTile differs a little:
    bilde

@ErlingHauan ErlingHauan removed their assignment Jan 17, 2025
@standeren
Copy link
Contributor Author

Test OK 🙂

I noticed two things that are not directly related to this PR, but I can create issues for them if you agree:

  1. StudioToggleableTextfield does not save on enter
  2. Styling for StudioToggleableTextfield and StudioDisplayTile differs a little:
    bilde

Gjerne lag issue for det første punktet! 🥳
Det andre punktet har jeg allerede en PR på, og det finnes en sak på det 🫡

@standeren standeren assigned ErlingHauan and unassigned standeren Jan 17, 2025
@ErlingHauan
Copy link
Contributor

Test OK 🙂
I noticed two things that are not directly related to this PR, but I can create issues for them if you agree:

  1. StudioToggleableTextfield does not save on enter
  2. Styling for StudioToggleableTextfield and StudioDisplayTile differs a little:
    bilde

Gjerne lag issue for det første punktet! 🥳 Det andre punktet har jeg allerede en PR på, og det finnes en sak på det 🫡

Så bra!
La meg prøve noe:

@coderabbitai create a new issue regarding StudioToggleableTextfield. The issue is that the component currently does not save and unfocus when pressing Enter.

Copy link
Contributor

coderabbitai bot commented Jan 20, 2025

Tip

For best results, initiate chat on the files or code changes.

@ErlingHauan I've created issue #14454 to track the Enter key support enhancement for StudioToggleableTextfield. Let me know if you'd like any adjustments to the issue description.

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Create a new GitHub issue
gh issue create \
  --title "feat: Add Enter key support to StudioToggleableTextfield" \
  --body "## Current Behavior
When using the \`StudioToggleableTextfield\` component, pressing the Enter key does not save the changes and unfocus the field.

## Expected Behavior
The component should save the changes and unfocus (exit edit mode) when the user presses the Enter key, similar to how most text input fields behave.

## Context
This improvement would enhance the user experience by providing a more intuitive way to complete text editing, in addition to the existing save button.

## References
- Identified in PR discussion: #14400" \
  --repo "Altinn/altinn-studio"

Length of output: 709

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/content-library Area: Related to library for shared resources 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
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants