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(admin): already signed message & create collection available #16537

Merged
merged 4 commits into from
Oct 23, 2024

Conversation

albinagu
Copy link
Member

@albinagu albinagu commented Oct 23, 2024

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

Release Notes

  • New Features

    • Introduced new messages for enhanced user feedback during the review process and error handling.
  • Improvements

    • Simplified the rendering logic for the CreateCollection component, allowing easier access when processing is permitted.
    • Enhanced error handling for upload operations, providing clearer messages based on specific failure reasons.
    • Updated success and modal messages in the ActionReviewComplete component to reflect the current review status of lists.

@albinagu albinagu requested a review from a team as a code owner October 23, 2024 14:17
Copy link
Contributor

coderabbitai bot commented Oct 23, 2024

Walkthrough

The pull request introduces several new message definitions and modifies existing ones in the messages.ts file, enhancing localization capabilities. It updates the rendering logic in the Constituency component to simplify the conditions for displaying the CreateCollection component. Additionally, error handling in the uploadPaperSignee mutation is refined to provide more specific feedback. Changes to the ActionReviewComplete component improve user feedback based on the review status of the list, affecting both toast notifications and modal content.

Changes

File Change Summary
libs/portals/admin/signature-collection/src/lib/messages.ts Added messages: toggleReviewSuccessToggleBack, paperSigneeErrorAlreadySigned. Updated existing defaultMessage properties.
libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx Modified rendering logic for CreateCollection to display when allowedToProcess is true, regardless of collectionStatus.
libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx Enhanced error handling in uploadPaperSignee mutation to provide specific feedback for 'alreadySigned' errors.
libs/portals/admin/signature-collection/src/shared-components/completeReview/index.tsx Updated onCompleted callback in ActionReviewComplete to conditionally display success messages and modal text based on list status.

Possibly related PRs

Suggested reviewers

  • kksteini

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a4e9ed0 and b01e92f.

📒 Files selected for processing (1)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx

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.

@albinagu albinagu added the automerge Merge this PR as soon as all checks pass label Oct 23, 2024
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

🧹 Outside diff range and nitpick comments (6)
libs/portals/admin/signature-collection/src/shared-components/completeReview/index.tsx (2)

Line range hint 13-16: Consider improving type safety for listStatus prop.

The listStatus prop is typed as string but appears to only accept specific values from ListStatus enum.

-  listStatus: string
+  listStatus: ListStatus

Line range hint 1-117: Enhance component reusability with proper documentation.

As this component resides in the libs/ directory and could be reused across different NextJS apps, consider adding:

  • JSDoc documentation for the component and its props
  • Exported TypeScript interfaces for the component props

Example addition:

export interface ActionReviewCompleteProps {
  /** Unique identifier for the list */
  listId: string
  /** Current status of the list */
  listStatus: ListStatus
}

/**
 * A component that handles the review completion action for lists.
 * Provides functionality to toggle list review status with appropriate user feedback.
 */
const ActionReviewComplete = ({ listId, listStatus }: ActionReviewCompleteProps) => {
  // ... existing implementation
}
libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx (1)

78-84: LGTM! Consider enhancing error handling further.

The error handling implementation is correct and improves user feedback. However, consider these enhancements:

  1. Extract error reasons to TypeScript enum/constants
  2. Add type definitions for error responses
  3. Consider handling multiple error reasons if applicable

Example enhancement:

enum SignatureErrors {
  ALREADY_SIGNED = 'alreadySigned',
  // ... other error types
}

type UploadResponse = {
  reasons?: SignatureErrors[];
  success: boolean;
}
libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx (1)

134-139: Consider adding status validation in CreateCollection.

To maintain data integrity while keeping the parent component simple, consider moving the status validation into the CreateCollection component itself.

Example approach:

interface CreateCollectionProps {
  collectionId: string;
  areaId: string;
  // Add optional status prop for internal validation
  collectionStatus?: CollectionStatus;
}
libs/portals/admin/signature-collection/src/lib/messages.ts (2)

504-508: Add a description to help translators.

The message definition is good, but the empty description field could be improved to help translators understand the context.

   toggleReviewSuccessToggleBack: {
     id: 'admin-portal.signature-collection:toggleReviewSuccessToggleBack',
     defaultMessage: 'Tókst að opna fyrir úrvinnslu',
-    description: '',
+    description: 'Success message shown when reopening a signature collection for review',
   },

762-766: Enhance error message clarity and add description.

The error message could be more specific, and the description field should be filled to help translators understand the context.

   paperSigneeErrorAlreadySigned: {
     id: 'admin-portal.signature-collection:paperSigneeErrorAlreadySigned',
-    defaultMessage: 'Kennitala er þegar á lista',
-    description: '',
+    defaultMessage: 'Kennitala er þegar skráð á meðmælalista',
+    description: 'Error message shown when attempting to add a national ID that is already registered on a signature collection list',
   },
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6e20081 and a4e9ed0.

📒 Files selected for processing (4)
  • libs/portals/admin/signature-collection/src/lib/messages.ts (2 hunks)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx (1 hunks)
  • libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx (1 hunks)
  • libs/portals/admin/signature-collection/src/shared-components/completeReview/index.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/portals/admin/signature-collection/src/lib/messages.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-parliamentary/List/paperSignees/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/completeReview/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 (3)
libs/portals/admin/signature-collection/src/shared-components/completeReview/index.tsx (1)

38-42: LGTM! Toast notification logic improvement.

The conditional toast message based on list status provides better user feedback.

libs/portals/admin/signature-collection/src/screens-parliamentary/List/paperSignees/index.tsx (1)

83-83: Verify the message key exists.

Ensure that the paperSigneeErrorAlreadySigned message key is properly defined in the messages file.

✅ Verification successful

Let me check the actual message definition to ensure it's properly defined.


Message key paperSigneeErrorAlreadySigned is properly defined

The message key is correctly defined in libs/portals/admin/signature-collection/src/lib/messages.ts with a proper ID, default message, and description fields. The usage in the code is valid.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for the paperSigneeErrorAlreadySigned message definition
rg "paperSigneeErrorAlreadySigned" --type ts

Length of output: 440


Script:

#!/bin/bash
# Get the full context of the message definition
rg "paperSigneeErrorAlreadySigned" -A 3 libs/portals/admin/signature-collection/src/lib/messages.ts

Length of output: 285

libs/portals/admin/signature-collection/src/screens-parliamentary/Constituency/index.tsx (1)

134-139: Verify the removal of CollectionStatus check.

The simplified condition makes the component more reusable, but please verify that removing the CollectionStatus dependency doesn't allow collection creation in invalid states.

✅ Verification successful

After analyzing the CreateCollection component implementation, I can now provide a final response regarding the removal of the CollectionStatus check.

Removal of CollectionStatus check is safe - component has internal validation

The CreateCollection component has robust internal validation mechanisms that make the CollectionStatus check redundant:

  • It performs candidate lookup and validation via candidateLookup query
  • Uses canCreate state to control whether collection creation is allowed
  • Button is disabled unless both canCreate is true and a valid name exists
  • Displays error messages when creation is not allowed via canCreateErrorReason
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for CollectionStatus usage in CreateCollection component
ast-grep --pattern 'const CreateCollection = $_' -A 20

Length of output: 22554

@datadog-island-is
Copy link

datadog-island-is bot commented Oct 23, 2024

Datadog Report

Branch report: admin_already_signed
Commit report: 7f6be12
Test service: api

✅ 0 Failed, 4 Passed, 0 Skipped, 3.29s Total Time
➡️ Test Sessions change in coverage: 1 no change

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.77%. Comparing base (88c085f) to head (b0ce592).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main   #16537    +/-   ##
========================================
  Coverage   36.76%   36.77%            
========================================
  Files        6851     6850     -1     
  Lines      142120   142000   -120     
  Branches    40542    40493    -49     
========================================
- Hits        52250    52219    -31     
+ Misses      89870    89781    -89     
Flag Coverage Δ
api 3.37% <ø> (ø)

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

see 20 files with indirect coverage changes


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 88c085f...b0ce592. Read the comment docs.

@kodiakhq kodiakhq bot merged commit a84ba44 into main Oct 23, 2024
36 checks passed
@kodiakhq kodiakhq bot deleted the admin_already_signed branch October 23, 2024 18:21
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