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(signature-collection): Admin create lists fix #16491

Merged
merged 3 commits into from
Oct 21, 2024

Conversation

juni-haukur
Copy link
Member

@juni-haukur juni-haukur commented Oct 21, 2024

...

Attach a link to issue if relevant

What

Specify what you're trying to achieve

Why

Specify why you need to achieve this

Screenshots / Gifs

image

Checklist:

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • Formatting passes locally with my changes
  • I have rebased against main before asking for a review

Summary by CodeRabbit

  • New Features

    • Introduced a new API endpoint for creating recommendation lists.
    • Enhanced the existing API endpoint for adding recommendation lists with better documentation.
    • Added areaId support to the CreateCollection component for improved data handling.
  • Bug Fixes

    • Improved error handling in candidate removal and list management methods.
  • Refactor

    • Updated filtering logic in the Lists component to enhance list management.
  • Style

    • Adjusted input handling in the CreateCollection component to conditionally display area information.

@juni-haukur juni-haukur requested a review from a team as a code owner October 21, 2024 14:24
Copy link
Contributor

coderabbitai bot commented Oct 21, 2024

Walkthrough

The pull request introduces modifications to the OpenAPI specification for the MedmaeliRestAPI, adding a new endpoint /Admin/Medmaelalisti for creating recommendation lists and updating the existing /Medmaelalistar endpoint to enhance its documentation. Changes to the SignatureCollectionAdminClientService class improve the logic of the createListsAdmin method and refine error handling in several methods. Additionally, the CreateCollection component is updated to include an areaId prop, enhancing the data handling in the Constituency and Lists components.

Changes

File Change Summary
libs/clients/signature-collection/src/clientConfig.json Added new endpoint POST /Admin/Medmaelalisti and updated /Medmaelalistar with new summary and request body.
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts Modified createListsAdmin logic for candidate retrieval and creation; improved error handling in removeCandidate, removeList, and getAreaSummaryReport.
libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx Added areaId variable to Constituency component and updated CreateCollection component to accept areaId.
libs/portals/admin/signature-collection/src/screens-presidential/AllLists/index.tsx Updated CreateCollection component's props to include areaId and enhanced filtering logic for displayed lists.
libs/portals/admin/signature-collection/src/shared-components/createCollection/index.tsx Expanded CreateCollection props to include areaId, integrated useParams for constituency name, and updated mutation handling.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • kksteini

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 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.

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.

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

🧹 Outside diff range and nitpick comments (7)
libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx (3)

51-52: LGTM! Consider using array destructuring for a slight optimization.

The introduction of areaId is a good addition, aligning with the changes mentioned in the summary. The logic for finding the corresponding area ID is correct.

For a slight optimization, consider using array destructuring:

const [areaId] = collection.areas.filter((a) => a.name === constituencyName).map(a => a.id);

This approach eliminates the need for optional chaining and directly assigns the ID or undefined if no match is found.


131-134: LGTM! Consider using prop spreading for cleaner code.

The addition of the areaId prop to the CreateCollection component is consistent with the earlier changes and aligns with the summary. This change enhances the component's functionality by providing area-specific data.

For cleaner and more maintainable code, consider using prop spreading:

<CreateCollection
  {...{
    collectionId: collection?.id,
    areaId,
  }}
/>

This approach makes it easier to add or remove props in the future without changing the component invocation structure.


Line range hint 1-234: Overall, the changes enhance area-specific functionality and maintain code quality.

The modifications to the Constituency component, including the introduction of areaId and its integration with the CreateCollection component, align well with the PR objectives and the AI-generated summary. These changes improve the handling of area-specific data in the signature collection process.

The code adheres to the provided coding guidelines, particularly in terms of TypeScript usage for props and maintaining the reusability of components across different NextJS apps.

To further improve the code:

  1. Consider extracting the areaId logic into a custom hook for reusability across components.
  2. Evaluate the possibility of using React Context for sharing the collection data, which could simplify prop passing and make the component more maintainable as it grows.
libs/portals/admin/signature-collection/src/screens-presidential/AllLists/index.tsx (1)

224-227: LGTM! Consider adding a comment for clarity.

The addition of the areaId prop to the CreateCollection component enhances its flexibility while maintaining backwards compatibility. This change aligns well with the library's goal of reusability across different NextJS apps.

Consider adding a brief comment explaining why areaId is set to undefined for presidential lists. This would improve code readability and maintainability. For example:

<CreateCollection
  collectionId={collection?.id}
  areaId={undefined} // Presidential lists are not area-specific
/>
libs/clients/signature-collection/src/clientConfig.json (1)

966-968: Good addition of summary, but consider enhancing the description.

The addition of a summary for the /Medmaelalistar POST endpoint improves the API documentation. However, the description field is now empty. Consider adding a more detailed description to provide additional context and usage information for this endpoint.

libs/portals/admin/signature-collection/src/shared-components/createCollection/index.tsx (2)

23-29: Use optional parameter syntax for the areaId prop

Simplify the prop definition by using the optional parameter syntax areaId?: string instead of areaId: string | undefined, which is more idiomatic in TypeScript.

Apply this diff to update the prop definition:

 const CreateCollection = ({
   collectionId,
   areaId,
 }: {
   collectionId: string
-  areaId: string | undefined
+  areaId?: string
 }) => {

Line range hint 63-73: Incorrect error message displayed on collection creation failure

In the createNewCollection function, when the collection creation fails (in the else branch), the error toast is displaying the success message. This could confuse users.

Apply this diff to fix the error message:

 } else {
-  toast.error(formatMessage(m.createCollectionSuccess))
+  toast.error(formatMessage(m.createCollectionError))
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f031834 and 55d20f4.

📒 Files selected for processing (5)
  • libs/clients/signature-collection/src/clientConfig.json (2 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1 hunks)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx (2 hunks)
  • libs/portals/admin/signature-collection/src/screens-presidential/AllLists/index.tsx (1 hunks)
  • libs/portals/admin/signature-collection/src/shared-components/createCollection/index.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
libs/clients/signature-collection/src/clientConfig.json (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/clients/signature-collection/src/lib/signature-collection-admin.service.ts (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/portals/admin/signature-collection/src/screens-presidential/AllLists/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
libs/portals/admin/signature-collection/src/shared-components/createCollection/index.tsx (1)

Pattern libs/**/*: "Confirm that the code adheres to the following:

  • Reusability of components and hooks across different NextJS apps.
  • TypeScript usage for defining props and exporting types.
  • Effective tree-shaking and bundling practices."
🔇 Additional comments (5)
libs/clients/signature-collection/src/clientConfig.json (2)

115-149: New admin endpoint for creating recommendation lists looks good.

The new /Admin/Medmaelalisti POST endpoint is well-structured and consistent with the existing API patterns. It provides a clear purpose for adding new recommendation lists to an established proposal, uses appropriate DTOs, and is correctly placed under the Admin section for proper access control.


115-149: Overall, these changes enhance the API's recommendation list management capabilities.

The addition of the new admin endpoint and the update to the existing endpoint for recommendation lists are consistent and well-structured. They maintain the separation between admin and non-admin functionalities, use appropriate DTOs, and follow existing API patterns. These changes should improve the flexibility and usability of the API for managing recommendation lists.

Also applies to: 966-968

libs/portals/admin/signature-collection/src/shared-components/createCollection/index.tsx (3)

56-56: LGTM

The addition of the areas field correctly incorporates areaId into the mutation variables when provided.


59-61: Ensure revalidate is appropriately triggered

Calling revalidate() in the onCompleted callback ensures that the data is refreshed after the mutation. Just make sure that this aligns with your data-fetching strategy and doesn't cause unnecessary re-renders.


172-179: Consider ensuring constituencyName is reliably obtained

When rendering the candidate area input, constituencyName is obtained via useParams(). Ensure that constituencyName is consistently available when areaId is present to prevent potential undefined values.

@juni-haukur juni-haukur added the automerge Merge this PR as soon as all checks pass label Oct 21, 2024
Copy link

codecov bot commented Oct 21, 2024

Codecov Report

Attention: Patch coverage is 0% with 9 lines in your changes missing coverage. Please review.

Project coverage is 36.78%. Comparing base (f031834) to head (fa297fc).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...tion/src/lib/signature-collection-admin.service.ts 0.00% 9 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16491      +/-   ##
==========================================
- Coverage   36.78%   36.78%   -0.01%     
==========================================
  Files        6845     6845              
  Lines      141740   141747       +7     
  Branches    40378    40380       +2     
==========================================
  Hits        52139    52139              
- Misses      89601    89608       +7     
Flag Coverage Δ
api 3.37% <ø> (ø)
application-system-api 41.36% <0.00%> (-0.01%) ⬇️
application-template-api-modules 27.79% <ø> (-0.02%) ⬇️
application-ui-shell 21.37% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...tion/src/lib/signature-collection-admin.service.ts 12.05% <0.00%> (-0.63%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f031834...fa297fc. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 21, 2024

Datadog Report

All test runs 6f99bff 🔗

4 Total Test Services: 0 Failed, 4 Passed
🔻 Test Sessions change in coverage: 2 decreased, 10 no change

Test Services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
api 0 0 0 4 0 3.17s 1 no change Link
application-system-api 0 0 0 120 2 2m 54.01s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 38.08s 1 decreased (-0.01%) Link
application-ui-shell 0 0 0 74 0 37.06s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • clients-signature-collection - jest 21.83% (-0.21%) - Details
  • application-template-api-modules - jest 30.04% (-0.01%) - Details

@kodiakhq kodiakhq bot merged commit e9edd28 into main Oct 21, 2024
41 checks passed
@kodiakhq kodiakhq bot deleted the fix/admin-create-lists-fix branch October 21, 2024 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants