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): Fix paper signatures for candidacy #16411

Merged
merged 2 commits into from
Oct 15, 2024

Conversation

juni-haukur
Copy link
Member

@juni-haukur juni-haukur commented Oct 15, 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

Attach Screenshots / Gifs to help reviewers understand the scope of the pull request

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

    • Expanded conditions for signing from paper, allowing more flexibility for signees.
    • Updated signature retrieval to include all signatures without filtering based on validity.
  • Bug Fixes

    • Improved error handling in the signature upload process, ensuring accurate success status reporting.
  • Documentation

    • Adjusted response handling in the PaperSignees component for better accuracy in success checks.

@juni-haukur juni-haukur requested a review from a team as a code owner October 15, 2024 15:08
Copy link
Contributor

coderabbitai bot commented Oct 15, 2024

Walkthrough

The pull request introduces modifications to several services and a component related to signature collection. Key changes include an update to the canSignFromPaper method in the SignatureCollectionService to allow additional conditions for signing, a change in the getSignatures method to return all signatures without validity filtering, and improvements to error handling in the candidacyUploadPaperSignature method. Additionally, the PaperSignees component's response handling in the upload mutation has been adjusted for accuracy.

Changes

File Change Summary
libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts Updated canSignFromPaper method to include ReasonKey.noInvalidSignature in signing conditions.
libs/clients/signature-collection/src/lib/signature-collection-shared.service.ts Modified getSignatures method to return all mapped signatures without filtering by validity.
libs/clients/signature-collection/src/lib/signature-collection.service.ts Enhanced error handling in candidacyUploadPaperSignature method with try-catch block.
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees/PaperSignees.tsx Updated response handling in upload mutation to check the correct success property.

Possibly related PRs

Suggested labels

automerge

Suggested reviewers

  • albinagu

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

🧹 Outside diff range and nitpick comments (3)
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees/PaperSignees.tsx (2)

76-76: Approved: Improved success condition check

The change correctly updates the success condition to check res.signatureCollectionUploadPaperSignature?.success. This is an improvement as it more accurately accesses the success status from the mutation response.

Consider adding an explicit error message for cases where the signatureCollectionUploadPaperSignature property is undefined:

if (res.signatureCollectionUploadPaperSignature?.success) {
  toast.success(formatMessage(m.paperSigneeSuccess))
  refetchSignees()
} else if (res.signatureCollectionUploadPaperSignature === undefined) {
  toast.error(formatMessage(m.unexpectedResponseError))
} else {
  toast.error(formatMessage(m.paperSigneeError))
}

This would provide more specific error handling and potentially help with debugging.


Line range hint 1-208: Suggestions for code improvements

While the component functions correctly, there are a few areas where it could be improved:

  1. Consider refactoring the national ID validation and name retrieval logic into a custom hook. This would improve readability and reusability.

  2. The error handling could be more centralized. Consider creating a custom error handling hook or utility function.

  3. Replace hardcoded error messages with localized messages using the formatMessage function consistently throughout the component.

  4. The onClearForm function could be memoized using useCallback to optimize performance, especially if it's passed as a prop to child components.

Here's an example of how you could refactor the national ID validation into a custom hook:

function useNationalIdValidation(nationalId: string, listId: string) {
  const [name, setName] = useState('')
  const [nationalIdTypo, setNationalIdTypo] = useState(false)

  const { data, loading } = useIdentityQuery({
    variables: { input: { nationalId } },
    skip: nationalId.length !== 10 || !nationalId.isValid(nationalId),
    onCompleted: (data) => setName(data.identity?.name || ''),
  })

  const { canSign, loadingCanSign } = useGetCanSign(
    nationalId,
    listId,
    nationalId.isValid(nationalId),
  )

  useEffect(() => {
    if (nationalId.length === 10) {
      setNationalIdTypo(
        !nationalId.isValid(nationalId) ||
          (!loading && !data?.identity?.name),
      )
    } else {
      setName('')
      setNationalIdTypo(false)
    }
  }, [nationalId, loading, data])

  return { name, nationalIdTypo, canSign, loading: loading || loadingCanSign }
}

This would simplify the main component and make the logic more reusable.

libs/clients/signature-collection/src/lib/signature-collection.service.ts (1)

280-302: Improved error handling, but consider logging errors

The refactoring of candidacyUploadPaperSignature method improves error handling by using a try-catch block. This change makes the method more robust against unexpected API responses or network issues.

Consider adding error logging in the catch block to facilitate debugging:

  } catch {
+   console.error('Error uploading paper signature:', error);
    return {
      success: false,
    }
  }

This will help in identifying and resolving issues in the future without changing the method's behavior.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c21a58f and d4c8c60.

📒 Files selected for processing (4)
  • libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts (1 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection-shared.service.ts (1 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection.service.ts (1 hunks)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees/PaperSignees.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
libs/api/domains/signature-collection/src/lib/signatureCollection.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/clients/signature-collection/src/lib/signature-collection-shared.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/clients/signature-collection/src/lib/signature-collection.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/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees/PaperSignees.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 (2)
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/ViewList/Signees/PaperSignees.tsx (1)

Line range hint 1-208: Adherence to coding guidelines for libs directory

The PaperSignees component adheres well to the coding guidelines for the libs directory:

  1. It's designed for reusability across different NextJS apps.
  2. TypeScript is used for defining props and implicit type exports.
  3. The component uses hooks that can be shared across apps.
  4. There are no apparent issues with tree-shaking or bundling practices.
libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts (1)

179-180: Approve with suggestions: Clarify business logic and consider additional logging

The changes to the canSignFromPaper method look good from a technical perspective. The addition of ReasonKey.noInvalidSignature as an acceptable condition for paper signing broadens the scenarios where this is allowed.

However, I have a few suggestions to improve clarity and maintainability:

  1. Please add a comment explaining the business logic behind allowing ReasonKey.noInvalidSignature for paper signatures. This will help future developers understand the reasoning.

  2. Consider adding logging for these new cases to track how often they occur. This could be valuable for monitoring and future optimizations.

  3. It might be beneficial to extract this condition into a separate method for better readability, e.g., canSignFromPaperBasedOnReasons(signatureSignee).

To ensure this change doesn't have unintended consequences, let's verify its usage:

This will help us understand if this change affects other parts of the codebase and if similar changes are needed elsewhere.

✅ Verification successful

Re-executing shell scripts with correct TypeScript type identifiers

The previous shell script failed to recognize the typescript file type. Let's rerun the searches using the correct type identifier ts to ensure accurate results.


Verification Successful: canSignFromPaper Method Update is Consistent Across the Codebase

The addition of ReasonKey.noInvalidSignature in the canSignFromPaper method has been successfully verified. This reason key is consistently utilized across the following files:

  • libs/clients/signature-collection/src/lib/types/success.dto.ts
  • libs/application/template-api-modules/src/lib/modules/templates/signature-collection/signature-list-signing/signature-list-signing.service.ts
  • libs/application/template-api-modules/src/lib/modules/templates/signature-collection/parliamentary-list-signing/parliamentary-list-signing.service.ts
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.service.ts

Additionally, the canSignFromPaper method is appropriately referenced in multiple resolver and service files:

  • libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts
  • libs/api/domains/signature-collection/src/lib/signatureCollectionAdmin.resolver.ts
  • libs/api/domains/signature-collection/src/lib/dto/index.ts
  • libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts

All usages align with the intended logic, ensuring that the change does not introduce inconsistencies or unintended behaviors.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other occurrences of ReasonKey.noInvalidSignature
# and canSignFromPaper method usage

echo "Searching for other occurrences of ReasonKey.noInvalidSignature:"
rg "ReasonKey.noInvalidSignature" --type typescript

echo "\nSearching for usages of canSignFromPaper method:"
rg "canSignFromPaper" --type typescript

Length of output: 411


Script:

#!/bin/bash
# Description: Check for other occurrences of ReasonKey.noInvalidSignature
# and canSignFromPaper method usage with correct TypeScript type identifier

echo "Searching for other occurrences of ReasonKey.noInvalidSignature:"
rg "ReasonKey.noInvalidSignature" --type ts

echo "\nSearching for usages of canSignFromPaper method:"
rg "canSignFromPaper" --type ts

Length of output: 1850

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

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

Project coverage is 36.73%. Comparing base (4a0a50a) to head (7501983).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...collection/src/lib/signature-collection.service.ts 0.00% 4 Missing ⚠️
...ion/src/lib/signature-collection-shared.service.ts 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #16411   +/-   ##
=======================================
  Coverage   36.73%   36.73%           
=======================================
  Files        6809     6809           
  Lines      141087   141080    -7     
  Branches    40225    40224    -1     
=======================================
  Hits        51825    51825           
+ Misses      89262    89255    -7     
Flag Coverage Δ
api 3.37% <ø> (ø)
api-domains-auth-admin 48.48% <ø> (ø)
api-domains-communications 39.89% <ø> (ø)
application-system-api 41.42% <0.00%> (+<0.01%) ⬆️
application-template-api-modules 27.89% <ø> (ø)
application-ui-shell 21.35% <ø> (ø)
cms 0.42% <ø> (ø)
cms-translations 39.02% <ø> (ø)
judicial-system-api 18.39% <ø> (ø)
judicial-system-backend 55.17% <ø> (ø)
services-user-notification 47.01% <ø> (ø)

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

Files with missing lines Coverage Δ
...ion/src/lib/signature-collection-shared.service.ts 9.83% <0.00%> (+0.31%) ⬆️
...collection/src/lib/signature-collection.service.ts 6.94% <0.00%> (-0.04%) ⬇️

... and 1 file 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 4a0a50a...7501983. Read the comment docs.

@datadog-island-is
Copy link

Datadog Report

All test runs c0ea5a5 🔗

4 Total Test Services: 0 Failed, 4 Passed
➡️ Test Sessions change in coverage: 13 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.1s 1 no change Link
application-system-api 0 0 0 120 2 3m 33.25s 1 no change Link
application-template-api-modules 0 0 0 123 0 2m 32.38s 1 no change Link
application-ui-shell 0 0 0 74 0 36.06s 1 no change Link

@albinagu albinagu added the automerge Merge this PR as soon as all checks pass label Oct 15, 2024
@kodiakhq kodiakhq bot merged commit 420313d into main Oct 15, 2024
63 checks passed
@kodiakhq kodiakhq bot deleted the fix/parliamentary-paper-signatures-candidate branch October 15, 2024 17:21
kksteini pushed a commit that referenced this pull request Oct 16, 2024
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
kodiakhq bot added a commit that referenced this pull request Oct 16, 2024
* fix(service-portal): company route signature collections (#16382)

* draft

* chore: nx format:write update dirty files

* fix: company path

* tweaks

* p

* view list company path

* chore: nx format:write update dirty files

* nav tweak

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: Ásdís Erna Guðmundsdóttir <[email protected]>

* fix(service-portal): sp list submitted (#16383)

* fix(service-portal): sp list submitted

* tweak

* chore: nx format:write update dirty files

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: andes-it <[email protected]>

* fix(portals-admin): adding report date (#16384)

* fix(portals-admin): adding report date

* chore: nx format:write update dirty files

* tweak

* tweak supervisors info

* chore: nx format:write update dirty files

* tweak

* message - company card

* tweak

* t

* t

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(signature-collection): tweaks 15.10 (#16402)

* tweaka

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(signature-collection): Tweaks for parliamentary collection (#16407)

* Tweaks for parliamentary collection

* revertt'

* Update libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

* managers should see other managers

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(signature-collection): Fix paper signatures for candidacy (#16411)

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

* fix(signature-collections): ongoing updates (#16409)

* tweaks

* tweak - create list

* copylink

* chore: nx format:write update dirty files

---------

Co-authored-by: andes-it <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>

---------

Co-authored-by: albinagu <[email protected]>
Co-authored-by: andes-it <[email protected]>
Co-authored-by: Ásdís Erna Guðmundsdóttir <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: juni-haukur <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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