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

Add YTD and last year to Reports headers #4019

Merged
merged 19 commits into from
Jan 17, 2025

Conversation

rodriguestiago0
Copy link
Contributor

@rodriguestiago0 rodriguestiago0 commented Dec 21, 2024

Add "Year to date" and "Last year" to header report

image

@actual-github-bot actual-github-bot bot changed the title Add YTD and last year to Reports headers [WIP] Add YTD and last year to Reports headers Dec 21, 2024
Copy link

netlify bot commented Dec 21, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit e6b49ac
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/67882bf6ac39ef000806a6b6
😎 Deploy Preview https://deploy-preview-4019.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 Dec 21, 2024

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.03 MB (+1.9 kB) +0.03%
Changeset
File Δ Size
src/components/reports/Header.tsx 📈 +817 B (+16.70%) 4.78 kB → 5.57 kB
src/components/reports/reportRanges.ts 📈 +284 B (+6.79%) 4.08 kB → 4.36 kB
src/components/reports/reports/NetWorth.tsx 📈 +240 B (+3.74%) 6.26 kB → 6.5 kB
src/components/reports/reports/CashFlow.tsx 📈 +240 B (+2.62%) 8.96 kB → 9.19 kB
src/components/reports/reports/Summary.tsx 📈 +240 B (+1.51%) 15.53 kB → 15.76 kB
src/components/reports/reports/Calendar.tsx 📈 +122 B (+0.46%) 26.07 kB → 26.19 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
static/js/ReportRouter.js 1.59 MB → 1.59 MB (+1.9 kB) +0.12%

Smaller

No assets were smaller

Unchanged

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

Copy link
Contributor

github-actions bot commented Dec 21, 2024

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

No files were changed

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%

@youngcw
Copy link
Member

youngcw commented Dec 21, 2024

The end date selector doesn't get a date added in when using the new buttons. That will need fixed.

@rodriguestiago0
Copy link
Contributor Author

The end date selector doesn't get a date added in when using the new buttons. That will need fixed.

Done

@rodriguestiago0 rodriguestiago0 changed the title [WIP] Add YTD and last year to Reports headers Add YTD and last year to Reports headers Dec 22, 2024
Copy link
Contributor

coderabbitai bot commented Dec 22, 2024

Walkthrough

The pull request introduces enhancements to date range management across multiple report components in the desktop client. The changes primarily focus on adding two new time frame modes: 'lastYear' and 'yearToDate' to the TimeFrame type. Components such as Calendar, CashFlow, NetWorth, and Summary now include new state variables earliestTransaction and firstDayOfWeekIdx. The Header component is updated to accept these new props, enabling more flexible date range selection. Additionally, the calculateTimeRange function in reportRanges.ts is expanded to handle the new time frame modes, calculating start and end dates for last year and year-to-date scenarios.

Possibly related PRs

  • Fix issue with Monthly Spending report not properly averaging previous three months #3723: The changes in the main PR regarding the Header component's handling of date-related functionalities and props are related to the updates made in the Calendar component, which also involves the earliestTransaction prop and its integration into the Header.
  • Summary report #3792: The introduction of new props in the Header component to manage date ranges and preferences aligns with the enhancements made in the Summary component, which also deals with date-related functionalities and user interactions.
  • Calendar Report #3828: The addition of the firstDayOfWeekIdx prop in the Header component is relevant to the new CalendarCard component, which utilizes this prop for rendering calendar-related data.

Suggested labels

:sparkles: Merged

Suggested reviewers

  • joel-jeremy
  • MikesGlitch

📜 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 18dc0fe and e6b49ac.

⛔ Files ignored due to path filters (6)
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-3-chromium-linux.png is excluded by !**/*.png
📒 Files selected for processing (1)
  • packages/desktop-client/src/components/reports/reports/Calendar.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/reports/reports/Calendar.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build (macos-latest)
  • GitHub Check: Analyze
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: Wait for Netlify build to finish

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

🧹 Nitpick comments (3)
packages/desktop-client/src/components/reports/Header.tsx (1)

34-35: Props type declarations need documentation.

The newly added props lack TypeScript documentation explaining their purpose and expected format.

Add JSDoc comments to document the props:

 type HeaderProps = {
+  /** ISO date string of the earliest transaction in the system */
   earliestTransaction: string;
+  /** Index of the first day of the week (0-6, where 0 is Sunday) */
   firstDayOfWeekIdx?: SyncedPrefs['firstDayOfWeekIdx'];
packages/desktop-client/src/components/reports/reports/NetWorth.tsx (1)

166-168: Remove unused state setter and improve variable naming.

  1. The state setter _ is unused and can be removed
  2. The variable name _firstDayOfWeekIdx is unclear

Apply these improvements:

-const [earliestTransaction, _] = useState('');
+const [earliestTransaction] = useState('');
-const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
-const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';
+const [syncedFirstDayOfWeek] = useSyncedPref('firstDayOfWeekIdx');
+const firstDayOfWeekIdx = syncedFirstDayOfWeek || '0';
packages/desktop-client/src/components/reports/reports/Calendar.tsx (1)

Line range hint 151-153: Consider creating a custom hook for transaction date management

The pattern of managing earliestTransaction and firstDayOfWeekIdx is repeated across components. Consider extracting this logic into a custom hook for better code reuse.

Example implementation:

// hooks/useTransactionDateManagement.ts
export function useTransactionDateManagement() {
  const [earliestTransaction, setEarliestTransaction] = useState('');
  const [_firstDayOfWeekIdx] = useSyncedPref('firstDayOfWeekIdx');
  const firstDayOfWeekIdx = _firstDayOfWeekIdx || '0';

  useEffect(() => {
    async function fetchEarliestTransaction() {
      try {
        const trans = await send('get-earliest-transaction');
        if (trans) {
          setEarliestTransaction(trans.date);
        }
      } catch (error) {
        console.error('Error fetching earliest transaction:', error);
      }
    }
    fetchEarliestTransaction();
  }, []);

  return { earliestTransaction, firstDayOfWeekIdx };
}

Also applies to: 463-464

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6cfb9d2 and 121d09b.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4019.md is excluded by !**/*.md
📒 Files selected for processing (5)
  • packages/desktop-client/src/components/reports/Header.tsx (6 hunks)
  • packages/desktop-client/src/components/reports/reports/Calendar.tsx (2 hunks)
  • packages/desktop-client/src/components/reports/reports/CashFlow.tsx (3 hunks)
  • packages/desktop-client/src/components/reports/reports/NetWorth.tsx (3 hunks)
  • packages/desktop-client/src/components/reports/reports/Summary.tsx (3 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/reports/reports/Summary.tsx (1)
Learnt from: lelemm
PR: actualbudget/actual#3792
File: packages/desktop-client/src/components/reports/reports/Summary.tsx:134-161
Timestamp: 2024-11-12T19:52:52.889Z
Learning: In `packages/desktop-client/src/components/reports/reports/Summary.tsx`, API calls like `get-earliest-transaction` are used without explicit error handling to maintain consistency with other components.
🔇 Additional comments (5)
packages/desktop-client/src/components/reports/Header.tsx (1)

173-206: Verify error handling in the new date range buttons.

The implementation assumes getLiveRange always returns valid dates, but there's no error handling if it fails.

Also, consider adding error boundaries to handle potential failures gracefully.

Add error handling:

 <Button
   variant="bare"
   onPress={() =>
-    onChangeDates(
-      ...convertToMonth(
-        ...getLiveRange(
-          'Year to date',
-          earliestTransaction,
-          true,
-          firstDayOfWeekIdx,
-        ),
-      ),
-    )
+    try {
+      const range = getLiveRange(
+        'Year to date',
+        earliestTransaction,
+        true,
+        firstDayOfWeekIdx,
+      );
+      onChangeDates(...convertToMonth(...range));
+    } catch (error) {
+      console.error('Failed to get date range:', error);
+      // Handle error appropriately
+    }
   }
 >
packages/desktop-client/src/components/reports/reports/CashFlow.tsx (2)

191-193: Same issues as in NetWorth component.

The implementation has the same issues regarding unused state setter and unclear variable naming.

Please apply the same improvements suggested for the NetWorth component:

  1. Remove unused state setter
  2. Improve variable naming clarity

232-233: 🛠️ Refactor suggestion

Consider initializing earliestTransaction.

The earliestTransaction is passed to Header while being initialized as an empty string, which might cause issues with the new date range buttons.

Consider initializing it with a proper value:

-const [earliestTransaction, _] = useState('');
+const [earliestTransaction] = useState(() => {
+  // Initialize with current date or fetch from API
+  return new Date().toISOString().split('T')[0];
+});
packages/desktop-client/src/components/reports/reports/Summary.tsx (1)

281-282: LGTM: Props correctly passed to Header component

The new props earliestTransaction and firstDayOfWeekIdx are properly passed to the Header component.

packages/desktop-client/src/components/reports/reports/Calendar.tsx (1)

497-498: LGTM: Props correctly passed to Header component

The new props earliestTransaction and firstDayOfWeekIdx are properly passed to the Header component, maintaining consistency with other components.

@youngcw
Copy link
Member

youngcw commented Dec 22, 2024

/update-vrt

@rodriguestiago0
Copy link
Contributor Author

/update-vrt

@rodriguestiago0
Copy link
Contributor Author

/update-vrt

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

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 121d09b and 9891c7d.

⛔ Files ignored due to path filters (6)
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-cash-flow-graph-and-checks-visuals-3-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-1-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-2-chromium-linux.png is excluded by !**/*.png
  • packages/desktop-client/e2e/reports.test.js-snapshots/Reports-loads-net-worth-graph-and-checks-visuals-3-chromium-linux.png is excluded by !**/*.png
📒 Files selected for processing (2)
  • packages/desktop-client/src/components/reports/Header.tsx (6 hunks)
  • packages/desktop-client/src/components/reports/reports/NetWorth.tsx (3 hunks)
🔇 Additional comments (6)
packages/desktop-client/src/components/reports/Header.tsx (4)

9-9: LGTM! Import statements are correctly added.

The new imports for SyncedPrefs type and getLiveRange function are necessary for implementing the YTD and last year functionality.

Also applies to: 19-19


34-35: LGTM! Props are well-typed and properly defined.

The new props earliestTransaction and optional firstDayOfWeekIdx are correctly typed and follow TypeScript best practices.


72-78: Consider adding input validation to convertToMonth.

The function assumes valid date strings but doesn't handle invalid inputs.


173-206: LGTM! New buttons are well-implemented.

The "Year to date" and "Last year" buttons are properly implemented with:

  • Consistent styling using the "bare" variant
  • Proper internationalization using the translation function
  • Correct prop passing for date calculations

However, let's verify the date calculations are working as expected.

Run this script to verify the getLiveRange implementation:

✅ Verification successful

✓ Date calculations are correctly implemented

The getLiveRange implementation properly handles both "Year to date" and "Last year" calculations:

  • YTD: Correctly spans from the start of current year to today
  • Last year: Properly covers the full previous year (Jan 1st to Dec 31st)
  • Both respect the earliest transaction date constraint
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify getLiveRange implementation for YTD and last year calculations

# Search for getLiveRange implementation and its tests
ast-grep --pattern 'function getLiveRange($_) {
  $$$
}'

# Search for related test cases
rg -A 5 'test.*getLiveRange|describe.*getLiveRange'

Length of output: 112


Script:

#!/bin/bash
# Try different patterns to find getLiveRange implementation
ast-grep --pattern 'const getLiveRange = $_'
ast-grep --pattern 'export const getLiveRange = $_'
ast-grep --pattern 'export function getLiveRange($_)'

# Search for files that might contain the implementation
fd -t f -e ts -e tsx getLiveRange

# Broader text-based search
rg -l "getLiveRange"

# Search for date-related utility files that might contain the implementation
fd -t f "date" -e ts -e tsx

Length of output: 7233


Script:

#!/bin/bash
# Get the implementation
cat packages/desktop-client/src/components/reports/getLiveRange.ts

# Check usage patterns in other files
rg -A 3 "getLiveRange\(" packages/desktop-client/src/components/reports/reports/CustomReport.tsx packages/desktop-client/src/components/reports/GetCardData.tsx packages/desktop-client/src/components/reports/ReportSidebar.tsx

Length of output: 2983

packages/desktop-client/src/components/reports/reports/NetWorth.tsx (2)

18-18: LGTM! Import statement is correctly added.

The import for useSyncedPref hook follows project conventions.


205-206: LGTM! Props are correctly passed to Header component.

The new props earliestTransaction and firstDayOfWeekIdx are properly passed with their respective state values.

@youngcw
Copy link
Member

youngcw commented Jan 10, 2025

Can you add a dummy commit to get the checks to run?

@youngcw
Copy link
Member

youngcw commented Jan 10, 2025

When I save a "last year" range in the reports, the range doesn't get saved right. The months in the start/end selection boxes are correct, but get shifted when going back to the reports dashboard and when viewing the report again after.

image
This is after choosing "last year" and saving and going back to the dashboard. In the report, after choosing the "last year" option the range is correct and shows Jan-2024 - Dec-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: 3

♻️ Duplicate comments (1)
packages/desktop-client/src/components/reports/reports/Summary.tsx (1)

151-153: 🛠️ Refactor suggestion

Initialize earliestTransaction state with data from useEffect.

The earliestTransaction state is initialized but never updated, despite having an effect that fetches the earliest transaction.

- const [earliestTransaction, _] = useState('');
+ const [earliestTransaction, setEarliestTransaction] = useState('');

  useEffect(() => {
    async function run() {
      const trans = await send('get-earliest-transaction');
+     if (trans) {
+       setEarliestTransaction(trans.date);
+     }
      // ... rest of the effect
    }
    run();
  }, []);
🧹 Nitpick comments (2)
packages/desktop-client/src/components/reports/Header.tsx (1)

72-79: Remove unused parameter from convertToMonth.

The function has an unused parameter _ which is redundant as the mode parameter serves the same purpose.

 function convertToMonth(
   start: string,
   end: string,
-  _: TimeFrame['mode'],
   mode: TimeFrame['mode'],
 ): [string, string, TimeFrame['mode']] {
   return [monthUtils.getMonth(start), monthUtils.getMonth(end), mode];
 }
packages/desktop-client/src/components/reports/ReportSidebar.tsx (1)

Line range hint 379-391: Consider adding validation for date range options.

The menu items for date range options could benefit from additional validation to ensure proper handling of the "Year to date" and "Last year" ranges.

Consider adding validation checks before applying the date range:

 onMenuSelect={type => {
   onReportChange({ type: 'modify' });

   if (type === 'include-current-interval') {
+    // Validate if the current interval makes sense for YTD and last year
+    const isValidForCurrentInterval = validateDateRangeForCurrentInterval(
+      customReportItems.dateRange,
+      customReportItems.interval
+    );
+    if (!isValidForCurrentInterval) {
+      return;
+    }
     setSessionReport(
       'includeCurrentInterval',
       !customReportItems.includeCurrentInterval,
     );
🧰 Tools
🪛 Biome (1.9.4)

[error] 92-92: This is an unexpected use of the debugger statement.

Unsafe fix: Remove debugger statement

(lint/suspicious/noDebugger)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0d0068c and 3062cb5.

📒 Files selected for processing (5)
  • packages/desktop-client/src/components/reports/Header.tsx (6 hunks)
  • packages/desktop-client/src/components/reports/ReportSidebar.tsx (1 hunks)
  • packages/desktop-client/src/components/reports/reportRanges.ts (2 hunks)
  • packages/desktop-client/src/components/reports/reports/Summary.tsx (4 hunks)
  • packages/loot-core/src/types/models/dashboard.d.ts (1 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/reports/reports/Summary.tsx (1)
Learnt from: lelemm
PR: actualbudget/actual#3792
File: packages/desktop-client/src/components/reports/reports/Summary.tsx:134-161
Timestamp: 2024-11-12T19:52:52.889Z
Learning: In `packages/desktop-client/src/components/reports/reports/Summary.tsx`, API calls like `get-earliest-transaction` are used without explicit error handling to maintain consistency with other components.
🪛 Biome (1.9.4)
packages/desktop-client/src/components/reports/reportRanges.ts

[error] 175-175: This is an unexpected use of the debugger statement.

Unsafe fix: Remove debugger statement

(lint/suspicious/noDebugger)

packages/desktop-client/src/components/reports/reports/Summary.tsx

[error] 227-227: This is an unexpected use of the debugger statement.

Unsafe fix: Remove debugger statement

(lint/suspicious/noDebugger)

packages/desktop-client/src/components/reports/ReportSidebar.tsx

[error] 92-92: This is an unexpected use of the debugger statement.

Unsafe fix: Remove debugger statement

(lint/suspicious/noDebugger)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: Analyze
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (5)
packages/desktop-client/src/components/reports/reportRanges.ts (1)

200-210: LGTM! Time frame modes implementation looks good.

The implementation correctly handles both new modes:

  • lastYear: Calculates previous year's range (Jan-Dec)
  • yearToDate: Calculates current year's range (Jan-current month)
packages/desktop-client/src/components/reports/Header.tsx (1)

174-209: LGTM! New time frame buttons implementation looks good.

The implementation correctly:

  • Adds "Year to date" and "Last year" buttons
  • Uses the getLiveRange function with appropriate parameters
  • Converts the dates to months using convertToMonth
packages/desktop-client/src/components/reports/ReportSidebar.tsx (1)

Line range hint 98-108: Verify date range handling for "Year to date" and "Last year" options.

Based on the reported issues with date ranges not being saved correctly, let's verify the implementation of getLiveRange which is crucial for the new "Year to date" and "Last year" options.

Run this script to analyze the date range handling implementation:

✅ Verification successful

Date range handling for "Year to date" and "Last year" options is properly implemented

The implementation in getLiveRange and its usage across components is consistent and complete, with proper handling of both "Year to date" and "Last year" options. The date calculations and type safety are correctly implemented.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze date range handling implementation
# Look for getLiveRange implementation and its usage with YTD and last year options

# Find getLiveRange implementation
echo "=== getLiveRange implementation ==="
ast-grep --pattern 'function getLiveRange($_) {
  $$$
}'

# Find all usages of getLiveRange
echo -e "\n=== getLiveRange usages ==="
rg -A 3 'getLiveRange\('

# Look for YTD and last year related code
echo -e "\n=== YTD and last year related code ==="
rg -i -A 3 'year.?to.?date|last.?year'

Length of output: 8862

🧰 Tools
🪛 Biome (1.9.4)

[error] 92-92: This is an unexpected use of the debugger statement.

Unsafe fix: Remove debugger statement

(lint/suspicious/noDebugger)

packages/loot-core/src/types/models/dashboard.d.ts (2)

7-7: LGTM! Verify consistent usage across components.

The addition of 'lastYear' and 'yearToDate' modes to the TimeFrame type is well-structured and aligns with the PR objectives.

Let's verify the consistent usage of these new modes across all components:

✅ Verification successful

Verified: New TimeFrame modes are consistently implemented

The new 'lastYear' and 'yearToDate' modes are properly integrated across all components:

  • Type definition in dashboard.d.ts
  • Time range calculations in getLiveRange.ts and reportRanges.ts
  • UI options in Header.tsx and ReportOptions.ts
  • Consistent usage in all report components through calculateTimeRange
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all components using TimeFrame.mode handle the new modes

# Search for TimeFrame usage
echo "Components using TimeFrame:"
rg -l "TimeFrame"

# Search for mode-related logic
echo -e "\nComponents with mode-related logic:"
rg "(lastYear|yearToDate)"

# Search for calculateTimeRange usage
echo -e "\nComponents using calculateTimeRange:"
rg "calculateTimeRange"

Length of output: 4490


Line range hint 22-29: Verify date persistence in affected widget types.

Based on PR comments about date persistence issues, ensure proper handling of the new modes in all widget types using TimeFrame (NetWorthWidget, CashFlowWidget, SummaryWidget, and CalendarWidget).

Let's check the persistence implementation:

Also applies to: 32-40, 93-100, 108-115

✅ Verification successful

TimeFrame persistence implementation verified

The codebase shows a robust and consistent persistence implementation for TimeFrame across all widget types:

  • All widgets use the same dashboard-update-widget mutation
  • Updates preserve existing metadata through proper spread operations
  • Changes are undoable for state management
  • Consistent implementation across NetWorth, CashFlow, Summary, and Calendar widgets
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify date persistence implementation

# Search for widget persistence logic
echo "Files handling widget persistence:"
rg -l "saveWidget|loadWidget|serializeWidget|deserializeWidget"

# Search for timeFrame-related storage
echo -e "\nTimeFrame storage handling:"
rg "timeFrame.*storage|storage.*timeFrame"

Length of output: 260


Script:

#!/bin/bash
# Broaden search for widget and persistence related code

# Find widget-related files
echo "=== Widget-related files ==="
fd -e ts -e js widget

# Look for TimeFrame usage
echo -e "\n=== TimeFrame usage ==="
rg -l "TimeFrame|timeFrame" --type ts --type js

# Look for storage/database operations related to widgets
echo -e "\n=== Storage operations ==="
rg -l "store|persist|save|load|serialize|deserialize" --type ts --type js | grep -i widget

Length of output: 1274


Script:

#!/bin/bash
# Examine widget data hook implementation

echo "=== Widget Data Hook Implementation ==="
cat "packages/loot-core/src/client/data-hooks/widget.ts"

echo -e "\n=== Widget Storage Operations ==="
rg -A 5 "function.*Widget" "packages/loot-core/src/client/data-hooks/widget.ts"

Length of output: 995


Script:

#!/bin/bash
# Search for dashboard table and query implementations

# Look for dashboard table schema
echo "=== Dashboard Table Schema ==="
rg -l "dashboard.*schema|schema.*dashboard|createTable.*dashboard"

# Look for query implementation
echo -e "\n=== Query Implementation ==="
rg -l "class.*Query|interface.*Query"

# Look for dashboard mutations/operations
echo -e "\n=== Dashboard Operations ==="
rg "dashboard.*update|dashboard.*insert|dashboard.*save" -A 3

Length of output: 6335

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

🧹 Nitpick comments (1)
packages/desktop-client/src/components/reports/reportRanges.ts (1)

199-209: Ensure consistent date validation across all modes.

The new 'lastYear' and 'yearToDate' modes bypass the validation logic present in validateRange, validateStart, and validateEnd functions. This could lead to inconsistent date handling.

Consider:

  1. Adding the new modes to boundedRange function's interval handling
  2. Ensuring the new modes work correctly with the validation functions
  3. Adding unit tests for the new modes with edge cases
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between fd90221 and 239e180.

📒 Files selected for processing (3)
  • packages/desktop-client/src/components/reports/Header.tsx (6 hunks)
  • packages/desktop-client/src/components/reports/reportRanges.ts (1 hunks)
  • packages/desktop-client/src/components/reports/reports/Summary.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/desktop-client/src/components/reports/reports/Summary.tsx
  • packages/desktop-client/src/components/reports/Header.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build (macos-latest)
  • GitHub Check: build (windows-latest)
  • GitHub Check: Wait for Netlify build to finish
  • GitHub Check: Analyze
  • GitHub Check: build (ubuntu-latest)

@rodriguestiago0
Copy link
Contributor Author

When I save a "last year" range in the reports, the range doesn't get saved right. The months in the start/end selection boxes are correct, but get shifted when going back to the reports dashboard and when viewing the report again after.

image This is after choosing "last year" and saving and going back to the dashboard. In the report, after choosing the "last year" option the range is correct and shows Jan-2024 - Dec-2024.

Done

@@ -4,7 +4,7 @@ import { type RuleConditionEntity } from './rule';
export type TimeFrame = {
start: string;
end: string;
mode: 'sliding-window' | 'static' | 'full';
mode: 'sliding-window' | 'static' | 'full' | 'lastYear' | 'yearToDate';
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary? The existing mode types are for how the window functions. Plus the existing window options aren't in this list, so it seems like you shouldn't need to change this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is. Sliding window will be always against current month.
With ytd and last year is not against current month.

In my opinion we could migrate it to other structure to be more productive but we can’t because they are already being used.

we should get the interval size, interval type and anchor.
3 month
Would be 3, month, current month

or
Last year would be
12, month, begin of current year

Two years
2, years, current month

@matt-fidd
Copy link
Contributor

matt-fidd commented Jan 13, 2025

There's a small width range where it doesn't wrap properly on my screen, all time is very slightly clipped into the save button

Screenshot 2025-01-13 at 16 41 25

youngcw
youngcw previously approved these changes Jan 15, 2025
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.

All seems to be good. I would like to get another review from someone who has worked with the reports more.

@youngcw
Copy link
Member

youngcw commented Jan 15, 2025

/update-vrt

@@ -129,7 +143,7 @@ export function Header({
</SpaceBetween>
</SpaceBetween>

<SpaceBetween>
<SpaceBetween gap={3}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we up this? I think it looks a bit squished.

Current:
image

Here's 10px
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

small screens would have a problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

is there any way to force it to wrap when the save button starts to overlap with the filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No idea. my knowledge of CSS is less than js

Copy link
Contributor

Choose a reason for hiding this comment

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

No worries, we'll go with it for now then. If anyone works out a way it can be a separate PR

@matt-fidd matt-fidd merged commit 626e797 into actualbudget:master Jan 17, 2025
20 checks passed
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.

3 participants