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

refactor: Clean up option list typing #14429

Merged
merged 9 commits into from
Jan 17, 2025
Merged

Conversation

TomasEng
Copy link
Contributor

@TomasEng TomasEng commented Jan 15, 2025

Description

Renamed and moved option list related types in order to follow general guidelines and our own conventions:

  • Consistent naming
  • Types that are independent from each other should be defined in separate files
  • The types/api folder should only contain Response, Params and Payload types
  • The types in the types/api folder should only be used by functions directly related to network requests

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings

Summary by CodeRabbit

Based on the comprehensive summary of changes, here are the high-level release notes:

  • Type System Refinement

    • Standardized naming conventions for option list types across the application.
    • Introduced more precise type definitions for option lists and related data structures.
  • Code Structure Improvements

    • Renamed utility functions and variables for better clarity.
    • Updated import statements to reflect new type locations.
    • Simplified data transformation logic in several components.
  • Key Changes

    • Replaced OptionsList with OptionList.
    • Updated type imports from app-shared/types/api/OptionsLists to more specific type modules.
    • Introduced new utility functions like mapToCodeListDataList and mapToCodeListUsages.
  • Testing

    • Updated test suites to align with new type definitions and function names.
    • Maintained existing test logic and coverage.

These changes primarily focus on improving type safety, code readability, and maintaining consistent naming conventions throughout the application.

Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive refactoring of type definitions and naming conventions related to option lists across multiple frontend packages. The changes involve renaming types, updating import statements, and modifying function signatures to improve type consistency and clarity. The refactoring focuses on standardizing how option lists are handled, including their data structures, references, and utility functions, while also eliminating outdated definitions.

Changes

File Path Change Summary
frontend/packages/shared/src/types/ Added new type definitions for OptionList, OptionListData, OptionListReferences, and OptionListsResponse
frontend/packages/shared/src/types/api/OptionsLists.ts Removed old type definitions
frontend/app-development/features/appContentLibrary/AppContentLibrary.test.tsx Updated type imports and variable declarations to use OptionListData instead of OptionsListsResponse
frontend/app-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.ts Removed file containing conversion logic for options lists
frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.test.ts Updated type imports and variable declarations to use OptionListReferences instead of OptionListsReferences
frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.ts Updated function parameter types and internal logic to use OptionListReferences
frontend/packages/shared/src/api/queries.ts Updated type imports and function signatures to use refined types for option lists
frontend/packages/shared/src/hooks/mutations/useUpdateOptionListIdMutation.test.ts Renamed type OptionsListsResponse to OptionListsResponse in test cases
frontend/packages/shared/src/hooks/mutations/useUpdateOptionListIdMutation.ts Renamed type OptionsListsResponse to OptionListsResponse in mutation logic
frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.ts Refactored types and variable names for consistency in mutation handling
frontend/packages/shared/src/hooks/queries/useOptionListQuery.ts Updated function signature to use OptionList instead of OptionsList
frontend/packages/shared/src/hooks/queries/useOptionListsQuery.ts Updated function signature to use OptionListsResponse instead of OptionsListsResponse
frontend/packages/shared/src/hooks/queries/useOptionListsReferencesQuery.ts Updated function signature to use OptionListReferences instead of OptionListsReferences
Multiple test files Updated type imports and variable declarations across various tests to align with new type definitions
frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListEditor.test.tsx Renamed type OptionsList to OptionList in tests
frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListEditor.tsx Updated prop names and types in LibraryOptionsEditor component
frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/ManualOptionsEditor/ManualOptionsEditor.tsx Updated prop names in OptionListLabels component
frontend/packages/ux-editor/src/utils/exportUtils.ts Updated property and constructor parameter types to use OptionListData

Possibly related PRs

Suggested labels

quality/testing, area/content-library

Suggested reviewers

  • ErlingHauan
  • Konrad-Simso

📜 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 96d4cb9 and 3dbbc0b.

📒 Files selected for processing (1)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListDataList.test.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListDataList.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build environment and run e2e test

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 15, 2025
@TomasEng TomasEng added 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 team/studio-domain1 labels Jan 15, 2025
@TomasEng TomasEng added the quality/code Violations from current rules for code, best practices, etc. Or just bad code. label Jan 15, 2025
Copy link

codecov bot commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.65%. Comparing base (cf7174b) to head (3dbbc0b).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14429      +/-   ##
==========================================
- Coverage   95.65%   95.65%   -0.01%     
==========================================
  Files        1889     1889              
  Lines       24554    24545       -9     
  Branches     2817     2817              
==========================================
- Hits        23488    23479       -9     
  Misses        805      805              
  Partials      261      261              

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

@TomasEng TomasEng marked this pull request as ready for review January 15, 2025 13:09
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 (4)
frontend/packages/shared/src/hooks/queries/useOptionListsQuery.ts (1)

5-15: Consider adding error type parameter for better type safety.

The type updates are consistent with the new type system. Consider enhancing type safety by explicitly defining the error type parameter in UseQueryResult and useQuery.

-): UseQueryResult<OptionListsResponse> => {
+): UseQueryResult<OptionListsResponse, Error> => {
   const { getOptionLists } = useServicesContext();
-  return useQuery<OptionListsResponse>({
+  return useQuery<OptionListsResponse, Error>({
frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.ts (1)

1-1: Type renaming implemented consistently.

The changes from OptionListsReferences to OptionListReferences are applied consistently in both import and type usage.

Consider renaming the function from mapToCodeListsUsage to mapToCodeListUsage to maintain consistency with the singular form convention being established in the types.

Also applies to: 5-5

frontend/app-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.ts (2)

1-2: Type renaming implemented consistently.

The changes from OptionsListData to OptionListData and OptionsListsResponse to OptionListsResponse are applied consistently across imports and parameter types.

To maintain complete consistency with the new singular form convention in types, consider:

-export const convertOptionsListsDataToCodeListsData = (optionListsData: OptionListsResponse) => {
-  const codeListsData = [];
+export const convertOptionListDataToCodeListData = (optionListsData: OptionListsResponse) => {
+  const codeListData = [];
   optionListsData.map((optionListData) => {
-    const codeListData = convertOptionsListDataToCodeListData(optionListData);
-    codeListsData.push(codeListData);
+    const convertedData = convertOptionListItemToCodeListItem(optionListData);
+    codeListData.push(convertedData);
   });
-  return codeListsData;
+  return codeListData;
 };

-const convertOptionsListDataToCodeListData = (optionListData: OptionListData) => {
+const convertOptionListItemToCodeListItem = (optionListData: OptionListData) => {

Also applies to: 5-5, 14-14


Line range hint 1-24: Overall type refactoring looks good with minor suggestions for complete consistency.

The type renaming from plural to singular form has been implemented consistently across all files. To fully achieve the PR's objective of consistent naming conventions, consider:

  1. Aligning function names with the singular form convention established in types
  2. Updating variable names to match the new naming pattern

These changes would make the codebase more uniform and easier to maintain.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 15bd10a and 71ec417.

📒 Files selected for processing (24)
  • frontend/app-development/features/appContentLibrary/AppContentLibrary.test.tsx (2 hunks)
  • frontend/app-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.test.ts (3 hunks)
  • frontend/app-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.ts (2 hunks)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.test.ts (2 hunks)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.ts (1 hunks)
  • frontend/packages/shared/src/api/queries.ts (2 hunks)
  • frontend/packages/shared/src/hooks/mutations/useUpdateOptionListIdMutation.test.ts (4 hunks)
  • frontend/packages/shared/src/hooks/mutations/useUpdateOptionListIdMutation.ts (3 hunks)
  • frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.ts (5 hunks)
  • frontend/packages/shared/src/hooks/queries/useOptionListQuery.test.ts (2 hunks)
  • frontend/packages/shared/src/hooks/queries/useOptionListQuery.ts (1 hunks)
  • frontend/packages/shared/src/hooks/queries/useOptionListsQuery.ts (1 hunks)
  • frontend/packages/shared/src/hooks/queries/useOptionListsReferencesQuery.ts (1 hunks)
  • frontend/packages/shared/src/mocks/queriesMock.ts (2 hunks)
  • frontend/packages/shared/src/types/OptionList.ts (1 hunks)
  • frontend/packages/shared/src/types/OptionListReferences.ts (1 hunks)
  • frontend/packages/shared/src/types/api/OptionListsResponse.ts (1 hunks)
  • frontend/packages/shared/src/types/api/OptionsLists.ts (0 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListEditor.test.tsx (4 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListLabels/OptionListLabels.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/utils/optionsUtils.test.ts (6 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/utils/optionsUtils.ts (7 hunks)
  • frontend/packages/ux-editor/src/utils/exportUtils.test.ts (2 hunks)
  • frontend/packages/ux-editor/src/utils/exportUtils.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • frontend/packages/shared/src/types/api/OptionsLists.ts
🔇 Additional comments (21)
frontend/packages/shared/src/types/api/OptionListsResponse.ts (1)

1-3: LGTM! Well-structured type definition.

The placement of OptionListsResponse in the types/api folder and its naming convention align perfectly with the PR objectives. The type is focused and properly imports its dependency.

frontend/packages/shared/src/types/OptionList.ts (1)

1-9: LGTM! Well-organized type definitions.

The type definitions are clear, properly structured, and follow TypeScript best practices:

  • Good separation of concerns between OptionList and OptionListData
  • Appropriate use of optional properties
  • Clear and consistent naming
frontend/packages/shared/src/types/OptionListReferences.ts (1)

1-8: LGTM! Clear and well-structured reference types.

The type definitions follow good practices:

  • Clear distinction between single reference and collection
  • Descriptive property names
  • Proper external dependency management
frontend/packages/shared/src/hooks/queries/useOptionListQuery.ts (1)

5-5: Type renaming implemented consistently.

The changes from OptionsList to OptionList are applied consistently across import, return type, and generic type parameter. This aligns with the PR's objective of maintaining consistent naming conventions.

Also applies to: 11-11, 13-13

frontend/packages/shared/src/hooks/queries/useOptionListsReferencesQuery.ts (1)

5-5: Type renaming implemented consistently.

The changes from OptionListsReferences to OptionListReferences are applied consistently across import, return type, and generic type parameter. This maintains the singular form convention for type names.

Also applies to: 10-10, 12-12

frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListLabels/OptionListLabels.tsx (1)

5-5: Type refactoring looks good!

The changes align well with the PR objectives:

  • Moving type definition out of the api folder
  • Using consistent singular form naming convention
  • Maintaining the same component functionality

Also applies to: 8-8

frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.test.ts (1)

3-3: Type refactoring looks good!

The changes maintain test integrity while improving type organization:

  • Moved type out of api folder as intended
  • Improved type naming consistency
  • Test functionality preserved

Also applies to: 13-13

frontend/packages/shared/src/hooks/queries/useOptionListQuery.test.ts (1)

7-7: Type refactoring looks good!

The changes successfully:

  • Relocated type definition out of api folder
  • Maintained consistent singular form naming
  • Preserved test functionality

Also applies to: 19-19

frontend/app-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.test.ts (1)

3-3: Type refactoring looks good!

The changes demonstrate proper type organization:

  • Kept Response type in api folder as intended
  • Improved type naming consistency
  • Maintained test functionality

Also applies to: 8-8, 33-33, 45-45

frontend/packages/shared/src/hooks/mutations/useUpdateOptionListIdMutation.ts (1)

2-2: LGTM! Type renaming is consistent throughout the file.

The changes correctly implement the type renaming from OptionsListsResponse to OptionListsResponse across imports and type annotations, aligning with the PR's objective of cleaning up option list typing.

Also applies to: 24-24, 41-41, 42-42, 44-44

frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.ts (2)

4-5: LGTM! Import statements correctly updated.

The import statements have been properly updated to reflect the new type structure, maintaining clear separation between API types and domain types.


24-24: LGTM! Type annotations consistently updated across all functions.

The type annotations have been systematically updated throughout the file, maintaining type safety and consistency in the mutation logic.

Also applies to: 40-40, 44-46, 56-58, 66-68, 81-83

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

2-2: LGTM! Consistent type updates across utility functions.

The type changes from OptionsList to OptionList have been applied consistently across all utility functions, maintaining the intended functionality while improving type clarity.

Also applies to: 21-21, 37-37, 54-54, 90-90, 123-123, 133-134

frontend/packages/shared/src/hooks/mutations/useUpdateOptionListIdMutation.test.ts (1)

9-9: LGTM! Test file correctly updated with new types.

The test file has been properly updated to use the new OptionListsResponse type, ensuring test coverage remains valid with the refactored types.

Also applies to: 41-41, 55-55, 68-68

frontend/packages/ux-editor/src/utils/exportUtils.ts (1)

13-13: LGTM! Type changes are consistent and well-implemented.

The refactoring from OptionsListsResponse to OptionListData[] improves type clarity while maintaining functionality. The changes are consistently applied across the import statement, class property, and constructor parameter.

Also applies to: 21-21, 31-31

frontend/app-development/features/appContentLibrary/AppContentLibrary.test.tsx (1)

14-14: LGTM! Test file updates maintain consistency with type changes.

The changes correctly update the test file to use OptionListData type, ensuring type consistency across the codebase. The mock data structure and test functionality remain intact.

Also applies to: 22-22, 150-150

frontend/packages/ux-editor/src/utils/exportUtils.test.ts (1)

8-8: LGTM! Test type definitions updated correctly.

The test file has been properly updated to use OptionListData type, maintaining consistency with the implementation changes. All test cases remain functionally equivalent.

Also applies to: 105-105

frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListEditor.test.tsx (1)

3-3: LGTM! Consistent type updates in test implementation.

The changes correctly update all occurrences of OptionsList to OptionList, maintaining type consistency throughout the test file. Mock implementations and test cases remain functionally equivalent.

Also applies to: 20-21, 27-27, 211-212, 218-218

frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/utils/optionsUtils.test.ts (1)

2-2: Type updates are consistent and complete.

The renaming from OptionsList to OptionList has been properly applied across all test cases while maintaining the original test functionality.

Also applies to: 29-29, 70-70, 138-139, 144-145, 182-182, 215-215, 222-222, 229-229, 236-236, 244-244, 250-250

frontend/packages/shared/src/api/queries.ts (1)

94-96: Type organization improvements are well-structured.

The refactoring of option list related types follows a clear pattern:

  • Types are properly segregated into separate imports
  • API-specific types are correctly placed in the types/api folder
  • Function signatures are consistently updated to use the new types

Also applies to: 125-127

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

72-73: Mock implementations correctly reflect type changes.

The mock implementations have been properly updated to use the new type system:

  • Import statements mirror the reorganization in queries.ts
  • Mock return types are consistent with their corresponding query functions
  • Empty array initializers maintain type safety

Also applies to: 76-76, 114-115, 117-118

@ErlingHauan ErlingHauan self-assigned this Jan 16, 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.

Fin opprydning!

Jeg ser at Option[] brukes flere steder hvor OptionList kunne vært brukt. Nå brukes de litt om hverandre. Burde vi kanskje forholde oss til OptionList der vi kan, for å holde koden konsistent?

Et annet punkt er at flere kodeelementer som ikke er typer fortsatt heter optionsList med s i midten. Kanskje det også kan fikses i denne PR-en?

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

@ErlingHauan, nå har jeg tatt en runde og oppdatert variablenavnene. Det er sikkert mer som kan gjøres, men det tenker jeg blir for mye for én PR.

@TomasEng TomasEng requested a review from ErlingHauan January 17, 2025 10:00
@TomasEng TomasEng assigned ErlingHauan and unassigned TomasEng Jan 17, 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: 1

🔭 Outside diff range comments (3)
frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListEditor.tsx (2)

Line range hint 39-52: Maintain consistent naming throughout the component.

While the prop was renamed to optionListId in the LibraryOptionsEditor, the type definition and parameter still use optionsId. For consistency, these should be updated as well.

 type OptionsListResolverProps = {
   handleDelete: () => void;
-  optionsId: string;
+  optionListId: string;
 };

 function OptionListResolver({
   handleDelete,
-  optionsId,
+  optionListId,
 }: OptionsListResolverProps): React.ReactNode {

Line range hint 33-33: Update the parent component's prop reference.

For completeness, this line should also use the new prop name.

-    return <OptionListResolver optionsId={component.optionsId} handleDelete={handleDelete} />;
+    return <OptionListResolver optionListId={component.optionsId} handleDelete={handleDelete} />;
frontend/packages/ux-editor/src/utils/exportUtils.ts (1)

Line range hint 144-148: Add null check to prevent runtime errors.

The code accesses optionListData.data without checking if a matching option list was found. This could cause runtime errors if component.optionsId doesn't match any option list title.

       const optionListData = this.optionListDataList.find(
         (optionListData) => optionListData.title === component.optionsId,
       );
+      if (!optionListData) {
+        return undefined;
+      }
       return optionListData.data;
🧹 Nitpick comments (7)
frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.test.ts (2)

16-16: Maintain consistent singular naming convention.

For consistency with the new naming convention established in this PR, rename updatedOptionsList to updatedOptionList.

-const updatedOptionsList: Option[] = [{ ...option1, description: 'description' }];
+const updatedOptionList: Option[] = [{ ...option1, description: 'description' }];

51-51: Update hyphenated ID to follow singular naming convention.

For consistency with the new naming convention, update the test ID from 'some-other-options-list-id' to 'some-other-option-list-id'.

-const existingOptionsList = { title: 'some-other-options-list-id', data: optionList };
+const existingOptionsList = { title: 'some-other-option-list-id', data: optionList };
frontend/packages/ux-editor/src/utils/exportUtils.ts (3)

21-21: Consider renaming to avoid redundancy.

The property name optionListDataList is redundant since the type OptionListData[] already indicates it's a list. Consider renaming to optionListData for better clarity.

-  private readonly optionListDataList: OptionListData[];
+  private readonly optionListData: OptionListData[];

31-31: Maintain consistent naming between parameter and property.

The parameter name optionListsData differs from the property name, which could be confusing. Consider using the same name for both.

-    optionListsData: OptionListData[],
+    optionListData: OptionListData[],

40-40: Update property initialization for consistency.

Update the initialization to match the suggested property and parameter naming.

-    this.optionListDataList = optionListsData;
+    this.optionListData = optionListData;
frontend/app-development/features/appContentLibrary/utils/convertOptionListDataListToCodeListDataList.ts (1)

4-6: Consider a more concise function name.

While descriptive, the function name is quite long. Consider shortening to convertToCodeListDataList since the context is already clear from the types.

frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/LibraryOptionsEditor/LibraryOptionsEditor.tsx (1)

33-36: Consider adding error handling for the update operation.

While the change handler is well-implemented, it might benefit from error handling for the update operation.

 const handleOptionsListChange = (newOptionList: OptionList) => {
   if (hasOptionListChanged(optionList, newOptionList)) {
-    updateOptionList({ optionListId, optionList: newOptionList });
+    updateOptionList(
+      { optionListId, optionList: newOptionList },
+      {
+        onError: (error) => {
+          console.error('Failed to update option list:', error);
+          // Consider showing a user-friendly error message
+        },
+      }
+    );
     doReloadPreview();
   }
 };
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 71ec417 and 4400c98.

📒 Files selected for processing (15)
  • frontend/app-development/features/appContentLibrary/AppContentLibrary.tsx (3 hunks)
  • frontend/app-development/features/appContentLibrary/utils/convertOptionListDataListToCodeListDataList.ts (1 hunks)
  • frontend/app-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.test.ts (3 hunks)
  • frontend/app-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.ts (0 hunks)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.test.ts (4 hunks)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.ts (1 hunks)
  • frontend/packages/shared/src/api/queries.ts (2 hunks)
  • frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.test.ts (5 hunks)
  • frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.ts (2 hunks)
  • frontend/packages/shared/src/mocks/queriesMock.ts (2 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/LibraryOptionsEditor/LibraryOptionsEditor.tsx (3 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/ManualOptionsEditor/ManualOptionsEditor.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListEditor.tsx (1 hunks)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListLabels/OptionListLabels.tsx (1 hunks)
  • frontend/packages/ux-editor/src/utils/exportUtils.ts (4 hunks)
💤 Files with no reviewable changes (1)
  • frontend/app-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.ts
✅ Files skipped from review due to trivial changes (1)
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/ManualOptionsEditor/ManualOptionsEditor.tsx
🚧 Files skipped from review as they are similar to previous changes (6)
  • frontend/app-development/features/appContentLibrary/utils/convertOptionsListsDataToCodeListsData.test.ts
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.test.ts
  • frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListLabels/OptionListLabels.tsx
  • frontend/packages/shared/src/mocks/queriesMock.ts
  • frontend/packages/shared/src/api/queries.ts
  • frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
🔇 Additional comments (6)
frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/OptionListEditor.tsx (1)

64-64: LGTM! Prop renaming aligns with the refactoring objectives.

The change from optionsId to optionListId follows the PR's goal of making option list related naming more consistent.

frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.test.ts (1)

Line range hint 21-77: Well-structured test cases with good coverage!

The test cases effectively cover various scenarios including parameter validation, cache updates for both existing and new lists, and single list updates. The implementation aligns well with the PR's objective of standardizing option list related types and naming conventions.

frontend/packages/ux-editor/src/utils/exportUtils.ts (1)

13-13: LGTM! Import changes align with refactoring goals.

The new import of OptionListData type follows the established naming conventions and modular organization principles outlined in the PR objectives.

frontend/app-development/features/appContentLibrary/utils/convertOptionListDataListToCodeListDataList.ts (1)

8-12: LGTM! Clean and efficient implementation.

The helper function is well-structured with clear property mapping.

frontend/packages/ux-editor/src/components/config/editModal/EditOptions/OptionTabs/EditTab/OptionListEditor/LibraryOptionsEditor/LibraryOptionsEditor.tsx (1)

14-14: LGTM! Consistent type usage and prop naming.

The renaming from optionsId to optionListId aligns well with the PR's objective of consistent naming conventions.

Also applies to: 18-18, 23-23

frontend/app-development/features/appContentLibrary/utils/mapToCodeListsUsage.ts (1)

4-11: LGTM! Clean and efficient implementation.

The function is well-structured with:

  • Proper null checking
  • Clear type definitions
  • Concise mapping logic

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.

@ErlingHauan, nå har jeg tatt en runde og oppdatert variablenavnene. Det er sikkert mer som kan gjøres, men det tenker jeg blir for mye for én PR.

Flott! Og jeg er helt enig 😊

@ErlingHauan ErlingHauan assigned TomasEng and unassigned ErlingHauan Jan 17, 2025
@TomasEng TomasEng requested a review from ErlingHauan January 17, 2025 11:44
@TomasEng TomasEng assigned ErlingHauan and unassigned TomasEng Jan 17, 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: 3

🧹 Nitpick comments (2)
frontend/app-development/features/appContentLibrary/utils/mapToCodeListUsages.test.ts (1)

20-35: Add more test cases for edge cases.

Consider adding tests for:

  1. Null input
  2. Empty array input
  3. Invalid/malformed input objects (missing required properties)
it('maps null optionListUsages to empty array', () => {
  const codeListUsages = mapToCodeListUsages(null);
  expect(codeListUsages).toEqual([]);
});

it('maps empty optionListUsages array to empty array', () => {
  const codeListUsages = mapToCodeListUsages([]);
  expect(codeListUsages).toEqual([]);
});

it('handles malformed optionListUsages objects', () => {
  const malformedUsages = [{ optionListId: 'id' }] as OptionListReferences;
  const codeListUsages = mapToCodeListUsages(malformedUsages);
  expect(codeListUsages).toEqual([{
    codeListId: 'id',
    codeListIdSources: undefined
  }]);
});
frontend/app-development/features/appContentLibrary/utils/mapToCodeListDataList.test.ts (1)

Line range hint 6-49: Add test cases for null checks.

Add test cases to verify the handling of:

  1. Null/undefined input
  2. Null/undefined properties in input objects
it('handles null input by returning empty array', () => {
  const result = mapToCodeListDataList(null);
  expect(result).toEqual([]);
});

it('handles undefined properties in option list data', () => {
  const optionListDataList = [{
    title: undefined,
    data: undefined,
    hasError: undefined
  }] as OptionListData[];
  
  const result = mapToCodeListDataList(optionListDataList);
  expect(result).toEqual([{
    title: '',
    data: null,
    hasError: false
  }]);
});
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4400c98 and 96d4cb9.

📒 Files selected for processing (6)
  • frontend/app-development/features/appContentLibrary/AppContentLibrary.tsx (4 hunks)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListDataList.test.ts (3 hunks)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListDataList.ts (1 hunks)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListUsages.test.ts (1 hunks)
  • frontend/app-development/features/appContentLibrary/utils/mapToCodeListUsages.ts (1 hunks)
  • frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.test.ts (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • frontend/app-development/features/appContentLibrary/AppContentLibrary.tsx
  • frontend/packages/shared/src/hooks/mutations/useUpdateOptionListMutation.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build environment and run e2e test
  • GitHub Check: Testing
🔇 Additional comments (1)
frontend/app-development/features/appContentLibrary/utils/mapToCodeListUsages.ts (1)

4-12: Clean implementation with proper null checks!

The function correctly handles falsy input and maintains a clear mapping between option list and code list properties.

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.

Godt jobbet 😄

@TomasEng TomasEng merged commit 5dda0fd into main Jan 17, 2025
12 checks passed
@TomasEng TomasEng deleted the cleanup-option-list-typing branch January 17, 2025 12:34
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 quality/code Violations from current rules for code, best practices, etc. Or just bad code. 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