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(documents): Sort by publication v1 and v2 by default #17157

Merged
merged 3 commits into from
Dec 6, 2024

Conversation

thordurhhh
Copy link
Member

@thordurhhh thordurhhh commented Dec 6, 2024

What

Sort by publication in documents v1 and v2 by default

Why

After client config update in october, Publication has been added. UI already sorts by publication, so the service should sort by publication by default.

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

@thordurhhh thordurhhh added the automerge Merge this PR as soon as all checks pass label Dec 6, 2024
@thordurhhh thordurhhh requested a review from a team as a code owner December 6, 2024 11:06
Copy link
Contributor

coderabbitai bot commented Dec 6, 2024

Walkthrough

The pull request introduces updates to the sorting capabilities of document-related input types across several files. The sortBy field in the GetDocumentListInput class and related types is modified to include a new option, Publication. Additionally, the default sorting behavior in the DocumentsInput class is changed to Publication. These changes affect how documents are sorted when no specific criteria are provided, enhancing the sorting options available in the document management system.

Changes

File Change Summary
libs/api/domains/documents/src/lib/dto/getDocumentListInput.ts Updated GetDocumentListInput class to include Publication in sortBy options.
libs/api/domains/documents/src/lib/models/v2/documents.input.ts Added Publication to DocumentPageSort enum and changed default sortBy in DocumentsInput from Date to Publication.
libs/clients/documents-v2/src/lib/dto/listDocuments.input.ts Modified ListDocumentsInputDto to include Publication in sortBy options.
libs/clients/documents/src/lib/documentClient.ts Changed default sorting in getDocumentList method from Date to Publication.
libs/clients/documents/src/lib/models/DocumentInput.ts Updated GetDocumentListInput type to include Publication in sortBy options.

Possibly related PRs

  • chore(documents-v2): Catch error and log warning #16207: The changes in this PR involve modifications to the DocumentServiceV2 class, which may relate to the overall document handling and sorting mechanisms, but do not directly affect the sortBy field or the GetDocumentListInput class as described in the main PR.

Suggested reviewers

  • svanaeinars
  • disaerna

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/clients/documents/src/lib/models/DocumentInput.ts (1)

8-8: Add JSDoc comment to document the new sort option.

The addition of 'Publication' sort option is correct, but it would be helpful to add documentation explaining what this sort option represents and when it was introduced.

+  /** Sort options for document list. 'Publication' sorts by document publication date (added in Oct 2024) */
   sortBy?: 'Date' | 'Category' | 'Type' | 'Subject' | 'Sender' | 'Publication'
libs/clients/documents-v2/src/lib/dto/listDocuments.input.ts (1)

11-11: Maintain documentation consistency with v1 client.

Add the same JSDoc documentation as in the v1 client to maintain consistency across versions.

+  /** Sort options for document list. 'Publication' sorts by document publication date (added in Oct 2024) */
   sortBy?: 'Date' | 'Category' | 'Type' | 'Sender' | 'Subject' | 'Publication'
libs/api/domains/documents/src/lib/dto/getDocumentListInput.ts (1)

24-24: Enhance GraphQL field documentation and validation.

Consider these improvements for the GraphQL field:

  1. Add description to the @field decorator
  2. Consider using an enum for better type safety and GraphQL schema documentation
+  /** Sort options for the document list */
+  @Field(() => DocumentSortBy, { 
+    nullable: true,
+    description: 'Determines the sort order of documents. Publication sorts by document publication date.'
+  })
   sortBy?: 'Date' | 'Category' | 'Type' | 'Subject' | 'Sender' | 'Publication'

Consider creating an enum:

export enum DocumentSortBy {
  Date = 'Date',
  Category = 'Category',
  Type = 'Type',
  Subject = 'Subject',
  Sender = 'Sender',
  Publication = 'Publication'
}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dfc8bec and e7148f2.

📒 Files selected for processing (5)
  • libs/api/domains/documents/src/lib/dto/getDocumentListInput.ts (1 hunks)
  • libs/api/domains/documents/src/lib/models/v2/documents.input.ts (2 hunks)
  • libs/clients/documents-v2/src/lib/dto/listDocuments.input.ts (1 hunks)
  • libs/clients/documents/src/lib/documentClient.ts (1 hunks)
  • libs/clients/documents/src/lib/models/DocumentInput.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
libs/clients/documents/src/lib/documentClient.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/documents-v2/src/lib/dto/listDocuments.input.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/documents/src/lib/models/DocumentInput.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/documents/src/lib/models/v2/documents.input.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/documents/src/lib/dto/getDocumentListInput.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/api/domains/documents/src/lib/dto/getDocumentListInput.ts (1)

24-24: Verify completeness of sort option updates.

The 'Publication' sort option has been consistently added across the codebase. Let's verify no other files need this update.

✅ Verification successful

'Publication' sort option is consistently implemented

All files containing sort options have been updated to include the 'Publication' option:

  • libs/clients/documents/src/lib/models/DocumentInput.ts
  • libs/clients/documents-v2/src/lib/dto/listDocuments.input.ts
  • libs/api/domains/documents/src/lib/dto/getDocumentListInput.ts
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other files that might need the sort option update
rg -t typescript "sortBy.*('Date'|'Category'|'Type'|'Subject'|'Sender')" --glob '!**/test/**'

Length of output: 160


Script:

#!/bin/bash
# Search for files containing sort options, using a more general pattern
rg "sortBy.*['\"](?:Date|Category|Type|Subject|Sender)" -g "*.ts" -g "!**/test/**" -g "!**/node_modules/**"

Length of output: 527

libs/api/domains/documents/src/lib/models/v2/documents.input.ts (1)

20-21: LGTM! Clear documentation for the Publication sort option.

The added comment effectively explains that Publication represents the document publication date and is now the default sorting option.

libs/clients/documents/src/lib/documentClient.ts (1)

136-136: Verify backward compatibility with existing clients.

While the change to default to 'Publication' aligns with the requirements, we should ensure existing clients are prepared for this change.

Let's verify the impact:

✅ Verification successful

Change to default sort order is safe to proceed

Based on the codebase analysis:

  1. No direct dependencies were found relying on the default 'Date' sorting
  2. All clients using getDocumentList pass their sort parameters explicitly or accept the default
  3. The only reference to 'Publication' sorting is in the changed code itself
  4. No test cases were found that assume a specific default sort order

The change appears to be an implementation detail that won't impact existing clients since:

  • Clients that need specific sorting already specify it explicitly
  • The default is only used when no sort parameter is provided
  • The API contract remains unchanged as both sort options are valid values
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for clients that might be affected by the sort change

# Look for direct API calls that might expect Date sorting
rg -A 3 "messages\?" --type ts

# Look for tests that might need updating
rg -l "sortBy.*Date.*test" --type ts

Length of output: 3694


Script:

#!/bin/bash
# Let's search for any usage of the DocumentClient's getDocumentList method
# and references to sortBy parameter to understand the impact

# Search for getDocumentList usage
rg -A 5 "getDocumentList" --type ts

# Search for DocumentSortBy enum usage
rg -A 2 "DocumentSortBy\." --type ts

# Search for test files that might be affected
fd "document.*test" -e ts -x cat {}

Length of output: 8448


Script:

#!/bin/bash
# Let's check for any references to the old default sort value and the new one

# Search for any references to sortBy=Date in tests or implementation
rg -A 2 "sortBy.*=.*Date" --type ts

# Search for any references to sortBy=Publication in tests or implementation
rg -A 2 "sortBy.*=.*Publication" --type ts

# Search for the DocumentSortBy enum definition to understand the available options
rg -A 5 "enum DocumentSortBy" --type ts

Length of output: 814

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 35.73%. Comparing base (202d2b1) to head (5dfffe4).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #17157      +/-   ##
==========================================
- Coverage   35.73%   35.73%   -0.01%     
==========================================
  Files        6926     6926              
  Lines      147678   147673       -5     
  Branches    42063    42060       -3     
==========================================
- Hits        52775    52772       -3     
+ Misses      94903    94901       -2     
Flag Coverage Δ
api 3.33% <ø> (ø)
judicial-system-api 19.98% <ø> (ø)
judicial-system-backend 55.72% <ø> (ø)

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

Files with missing lines Coverage Δ
libs/clients/documents/src/lib/documentClient.ts 13.63% <ø> (+0.15%) ⬆️

... and 3 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 202d2b1...5dfffe4. Read the comment docs.

@datadog-island-is
Copy link

datadog-island-is bot commented Dec 6, 2024

Datadog Report

All test runs 6fb2e61 🔗

4 Total Test Services: 0 Failed, 3 Passed
➡️ Test Sessions change in coverage: 7 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.84s 1 no change Link
download-service 0 0 0 0 0 490.97ms 1 no change Link
judicial-system-api 0 0 0 61 0 6.77s 1 no change Link
judicial-system-backend 0 0 0 21306 0 25m 5.86s 1 no change Link

Copy link
Member

@thorkellmani thorkellmani left a comment

Choose a reason for hiding this comment

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

LGTM

@kodiakhq kodiakhq bot merged commit c4685ef into main Dec 6, 2024
45 checks passed
@kodiakhq kodiakhq bot deleted the documents/sortby-publication branch December 6, 2024 12:34
thorhildurt pushed a commit that referenced this pull request Dec 11, 2024
* Sort by publication v1 and v2 by default

* Remove logg

---------

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