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: frontend mock endpoint to edit org codelist #14522

Closed
wants to merge 2 commits into from

Conversation

wrt95
Copy link
Contributor

@wrt95 wrt95 commented Jan 27, 2025

Description

  • Creating mock endpoint in frontend for edit org code list

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

Release Notes

  • New Features

    • Added functionality to edit organization-level code lists
    • Introduced a new custom mutation hook for managing code list updates
  • Improvements

    • Enhanced query key management for better data synchronization
    • Improved type definitions for API interactions
  • Testing

    • Added comprehensive unit tests for the new code list mutation hook

Copy link
Contributor

coderabbitai bot commented Jan 27, 2025

Warning

Rate limit exceeded

@wrt95 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 11 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 6cec080 and 57d3f9d.

📒 Files selected for processing (1)
  • frontend/packages/shared/src/api/mutations.ts (2 hunks)
📝 Walkthrough

Walkthrough

This pull request introduces functionality for editing organization-level code lists across multiple frontend files. The changes include adding a new mutation function editOrgLevelCodeList, creating a corresponding custom hook useEditOrgCodeListMutation, and updating the QueryKey enum. The implementation involves adding type imports, creating mock functions for testing, and setting up the necessary infrastructure to support editing code lists with proper query invalidation.

Changes

File Change Summary
frontend/packages/shared/src/api/mutations.ts Added new async function editOrgLevelCodeList with OptionListsResponse type
frontend/packages/shared/src/hooks/mutations/useEditOrgCodeListMutation.ts Created new custom hook for editing org-level code lists using React Query
frontend/packages/shared/src/hooks/mutations/useEditOrgCodeListMutation.test.ts Added unit tests for the new mutation hook
frontend/packages/shared/src/mocks/queriesMock.ts Added mock implementation for editOrgLevelCodeList
frontend/packages/shared/src/types/QueryKey.ts Removed UserOrgPermissions and added OrgLevelCodeLists enum entries

Possibly related PRs

Suggested labels

area/ui-editor, frontend, quality/testing, skip-manual-testing, added-to-sprint

Suggested reviewers

  • github-actions
  • ErlingHauan

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
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/packages/shared/src/hooks/mutations/useEditOrgCodeListMutation.ts (1)

11-11: Simplify query invalidation.

The Promise.all is unnecessary when invalidating a single query.

-    onSuccess: () => Promise.all([q.invalidateQueries({ queryKey: [QueryKey.OrgLevelCodeLists] })]),
+    onSuccess: () => q.invalidateQueries({ queryKey: [QueryKey.OrgLevelCodeLists] }),
frontend/packages/shared/src/hooks/mutations/useEditOrgCodeListMutation.test.ts (1)

20-46: Enhance test coverage with error and loading states.

The tests cover the happy path well, but consider adding:

  1. Error case testing
  2. Loading state verification
 describe('useEditOrgCodeListMutation', () => {
+  it('Shows loading state during mutation', async () => {
+    const result = renderHookWithProviders()(() => useEditOrgCodeListMutation()).renderHookResult.result;
+    result.current.mutate(codeListToEdit);
+    expect(result.current.isLoading).toBe(true);
+    await waitFor(() => expect(result.current.isSuccess).toBe(true));
+  });
+
+  it('Handles error states correctly', async () => {
+    const error = new Error('Failed to edit code list');
+    jest.spyOn(queriesMock, 'editOrgLevelCodeList').mockRejectedValueOnce(error);
+    const result = renderHookWithProviders()(() => useEditOrgCodeListMutation()).renderHookResult.result;
+    result.current.mutate(codeListToEdit);
+    await waitFor(() => expect(result.current.isError).toBe(true));
+    expect(result.current.error).toBe(error);
+  });
frontend/packages/shared/src/api/mutations.ts (2)

172-172: Track the TODO comment.

The TODO comment about replacing mocks should be tracked in your issue system.

Would you like me to create an issue to track the implementation of the actual API endpoints?


173-179: Remove console.log before production.

The console.log statement should be removed as it's only useful for development.

 export const editOrgLevelCodeList = async (codeListItem: OptionListsResponse): Promise<void> =>
   new Promise((resolve) => {
     setTimeout(() => {
-      console.log('Code list edited:', codeListItem);
       resolve();
     }, 1000);
   });
frontend/packages/shared/src/mocks/queriesMock.ts (1)

206-206: Consider adding type information to the mock implementation.

The mock implementation looks good and follows the established pattern. However, consider adding type information to make it more type-safe:

-  editOrgLevelCodeList: jest.fn().mockImplementation(() => Promise.resolve()),
+  editOrgLevelCodeList: jest.fn().mockImplementation(() => Promise.resolve<void>()),
📜 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 6cec080.

📒 Files selected for processing (5)
  • frontend/packages/shared/src/api/mutations.ts (2 hunks)
  • frontend/packages/shared/src/hooks/mutations/useEditOrgCodeListMutation.test.ts (1 hunks)
  • frontend/packages/shared/src/hooks/mutations/useEditOrgCodeListMutation.ts (1 hunks)
  • frontend/packages/shared/src/mocks/queriesMock.ts (1 hunks)
  • frontend/packages/shared/src/types/QueryKey.ts (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 (1)
frontend/packages/shared/src/types/QueryKey.ts (1)

52-52: LGTM!

The new enum value follows the existing naming pattern and maintains alphabetical order.

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 (789cfb3) to head (57d3f9d).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #14522   +/-   ##
=======================================
  Coverage   95.70%   95.70%           
=======================================
  Files        1901     1902    +1     
  Lines       24739    24749   +10     
  Branches     2833     2833           
=======================================
+ Hits        23676    23686   +10     
  Misses        802      802           
  Partials      261      261           

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

@TomasEng
Copy link
Contributor

Closing this as it has become fixed during today's workshop.

@TomasEng TomasEng closed this Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend 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