Skip to content

Conversation

matt-fidd
Copy link
Member

related to #3660

@actual-github-bot actual-github-bot bot changed the title show all occurrences of upcoming schedules within the upcoming period [WIP] show all occurrences of upcoming schedules within the upcoming period Jan 16, 2025
Copy link

netlify bot commented Jan 16, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit ad142cc
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67892f91d696b500088acb0d
😎 Deploy Preview https://deploy-preview-4166.demo.actualbudget.org
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Contributor

github-actions bot commented Jan 16, 2025

Bundle Stats — desktop-client

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
13 6.02 MB → 6.43 MB (+420.88 kB) +6.83%
Changeset (largest 100 files by percent change)
File Δ Size
node_modules/@rschedule/core/es2015/generators.js 🆕 +65.66 kB 0 B → 65.66 kB
node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js 🆕 +46.5 kB 0 B → 46.5 kB
node_modules/source-map/lib/source-map-consumer.js 🆕 +40.81 kB 0 B → 40.81 kB
node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js 🆕 +35.1 kB 0 B → 35.1 kB
node_modules/@rschedule/core/es2015/rules.js 🆕 +33.61 kB 0 B → 33.61 kB
node_modules/@rschedule/core/es2015/main.js 🆕 +29.87 kB 0 B → 29.87 kB
node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js 🆕 +15.47 kB 0 B → 15.47 kB
node_modules/source-map/lib/source-map-generator.js 🆕 +14.59 kB 0 B → 14.59 kB
node_modules/source-map/lib/source-node.js 🆕 +14.01 kB 0 B → 14.01 kB
node_modules/source-map/lib/util.js 🆕 +13.63 kB 0 B → 13.63 kB
node_modules/handlebars/dist/cjs/handlebars/runtime.js 🆕 +12.6 kB 0 B → 12.6 kB
home/runner/work/actual/actual/packages/loot-core/src/server/accounts/rules.ts 🆕 +11.84 kB 0 B → 11.84 kB
node_modules/handlebars/dist/cjs/handlebars/compiler/whitespace-control.js 🆕 +6.72 kB 0 B → 6.72 kB
node_modules/handlebars/dist/cjs/handlebars/compiler/helpers.js 🆕 +5.25 kB 0 B → 5.25 kB
node_modules/source-map/lib/base64-vlq.js 🆕 +4.87 kB 0 B → 4.87 kB
node_modules/source-map/lib/binary-search.js 🆕 +4.56 kB 0 B → 4.56 kB
node_modules/@rschedule/standard-date-adapter/es2015/main.js 🆕 +4.42 kB 0 B → 4.42 kB
node_modules/handlebars/dist/cjs/handlebars/compiler/code-gen.js 🆕 +4.3 kB 0 B → 4.3 kB
node_modules/handlebars/dist/cjs/handlebars/compiler/visitor.js 🆕 +3.83 kB 0 B → 3.83 kB
node_modules/source-map/lib/quick-sort.js 🆕 +3.78 kB 0 B → 3.78 kB
node_modules/source-map/lib/array-set.js 🆕 +3.37 kB 0 B → 3.37 kB
node_modules/handlebars/dist/cjs/handlebars/base.js 🆕 +3.16 kB 0 B → 3.16 kB
node_modules/handlebars/dist/cjs/handlebars/utils.js 🆕 +2.9 kB 0 B → 2.9 kB
node_modules/handlebars/dist/cjs/handlebars/helpers/each.js 🆕 +2.89 kB 0 B → 2.89 kB
node_modules/handlebars/dist/cjs/handlebars/internal/proto-access.js 🆕 +2.69 kB 0 B → 2.69 kB
node_modules/source-map/lib/mapping-list.js 🆕 +2.51 kB 0 B → 2.51 kB
node_modules/handlebars/dist/cjs/handlebars.runtime.js 🆕 +2.03 kB 0 B → 2.03 kB
node_modules/handlebars/dist/cjs/handlebars.js 🆕 +1.98 kB 0 B → 1.98 kB
node_modules/handlebars/dist/cjs/handlebars/exception.js 🆕 +1.77 kB 0 B → 1.77 kB
node_modules/source-map/lib/base64.js 🆕 +1.68 kB 0 B → 1.68 kB
node_modules/handlebars/dist/cjs/handlebars/helpers.js 🆕 +1.55 kB 0 B → 1.55 kB
node_modules/handlebars/dist/cjs/handlebars/helpers/if.js 🆕 +1.53 kB 0 B → 1.53 kB
node_modules/handlebars/dist/cjs/handlebars/compiler/base.js 🆕 +1.51 kB 0 B → 1.51 kB
node_modules/handlebars/dist/cjs/handlebars/logger.js 🆕 +1.28 kB 0 B → 1.28 kB
node_modules/handlebars/dist/cjs/handlebars/helpers/with.js 🆕 +1.19 kB 0 B → 1.19 kB
node_modules/handlebars/dist/cjs/handlebars/compiler/ast.js 🆕 +1.11 kB 0 B → 1.11 kB
node_modules/handlebars/dist/cjs/handlebars/helpers/block-helper-missing.js 🆕 +1.11 kB 0 B → 1.11 kB
node_modules/date-fns/esm/previousDay/index.js 🆕 +898 B 0 B → 898 B
node_modules/handlebars/dist/cjs/handlebars/no-conflict.js 🆕 +864 B 0 B → 864 B
node_modules/date-fns/esm/nextDay/index.js 🆕 +857 B 0 B → 857 B
node_modules/handlebars/dist/cjs/handlebars/helpers/helper-missing.js 🆕 +849 B 0 B → 849 B
node_modules/handlebars/dist/cjs/handlebars/decorators/inline.js 🆕 +813 B 0 B → 813 B
node_modules/handlebars/dist/cjs/handlebars/helpers/log.js 🆕 +722 B 0 B → 722 B
node_modules/handlebars/dist/cjs/handlebars/internal/create-new-lookup-object.js 🆕 +692 B 0 B → 692 B
node_modules/handlebars/dist/cjs/handlebars/internal/wrapHelper.js 🆕 +637 B 0 B → 637 B
node_modules/date-fns/esm/isWeekend/index.js 🆕 +591 B 0 B → 591 B
node_modules/date-fns/esm/getDay/index.js 🆕 +587 B 0 B → 587 B
node_modules/date-fns/esm/previousFriday/index.js 🆕 +558 B 0 B → 558 B
node_modules/source-map/source-map.js 🆕 +536 B 0 B → 536 B
node_modules/date-fns/esm/nextMonday/index.js 🆕 +524 B 0 B → 524 B
node_modules/handlebars/dist/cjs/handlebars/helpers/lookup.js 🆕 +437 B 0 B → 437 B
node_modules/handlebars/dist/cjs/handlebars/decorators.js 🆕 +424 B 0 B → 424 B
node_modules/handlebars/dist/cjs/handlebars/safe-string.js 🆕 +384 B 0 B → 384 B
home/runner/work/actual/actual/packages/loot-core/src/server/errors.ts 🆕 +134 B 0 B → 134 B
node_modules/@rschedule/standard-date-adapter/es2015/setup.js 🆕 +83 B 0 B → 83 B
node_modules/handlebars/dist/cjs/handlebars.runtime.js?commonjs-module 🆕 +39 B 0 B → 39 B
node_modules/handlebars/dist/cjs/handlebars/helpers/block-helper-missing.js?commonjs-module 🆕 +39 B 0 B → 39 B
node_modules/handlebars/dist/cjs/handlebars/compiler/javascript-compiler.js?commonjs-module 🆕 +39 B 0 B → 39 B
node_modules/handlebars/dist/cjs/handlebars/compiler/whitespace-control.js?commonjs-module 🆕 +38 B 0 B → 38 B
node_modules/handlebars/dist/cjs/handlebars/helpers/helper-missing.js?commonjs-module 🆕 +34 B 0 B → 34 B
node_modules/handlebars/dist/cjs/handlebars/internal/create-new-lookup-object.js?commonjs-exports 🆕 +33 B 0 B → 33 B
node_modules/handlebars/dist/cjs/handlebars.js?commonjs-module 🆕 +31 B 0 B → 31 B
node_modules/handlebars/dist/cjs/handlebars/safe-string.js?commonjs-module 🆕 +31 B 0 B → 31 B
node_modules/handlebars/dist/cjs/handlebars/no-conflict.js?commonjs-module 🆕 +31 B 0 B → 31 B
node_modules/handlebars/dist/cjs/handlebars/exception.js?commonjs-module 🆕 +30 B 0 B → 30 B
node_modules/handlebars/dist/cjs/handlebars/compiler/visitor.js?commonjs-module 🆕 +28 B 0 B → 28 B
node_modules/handlebars/dist/cjs/handlebars/compiler/code-gen.js?commonjs-module 🆕 +28 B 0 B → 28 B
node_modules/source-map/lib/source-map-generator.js?commonjs-exports 🆕 +28 B 0 B → 28 B
node_modules/handlebars/dist/cjs/handlebars/helpers/lookup.js?commonjs-module 🆕 +27 B 0 B → 27 B
node_modules/handlebars/dist/cjs/handlebars/decorators/inline.js?commonjs-module 🆕 +27 B 0 B → 27 B
node_modules/handlebars/dist/cjs/handlebars/logger.js?commonjs-module 🆕 +27 B 0 B → 27 B
node_modules/handlebars/dist/cjs/handlebars/compiler/parser.js?commonjs-module 🆕 +27 B 0 B → 27 B
node_modules/source-map/lib/source-map-consumer.js?commonjs-exports 🆕 +27 B 0 B → 27 B
node_modules/handlebars/dist/cjs/handlebars/helpers/log.js?commonjs-module 🆕 +26 B 0 B → 26 B
node_modules/handlebars/dist/cjs/handlebars/helpers/with.js?commonjs-module 🆕 +26 B 0 B → 26 B
node_modules/handlebars/dist/cjs/handlebars/helpers/each.js?commonjs-module 🆕 +25 B 0 B → 25 B
node_modules/handlebars/dist/cjs/handlebars/helpers/if.js?commonjs-module 🆕 +24 B 0 B → 24 B
node_modules/handlebars/dist/cjs/handlebars/compiler/ast.js?commonjs-module 🆕 +24 B 0 B → 24 B
node_modules/handlebars/dist/cjs/handlebars/internal/wrapHelper.js?commonjs-exports 🆕 +22 B 0 B → 22 B
node_modules/source-map/lib/binary-search.js?commonjs-exports 🆕 +22 B 0 B → 22 B
node_modules/handlebars/dist/cjs/handlebars/internal/proto-access.js?commonjs-exports 🆕 +21 B 0 B → 21 B
node_modules/source-map/lib/mapping-list.js?commonjs-exports 🆕 +21 B 0 B → 21 B
node_modules/handlebars/dist/cjs/handlebars/decorators.js?commonjs-exports 🆕 +20 B 0 B → 20 B
node_modules/handlebars/dist/cjs/handlebars/compiler/compiler.js?commonjs-exports 🆕 +20 B 0 B → 20 B
node_modules/source-map/lib/source-node.js?commonjs-exports 🆕 +20 B 0 B → 20 B
node_modules/handlebars/dist/cjs/handlebars/helpers.js?commonjs-exports 🆕 +19 B 0 B → 19 B
node_modules/source-map/source-map.js?commonjs-exports 🆕 +19 B 0 B → 19 B
node_modules/source-map/lib/base64-vlq.js?commonjs-exports 🆕 +19 B 0 B → 19 B
node_modules/source-map/lib/quick-sort.js?commonjs-exports 🆕 +19 B 0 B → 19 B
node_modules/source-map/lib/array-set.js?commonjs-exports 🆕 +18 B 0 B → 18 B
node_modules/handlebars/dist/cjs/handlebars/runtime.js?commonjs-exports 🆕 +17 B 0 B → 17 B
node_modules/handlebars/dist/cjs/handlebars/compiler/helpers.js?commonjs-exports 🆕 +17 B 0 B → 17 B
node_modules/handlebars/dist/cjs/handlebars/base.js?commonjs-exports 🆕 +16 B 0 B → 16 B
node_modules/handlebars/dist/cjs/handlebars/compiler/base.js?commonjs-exports 🆕 +16 B 0 B → 16 B
node_modules/source-map/lib/base64.js?commonjs-exports 🆕 +16 B 0 B → 16 B
node_modules/handlebars/dist/cjs/handlebars/utils.js?commonjs-exports 🆕 +15 B 0 B → 15 B
node_modules/source-map/lib/util.js?commonjs-exports 🆕 +14 B 0 B → 14 B
home/runner/work/actual/actual/packages/loot-core/src/shared/schedules.ts 📈 +2.59 kB (+49.02%) 5.29 kB → 7.88 kB
home/runner/work/actual/actual/packages/loot-core/src/client/data-hooks/transactions.ts 📈 +1 kB (+21.59%) 4.63 kB → 5.63 kB
home/runner/work/actual/actual/packages/loot-core/src/shared/rules.ts 📈 +233 B (+2.92%) 7.81 kB → 8.03 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/index.js 3.78 MB → 4.19 MB (+420.88 kB) +10.88%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/workbox-window.prod.es5.js 5.69 kB 0%
static/js/AppliedFilters.js 10.21 kB 0%
static/js/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/BackgroundImage.js 122.29 kB 0%
static/js/resize-observer.js 18.37 kB 0%
static/js/indexeddb-main-thread-worker-e59fee74.js 13.5 kB 0%
static/js/en.js 96.91 kB 0%
static/js/uk.js 120.47 kB 0%
static/js/wide.js 100.98 kB 0%
static/js/narrow.js 84.3 kB 0%
static/js/en-GB.js 96.9 kB 0%
static/js/ReportRouter.js 1.59 MB 0%

Copy link
Contributor

github-actions bot commented Jan 16, 2025

Bundle Stats — loot-core

Hey there, this message comes from a GitHub action that helps you and reviewers to understand how these changes affect the size of this project's bundle.

As this PR is updated, I'll keep you updated on how the bundle size is impacted.

Total

Files count Total bundle size % Changed
1 1.33 MB 0%
Changeset
File Δ Size
packages/loot-core/src/shared/schedules.ts 📈 +1.51 kB (+16.18%) 9.35 kB → 10.87 kB
packages/loot-core/src/server/schedules/app.ts 📉 -1.38 kB (-8.07%) 17.11 kB → 15.73 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

No assets were bigger

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
kcab.worker.js 1.33 MB 0%

@matt-fidd
Copy link
Member Author

/update-vrt

@matt-fidd matt-fidd changed the title [WIP] show all occurrences of upcoming schedules within the upcoming period show all occurrences of upcoming schedules within the upcoming period Jan 16, 2025
Copy link
Contributor

coderabbitai bot commented Jan 16, 2025

Walkthrough

The pull request introduces enhancements to transaction handling and scheduling across multiple files in the Actual app. The changes primarily focus on improving the representation of transaction statuses by adding a new property, forceUpcoming, to the transaction object. This modification affects the rendering logic in the TransactionsTable.jsx component, which now utilizes previewStatus for displaying transaction categories. Additionally, the backend logic in transactions.ts has been updated to support a more dynamic calculation of scheduled transactions, including a new state variable, upcomingLength, to track upcoming scheduled transactions. The getNextDate and getDateWithSkippedWeekend functions have been introduced in schedules.ts to enhance date calculations, further refining the management of scheduled transactions. The changes also include the restructuring of import statements and minor updates to other components without altering their core functionality.

Possibly related PRs

Suggested labels

sparkles: Merged

Suggested reviewers

  • youngcw

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba15ac8 and ad142cc.

📒 Files selected for processing (1)
  • packages/desktop-client/src/components/schedules/UpcomingLength.tsx (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/desktop-client/src/components/schedules/UpcomingLength.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Wait for Netlify build to finish
  • GitHub Check: Analyze

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.

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.

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: 5

🧹 Nitpick comments (6)
packages/loot-core/src/client/data-hooks/transactions.ts (2)

148-149: Ensure default value for upcomingLength when user preference is unavailable

When upcomingLength is null or undefined, the parseInt function defaults to '7', but it's safer to set a default value upfront to prevent unexpected behavior.

Initialize upcomingLength with a default value using the nullish coalescing operator:

 const [upcomingLength] = useSyncedPref('upcomingScheduledTransactionLength');
+const upcomingLengthValue = upcomingLength ?? '7';

And then use upcomingLengthValue in subsequent code.


3-4: Organize imports for better readability and maintainability

There's an opportunity to group related imports together and remove any unused imports to enhance code clarity.

Consider organizing the imports as follows:

 import { useEffect, useRef, useState, useMemo, useCallback } from 'react';
 import debounce from 'lodash/debounce';

 import { send } from '../../platform/client/fetch';
 import { type Query } from '../../shared/query';
+import { useSyncedPref } from '@actual-app/web/src/hooks/useSyncedPref';
+import * as d from 'date-fns';
+import { currentDay, addDays, parseDate } from '../../shared/months';
+import {
+  getScheduledAmount,
+  extractScheduleConds,
+  getNextDate,
+} from '../../shared/schedules';

This groups external library imports separately from internal modules.

Also applies to: 8-14

packages/loot-core/src/shared/schedules.ts (2)

314-327: Validate solveMode in getDateWithSkippedWeekend to prevent errors

The function assumes that solveMode is either 'after' or 'before', but if an invalid value is passed, it throws a generic error.

Add validation for solveMode and provide a clearer error message:

 export function getDateWithSkippedWeekend(
   date: Date,
   solveMode: 'after' | 'before',
 ) {
+  if (solveMode !== 'after' && solveMode !== 'before') {
+    throw new Error(`Invalid solveMode '${solveMode}'. Expected 'after' or 'before'.`);
+  }

   if (d.isWeekend(date)) {
     if (solveMode === 'after') {
       return d.nextMonday(date);
     } else {
       return d.previousFriday(date);
     }
   }
   return date;
 }

319-322: Simplify the logic in getDateWithSkippedWeekend

The if-else structure can be simplified for better readability.

Refactor the code:

   if (solveMode === 'after') {
     return d.nextMonday(date);
-  } else if (solveMode === 'before') {
+  }
+  // solveMode === 'before'
   return d.previousFriday(date);

Since the invalid solveMode case is already handled, an else clause is not necessary.

packages/desktop-client/src/components/transactions/TransactionsTable.jsx (2)

1033-1035: Consider using early returns for clearer status precedence.

The current logic could be more explicit about status precedence. Consider refactoring to:

-  let previewStatus = categoryId;
-  if (upcoming) previewStatus = 'upcoming';
+  let previewStatus;
+  if (upcoming) {
+    previewStatus = 'upcoming';
+  } else {
+    previewStatus = categoryId;
+  }

1611-1613: Simplify nested ternary operators for better readability.

The status determination logic using nested ternary operators is hard to read. Consider refactoring to:

-  status={
-    isPreview
-      ? upcoming === true
-        ? 'upcoming'
-        : categoryId
-      : reconciled
-        ? 'reconciled'
-        : cleared
-          ? 'cleared'
-          : null
-  }
+  status={(() => {
+    if (isPreview) {
+      return upcoming ? 'upcoming' : categoryId;
+    }
+    if (reconciled) {
+      return 'reconciled';
+    }
+    if (cleared) {
+      return 'cleared';
+    }
+    return null;
+  })()}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b9eaeaf and bbb90a8.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4166.md is excluded by !**/*.md
📒 Files selected for processing (6)
  • packages/desktop-client/src/components/transactions/TransactionsTable.jsx (4 hunks)
  • packages/loot-core/src/client/data-hooks/transactions.ts (3 hunks)
  • packages/loot-core/src/server/budget/goalsSchedule.ts (1 hunks)
  • packages/loot-core/src/server/schedules/app.test.ts (1 hunks)
  • packages/loot-core/src/server/schedules/app.ts (1 hunks)
  • packages/loot-core/src/shared/schedules.ts (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/loot-core/src/server/budget/goalsSchedule.ts
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: Functional
  • GitHub Check: Visual regression
  • GitHub Check: Analyze
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (6)
packages/loot-core/src/server/schedules/app.test.ts (2)

5-5: Ensure consistent usage of getNextDate across the codebase

By importing getNextDate from '../../shared/schedules', the test now uses the shared implementation, promoting consistency. Ensure that the shared getNextDate function behaves as expected in the test context.

Run the tests to confirm that getNextDate works correctly with the shared implementation.


Line range hint 75-80: Update test cases to reflect changes in getNextDate behavior

Since getNextDate is now imported from a shared module, there may be differences in its behavior. Verify that the test cases still accurately test the intended functionality.

Ensure that the test inputs and expected outputs are still valid with the new getNextDate function.

packages/loot-core/src/shared/schedules.ts (2)

285-287: Ensure correct handling of condition values in getNextDate

When creating a new Condition instance, verify that the condition value is valid and handle any potential errors.

Add error checking to confirm that cond.getValue() returns a valid value.


300-308: Account for possible empty dates array in getNextDate

If no dates are found after attempting to get occurrences, dates may still be empty, leading to a null return. Ensure this is the intended behavior or handle it appropriately.

Consider providing a default date or logging a warning if no dates are found.

packages/loot-core/src/server/schedules/app.ts (1)

16-17: LGTM! Good refactoring of date utilities.

Moving date-related utility functions to a shared module improves code reusability and maintainability.

packages/desktop-client/src/components/transactions/TransactionsTable.jsx (1)

1028-1032: LGTM! Clean addition of the upcoming property.

The upcoming property is properly integrated into the transaction object destructuring.

youngcw
youngcw previously approved these changes Jan 16, 2025
@matt-fidd
Copy link
Member Author

@youngcw sorry, small variable naming change

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)
packages/loot-core/src/client/data-hooks/transactions.ts (2)

3-3: Consider moving shared hooks to a common package.

The import from @actual-app/web crosses package boundaries. Consider moving shared hooks to a common package to maintain better architectural boundaries and prevent tight coupling between packages.


165-209: Consider memoizing date parsing operations.

The implementation correctly handles schedule generation and date calculations. However, parseDate is called multiple times within the loop and sort comparator. Consider memoizing parsed dates to optimize performance, especially for large schedules.

        const dates: Set<string> = new Set();
+       const parsedDates = new Map<string, Date>();
+       const getOrParseDateMemo = (date: string) => {
+         let parsed = parsedDates.get(date);
+         if (!parsed) {
+           parsed = parseDate(date);
+           parsedDates.set(date, parsed);
+         }
+         return parsed;
+       };
        while (day <= upcomingPeriodEnd) {
          const nextDate = getNextDate(dateConditions, day);
-         day = parseDate(addDays(nextDate, 1));
+         day = getOrParseDateMemo(addDays(nextDate, 1));

          if (dates.has(nextDate)) break;
-         if (parseDate(nextDate) > upcomingPeriodEnd) break;
+         if (getOrParseDateMemo(nextDate) > upcomingPeriodEnd) break;

          dates.add(nextDate);
        }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbb90a8 and ba15ac8.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/transactions/TransactionsTable.jsx (4 hunks)
  • packages/loot-core/src/client/data-hooks/transactions.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/transactions/TransactionsTable.jsx
🧰 Additional context used
📓 Learnings (1)
packages/loot-core/src/client/data-hooks/transactions.ts (3)
Learnt from: matt-fidd
PR: actualbudget/actual#4166
File: packages/loot-core/src/client/data-hooks/transactions.ts:155-158
Timestamp: 2025-01-16T14:30:36.518Z
Learning: In packages/loot-core/src/client/data-hooks/transactions.ts, the `upcomingLength` preference is always stored as a number in string format, so no additional type checking is needed when using `parseInt`.
Learnt from: matt-fidd
PR: actualbudget/actual#4166
File: packages/loot-core/src/client/data-hooks/transactions.ts:200-200
Timestamp: 2025-01-16T14:29:13.188Z
Learning: In the scheduled transactions implementation within `packages/loot-core/src/client/data-hooks/transactions.ts`, the `upcoming` flag is set based on `schedules.length > 0` to act as an override, where the first occurrence gets `false` and subsequent occurrences get `true`. This is intentional and should not be changed to date-based comparison.
Learnt from: matt-fidd
PR: actualbudget/actual#4166
File: packages/loot-core/src/client/data-hooks/transactions.ts:173-181
Timestamp: 2025-01-16T14:29:03.337Z
Learning: The `getNextDate` function in `packages/loot-core/src/shared/schedules.ts` is designed to always return a date value, either directly from the condition value or after processing schedule occurrences. It does not return null.
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: Analyze
  • GitHub Check: Wait for Netlify build to finish
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (2)
packages/loot-core/src/client/data-hooks/transactions.ts (2)

148-158: LGTM! Clean implementation of the upcoming period calculation.

The implementation correctly uses the synced preference for upcomingLength and properly calculates the upcoming period end date.


258-258: LGTM! Dependencies are correctly specified.

The effect dependencies are properly updated to include upcomingLength, ensuring the effect runs when the preference changes.

@youngcw
Copy link
Member

youngcw commented Jan 16, 2025

This should probable pull in the other change first before merging to check all is still good.

So far all is good other than this still includes the message about only one instance

Copy link
Member

@youngcw youngcw left a comment

Choose a reason for hiding this comment

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

This all seems good. We may want to have an option to only show the next instance, especially if the schedule is daily. That can be for another time though. Maybe that would be per schedule even.

@matt-fidd matt-fidd merged commit 6655f51 into actualbudget:master Jan 16, 2025
20 checks passed
@matt-fidd matt-fidd deleted the upcoming/all-schedules branch January 16, 2025 17:04
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