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(web): add missing sorting and modify organization filter #17936

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

thorkellmani
Copy link
Member

@thorkellmani thorkellmani commented Feb 12, 2025

What

  • Implement sorting for grant card list slice
  • Change orkustofnun to umhverfisstofnun

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
    • Enhanced grant listings with flexible sorting options allowing you to view grants ordered either by their most recent update or alphabetically.
    • Updated the organization filter in grant search results by replacing an outdated option with a refined alternative, improving your filtering experience.

@thorkellmani thorkellmani requested review from a team as code owners February 12, 2025 13:04
Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request introduces a new sorting mechanism in the grant cards list component. The grants are sorted either by the most recently updated timestamp or alphabetically based on a new GrantCardsListSorting import. The implementation uses a non-mutative approach by initializing a new array with spread syntax. Additionally, the grant model has been updated with a new lastUpdateTimestamp field, and the organization filter in the search results component has been updated by replacing one filter option with another.

Changes

Files Change Summary
apps/web/components/GrantCardsList/GrantCardsList.tsx
libs/cms/src/lib/models/grant.model.ts
Introduced a new sorting mechanism using a new import (GrantCardsListSorting) and updated the grant model by adding a non-nullable lastUpdateTimestamp field; sorting logic now orders grants by update time or name.
apps/web/screens/Grants/SearchResults/SearchResultsFilter.tsx Modified the organization filter: replaced 'Orkustofnun' with 'Umhverfis- og orkustofnun' in the FilterMultiChoice component.

Sequence Diagram(s)

sequenceDiagram
    participant GC as GrantCardsList Component
    participant DT as Grant Data
    GC->>DT: Initialize grantItems using spread operator
    GC->>GC: Check if multiple grant items exist
    alt Sorting is MostRecentlyUpdatedFirst
        GC->>DT: Sort grantItems by lastUpdateTimestamp (ascending)
    else Sorting is Alphabetical
        GC->>DT: Sort grantItems by name (alphabetically)
    end
    GC->>GC: Map sorted grantItems to cards for display
Loading

Possibly related PRs

Suggested labels

automerge, high priority

Suggested reviewers

  • disaerna
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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. (Beta)
  • @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: 0

🧹 Nitpick comments (2)
apps/web/screens/Grants/SearchResults/SearchResultsFilter.tsx (1)

136-146: Consider making organization filter options configurable.

The organization filter options are currently hardcoded. Consider moving these to a configuration file or fetching them from an API to improve maintainability and make future organization changes easier to manage.

-                filters: [
-                  {
-                    value: 'rannis',
-                    label: 'Rannís',
-                  },
-                  {
-                    value: 'umhverfisstofnun',
-                    label: 'Umhverfis- og orkustofnun',
-                  },
-                ],
+                filters: ORGANIZATION_FILTERS, // Import from a config file
apps/web/components/GrantCardsList/GrantCardsList.tsx (1)

169-173: Consider simplifying the date comparison.

The timestamp comparison can be simplified by directly comparing the ISO strings, as they are in a format that allows lexicographical comparison.

-      grantItems.sort(
-        (a, b) =>
-          new Date(a.lastUpdateTimestamp).getTime() -
-          new Date(b.lastUpdateTimestamp).getTime(),
-      )
+      grantItems.sort((a, b) => 
+        a.lastUpdateTimestamp.localeCompare(b.lastUpdateTimestamp)
+      )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 19972e3 and c3deac3.

📒 Files selected for processing (3)
  • apps/web/components/GrantCardsList/GrantCardsList.tsx (3 hunks)
  • apps/web/screens/Grants/SearchResults/SearchResultsFilter.tsx (1 hunks)
  • libs/cms/src/lib/models/grant.model.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`apps/**/*`: "Confirm that the code adheres to the following...

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/SearchResults/SearchResultsFilter.tsx
  • apps/web/components/GrantCardsList/GrantCardsList.tsx
`libs/**/*`: "Confirm that the code adheres to the following...

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
🔇 Additional comments (2)
libs/cms/src/lib/models/grant.model.ts (1)

38-39: LGTM! Well-implemented timestamp field.

The implementation of lastUpdateTimestamp is robust:

  • Proper GraphQL field decoration
  • Non-nullable field type
  • Fallback to creation timestamp using nullish coalescing

Also applies to: 154-154

apps/web/components/GrantCardsList/GrantCardsList.tsx (1)

126-127: LGTM! Clean implementation of sorting functionality.

The implementation is well-structured:

  • Creates a new array to avoid mutations
  • Applies sorting only when needed (multiple items)
  • Clear and readable sorting logic

Also applies to: 167-177

Copy link

nx-cloud bot commented Feb 12, 2025

View your CI Pipeline Execution ↗ for commit c3deac3.

Command Status Duration Result
nx run-many --projects judicial-system-backend ... ✅ Succeeded 22m 37s View ↗
nx run-many --target=build --projects=web --par... ✅ Succeeded 16m 37s View ↗
nx run-many --projects application-system-api -... ✅ Succeeded 14m 29s View ↗
nx run-many --projects application-api-history,... ✅ Succeeded 7m 51s View ↗
nx run-many --target=build --projects=api --par... ✅ Succeeded 3m 36s View ↗
nx run-many --projects cms,cms-translations --t... ✅ Succeeded 1m 44s View ↗
nx run-many --target=build --projects=applicati... ✅ Succeeded 2m 55s View ↗
nx run-many --projects web --target test --para... ✅ Succeeded 15s View ↗
Additional runs (13) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-02-12 13:48:24 UTC

@thorkellmani thorkellmani added this pull request to the merge queue Feb 12, 2025
Merged via the queue into main with commit 83d7060 Feb 12, 2025
55 checks passed
@thorkellmani thorkellmani deleted the fix/missing-sorting branch February 12, 2025 14:13
thoreyjona pushed a commit that referenced this pull request Feb 21, 2025
fix: add missing sorting and modify organization filter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants