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: sort transactions better #470

Merged

Conversation

UnderKoen
Copy link
Member

@UnderKoen UnderKoen commented Oct 1, 2024

I noticed that the transaction that were synced were really out of order of how they happend. This should fix this by also sorting on time

@actual-github-bot actual-github-bot bot changed the title feat: sort transactions better [WIP] feat: sort transactions better Oct 1, 2024
Copy link
Contributor

coderabbitai bot commented Oct 1, 2024

Walkthrough

The changes include the addition of new test cases for the sortByBookingDateOrValueDate function to enhance its coverage, specifically addressing sorting by valueDate and handling multiple date fields. A new function compareDates is introduced in the utils.js file to facilitate date comparisons, and the existing sorting function is modified to utilize this new comparison mechanism. The method signature of sortByBookingDateOrValueDate has been updated, and the compareDates method has been added.

Changes

Files Change Summary
src/app-gocardless/tests/utils.spec.js Added new test cases for sortByBookingDateOrValueDate to cover sorting by valueDate and multiple fields. Retained existing tests for bookingDate.
src/app-gocardless/utils.js Introduced compareDates function for date comparisons and modified sortByBookingDateOrValueDate to use new comparison functions. Updated method signature.

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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@UnderKoen UnderKoen changed the title [WIP] feat: sort transactions better feat: sort transactions better Oct 1, 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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0757f9d and 95b7bd4.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/470.md is excluded by !**/*.md
📒 Files selected for processing (2)
  • src/app-gocardless/tests/utils.spec.js (1 hunks)
  • src/app-gocardless/utils.js (1 hunks)
🔇 Additional comments (4)
src/app-gocardless/utils.js (2)

19-27: compareFunctions array is correctly structured for sequential date comparisons

The array compareFunctions is well-defined, allowing the sorting mechanism to compare multiple date fields in sequence. This approach ensures that if one date field is equal or unavailable, the next available date field is used for comparison, enhancing the robustness and accuracy of the sorting process.


30-38: Confirm the argument order in sortFunction(b, a) to ensure correct sorting order

In the sortByBookingDateOrValueDate function, the comparator calls sortFunction(b, a) instead of sortFunction(a, b). Swapping the arguments reverses the comparison result, which will sort the transactions in descending order (newest first). Please verify that this ordering aligns with the intended sorting behavior.

If the goal is to sort transactions from newest to oldest, then the current implementation is correct. Otherwise, consider changing the call to sortFunction(a, b) to sort in ascending order.

src/app-gocardless/tests/utils.spec.js (2)

37-66: Test case correctly verifies sorting by valueDate when bookingDate is missing

The test case 'should sort by valueDate if bookingDate is missing' appropriately checks that transactions are sorted from newest to oldest based on the valueDate field when the bookingDate is unavailable.


115-160: Clarify the purpose of discrepancies between bookingDate and valueDateTime

In the test case 'should sort on booking date if value date is widely off', some transactions have valueDateTime values that are significantly different from their bookingDate. For instance:

  • At lines 128-131, a transaction has:
    • bookingDate: '2023-01-30'
    • valueDateTime: '2023-01-01T12:00:00Z'

This could either be intentional to simulate scenarios where valueDateTime is not aligned with bookingDate, or it might be an oversight.

Please verify if this discrepancy is intentional. If it is meant to test the sorting behavior when valueDateTime deviates significantly from bookingDate, consider adding comments to explain the scenario. Ensuring clarity will help maintainers and future contributors understand the purpose of the test.

src/app-gocardless/utils.js Outdated Show resolved Hide resolved
src/app-gocardless/tests/utils.spec.js Outdated Show resolved Hide resolved
Copy link
Contributor

@matt-fidd matt-fidd left a comment

Choose a reason for hiding this comment

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

Thank you for this, I like the idea. I think there is a consideration to be made regarding the performance hit, but I did some testing and it doesn't seem to cause a pronounced slowdown even with a full 90 days of data.

@matt-fidd matt-fidd merged commit 49c5adc into actualbudget:master Oct 23, 2024
8 checks passed
@UnderKoen UnderKoen deleted the feat/sort-transactions-better branch October 23, 2024 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants