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(web): updated grant status logic #17127

Merged
merged 13 commits into from
Dec 12, 2024
Merged

feat(web): updated grant status logic #17127

merged 13 commits into from
Dec 12, 2024

Conversation

thorkellmani
Copy link
Member

@thorkellmani thorkellmani commented Dec 4, 2024

What

  • Complex ui logic for rendering strings based on application status

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 a new utility function for improved grant status handling.
    • Added multiple new message definitions for application statuses and timelines.
    • Set up new server-side rendered pages for grant detail and grants index views.
  • Improvements

    • Enhanced the GrantSidebar and SearchResultsContent components to utilize the new status parsing logic.
    • Updated GraphQL queries to include statusText and date fields for grants.
    • Expanded the GrantStatus enum with new values for better status representation.
  • Bug Fixes

    • Corrected grammatical issues in message definitions.

These changes aim to provide a more structured approach to managing grant statuses and improve user experience.

@thorkellmani thorkellmani requested review from a team as code owners December 4, 2024 13:44
Copy link
Contributor

coderabbitai bot commented Dec 4, 2024

Walkthrough

The pull request introduces significant updates to the grant management components, primarily enhancing the handling of grant statuses across various files. A new utility function, parseStatus, is added to centralize status parsing logic, impacting components like GrantSidebar and SearchResultsContent. The message definitions are updated to reflect grammatical changes and new entries related to application statuses. Additionally, modifications to GraphQL queries and the CmsElasticsearchService class streamline data retrieval processes. Overall, these changes improve the structure and clarity of the code while ensuring consistent status representation.

Changes

File Path Change Summary
apps/web/screens/Grants/Grant/GrantSidebar.tsx - Added import for parseStatus.
- Updated to use status object for deadlineStatus and applicationStatus.
- Memoization dependencies updated to include status.
apps/web/screens/Grants/SearchResults/SearchResultsContent.tsx - Added import for parseStatus.
- Updated to use status object for applicationStatus and applicationDeadlineStatus.
apps/web/screens/Grants/messages.ts - Updated defaultMessage for applicationStatus.
- Added new messages: applicationOpensAt, applicationEstimatedOpensAt, applicationOpensTo, applicationWasOpenTo, applicationAlwaysOpen.
apps/web/screens/Grants/utils.ts - Added Status interface.
- Updated parseStatus to accept a Grant object and return a Status object.
- Modified generateStatusTag to accept applicationStatus from Status.
apps/web/screens/queries/Grants.ts - In GET_GRANTS_QUERY, removed isOpen, added statusText.
- In GET_GRANT_QUERY, added statusText, dateFrom, and dateTo.
libs/cms/src/lib/cms.elasticsearch.service.ts - Removed GrantStatus import.
- Updated getGrants method to remove statuses parameter and associated logic.
libs/cms/src/lib/models/grant.model.ts - Expanded GrantStatus enum with new values and removed SEE_DESCRIPTION.
- Refactored mapGrant function to use parseStatus.
- Added parseStatus method.
libs/cms/src/lib/search/importers/grants.service.ts - Updated doMapping method to remove case for GrantStatus.SEE_DESCRIPTION and added cases for new statuses.
apps/web/pages/en/grants-plaza/grant/[id].ts - Added server-side rendered page for grant detail view.
- Composed Screen component with withApollo and withLocale.
- Defined getServerSideProps for data fetching.
apps/web/pages/en/grants-plaza/grants/index.ts - Added page component for grants.
- Composed Screen component with withApollo and withLocale.
- Defined getServerSideProps for data fetching.
apps/web/pages/en/grants-plaza/index.ts - Added page for grants plaza with Apollo integration.
- Defined getServerSideProps for server-side rendering.
apps/web/screens/Grants/Home/GrantsHome.tsx - Renamed formatMessage variable to intl for better scoping.
- Updated access to formatMessage using the new intl variable.

Possibly related PRs

  • feat(portals-admin): Set up for Parliamentary Lists #15892: The changes in the main PR involve updates to the GrantSidebar component, which may relate to the overall structure and organization of components, similar to the setup for Parliamentary Lists in this PR.
  • fix(portals-admin): signature collections pdf summary #16237: The introduction of the supportLinks field in the main PR aligns with the enhancements made in this PR regarding the handling of signature collections, indicating a focus on improving user access to relevant information.
  • fix(web-grants): Tag descriptions #16941: The modifications to the GrantSidebar component in the main PR, particularly the introduction of a new helper function for rendering sidebar panels, relate to the various fixes and enhancements made in this PR, which also focuses on improving navigation and user experience.
  • feat(web): add support links to grants #17189: The addition of support links in the main PR directly corresponds to the objective of this PR, which aims to enhance user accessibility to relevant support resources within the grants section.

Suggested labels

deploy-feature

Suggested reviewers

  • disaerna
  • RunarVestmann

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3301830 and e2080c6.

📒 Files selected for processing (2)
  • apps/web/screens/Grants/Grant/GrantSidebar.tsx (5 hunks)
  • apps/web/screens/queries/Grants.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/screens/queries/Grants.ts
  • apps/web/screens/Grants/Grant/GrantSidebar.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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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 (1)
apps/web/screens/Grants/utils.ts (1)

31-104: Consider refactoring 'parseStatus' to reduce code duplication

The parseStatus function contains multiple cases with similar return structures. Refactoring could reduce code duplication and enhance maintainability.

For example, you could extract common properties into variables or use a mapping object to handle the different statuses.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4a229a4 and 0f766cb.

⛔ Files ignored due to path filters (1)
  • libs/cms/src/lib/generated/contentfulTypes.d.ts is excluded by !**/generated/**
📒 Files selected for processing (8)
  • apps/web/screens/Grants/Grant/GrantSidebar.tsx (3 hunks)
  • apps/web/screens/Grants/SearchResults/SearchResultsContent.tsx (4 hunks)
  • apps/web/screens/Grants/messages.ts (2 hunks)
  • apps/web/screens/Grants/utils.ts (1 hunks)
  • apps/web/screens/queries/Grants.ts (2 hunks)
  • libs/cms/src/lib/cms.elasticsearch.service.ts (1 hunks)
  • libs/cms/src/lib/models/grant.model.ts (3 hunks)
  • libs/cms/src/lib/search/importers/grants.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
apps/web/screens/Grants/SearchResults/SearchResultsContent.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/cms/src/lib/search/importers/grants.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."
apps/web/screens/queries/Grants.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/web/screens/Grants/Grant/GrantSidebar.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/web/screens/Grants/messages.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/web/screens/Grants/utils.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/cms/src/lib/cms.elasticsearch.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/cms/src/lib/models/grant.model.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 (8)
apps/web/screens/Grants/utils.ts (1)

17-24: Well-implemented date formatting function

The formatDate function correctly handles locale-specific date formatting using date-fns and adheres to best practices.

apps/web/screens/queries/Grants.ts (1)

20-20: GraphQL queries updated correctly

The modifications to GET_GRANTS_QUERY and GET_GRANT_QUERY appropriately reflect the data model changes, ensuring consistency.

Also applies to: 72-74

apps/web/screens/Grants/Grant/GrantSidebar.tsx (1)

37-41: Improved status handling using 'parseStatus'

Refactoring to use parseStatus enhances code clarity and ensures consistent status representation across the component.

Also applies to: 82-93

apps/web/screens/Grants/SearchResults/SearchResultsContent.tsx (1)

Line range hint 46-93: Updated status handling promotes consistency

The integration of parseStatus refines status management and aligns with the overall application architecture.

libs/cms/src/lib/search/importers/grants.service.ts (1)

113-114: LGTM: Status handling enhancement is well-structured

The new status cases are logically grouped and maintain the binary open/closed tagging system while providing more granular status information.

Also applies to: 122-124

apps/web/screens/Grants/messages.ts (2)

37-37: LGTM: Improved grammatical accuracy

The message has been updated from singular to plural form, which better reflects the context of multiple applications.


55-74: LGTM: Well-structured status messages

The new messages effectively support the enhanced status granularity while maintaining consistent formatting with {arg} placeholders.

libs/cms/src/lib/cms.elasticsearch.service.ts (1)

50-50: Verify impact of removing status filtering

The removal of status-based filtering from the Elasticsearch query suggests that status filtering has been moved to the application layer. Let's verify this change doesn't break existing functionality.

✅ Verification successful

Status filtering has been properly moved to the application layer

The verification confirms that status filtering has been successfully moved from the Elasticsearch service to the application layer:

  • Status parsing logic is centralized in apps/web/screens/Grants/utils.ts with the parseStatus function
  • Status filtering UI is implemented in SearchResultsFilter.tsx using the GrantStatus enum
  • Status display is handled consistently across components:
    • SearchResultsContent.tsx
    • GrantSidebar.tsx
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that status filtering logic exists in the application layer

# Check for status filtering implementation in application layer
rg -A 5 "parseStatus|filterByStatus" apps/web/screens/Grants/

# Check for any remaining direct status filtering
rg -A 5 "GrantStatus\." apps/web/screens/Grants/

Length of output: 6560

libs/cms/src/lib/models/grant.model.ts Outdated Show resolved Hide resolved
@datadog-island-is
Copy link

datadog-island-is bot commented Dec 4, 2024

Datadog Report

All test runs ec87436 🔗

98 Total Test Services: 0 Failed, 90 Passed
🔻 Test Sessions change in coverage: 6 decreased, 2 increased, 192 no change

Test Services
This report shows up to 10 services
Service Name Failed Known Flaky New Flaky Passed Skipped Total Time Code Coverage Change Test Service View
air-discount-scheme-backend 0 0 0 63 0 24.52s N/A Link
air-discount-scheme-web 0 0 0 2 0 8.45s N/A Link
api 0 0 0 4 0 3.08s N/A Link
api-catalogue-services 0 0 0 23 0 12.38s N/A Link
api-domains-air-discount-scheme 0 0 0 6 0 21.79s N/A Link
api-domains-assets 0 0 0 3 0 13.47s N/A Link
api-domains-auth-admin 0 0 0 18 0 14.56s 1 no change Link
api-domains-communications 0 0 0 5 0 38.18s N/A Link
api-domains-criminal-record 0 0 0 5 0 10.62s N/A Link
api-domains-driving-license 0 0 0 23 0 30.21s N/A Link

🔻 Code Coverage Decreases vs Default Branch (6)

This report shows up to 5 code coverage decreases.

  • services-university-gateway - jest 45.19% (-0.06%) - Details
  • judicial-system-backend - jest 59.48% (-0.04%) - Details
  • services-user-notification - jest 68.94% (-0.04%) - Details
  • services-auth-delegation-api - jest 50.43% (-0.04%) - Details
  • cms-translations - jest 48.17% (-0.04%) - 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 (3)
apps/web/screens/Grants/utils.ts (3)

17-24: Enhance type safety for date formatting

Consider improving type safety and maintainability:

 const formatDate = (
   date: Date,
   locale: Locale,
-  stringFormat = 'dd.MMMM yyyy',
+  stringFormat: 'dd.MMMM yyyy' | 'dd.MMMM.' | 'MMMM yyyy' = 'dd.MMMM yyyy',
 ) =>
   format(date, stringFormat, {
     locale: locale === 'is' ? localeIS : localeEn,
   })

106-118: Improve type safety for status tag variants

Consider defining proper types for the variants instead of using type assertions:

+type TagVariant = 'mint' | 'rose';
+
 export const generateStatusTag = (
   status: Status['applicationStatus'],
   formatMessage: FormatMessage,
-) =>
+): { label: string; variant: TagVariant } | undefined =>
   status !== 'unknown'
     ? {
         label:
           status === 'open'
             ? formatMessage(m.search.applicationOpen)
             : formatMessage(m.search.applicationClosed),
-        variant: status === 'open' ? ('mint' as const) : ('rose' as const),
+        variant: status === 'open' ? 'mint' : 'rose',
       }
     : undefined

1-118: Overall implementation follows NextJS and TypeScript best practices

The code demonstrates:

  • Strong typing with TypeScript
  • Modular and reusable utility functions
  • Clear separation of concerns
  • Proper error handling

Consider adding unit tests to verify the behavior of these utility functions, especially the edge cases in status parsing.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0f766cb and b9bdb0e.

⛔ Files ignored due to path filters (1)
  • libs/cms/src/lib/generated/contentfulTypes.d.ts is excluded by !**/generated/**
📒 Files selected for processing (2)
  • apps/web/screens/Grants/messages.ts (2 hunks)
  • apps/web/screens/Grants/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/screens/Grants/messages.ts
🧰 Additional context used
📓 Path-based instructions (1)
apps/web/screens/Grants/utils.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (1)
apps/web/screens/Grants/utils.ts (1)

11-15: Well-structured Status interface!

The interface follows TypeScript best practices with clear type definitions and optional properties.

apps/web/screens/Grants/utils.ts Outdated Show resolved Hide resolved
Copy link

codecov bot commented Dec 4, 2024

Codecov Report

Attention: Patch coverage is 10.93750% with 114 lines in your changes missing coverage. Please review.

Project coverage is 35.72%. Comparing base (de0bf4c) to head (36fa4fc).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
libs/cms/src/lib/models/grant.model.ts 22.58% 48 Missing ⚠️
apps/web/screens/Grants/utils.ts 0.00% 47 Missing ⚠️
apps/web/screens/Grants/Grant/GrantSidebar.tsx 0.00% 5 Missing ⚠️
...ibs/cms/src/lib/search/importers/grants.service.ts 0.00% 5 Missing ⚠️
apps/web/pages/en/grants-plaza/grant/[id].ts 0.00% 2 Missing ⚠️
apps/web/pages/en/grants-plaza/grants/index.ts 0.00% 2 Missing ⚠️
apps/web/pages/en/grants-plaza/index.ts 0.00% 2 Missing ⚠️
apps/web/screens/Grants/Home/GrantsHome.tsx 0.00% 2 Missing ⚠️
...eens/Grants/SearchResults/SearchResultsContent.tsx 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17127      +/-   ##
==========================================
- Coverage   35.76%   35.72%   -0.05%     
==========================================
  Files        6932     6935       +3     
  Lines      147984   148346     +362     
  Branches    42172    42381     +209     
==========================================
+ Hits        52931    52990      +59     
- Misses      95053    95356     +303     
Flag Coverage Δ
air-discount-scheme-backend 48.20% <ø> (ø)
air-discount-scheme-web 0.00% <ø> (ø)
api 3.33% <ø> (ø)
api-catalogue-services 75.81% <ø> (ø)
api-domains-air-discount-scheme 37.90% <ø> (ø)
api-domains-assets 26.71% <ø> (ø)
api-domains-auth-admin 48.49% <ø> (ø)
api-domains-communications 39.39% <20.89%> (-0.03%) ⬇️
api-domains-criminal-record 47.92% <ø> (ø)
api-domains-driving-license 44.81% <ø> (ø)
api-domains-education 31.22% <ø> (ø)
api-domains-health-insurance 35.33% <ø> (ø)
api-domains-mortgage-certificate 35.16% <ø> (ø)
api-domains-payment-schedule 42.04% <ø> (ø)
application-api-files 61.73% <ø> (ø)
application-core 76.01% <ø> (ø)
application-system-api 38.74% <20.89%> (+<0.01%) ⬆️
application-template-api-modules 27.82% <20.89%> (+0.01%) ⬆️
application-templates-accident-notification 28.83% <ø> (ø)
application-templates-car-recycling 3.12% <ø> (ø)
application-templates-criminal-record 25.78% <ø> (ø)
application-templates-driving-license 18.12% <ø> (ø)
application-templates-estate 13.79% <ø> (ø)
application-templates-example-payment 24.71% <ø> (ø)
application-templates-financial-aid 14.42% <ø> (ø)
application-templates-general-petition 23.13% <ø> (ø)
application-templates-inheritance-report 6.54% <ø> (ø)
application-templates-marriage-conditions 15.11% <ø> (ø)
application-templates-mortgage-certificate 43.60% <ø> (ø)
application-templates-parental-leave 29.95% <ø> (ø)
application-types 6.57% <ø> (ø)
application-ui-components 1.24% <ø> (ø)
application-ui-shell 22.47% <ø> (ø)
auth-admin-web 2.43% <ø> (ø)
auth-nest-tools 31.52% <ø> (ø)
auth-shared 75.00% <ø> (ø)
clients-charge-fjs-v2 28.35% <ø> (ø)
clients-driving-license 40.79% <ø> (ø)
clients-driving-license-book 43.83% <ø> (ø)
clients-financial-statements-inao 49.59% <ø> (ø)
clients-license-client 1.26% <ø> (ø)
clients-middlewares 73.21% <ø> (+0.08%) ⬆️
clients-regulations 42.87% <ø> (ø)
clients-rsk-company-registry 31.04% <ø> (ø)
clients-rsk-personal-tax-return 38.32% <ø> (ø)
clients-smartsolutions 12.77% <ø> (ø)
clients-syslumenn 49.41% <ø> (ø)
clients-zendesk 50.46% <ø> (ø)
cms 0.39% <0.00%> (-0.01%) ⬇️
cms-translations 38.72% <20.89%> (-0.03%) ⬇️
content-search-index-manager 95.65% <ø> (ø)
content-search-toolkit 8.16% <ø> (ø)
contentful-apps 4.72% <ø> (ø)
dokobit-signing 62.10% <ø> (ø)
email-service 60.07% <ø> (ø)
feature-flags 90.76% <ø> (ø)
file-storage 45.86% <ø> (ø)
financial-aid-backend 51.40% <ø> (ø)
financial-aid-shared 17.88% <ø> (ø)
icelandic-names-registry-backend 54.33% <ø> (ø)
infra-nest-server 48.06% <ø> (ø)
infra-tracing 69.63% <ø> (ø)
island-ui-core 30.92% <ø> (ø)
judicial-system-api 20.16% <ø> (ø)
judicial-system-audit-trail 68.94% <ø> (ø)
judicial-system-backend 55.83% <20.89%> (-0.04%) ⬇️
judicial-system-formatters 78.28% <ø> (ø)
judicial-system-message 66.47% <ø> (ø)
judicial-system-message-handler 48.23% <ø> (ø)
judicial-system-scheduler 70.97% <ø> (ø)
judicial-system-types 42.22% <ø> (ø)
judicial-system-web 27.89% <ø> (ø)
license-api 42.97% <ø> (ø)
localization 10.15% <ø> (ø)
logging 58.02% <ø> (ø)
message-queue 67.76% <ø> (ø)
nest-audit 65.78% <ø> (ø)
nest-aws 51.93% <ø> (ø)
nest-config 76.38% <ø> (ø)
nest-core 53.16% <ø> (ø)
nest-feature-flags 51.00% <ø> (ø)
nest-problem 45.64% <ø> (ø)
nest-sequelize 94.44% <ø> (ø)
nest-swagger 51.13% <ø> (ø)
nova-sms 61.42% <ø> (ø)
portals-admin-regulations-admin 1.80% <ø> (ø)
portals-core 19.83% <ø> (ø)
regulations 16.78% <ø> (ø)
residence-history 85.00% <ø> (ø)
services-auth-admin-api 52.55% <ø> (ø)
services-auth-delegation-api 58.44% <ø> (-0.09%) ⬇️
services-auth-ids-api 52.52% <ø> (-0.02%) ⬇️
services-auth-public-api 49.40% <ø> (ø)
services-sessions 65.30% <ø> (-0.05%) ⬇️
services-university-gateway 49.28% <ø> (-0.21%) ⬇️
services-user-notification 46.53% <20.89%> (-0.04%) ⬇️
services-user-profile 56.98% <ø> (ø)
shared-components 30.06% <ø> (ø)
shared-mocking 58.64% <ø> (ø)
shared-pii 92.85% <ø> (ø)
shared-problem 87.50% <ø> (ø)
shared-utils 27.69% <ø> (ø)
skilavottord-ws 24.31% <ø> (ø)
web 2.42% <0.00%> (-0.01%) ⬇️

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

Files with missing lines Coverage Δ
apps/web/screens/Grants/messages.ts 0.00% <ø> (ø)
apps/web/screens/queries/Grants.ts 0.00% <ø> (ø)
libs/cms/src/lib/cms.elasticsearch.service.ts 2.89% <ø> (+0.02%) ⬆️
...eens/Grants/SearchResults/SearchResultsContent.tsx 0.00% <0.00%> (ø)
apps/web/pages/en/grants-plaza/grant/[id].ts 0.00% <0.00%> (ø)
apps/web/pages/en/grants-plaza/grants/index.ts 0.00% <0.00%> (ø)
apps/web/pages/en/grants-plaza/index.ts 0.00% <0.00%> (ø)
apps/web/screens/Grants/Home/GrantsHome.tsx 0.00% <0.00%> (ø)
apps/web/screens/Grants/Grant/GrantSidebar.tsx 0.00% <0.00%> (ø)
...ibs/cms/src/lib/search/importers/grants.service.ts 10.60% <0.00%> (-0.34%) ⬇️
... and 2 more

... and 14 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 de0bf4c...36fa4fc. Read the comment docs.

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 (2)
apps/web/screens/Grants/utils.ts (1)

29-115: Consider enhancing date handling and status messages.

While the status parsing logic is comprehensive, consider these improvements:

  1. Add timezone handling for date comparisons
  2. Consider using date-fns's isAfter/isBefore for more readable date comparisons
  3. Add more descriptive status messages for edge cases
 export const parseStatus = (
   grant: Grant,
   formatMessage: FormatMessage,
   locale: Locale,
 ): Status => {
+  const now = new Date()
   switch (grant.status) {
     case GrantStatus.Closed: {
       return {
         applicationStatus: 'closed',
         deadlineStatus: grant.dateTo
           ? formatMessage(
-              containsTimePart(grant.dateTo)
+              isAfter(parseISO(grant.dateTo), startOfDay(now))
               ? m.search.applicationWasOpenToAndWith
               : m.search.applicationWasOpenTo,
libs/cms/src/lib/models/grant.model.ts (1)

175-184: Consider adding date validation and error handling.

The parseDate function could benefit from additional validation and error handling.

 const parseDate = (date?: string, time?: number): string | undefined => {
   if (!date) {
     return
   }
   const parsedDate = new Date(date)
+  if (isNaN(parsedDate.getTime())) {
+    return undefined
+  }
   if (!time) {
     return format(parsedDate, 'yyyy-MM-dd')
   }
+  if (time < 0 || time > 23) {
+    return undefined
+  }
   return addHours(new Date(date), time).toISOString()
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b9bdb0e and 1507cab.

📒 Files selected for processing (3)
  • apps/web/screens/Grants/messages.ts (2 hunks)
  • apps/web/screens/Grants/utils.ts (1 hunks)
  • libs/cms/src/lib/models/grant.model.ts (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/web/screens/Grants/utils.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/web/screens/Grants/messages.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
libs/cms/src/lib/models/grant.model.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 (4)
apps/web/screens/Grants/utils.ts (2)

12-25: LGTM! Well-structured interface and date formatting.

The Status interface clearly defines the possible states, and the formatDate function properly handles locale-specific date formatting using date-fns.


119-131: LGTM! Clean and type-safe status tag generation.

The function effectively maps application statuses to UI tags while maintaining type safety.

libs/cms/src/lib/models/grant.model.ts (2)

Line range hint 14-74: LGTM! Well-structured enum and class definition.

The GrantStatus enum and Grant class are well-organized with proper GraphQL decorators and type definitions.


123-126: ⚠️ Potential issue

Fix critical logical error in statusText assignment.

The current condition will always evaluate to a truthy value as it's comparing enum values directly instead of checking the current status.

 statusText:
-  GrantStatus.CLOSED_WITH_NOTE || GrantStatus.OPEN_WITH_NOTE
+  status === GrantStatus.CLOSED_WITH_NOTE || status === GrantStatus.OPEN_WITH_NOTE
     ? fields.grantStatusNote
     : undefined,

Likely invalid or redundant comment.

apps/web/screens/Grants/messages.ts Outdated Show resolved Hide resolved
@thorkellmani thorkellmani added the deploy-feature Deploys features to dev label Dec 5, 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 (3)
libs/cms/src/lib/models/grant.model.ts (3)

91-136: Consider adding error handling and simplifying nested operations

While the mapping logic is correct, consider these improvements:

  1. Add error handling for malformed input
  2. Simplify nested ternary operations using optional chaining

Consider this refactoring:

 export const mapGrant = ({ fields, sys }: IGrant): Grant => {
+  if (!fields || !sys?.id) {
+    throw new Error('Invalid grant data: missing required fields');
+  }
   return {
     id: sys.id,
     name: fields.grantName,
-    applicationUrl: fields.granApplicationUrl?.fields
-      ? mapReferenceLink(fields.granApplicationUrl)
-      : undefined,
+    applicationUrl: fields.granApplicationUrl?.fields && mapReferenceLink(fields.granApplicationUrl),
     // ... rest of the mapping
   }
 }

138-170: Enhance maintainability of status parsing logic

The status parsing logic could be improved in several ways:

  1. Extract magic strings into constants
  2. Extract repeated date parsing
  3. Add more descriptive comments explaining the business logic

Consider this refactoring:

+const GRANT_STATUS = {
+  AUTOMATIC: 'Automatic',
+  ALWAYS_OPEN: 'Always open',
+  CLOSED_WITH_NOTE: 'Closed with note',
+  OPEN_WITH_NOTE: 'Open with note',
+} as const;

+const parseGrantDates = (dateFrom?: string, dateTo?: string) => {
+  const parsedDateTo = new Date(dateTo ?? '');
+  const parsedDateFrom = new Date(dateFrom ?? '');
+  return { parsedDateTo, parsedDateFrom };
+};

 const parseStatus = (fields: IGrantFields): GrantStatus => {
   switch (fields.grantStatus) {
-    case 'Automatic': {
+    case GRANT_STATUS.AUTOMATIC: {
-      const parsedDateTo = new Date(fields.grantDateTo ?? '')
-      const parsedDateFrom = new Date(fields.grantDateFrom ?? '')
+      const { parsedDateTo, parsedDateFrom } = parseGrantDates(
+        fields.grantDateFrom,
+        fields.grantDateTo
+      );
       // ... rest of the function
     }
   }
 }

172-181: Improve date parsing robustness

The date parsing function could be enhanced with:

  1. Input validation using isValidDate
  2. Explicit time parameter typing
  3. Configurable date format

Consider this refactoring:

-const parseDate = (date?: string, time?: number): string | undefined => {
+const DEFAULT_DATE_FORMAT = 'yyyy-MM-dd';
+
+const parseDate = (
+  date?: string,
+  time?: number,
+  format: string = DEFAULT_DATE_FORMAT
+): string | undefined => {
   if (!date) {
     return;
   }
   const parsedDate = new Date(date);
+  if (!isValidDate(parsedDate)) {
+    return;
+  }
   if (!time) {
-    return format(parsedDate, 'yyyy-MM-dd');
+    return format(parsedDate, format);
   }
   return addHours(new Date(date), time).toISOString();
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1507cab and 9ec4527.

📒 Files selected for processing (3)
  • apps/web/screens/Grants/messages.ts (2 hunks)
  • apps/web/screens/Grants/utils.ts (1 hunks)
  • libs/cms/src/lib/models/grant.model.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/web/screens/Grants/utils.ts
  • apps/web/screens/Grants/messages.ts
🧰 Additional context used
📓 Path-based instructions (1)
libs/cms/src/lib/models/grant.model.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 (3)
libs/cms/src/lib/models/grant.model.ts (3)

3-3: LGTM! Well-structured enum expansion

The new GrantStatus values provide a comprehensive set of states that clearly represent different grant scenarios. The additional date-related imports support the new date parsing functionality.

Also applies to: 10-12, 16-23


72-74: LGTM! Well-typed field addition

The statusText field is properly typed and decorated for GraphQL integration, following TypeScript best practices.


Line range hint 1-181: Confirms compliance with coding guidelines

The implementation adheres to the coding guidelines for libs/**/*:

  • ✅ Reusable components with clear separation of concerns
  • ✅ Strong TypeScript typing with proper decorators and interfaces
  • ✅ Clean exports enabling effective tree-shaking

Copy link
Contributor

github-actions bot commented Dec 5, 2024

Affected services are: air-discount-scheme-api,api,application-system-api,judicial-system-api,judicial-system-backend,services-search-indexer,services-user-notification,web,
Feature deployment of your services will begin shortly. Your feature will be accessible here:
https://featupdated-stats-logic-api-catalogue.dev01.devland.is/api
https://featupdated-stats-logic-application-callback-xrd.internal.dev01.devland.is/application-payment
https://featupdated-stats-logic-application-callback-xrd.internal.dev01.devland.is/applications
https://featupdated-stats-logic-application-payment-callback-xrd.internal.dev01.devland.is/application-payment
https://featupdated-stats-logic-application-payment-callback-xrd.internal.dev01.devland.is/applications
https://featupdated-stats-logic-beta.dev01.devland.is/
https://featupdated-stats-logic-beta.dev01.devland.is/api
https://featupdated-stats-logic-beta.dev01.devland.is/bff
https://featupdated-stats-logic-beta.dev01.devland.is/samradsgatt
https://featupdated-stats-logic-beta.dev01.devland.is/stjornbord/bff
https://featupdated-stats-logic-loftbru-cf.dev01.devland.is/
https://featupdated-stats-logic-loftbru-cf.dev01.devland.is/api/graphql
https://featupdated-stats-logic-loftbru.dev01.devland.is/
https://featupdated-stats-logic-loftbru.dev01.devland.is/api/graphql

Deployed services: application-system-api,api,web,air-discount-scheme-api,application-system-api-worker,consultation-portal,services-bff-portals-admin,services-bff-portals-my-pages,air-discount-scheme-web.
Excluded services: search-indexer-service,user-notification,user-notification-worker,user-notification-cleanup-worker

@thorkellmani thorkellmani added deprecated:automerge (Disabled) Merge this PR as soon as all checks pass and removed deploy-feature Deploys features to dev labels Dec 10, 2024
@thorkellmani thorkellmani removed the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Dec 10, 2024
@thorkellmani thorkellmani added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Dec 11, 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: 2

🧹 Outside diff range and nitpick comments (3)
apps/web/pages/en/grants-plaza/grant/[id].ts (1)

5-8: Remove redundant comment line.

There's an extra empty comment line that should be removed.

 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
 // @ts-ignore make web strict
-//
 const Screen = withApollo(withLocale('en')(GrantSinglePage))
apps/web/screens/Grants/utils.ts (2)

29-117: Consider extracting common status patterns

The status object construction follows similar patterns across different cases. Consider extracting common logic to reduce duplication.

const createStatusObject = (
  applicationStatus: Status['applicationStatus'],
  deadlineStatus: string,
  note?: string
): Status => ({
  applicationStatus,
  deadlineStatus,
  note: note ?? undefined,
});

const getDeadlineStatus = (
  grant: Grant,
  formatMessage: IntlShape['formatMessage'],
  locale: Locale,
  messageKey: keyof typeof m.search,
  dateFormat?: string
) => {
  return grant.dateTo
    ? formatMessage(messageKey, {
        arg: formatDate(new Date(grant.dateTo), locale, dateFormat),
      })
    : formatMessage(m.search.applicationClosed);
};

119-131: Extract status variants as constants

Consider extracting the tag variants and labels into named constants for better maintainability.

+const STATUS_VARIANTS = {
+  open: 'mint' as const,
+  closed: 'rose' as const,
+} as const;

 export const generateStatusTag = (
   status: Status['applicationStatus'],
   formatMessage: IntlShape['formatMessage'],
 ) =>
   status !== 'unknown'
     ? {
         label:
           status === 'open'
             ? formatMessage(m.search.applicationOpen)
             : formatMessage(m.search.applicationClosed),
-        variant: status === 'open' ? ('mint' as const) : ('rose' as const),
+        variant: STATUS_VARIANTS[status === 'open' ? 'open' : 'closed'],
       }
     : undefined
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9ec4527 and 3301830.

📒 Files selected for processing (6)
  • apps/web/pages/en/grants-plaza/grant/[id].ts (1 hunks)
  • apps/web/pages/en/grants-plaza/grants/index.ts (1 hunks)
  • apps/web/pages/en/grants-plaza/index.ts (1 hunks)
  • apps/web/screens/Grants/Grant/GrantSidebar.tsx (4 hunks)
  • apps/web/screens/Grants/Home/GrantsHome.tsx (1 hunks)
  • apps/web/screens/Grants/utils.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/screens/Grants/Grant/GrantSidebar.tsx
🧰 Additional context used
📓 Path-based instructions (5)
apps/web/pages/en/grants-plaza/index.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/web/pages/en/grants-plaza/grant/[id].ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/web/pages/en/grants-plaza/grants/index.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/web/screens/Grants/Home/GrantsHome.tsx (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
apps/web/screens/Grants/utils.ts (1)

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

  • NextJS best practices, including file structure, API routes, and static generation methods.
  • Efficient state management and server-side rendering techniques.
  • Optimal use of TypeScript for component and utility type safety."
🔇 Additional comments (6)
apps/web/pages/en/grants-plaza/index.ts (1)

1-4: Consider implementing static generation where possible.

While server-side rendering is valid, for better performance consider:

  1. Using getStaticProps if the data doesn't need to be real-time
  2. Implementing incremental static regeneration (ISR) for dynamic data that doesn't change frequently

Let's check if other grant pages use SSR consistently:

Also applies to: 7-12

✅ Verification successful

Let me check if the grants data is dynamic by examining the GraphQL queries and data fetching patterns.


Let me check one final thing - the actual GraphQL query to understand the data requirements.


Server-side rendering is appropriate for this grants plaza implementation

Based on the codebase analysis:

  • All grant pages consistently use server-side rendering via getServerSidePropsWrapper
  • The pages appear to handle dynamic data through Apollo Client queries
  • The grant details and search results are likely to require real-time data for:
    • Up-to-date grant availability
    • Latest grant details and requirements
    • Real-time search functionality

While static generation could be considered for some content, the current SSR implementation is justified given the dynamic nature of grants data.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check SSR/SSG usage patterns across grant pages
rg -A 3 "getServerSideProps|getStaticProps" "apps/web/pages/en/grants-plaza/"

Length of output: 1567


Script:

#!/bin/bash
# Check GraphQL queries and data fetching in grants components
ast-grep --pattern 'useQuery($$$)' apps/web/screens/Grants/
rg -A 5 "query |mutation " apps/web/screens/Grants/

Length of output: 2304


Script:

#!/bin/bash
# Find the GraphQL query definitions
rg -A 10 "GET_GRANT_QUERY = gql|GET_GRANTS_QUERY = gql" apps/web/screens/Grants/

Length of output: 82

apps/web/pages/en/grants-plaza/grant/[id].ts (1)

1-12: 🛠️ Refactor suggestion

Consider extracting common HOC pattern.

The HOC composition pattern is duplicated across multiple files. Consider creating a shared utility:

// utils/withPageWrapper.ts
export const withPageWrapper = (Component: React.ComponentType) => 
  withApollo(withLocale('en')(Component))

// Usage in this file:
const Screen = withPageWrapper(GrantSinglePage)

Additionally, consider implementing error boundaries for the dynamic [id] route to handle invalid grant IDs gracefully.

Let's check for error handling patterns:

apps/web/pages/en/grants-plaza/grants/index.ts (2)

5-7: Remove redundant comment line.

Similar to the grant/[id].ts file, there's an extra empty comment line that should be removed.


1-12: Consider implementing client-side search optimization.

For search results pages, consider implementing:

  1. Client-side state management (e.g., React Query, SWR) for better user experience
  2. Debounced search with loading states
  3. URL-based search parameters for better SEO and sharing

The current implementation could be enhanced with proper loading states and error handling:

Let's check the search implementation:

apps/web/screens/Grants/utils.ts (1)

12-16: Well-designed type-safe interface!

The Status interface provides a clear contract for grant status representation with appropriate type constraints.

apps/web/screens/Grants/Home/GrantsHome.tsx (1)

45-47: LGTM! Clean variable extraction

The extraction of formatMessage from the intl object follows React best practices and improves code organization.

apps/web/pages/en/grants-plaza/index.ts Show resolved Hide resolved
apps/web/screens/Grants/utils.ts Show resolved Hide resolved
@kodiakhq kodiakhq bot removed the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Dec 12, 2024
Copy link
Contributor

kodiakhq bot commented Dec 12, 2024

This PR currently has a merge conflict. Please resolve this and then re-add the automerge label.

@thorkellmani thorkellmani added the deprecated:automerge (Disabled) Merge this PR as soon as all checks pass label Dec 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecated:automerge (Disabled) Merge this PR as soon as all checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants