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: update app title in all available languages #14546

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

standeren
Copy link
Contributor

@standeren standeren commented Jan 30, 2025

Description

The updated view in About in the settings modal shows all available languages the app has, which is deduced from the language resource files in the app. The view does also include the recommended languages, nn, nb and en, but as readonly if the app does not have resource files for these. The same accounts for other titles existing in in appmetadata that does not have resource files for the languages.
Skjermbilde 2025-01-30 kl  08 29 48

When updating a app name in a language, the app name is updated both in resource file and in applicationmetadata, without overriding the existing title in applicationmetadata. Also, the .config file is not written to repo. This controller can be deleted.
Skjermbilde 2025-01-30 kl  09 34 32

⚠️ The flags can be removed as I believe we have agreed that there are a few issues connected to using them. However, in this PR, I suggest only using them for the recommended languages, and using the Norwegian flag for both nynorsk and bokmål.

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

Summary by CodeRabbit

  • Refactor

    • Simplified test and component structures for settings modal and about tab.
    • Updated import statements and data handling for language-specific service names.
  • New Features

    • Added support for language-specific app titles.
    • Introduced new input fields for service names across different languages.
  • Documentation

    • Updated Norwegian localization strings for settings modal.
    • Improved guidance for app naming conventions.
  • Bug Fixes

    • Improved error handling for language and metadata queries.
  • Style

    • Added new CSS class for service name input spacing.

Copy link
Contributor

coderabbitai bot commented Jan 30, 2025

📝 Walkthrough

Walkthrough

The pull request introduces significant changes to the application's settings modal, specifically in the About Tab and related components. The modifications focus on refactoring how application metadata and service names are handled, with an emphasis on language-specific configurations. The changes involve updating test files, component implementations, and localization strings to support more flexible and language-aware service name management.

Changes

File Change Summary
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.test.tsx Removed imports and mocks related to useAppConfigMutation
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/AboutTab.test.tsx Refactored tests to focus on language fetching and metadata, updated function signatures and test cases
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/AboutTab.tsx Updated data fetching logic, replaced useAppConfigQuery with useLanguagesQuery, modified save and display functions
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.module.css Added new .serviceName CSS class
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.test.tsx Updated test props and assertions to match new component structure
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.tsx Significant refactoring of component structure, added new types and functions for service name handling
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/mocks/appConfigMock.ts Deleted mock configuration file
frontend/language/src/nb.json Updated localization strings for settings modal
frontend/packages/shared/src/mocks/mocks.ts Added title property to applicationMetadata

Possibly related PRs

Suggested labels

area/ui-editor, skip-manual-testing, skip-releasenotes, team/studio-domain1

Suggested reviewers

  • Jondyr
  • lassopicasso

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 solution/studio/designer Issues related to the Altinn Studio Designer solution. frontend labels Jan 30, 2025
@standeren standeren marked this pull request as ready for review January 30, 2025 07:36
@standeren standeren added kind/bug Used when there is a defect / something is not working as it should. area/settings Area: Related to the settings modal team/studio-domain2 labels Jan 30, 2025
Copy link

codecov bot commented Jan 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.70%. Comparing base (7578699) to head (019bd23).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14546      +/-   ##
==========================================
- Coverage   95.71%   95.70%   -0.02%     
==========================================
  Files        1904     1903       -1     
  Lines       24801    24805       +4     
  Branches     2840     2841       +1     
==========================================
+ Hits        23738    23739       +1     
- Misses        802      805       +3     
  Partials      261      261              

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

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

🧹 Nitpick comments (7)
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/AboutTab.test.tsx (4)

Line range hint 54-69: Consider adding specific error scenario tests.

While the current parametrized test is good, consider adding tests for specific error scenarios (e.g., network errors, validation errors) to ensure proper error handling for different failure modes.


80-89: Consider adding input validation tests.

While the basic input functionality is tested, consider adding tests for:

  • Maximum length validation
  • Special character handling
  • Empty string validation

92-148: Consider adding edge cases for language handling.

The language-specific tests are well-structured, but consider adding tests for:

  • Handling of RTL languages
  • Unicode character support in titles
  • Maximum length validation per language

198-220: Consider enhancing helper function robustness.

The helper functions could benefit from:

  • Timeout handling for waitForElementToBeRemoved
  • Error handling for failed renders
  • Type validation for input parameters

Example implementation for timeout handling:

 const resolveAndWaitForSpinnerToDisappear = async (
   queries: Partial<ServicesContextProps> = {},
   previewContextProps: Partial<PreviewContextProps> = {},
 ) => {
   const getTextLanguages = jest.fn().mockImplementation(() => Promise.resolve([DEFAULT_LANGUAGE]));
   const getRepoMetadata = jest.fn().mockImplementation(() => Promise.resolve(mockRepository1));
   const getAppMetadata = jest.fn().mockImplementation(() => Promise.resolve(mockAppMetadata));

   renderAboutTab(
     { getTextLanguages, getRepoMetadata, getAppMetadata, ...queries },
     { ...previewContextProps },
   );
-  await waitForElementToBeRemoved(() =>
-    screen.queryByTitle(textMock('settings_modal.loading_content')),
-  );
+  await waitForElementToBeRemoved(
+    () => screen.queryByTitle(textMock('settings_modal.loading_content')),
+    { timeout: 5000 }
+  ).catch(() => {
+    throw new Error('Spinner did not disappear within timeout period');
+  });
 };
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/AboutTab.tsx (2)

45-49: Reload after successful title update.

doReloadPreview() is triggered before calling updateAppTitle. If updateAppTitle is an async mutation, consider waiting for it to complete before reloading the preview for a more predictable user experience.


60-60: Combine error messaging if needed.

Currently, each error is displayed separately. You could unify them in a single container or return them in a mapped list if avoiding repeated <ErrorMessage> calls is desired.

frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.test.tsx (1)

66-66: Consider adding tests for read-only recommended languages without resource files.
Currently, the tests confirm behavior for an existing app language (e.g., nb). To strengthen coverage, add a scenario where a recommended language is absent from appLangCodes to verify that the input is read-only and validation is skipped.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7578699 and fce6790.

📒 Files selected for processing (9)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.test.tsx (1 hunks)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/AboutTab.test.tsx (5 hunks)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/AboutTab.tsx (3 hunks)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.module.css (1 hunks)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.test.tsx (2 hunks)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.tsx (1 hunks)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/mocks/appConfigMock.ts (0 hunks)
  • frontend/language/src/nb.json (1 hunks)
  • frontend/packages/shared/src/mocks/mocks.ts (1 hunks)
💤 Files with no reviewable changes (1)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/mocks/appConfigMock.ts
✅ Files skipped from review due to trivial changes (1)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.module.css
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.tsx

[error] 100-101: Don't use 'Boolean' as a type.

Use lowercase primitives for consistency.
Safe fix: Use 'boolean' instead

(lint/complexity/noBannedTypes)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
🔇 Additional comments (36)
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/AboutTab.test.tsx (3)

17-20: Well-structured language constants!

Good practice using constants for language codes instead of magic strings. This improves maintainability and reduces the risk of typos.


Line range hint 33-38: Good test for initial loading state!

The test properly verifies the loading indicator's presence, which is crucial for user experience.


39-52: Well-structured data fetching tests!

Good separation of concerns with individual tests for each API call. This makes it easier to identify which fetch operation failed when tests break.

frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.test.tsx (2)

8-8: LGTM! Good addition of type import.

The explicit import of QueryClient type improves type safety.


Line range hint 1-150: Verify test coverage for new language-related functionality.

The test file has good coverage of modal behavior and tab navigation, but seems to be missing tests for the new language-related functionality mentioned in the PR objectives (available languages display, recommended languages, app name updates).

Let's verify the test coverage:

frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/AboutTab.tsx (6)

15-17: Ensure typed imports remain consistent.

These added imports look correctly typed. Just make sure all references for ServiceNames, useUpdateAppTitle, and useLanguagesQuery remain consistent throughout the codebase.


28-31: Verify fallback for missing language data.

When appLangCodesData is undefined or empty, ensure that the component still renders gracefully. Consider adding defensive checks before consuming appLangCodesData.


43-43: Confirm stable usage of the update hook.

Invoking useUpdateAppTitle(applicationMetadataData) at the top level is fine. Ensure that no re-render side effects inadvertently occur if applicationMetadataData is re-fetched and remains unchanged.


53-53: No issues with the switch statement.

This status-based render logic is clear. The fallback steps for pending, success, and error states are correctly implemented.


69-72: Handle missing or partial titles.

When constructing appTitles, ensure you handle any missing properties in applicationMetadataData.title or appLangCodesData. Consider fallback checks so the UI doesn’t break on partially-loaded data.


75-80: Ensure repository data is loaded.

If repositoryData is still loading or unavailable, adding optional chaining or fallback text for repositoryData.name can prevent runtime issues.

frontend/packages/shared/src/mocks/mocks.ts (1)

171-173: Added title field looks good.

Adding title to applicationMetadata is straightforward. If you plan to add more localized keys, be sure to handle them consistently in the consuming components.

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

1071-1071: New translation key for missing translation file.

The new key "settings_modal.about_tab_app_title_no_translation_file" is well-structured and consistent with naming conventions.


1077-1077: Updated app name advice text.

The updated description encouraging Bokmål, Nynorsk, and English is succinct and user-friendly.

frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.tsx (15)

1-2: Good import structure.
The updated imports from React and CSS modules are properly organized.


5-10: Successful transition to Studio components.
Replacing Textfield with StudioTextfield and related components aligns well with the standardized component library.


12-14: Ensure consistency with prop usage.
The serviceNames type correctly allows for undefined. However, verify that consumer components, especially in EditServiceNameForLanguage, also handle undefined safely.


16-20: Well-defined recommended language flags.
Using an enum for recognized flags helps maintain clarity regarding which languages are fully recommended or officially supported.


22-26: Props definition aligns with new approach.
The renamed props focus on language-based service names, removing dependency on appConfig. This fosters a more modular structure.


29-47: Clear separation of repository name from service names.
Using a read-only field to display the repo name is a good UX measure. The overall layout in this component remains clean and intuitive.


49-50: Omitting 'repositoryName' in the sub-props is a logical refinement.
This ensures EditServiceNames only deals with language-specific service name handling.


51-75: Straightforward iteration over service name languages.
Iterating over all keys in serviceNames is a clean way to handle the service name fields for each language.


84-92: Effective local error state management.
Using useState for storing error messages is appropriate for onBlur validation logic.


93-94: Good presence check for translation file.
Conditionally toggling readOnly based on the presence of the language in appLangCodes ensures that the user doesn’t mistakenly edit a language that doesn't have a dedicated resource file.


95-97: onBlur validation is straightforward.
Fine-grained form validation on blur fosters a good user experience and simpler code.


109-111: Concise external description assignment.
It’s good practice to gather the computed description in a local variable for clarity.


113-123: Appropriate usage of StudioIconTextfield.
Providing an icon for each language and an optional readonly property effectively combines clarity with controlled editing.


127-130: Type extraction for flag icons is adequately scoped.
Defining FlagIconProps within the same file keeps implementation cohesive.


131-132: Fallback for unsupported flags is smooth.
Returning null when a language flag isn’t available ensures minimal visual interruptions.

frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.test.tsx (7)

3-3: Accurate import usage of new types.
Importing InputFieldsProps and ServiceNames affirms alignment with the updated props.


9-15: Appropriate mock data setup.
Using typed mock data ensures test coverage for the newly introduced props like appLangCodes and serviceNames.


17-21: Well-defined defaultProps.
Gathering default props in a dedicated object fosters test readability and consistency across multiple test cases.


27-31: Read-only repository name assertion is correctly tested.
Confirming that the input is both read-only and accurately contains repositoryName is an important validation step.


35-44: Thorough testing of language-specific service name input.
Ensuring the correct value is displayed and can be updated verifies the core business logic of localized service name handling.


49-57: Validation success scenario is clearly covered.
Verifying that onSave is called upon losing focus confirms that valid changes are indeed committed.


66-66: Validation failure scenario is clearly covered.
Testing that onSave isn’t called when the service name is invalid ensures robust validation.

@standeren standeren changed the title fix: update app title in resource and appmetadata fix: update app title in all available languages Jan 30, 2025
@nkylstad nkylstad self-assigned this Jan 31, 2025
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/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.tsx (2)

94-101: Separate validation logic from side effects.

The validation function currently handles both validation and error state management. Consider separating these concerns for better maintainability and testability.

-const validateServiceName = (newServiceName: string): boolean => {
+const isServiceNameValid = (newServiceName: string): boolean => {
+  return newServiceName.length > 0;
+};
+
+const validateServiceName = (newServiceName: string): boolean => {
+  const isValid = isServiceNameValid(newServiceName);
   if (newServiceName.length <= 0) {
     setServiceNameError(t('settings_modal.about_tab_name_error'));
     return false;
   }
   setServiceNameError('');
   return true;
 };

89-92: Consider validating on change for better UX.

The current implementation only validates on blur, which might delay error feedback to users. Consider adding onChange validation for a more responsive user experience.

+const handleOnChange = (event: ChangeEvent<HTMLInputElement>) => {
+  const isValid = isServiceNameValid(event.target.value);
+  if (!isValid) {
+    setServiceNameError(t('settings_modal.about_tab_name_error'));
+  } else {
+    setServiceNameError('');
+  }
+};

 const handleOnBlur = (event: ChangeEvent<HTMLInputElement>) => {
   const isValid = validateServiceName(event.target.value);
   if (isValid) onSave(event.target.value, language);
 };

Then update the StudioIconTextfield:

 <StudioIconTextfield
   size='small'
   label={t(`language.${language}`)}
   description={description}
   error={serviceNameError}
   value={serviceName}
   onBlur={handleOnBlur}
+  onChange={handleOnChange}
   readOnly={!appHasLanguageTranslation}
   className={classes.serviceName}
 />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fce6790 and 019bd23.

📒 Files selected for processing (1)
  • frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
🔇 Additional comments (3)
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/InputFields/InputFields.tsx (3)

12-20: LGTM! Well-structured type definitions.

The generic type definitions are well-designed, with proper handling of undefined values and clear prop interfaces.


23-41: LGTM! Clean component structure.

The component has a clear separation of concerns and proper prop handling. The read-only repository name field is well-implemented.


43-69: LGTM! Well-implemented service names editor.

The component effectively manages multiple language entries with proper React patterns and UI components.

Copy link
Member

@nkylstad nkylstad left a comment

Choose a reason for hiding this comment

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

Changes:

  • Removed flags as suggested in PR description and internal discussion.
  • Made minor changes as suggested by CodeRabbit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/settings Area: Related to the settings modal frontend kind/bug Used when there is a defect / something is not working as it should. solution/studio/designer Issues related to the Altinn Studio Designer solution. team/studio-domain2
Projects
Status: 🔎 Review
Development

Successfully merging this pull request may close these issues.

2 participants