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): Get candidate collectors #16146

Merged
merged 4 commits into from
Sep 25, 2024

Conversation

juni-haukur
Copy link
Member

@juni-haukur juni-haukur commented Sep 25, 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

    • Introduced a new GraphQL query to fetch collectors' information, including their national ID and name.
    • Added a new hook to manage data fetching for collectors, improving the user experience in the OwnerView component.
    • Implemented a skeleton loader for collectors to enhance the loading experience while data is being fetched.
  • Bug Fixes

    • Improved handling of scenarios where candidate data might be undefined.
  • Documentation

    • Updated method signatures and descriptions to reflect new functionality.

@juni-haukur juni-haukur requested a review from a team as a code owner September 25, 2024 10:27
Copy link
Contributor

coderabbitai bot commented Sep 25, 2024

Walkthrough

The pull request introduces a new query method signatureCollectionCollectors in the SignatureCollectionResolver class, along with corresponding methods collectors in the SignatureCollectionService and getCollectors in the SignatureCollectionClientService. These methods enable the retrieval of signature collection data based on user input and authentication, thereby enhancing the functionality of the signature collection module.

Changes

File Change Summary
libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts Added method async signatureCollectionCollectors(user: User, signee: SignatureCollectionSignee): Promise<SignatureCollectionCollector[]> to retrieve collectors.
libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts Added method `async collectors(user: User, candidateId: string
libs/clients/signature-collection/src/lib/signature-collection.service.ts Added method async getCollectors(auth: User, candidateId: string): Promise<{ name: string; nationalId: string }[]> to fetch collector data.
libs/service-portal/signature-collection/src/hooks/graphql/queries.ts Added new GraphQL query GetCollectors to retrieve collector information.
libs/service-portal/signature-collection/src/hooks/index.ts Introduced hook useGetCollectors to utilize the GetCollectors query for data fetching.
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx Integrated useGetCollectors hook into OwnerView component for dynamic collector data.
libs/service-portal/signature-collection/src/skeletons.tsx Added new functional component CollectorSkeleton for loading state representation.

Possibly related PRs

Suggested labels

automerge, high priority

Suggested reviewers

  • kksteini
  • 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: 2

🧹 Outside diff range and nitpick comments (1)
libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts (1)

167-175: LGTM: New collectors method is well-structured and follows best practices.

The method is correctly typed and uses async/await syntax appropriately. It delegates the work to the client service, which is good for separation of concerns and reusability across different NextJS apps.

Consider adding error handling to improve robustness:

async collectors(
  user: User,
  input: SignatureCollectionCandidateIdInput,
): Promise<SignatureCollectionCollector[]> {
  try {
    return await this.signatureCollectionClientService.getCollectors(
      user,
      input,
    );
  } catch (error) {
    // Log the error or handle it appropriately
    console.error('Error fetching collectors:', error);
    throw error; // or return an empty array, depending on your error handling strategy
  }
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 621b5bb and 38590bc.

📒 Files selected for processing (3)
  • libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts (2 hunks)
  • libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts (2 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.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/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.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."
🔇 Additional comments not posted (4)
libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts (2)

22-23: LGTM: New imports are correctly typed and follow best practices.

The new imports for SignatureCollectionCandidateIdInput and SignatureCollectionCollector are well-structured and contribute to effective tree-shaking. They align with TypeScript usage guidelines for defining and exporting types.


22-23: Confirm: Changes comply with coding guidelines for libs/**/* files.

The new code adheres to the following guidelines:

  1. Reusability: The SignatureCollectionService class and its new collectors method are designed for use across different NextJS apps.
  2. TypeScript usage: Props and types are correctly defined and exported.
  3. Effective tree-shaking: Specific imports and modular method design contribute to efficient bundling.

Also applies to: 167-175

libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts (2)

37-38: LGTM!

The added imports correctly include the required models and inputs for the new method.


192-201: LGTM!

The new query method signatureCollectionCollectors is correctly implemented with appropriate decorators, access controls, and type annotations. It aligns with the existing patterns in the resolver.

Copy link

codecov bot commented Sep 25, 2024

Codecov Report

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

Project coverage is 36.70%. Comparing base (8f37c3d) to head (2b278f2).
Report is 1 commits behind head on main.

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

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #16146      +/-   ##
==========================================
+ Coverage   36.64%   36.70%   +0.05%     
==========================================
  Files        6769     6768       -1     
  Lines      139439   139214     -225     
  Branches    39656    39562      -94     
==========================================
- Hits        51100    51096       -4     
+ Misses      88339    88118     -221     
Flag Coverage Δ
api 3.39% <ø> (ø)
application-system-api 41.55% <0.00%> (-0.01%) ⬇️
application-template-api-modules 23.61% <ø> (-0.01%) ⬇️
application-ui-shell 21.29% <ø> (ø)
web 1.83% <ø> (ø)

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

Files with missing lines Coverage Δ
...collection/src/lib/signature-collection.service.ts 7.00% <0.00%> (-0.24%) ⬇️

... and 11 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 8f37c3d...2b278f2. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Sep 25, 2024

Datadog Report

All test runs e202c0d 🔗

5 Total Test Services: 0 Failed, 5 Passed
🔻 Test Sessions change in coverage: 2 decreased, 14 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 2.74s 1 no change Link
application-system-api 0 0 0 111 2 3m 30.32s 1 no change Link
application-template-api-modules 0 0 0 109 0 1m 42.13s 1 decreased (-0.01%) Link
application-ui-shell 0 0 0 74 0 31.97s 1 no change Link
web 0 0 0 84 0 27.99s 1 no change Link

🔻 Code Coverage Decreases vs Default Branch (2)

  • clients-signature-collection - jest 22.83% (-0.04%) - Details
  • application-template-api-modules - jest 25.68% (-0.01%) - Details

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 (6)
libs/service-portal/signature-collection/src/skeletons.tsx (2)

25-29: Good implementation, consider adding TypeScript types

The CollectorSkeleton component is well-implemented and consistent with other skeleton components in the file. It's a reusable component that can be used across different NextJS apps.

To improve type safety and adhere to TypeScript best practices:

  1. Consider defining prop types for the component, even if it currently doesn't accept any props. This will make it easier to add props in the future if needed.
  2. Export the component type for better integration with other parts of the application.

Here's a suggested improvement:

import React from 'react';
import { SkeletonLoader } from '@island.is/island-ui/core';

export type CollectorSkeletonProps = {
  // Add any future props here
};

export const CollectorSkeleton: React.FC<CollectorSkeletonProps> = () => {
  return (
    <SkeletonLoader height={50} borderRadius="large" repeat={2} space={1} />
  );
};

This change adds explicit typing and exports the component type, which aligns with TypeScript best practices and improves the overall type safety of the module.


Line range hint 1-29: Overall good implementation, consider enhancing TypeScript usage

The file structure and implementation are well done. The skeleton components are focused and reusable, which aligns with the guidelines for libs/**/* files. The use of named exports is excellent for effective tree-shaking and bundling.

To further improve the file:

  1. Consider adding TypeScript prop types and exporting types for all components in the file, not just the new CollectorSkeleton. This will enhance type safety and consistency across the module.
  2. Ensure that all components follow the same pattern of explicit typing and type exports.

Here's an example of how you could enhance the Skeleton component (apply similar changes to other components):

import React from 'react';
import { Box, SkeletonLoader } from '@island.is/island-ui/core';

export type SkeletonProps = {
  // Add any future props here
};

export const Skeleton: React.FC<SkeletonProps> = () => {
  return (
    <Box marginTop={[5, 10]}>
      <SkeletonLoader height={150} borderRadius="large" repeat={3} space={2} />
    </Box>
  );
};

Applying this pattern to all components will improve overall type safety and maintainability of the module.

libs/service-portal/signature-collection/src/hooks/graphql/queries.ts (1)

167-174: LGTM! Consider adding a type for the query response.

The new GetCollectors query looks good and aligns with the existing code structure and PR objectives. It provides a way to retrieve collector information, which is relevant to the signature collection process.

To improve consistency with other queries and enhance type safety, consider defining and exporting a type for the query response. This would be in line with the TypeScript usage guideline for the libs directory.

You could add a type definition like this:

export type GetCollectorsQuery = {
  signatureCollectionCollectors: Array<{
    nationalId: string;
    name: string;
  }>;
};

This type can then be used when consuming the query results, enhancing type safety across the application.

libs/service-portal/signature-collection/src/hooks/index.ts (1)

175-182: LGTM: New useGetCollectors hook implemented correctly

The new useGetCollectors hook is well-implemented and follows the existing patterns in the file. It correctly uses the useQuery hook and handles the case where no data is returned.

Suggestions for improvement:

  1. Consider adding error handling to manage potential query failures.
  2. You might want to include a refetch function in the return object, similar to other hooks in this file, to allow manual refetching of the data if needed.

Example:

export const useGetCollectors = () => {
  const { data: getCollectorsData, loading: loadingCollectors, error, refetch } =
    useQuery(GetCollectors)
  const collectors =
    (getCollectorsData?.signatureCollectionCollectors as SignatureCollectionCollector[]) ??
    []
  return { collectors, loadingCollectors, error, refetch }
}

This change would make the hook more consistent with others in the file and provide more flexibility for error handling and data refreshing.

libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (2)

23-27: LGTM! Consider grouping related imports.

The new imports for skeleton components and hooks are appropriate for the changes made to the component. To improve code organization, consider grouping related imports together.

You could group the imports like this:

import {
  CollectorSkeleton,
  OwnerParliamentarySkeleton,
} from '../../../skeletons'
import { useGetCollectors, useGetListsForOwner } from '../../../hooks'

42-42: LGTM! Consider adding error handling.

The addition of the useGetCollectors hook and the loadingCollectors state is a good improvement for fetching and managing collector data. This aligns well with the PR objective.

Consider adding error handling for the useGetCollectors hook to improve robustness:

const { collectors, loadingCollectors, error } = useGetCollectors()

// Later in the component
if (error) {
  // Handle the error, e.g., display an error message
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 38590bc and 318bb3e.

📒 Files selected for processing (7)
  • libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts (2 hunks)
  • libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts (2 hunks)
  • libs/clients/signature-collection/src/lib/signature-collection.service.ts (1 hunks)
  • libs/service-portal/signature-collection/src/hooks/graphql/queries.ts (1 hunks)
  • libs/service-portal/signature-collection/src/hooks/index.ts (3 hunks)
  • libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (3 hunks)
  • libs/service-portal/signature-collection/src/skeletons.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • libs/api/domains/signature-collection/src/lib/signatureCollection.service.ts
  • libs/clients/signature-collection/src/lib/signature-collection.service.ts
🧰 Additional context used
📓 Path-based instructions (5)
libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.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/hooks/graphql/queries.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/hooks/index.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/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/service-portal/signature-collection/src/skeletons.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."
Biome
libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx

[error] 194-194: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 195-195: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

🔇 Additional comments not posted (5)
libs/service-portal/signature-collection/src/hooks/index.ts (2)

11-11: LGTM: New imports added correctly

The new imports for GetCollectors and SignatureCollectionCollector are correctly placed and necessary for the new useGetCollectors hook. They follow the existing import pattern in the file.

Also applies to: 20-20


Line range hint 1-182: Summary: New useGetCollectors hook enhances signature collection functionality

The changes in this file introduce a new useGetCollectors hook, which enhances the signature collection functionality. The implementation follows existing patterns and adheres to the provided coding guidelines, including:

  1. Reusability: The new hook can be used across different NextJS apps.
  2. TypeScript usage: The hook correctly uses TypeScript for defining types.
  3. Effective bundling: The hook is exported individually, allowing for effective tree-shaking.

The changes are well-integrated into the existing codebase and should provide valuable functionality for collecting signature collectors. Consider implementing the suggested improvements to error handling and refetch functionality for consistency with other hooks in the file.

libs/service-portal/signature-collection/src/screens/Parliamentary/OwnerView/index.tsx (1)

Line range hint 1-238: Overall good improvements with minor issues to address.

The changes in this file align well with the PR objective of getting candidate collectors. The introduction of the useGetCollectors hook and the dynamic rendering of collectors improve the component's functionality and maintainability. The use of skeleton components for loading states enhances the user experience.

To further improve the code:

  1. Address the table structure and missing key prop issues in the collectors rendering logic.
  2. Consider adding error handling for the useGetCollectors hook.
  3. Group related imports for better code organization.

Once these minor issues are addressed, the changes will be ready for approval.

🧰 Tools
Biome

[error] 194-194: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


[error] 195-195: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts (2)

37-38: LGTM: New imports added correctly.

The new imports for SignatureCollectionCollector and SignatureCollectionCandidateIdInput are correctly added and follow the existing import style in the file.


192-204: LGTM: New query method added correctly.

The signatureCollectionCollectors method is well-structured and consistent with other query methods in the class. It correctly uses decorators, TypeScript types, and follows the coding guidelines for reusability.

Please verify that the OwnerAccess.AllowActor access requirement is the intended setting for this query. If it should be more restrictive, consider using OwnerAccess.RestrictActor instead.

To verify the usage of OwnerAccess.AllowActor in other similar methods, you can run the following command:

✅ Verification successful

Action Required: Adjust the Ripgrep Command to Target TypeScript Files Correctly.

The previous shell script failed because ripgrep does not recognize typescript as a valid file type. To search within .ts files, modify the command to use the --glob option instead.

[/run_scripts]


Action Required: Verify Usage of OwnerAccess.AllowActor Across the Entire Codebase.

To ensure that OwnerAccess.AllowActor is used consistently throughout the codebase, please run the following command to search for its usage in all TypeScript files:

[/run_scripts]


Verification Successful: OwnerAccess.AllowActor Usage is Consistent.

All instances of @AccessRequirement(OwnerAccess.AllowActor) are consistently used within the signatureCollection.resolver.ts file. The access requirement is appropriately applied to the relevant query methods, ensuring proper access control as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other query methods using OwnerAccess.AllowActor
rg --type typescript 'AccessRequirement\(OwnerAccess\.AllowActor\).*@Query' libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts

Length of output: 190


Script:

#!/bin/bash
# Search for other query methods using OwnerAccess.AllowActor in TypeScript files
rg 'AccessRequirement\(OwnerAccess\.AllowActor\).*@Query' --glob '*.ts' libs/api/domains/signature-collection/src/lib/signatureCollection.resolver.ts

Length of output: 151


Script:

#!/bin/bash
# Search for all instances of OwnerAccess.AllowActor in TypeScript files across the repository
rg 'AccessRequirement\(OwnerAccess\.AllowActor\)' --glob '**/*.ts'

Length of output: 683

Copy link
Member

@albinagu albinagu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@albinagu albinagu added the automerge Merge this PR as soon as all checks pass label Sep 25, 2024
@kodiakhq kodiakhq bot merged commit aae6610 into main Sep 25, 2024
51 checks passed
@kodiakhq kodiakhq bot deleted the fix/add-collectors-endpoint branch September 25, 2024 13:49
thoreyjona pushed a commit that referenced this pull request Oct 2, 2024
* get candidate collectors

* add collectors to frontend

* coderabbit suggestion

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[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