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

feat: add function to get relevant app titles to display as input field #14521

Merged
merged 2 commits into from
Jan 30, 2025

Conversation

standeren
Copy link
Contributor

@standeren standeren commented Jan 27, 2025

Description

This PR creates a function getAppTitlesToDisplay in a utils folder in the About tab in SettingsModal. The function takes as parameters:

  1. The title object from applicationmetadata that has languages as keys and the actual title as the value, and
  2. An array of languages that the application has translations for.
    The function uses these parameters to create a result object of the type ServiceNames with keys that equal the union of all languages in both appCodeLanguages and applicationmetadata titles. The values are fetched only from the applicationmetadata titles. If a language does not have an app name available in applicationmetadata titles, the value is undefined.

Adding the skip-manual-testing label since the function is not used in this PR and there are tests covering the functionality of it.

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

    • Introduced a new utility function for processing application metadata titles based on language codes
    • Added type definition for flexible service name mappings
  • Tests

    • Added comprehensive unit tests for the new getAppTitlesToDisplay function, covering various input scenarios and edge cases

@standeren standeren added kind/bug Used when there is a defect / something is not working as it should. skip-releasenotes Issues that do not make sense to list in our release notes team/studio-domain2 skip-manual-testing PRs that do not need to be tested manually skip-documentation Issues where updating documentation is not relevant labels Jan 27, 2025
Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

📝 Walkthrough

Walkthrough

A new utility function getAppTitlesToDisplay has been implemented to process application metadata titles based on language codes. The implementation involves creating a comprehensive list of language codes by combining recommended languages, metadata titles, and provided language codes. The function ensures unique language codes and maps them to corresponding titles, with a new ServiceNames type definition supporting flexible key-value pairs for service names.

Changes

File Path Change Summary
frontend/.../types/ServiceNames.ts Added ServiceNames type definition: an object with string keys mapping to string or undefined values
frontend/.../utils/getAppTitlesToDisplay.ts Introduced getAppTitlesToDisplay function to process application titles across different languages
Added recommendedLanguages constant
frontend/.../getAppTitlesToDisplay.test.ts Created comprehensive unit tests for getAppTitlesToDisplay function
Covered scenarios with empty/populated metadata and language codes
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 27, 2025
@standeren standeren force-pushed the add-app-titles-utils branch from be25f52 to 1a939f5 Compare January 27, 2025 14:58
@standeren standeren force-pushed the add-app-titles-utils branch from 1a939f5 to 2d9b159 Compare January 27, 2025 15:01
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 (5)
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/types/ServiceNames.ts (1)

1-3: LGTM! Consider adding JSDoc comments.

The type definition is well-structured and correctly allows for undefined values. Consider adding JSDoc comments to document the purpose and structure of this type.

+/**
+ * Represents a mapping of language codes to their corresponding service names.
+ * Keys are language codes (e.g., 'en', 'nb') and values are either the translated service name or undefined if no translation exists.
+ */
 export type ServiceNames = {
   [key: string]: string | undefined;
 };
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/utils/getAppTitlesToDisplay.ts (2)

4-4: Consider moving recommendedLanguages to a configuration file.

The hardcoded array of recommended languages would be better maintained in a dedicated configuration file, making it easier to update and reuse across the application.


6-16: LGTM! Consider adding JSDoc documentation.

The implementation is clean and efficient. Consider adding JSDoc comments to document the function's purpose, parameters, and return value.

+/**
+ * Generates a mapping of language codes to their corresponding application titles.
+ * Combines recommended languages, metadata titles, and provided language codes,
+ * ensuring unique entries and mapping them to their respective titles.
+ *
+ * @param appMetadataTitles - Object containing existing language-title mappings
+ * @param appLangCodesData - Array of additional language codes to include
+ * @returns Object mapping all unique language codes to their titles (undefined if no title exists)
+ */
 export const getAppTitlesToDisplay = (
   appMetadataTitles: ServiceNames,
   appLangCodesData: string[],
 ): ServiceNames => {
frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/components/Tabs/AboutTab/utils/getAppTitlesToDisplay.test.ts (2)

5-10: Consider moving language code constants to a shared location.

These language code constants might be useful in other files. Consider moving them to a shared constants file.


11-76: Add test cases for edge cases and improve test structure.

The test coverage is good but could be enhanced:

  1. Add test cases for:

    • Invalid inputs (null/undefined)
    • Empty string language codes
    • Case sensitivity handling
  2. Consider using beforeEach to set up common test data.

Example structure:

describe('getAppTitlesToDisplay', () => {
  const appNameNb = 'appNameNb';
  let appMetadataTitles: KeyValuePairs<string>;
  let appLangCodesData: string[];

  beforeEach(() => {
    appMetadataTitles = {};
    appLangCodesData = [];
  });

  // ... existing tests ...

  it('handles null/undefined inputs gracefully', () => {
    expect(() => getAppTitlesToDisplay(null as any, [])).toThrow();
    expect(() => getAppTitlesToDisplay({}, null as any)).toThrow();
  });

  it('handles empty string language codes', () => {
    appMetadataTitles = { '': 'empty' };
    appLangCodesData = [''];
    const result = getAppTitlesToDisplay(appMetadataTitles, appLangCodesData);
    expect(result).toEqual({
      nb: undefined,
      nn: undefined,
      en: undefined,
      '': 'empty'
    });
  });
});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 789cfb3 and 2d9b159.

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

Copy link

codecov bot commented Jan 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.70%. Comparing base (52bb520) to head (f18f00d).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14521   +/-   ##
=======================================
  Coverage   95.70%   95.70%           
=======================================
  Files        1902     1903    +1     
  Lines       24771    24777    +6     
  Branches     2839     2839           
=======================================
+ Hits        23707    23713    +6     
  Misses        803      803           
  Partials      261      261           

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

Copy link
Contributor

@lassopicasso lassopicasso left a comment

Choose a reason for hiding this comment

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

🚀

@lassopicasso lassopicasso merged commit 7578699 into main Jan 30, 2025
11 checks passed
@lassopicasso lassopicasso deleted the add-app-titles-utils branch January 30, 2025 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend kind/bug Used when there is a defect / something is not working as it should. 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-domain2
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants