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 Copy last 6/12 months to budget menu #4096

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

psybers
Copy link
Contributor

@psybers psybers commented Jan 5, 2025

Currently, the individual categories have option to copy last 3, 6, or 12 months. But the overall budget only has last 3. This makes them similar.

@actual-github-bot actual-github-bot bot changed the title Add Copy last 6/12 months to budget menu [WIP] Add Copy last 6/12 months to budget menu Jan 5, 2025
Copy link

netlify bot commented Jan 5, 2025

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 5e3384b
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/677c8b9bd49af300089a844a
😎 Deploy Preview https://deploy-preview-4096.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 5, 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
10 5.64 MB → 5.65 MB (+3.97 kB) +0.07%
Changeset
File Δ Size
src/components/budget/envelope/budgetsummary/BudgetSummary.tsx 📈 +1.69 kB (+23.16%) 7.31 kB → 9 kB
src/components/budget/tracking/budgetsummary/BudgetMonthMenu.tsx 📈 +344 B (+21.91%) 1.53 kB → 1.87 kB
src/components/budget/tracking/budgetsummary/BudgetSummary.tsx 📈 +1.38 kB (+20.68%) 6.7 kB → 8.08 kB
src/components/budget/envelope/budgetsummary/BudgetMonthMenu.tsx 📈 +344 B (+19.27%) 1.74 kB → 2.08 kB
home/runner/work/actual/actual/packages/loot-core/src/client/actions/queries.ts 📈 +228 B (+2.71%) 8.21 kB → 8.43 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.71 MB → 3.72 MB (+3.97 kB) +0.10%

Smaller

No assets were smaller

Unchanged

Asset File Size % Changed
static/js/workbox-window.prod.es5.js 5.69 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/BackgroundImage.js 122.29 kB 0%
static/js/useAccountPreviewTransactions.js 1.63 kB 0%
static/js/AppliedFilters.js 10.24 kB 0%
static/js/narrow.js 84.22 kB 0%
static/js/wide.js 104.11 kB 0%
static/js/ReportRouter.js 1.58 MB 0%

Copy link
Contributor

github-actions bot commented Jan 5, 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 → 1.33 MB (+468 B) +0.03%
Changeset
File Δ Size
packages/loot-core/src/server/budget/app.ts 📈 +158 B (+8.18%) 1.89 kB → 2.04 kB
packages/loot-core/src/server/budget/actions.ts 📈 +906 B (+7.24%) 12.23 kB → 13.11 kB
View detailed bundle breakdown

Added

No assets were added

Removed

No assets were removed

Bigger

Asset File Size % Changed
kcab.worker.js 1.33 MB → 1.33 MB (+468 B) +0.03%

Smaller

No assets were smaller

Unchanged

No assets were unchanged

@psybers psybers changed the title [WIP] Add Copy last 6/12 months to budget menu Add Copy last 6/12 months to budget menu Jan 5, 2025
@psybers
Copy link
Contributor Author

psybers commented Jan 5, 2025

image

Copy link
Contributor

coderabbitai bot commented Jan 5, 2025

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetSummary.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eslint-plugin".

(The package "eslint-plugin-eslint-plugin" was not found when loaded as a Node module from the directory "/packages/eslint-plugin-actual".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eslint-plugin@latest --save-dev

The plugin "eslint-plugin-eslint-plugin" was referenced from the config file in "packages/eslint-plugin-actual/.eslintrc.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

Walkthrough

This pull request introduces enhanced budget management functionality across multiple components and files. The changes primarily focus on adding new options for setting 6-month and 12-month budget averages. The modifications span the desktop client's user interface components, core client actions, server-side budget actions, and type definitions. Specifically, new cases are added to the onMenuSelect handler in the BudgetMonthMenu component, corresponding action handlers are implemented in the queries and actions files, and the application's method registry is updated to support these new budget average calculation features. Additionally, the BudgetSummary components are enhanced with localization support and user feedback notifications. The overall structure of the components remains intact, with the new functionalities seamlessly integrated.

Possibly related PRs

Suggested labels

:sparkles: Merged, :sparkles: Merged

Suggested reviewers

  • youngcw

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

🧹 Nitpick comments (4)
packages/loot-core/src/server/budget/types/handlers.d.ts (1)

16-19: Consider consolidating methods with 'budget/set-n-month-avg'.

Since there is already a 'budget/set-n-month-avg' method, these dedicated six- and twelve-month methods might lead to duplication. It is perfectly valid to keep these as convenience methods if they are heavily used, but you could alternatively route their logic through 'budget/set-n-month-avg' to streamline maintenance and testing.

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

23-24: Methods look good, but consider possible redundancy.

Both methods are straightforward wrappers around setNMonthAvg. As noted elsewhere, unifying them under 'budget/set-n-month-avg' with different arguments may reduce potential duplication, but this is purely a design preference.

packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetMonthMenu.tsx (1)

68-75: Optional textual or grouping improvement.

The text for "Set budgets to 6 month average" and "Set budgets to 12 month average" is clear. For stylistic consistency, consider using "6-month" and "12-month" with a hyphen, as already done with "3 month." This is a minor UI/UX improvement, but not mandatory.

packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetMonthMenu.tsx (1)

73-80: Minor consistency suggestion.

The labels "Set budgets to 6 month average" and "Set budgets to 12 month average" are clear. You could align the grammar with the existing "Set budgets to 3 month average," perhaps by consistently adding a hyphen ("6-month" or "12-month"), but this is fully optional and not a functional issue.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 832fd1e and 895b7d2.

⛔ Files ignored due to path filters (1)
  • upcoming-release-notes/4096.md is excluded by !**/*.md
📒 Files selected for processing (6)
  • packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetMonthMenu.tsx (2 hunks)
  • packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetMonthMenu.tsx (2 hunks)
  • packages/loot-core/src/client/actions/queries.ts (1 hunks)
  • packages/loot-core/src/server/budget/actions.ts (1 hunks)
  • packages/loot-core/src/server/budget/app.ts (1 hunks)
  • packages/loot-core/src/server/budget/types/handlers.d.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Visual regression
  • GitHub Check: Functional
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (4)
packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetMonthMenu.tsx (1)

44-49: No issues found.

The new menu options for 6 and 12 months integrate cleanly into the existing switch block. The logic to call onSetMonthsAverage is consistent with the approach for other menu items.

packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetMonthMenu.tsx (1)

46-51: Implementation mirrors the tracking menu, which is good for consistency.

The switch case additions for 6- and 12-month ranges are correct, and calling onSetMonthsAverage is consistent with the existing code. This ensures consistent behavior between different budget menu components.

packages/loot-core/src/client/actions/queries.ts (2)

32-34: The new 'set-6-avg' case aligns well with existing budget actions.
No issues found with this implementation, and it remains consistent with the established pattern of calling await send(...) for budget updates.


35-37: The new 'set-12-avg' case follows the same pattern successfully.
All logic appears coherent, with consistent usage of await send(...).

Comment on lines +285 to +302
export async function set12MonthAvg({
month,
}: {
month: string;
}): Promise<void> {
const categories = await db.all(
'SELECT * FROM v_categories WHERE tombstone = 0',
);

await batchMessages(async () => {
for (const cat of categories) {
if (cat.is_income === 1 && !isReflectBudget()) {
continue;
}
setNMonthAvg({ month, N: 12, category: cat.id });
}
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Await the async calls within the loop to prevent premature return.
Inside the for loop, setNMonthAvg is an async function, and currently it's not awaited. This means the parent function may resolve before all asynchronous operations have completed, potentially causing unexpected delays or race conditions.

Below is an essential fix to ensure each async operation completes:

-      setNMonthAvg({ month, N: 12, category: cat.id });
+      await setNMonthAvg({ month, N: 12, category: cat.id });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function set12MonthAvg({
month,
}: {
month: string;
}): Promise<void> {
const categories = await db.all(
'SELECT * FROM v_categories WHERE tombstone = 0',
);
await batchMessages(async () => {
for (const cat of categories) {
if (cat.is_income === 1 && !isReflectBudget()) {
continue;
}
setNMonthAvg({ month, N: 12, category: cat.id });
}
});
}
export async function set12MonthAvg({
month,
}: {
month: string;
}): Promise<void> {
const categories = await db.all(
'SELECT * FROM v_categories WHERE tombstone = 0',
);
await batchMessages(async () => {
for (const cat of categories) {
if (cat.is_income === 1 && !isReflectBudget()) {
continue;
}
await setNMonthAvg({ month, N: 12, category: cat.id });
}
});
}

Comment on lines +304 to +322
export async function set6MonthAvg({
month,
}: {
month: string;
}): Promise<void> {
const categories = await db.all(
'SELECT * FROM v_categories WHERE tombstone = 0',
);

await batchMessages(async () => {
for (const cat of categories) {
if (cat.is_income === 1 && !isReflectBudget()) {
continue;
}
setNMonthAvg({ month, N: 6, category: cat.id });
}
});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Await the async calls for setting 6-month averages.
Similar to the 12-month average function, ensure that the call to setNMonthAvg is awaited within the loop:

-      setNMonthAvg({ month, N: 6, category: cat.id });
+      await setNMonthAvg({ month, N: 6, category: cat.id });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
export async function set6MonthAvg({
month,
}: {
month: string;
}): Promise<void> {
const categories = await db.all(
'SELECT * FROM v_categories WHERE tombstone = 0',
);
await batchMessages(async () => {
for (const cat of categories) {
if (cat.is_income === 1 && !isReflectBudget()) {
continue;
}
setNMonthAvg({ month, N: 6, category: cat.id });
}
});
}
export async function set6MonthAvg({
month,
}: {
month: string;
}): Promise<void> {
const categories = await db.all(
'SELECT * FROM v_categories WHERE tombstone = 0',
);
await batchMessages(async () => {
for (const cat of categories) {
if (cat.is_income === 1 && !isReflectBudget()) {
continue;
}
await setNMonthAvg({ month, N: 6, category: cat.id });
}
});
}

@youngcw
Copy link
Member

youngcw commented Jan 5, 2025

Should we do this or should we point people to the average template? With templates enabled that menu will be pretty long.

@psybers
Copy link
Contributor Author

psybers commented Jan 5, 2025

Not everyone (such as me) uses goal templates?

@psybers
Copy link
Contributor Author

psybers commented Jan 6, 2025

Based on the discussion in Discord, I had these added actions (and the existing ones) make use of the showUndoNotification() function so it will show a notification (with an undo button). I will open another PR to make that function only show on mobile, as it currently shows on desktop too.

@psybers
Copy link
Contributor Author

psybers commented Jan 6, 2025

I also added translations to one of the files since they were missing.

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

🧹 Nitpick comments (3)
packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetSummary.tsx (1)

171-176: Ensure consistent placeholder usage in translations.
You are mixing placeholder-based translations (e.g., {{displayMonth}}) with template literals (e.g., `${displayMonth} budgets...`). While both approaches work, consistency helps translators handle the strings more reliably.

Below is an example refactor for lines 191-200 that aligns with the placeholder style used in lines 171-186:

- message:
-   numberOfMonths === 12
-     ? t(
-         `${displayMonth} budgets have all been set to yearly average.`,
-       )
-     : t(
-         `${displayMonth} budgets have all been set to ${numberOfMonths} month average.`,
-       ),
+ message: numberOfMonths === 12
+   ? t('{{displayMonth}} budgets have all been set to yearly average.', {
+       displayMonth,
+     })
+   : t('{{displayMonth}} budgets have all been set to {{months}} month average.', {
+       displayMonth,
+       months: numberOfMonths,
+     }),

Similarly, consider using placeholders in other lines to keep the code uniform and translator-friendly.

Also applies to: 181-186, 191-200, 209-214, 219-224, 229-234

packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetSummary.tsx (2)

54-54: Watch for typographic quotes
The line 'MMMM ‘yy' contains a curly single quote “‘”. Confirm that this character is intentional and correctly interpreted by the monthUtils.format function. If accidental, replace it with a standard apostrophe '.

-const displayMonth = monthUtils.format(month, 'MMMM ‘yy');
+const displayMonth = monthUtils.format(month, 'MMMM \'yy');

187-196: Ternary-based message
Using a ternary for 12 vs. other months is valid. If further averaging options are added in the future, consider a more general approach.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 895b7d2 and 6be66a5.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetSummary.tsx (7 hunks)
  • packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetSummary.tsx (5 hunks)
⏰ 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: Wait for Netlify build to finish
  • GitHub Check: build (ubuntu-latest)
🔇 Additional comments (12)
packages/desktop-client/src/components/budget/envelope/budgetsummary/BudgetSummary.tsx (6)

2-2: Great introduction of translation support.
Using useTranslation from react-i18next is a solid approach to ensure internationalization in the BudgetSummary component.


8-8: Undo handling is well-integrated.
Importing the custom useUndo hook is a neat solution for providing user feedback with undo notifications.


37-37: Confirmation of undo notification usage.
Extracting showUndoNotification from useUndo() centralizes the undo logic and keeps the component concise. Good practice.


54-54: Well-placed translation extraction.
Using t from react-i18next right before rendering ensures straightforward localization.


98-102: Localized aria-label expressions.
Good job on localizing the expand/collapse aria-label. Improves accessibility for non-English speakers.


152-152: Localized menu label.
Replacing the hardcoded "Menu" string with t('Menu') is consistent with the rest of the component's localization approach.

packages/desktop-client/src/components/budget/tracking/budgetsummary/BudgetSummary.tsx (6)

9-9: Import usage looks good
The import of the useUndo hook appears correct and aligns with its usage below. No issues spotted here.


167-172: Undo notification message
The displayed text is clear. No further issues found.


177-182: Undo notification for zero budgets
This notification mirrors the pattern in the previous block, ensuring consistent user feedback. Looks good.


205-210: Template application notification
The message properly references displayMonth. Implementation is consistent with other notifications.


215-220: Overwrite template notification
No issues found with logic or messaging.


40-40: Properly extracting showUndoNotification
Calling useUndo() and extracting showUndoNotification is appropriate. Make sure the component remains mounted when triggering notifications to avoid potential React state warnings.

✅ Verification successful

Notification System Implementation is Unmount-Safe
The showUndoNotification implementation uses Redux for state management and operates independently of component lifecycle, making it safe to use even if the component unmounts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that showUndoNotification is unmounted-safe usage.
rg -A 5 "showUndoNotification"

Length of output: 38025

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.

I don't mind these being in the menu, they can be useful as one-offs outside of templates too.

I agree we can't stuff everything in here though - some things are best left to templates

@matt-fidd matt-fidd merged commit 7dad365 into actualbudget:master Jan 8, 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.

4 participants