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

[WIP] POC Budget Bar Graph #3424

Closed
wants to merge 28 commits into from
Closed

Conversation

carkom
Copy link
Contributor

@carkom carkom commented Sep 12, 2024

I know there's a custom user script out there for doing something similar with goal templates but I thought it would be helpful to have something like this in the code base. It's also really useful to see any rollover spending that may otherwise be difficult to decipher as just numbers.

Happy to adjust as needed. Open to any feedback you all have!

@actual-github-bot actual-github-bot bot changed the title POC Budget Bar Graph [WIP] POC Budget Bar Graph Sep 12, 2024
Copy link

netlify bot commented Sep 12, 2024

Deploy Preview for actualbudget ready!

Name Link
🔨 Latest commit 6146d00
🔍 Latest deploy log https://app.netlify.com/sites/actualbudget/deploys/66f79f12cc04560008cec279
😎 Deploy Preview https://deploy-preview-3424.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 Sep 12, 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
9 5.29 MB → 5.3 MB (+16.1 kB) +0.30%
Changeset (largest 100 files by percent change)
File Δ Size
src/components/reports/graphs/BarGraphVertical.tsx 🆕 +2.88 kB 0 B → 2.88 kB
src/components/budget/BudgetTotals.tsx 📈 +2.75 kB (+87.10%) 3.16 kB → 5.91 kB
src/components/budget/tracking/TrackingBudgetComponents.tsx 📈 +3.4 kB (+26.30%) 12.92 kB → 16.32 kB
src/components/common/Menu.tsx 📈 +1.49 kB (+26.28%) 5.67 kB → 7.16 kB
src/components/budget/envelope/EnvelopeBudgetComponents.tsx 📈 +3.4 kB (+24.58%) 13.84 kB → 17.24 kB
src/components/budget/ExpenseCategory.tsx 📈 +94 B (+4.85%) 1.89 kB → 1.98 kB
node_modules/react-dnd-html5-backend/dist/BrowserDetector.js 📈 +4 B (+3.23%) 124 B → 128 B
node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js 📈 +6 B (+3.11%) 193 B → 199 B
node_modules/@babel/runtime/helpers/esm/createSuper.js 📈 +10 B (+3.00%) 333 B → 343 B
node_modules/react-is/cjs/react-is.production.min.js 📈 +82 B (+2.95%) 2.71 kB → 2.79 kB
node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js 📈 +6 B (+2.93%) 205 B → 211 B
node_modules/unist-util-visit-parents/lib/color.js 📈 +2 B (+2.44%) 82 B → 84 B
src/style/themes/development.ts 📈 +147 B (+1.89%) 7.59 kB → 7.73 kB
node_modules/@babel/runtime/helpers/esm/createClass.js 📈 +8 B (+1.89%) 423 B → 431 B
src/style/themes/dark.ts 📈 +147 B (+1.88%) 7.66 kB → 7.8 kB
src/style/themes/light.ts 📈 +147 B (+1.86%) 7.72 kB → 7.86 kB
src/style/themes/midnight.ts 📈 +139 B (+1.85%) 7.36 kB → 7.49 kB
node_modules/property-information/lib/normalize.js 📈 +2 B (+1.79%) 112 B → 114 B
node_modules/@babel/runtime/helpers/esm/classCallCheck.js 📈 +2 B (+1.71%) 117 B → 119 B
src/components/common/Label.tsx 📈 +6 B (+1.61%) 372 B → 378 B
node_modules/property-information/lib/aria.js 📈 +24 B (+1.60%) 1.47 kB → 1.49 kB
node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js 📈 +4 B (+1.56%) 257 B → 261 B
node_modules/@babel/runtime/helpers/esm/inheritsLoose.js 📈 +2 B (+1.55%) 129 B → 131 B
node_modules/@babel/runtime/helpers/esm/isNativeReflectConstruct.js 📈 +4 B (+1.54%) 259 B → 263 B
node_modules/@babel/runtime/helpers/esm/unsupportedIterableToArray.js 📈 +6 B (+1.52%) 394 B → 400 B
node_modules/@babel/runtime/helpers/esm/arrayLikeToArray.js 📈 +2 B (+1.30%) 154 B → 156 B
node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js 📈 +2 B (+1.27%) 157 B → 159 B
src/components/common/Text.tsx 📈 +4 B (+1.25%) 321 B → 325 B
node_modules/date-fns/esm/parse/_lib/parsers/TimestampSecondsParser.js 📈 +12 B (+1.21%) 995 B → 1007 B
node_modules/date-fns/esm/parse/_lib/parsers/TimestampMillisecondsParser.js 📈 +12 B (+1.17%) 1023 B → 1.01 kB
node_modules/date-fns/esm/locale/en-US/index.js 📈 +6 B (+1.07%) 560 B → 566 B
node_modules/@babel/runtime/helpers/esm/inherits.js 📈 +4 B (+1.06%) 378 B → 382 B
node_modules/date-fns/esm/parse/_lib/parsers/ExtendedYearParser.js 📈 +12 B (+1.05%) 1.11 kB → 1.12 kB
node_modules/date-fns/esm/parse/_lib/parsers/FractionOfSecondParser.js 📈 +12 B (+1.04%) 1.13 kB → 1.14 kB
node_modules/date-fns/esm/parse/_lib/Setter.js 📈 +24 B (+0.99%) 2.38 kB → 2.4 kB
node_modules/date-fns/esm/parse/_lib/parsers/ISOWeekYearParser.js 📈 +12 B (+0.96%) 1.22 kB → 1.23 kB
node_modules/lodash/_baseAssignValue.js 📈 +6 B (+0.96%) 623 B → 629 B
node_modules/lodash/_stringToPath.js 📈 +8 B (+0.96%) 833 B → 841 B
node_modules/date-fns/esm/parse/_lib/parsers/SecondParser.js 📈 +12 B (+0.92%) 1.27 kB → 1.28 kB
node_modules/date-fns/esm/parse/_lib/parsers/MinuteParser.js 📈 +12 B (+0.92%) 1.27 kB → 1.29 kB
node_modules/date-fns/esm/parse/_lib/parsers/Hour0to23Parser.js 📈 +12 B (+0.89%) 1.32 kB → 1.33 kB
node_modules/date-fns/esm/parse/_lib/parsers/ISOWeekParser.js 📈 +12 B (+0.88%) 1.34 kB → 1.35 kB
node_modules/date-fns/esm/parse/_lib/parsers/LocalWeekParser.js 📈 +12 B (+0.86%) 1.37 kB → 1.38 kB
node_modules/date-fns/esm/parse/_lib/parsers/Hour1To24Parser.js 📈 +12 B (+0.86%) 1.37 kB → 1.38 kB
node_modules/date-fns/esm/parse/_lib/parsers/DayOfYearParser.js 📈 +14 B (+0.83%) 1.65 kB → 1.67 kB
node_modules/date-fns/esm/parse/_lib/parsers/Hour0To11Parser.js 📈 +12 B (+0.81%) 1.45 kB → 1.46 kB
node_modules/lodash/now.js 📈 +4 B (+0.79%) 505 B → 509 B
node_modules/date-fns/esm/parse/_lib/parsers/ISOTimezoneParser.js 📈 +12 B (+0.78%) 1.5 kB → 1.51 kB
node_modules/date-fns/esm/parse/_lib/parsers/Hour1to12Parser.js 📈 +12 B (+0.77%) 1.53 kB → 1.54 kB
node_modules/date-fns/esm/parse/_lib/parsers/ISOTimezoneWithZParser.js 📈 +12 B (+0.76%) 1.53 kB → 1.54 kB
node_modules/date-fns/esm/_lib/setUTCWeek/index.js 📈 +2 B (+0.76%) 262 B → 264 B
node_modules/date-fns/esm/_lib/setUTCISOWeek/index.js 📈 +2 B (+0.76%) 262 B → 264 B
node_modules/property-information/lib/svg.js 📈 +106 B (+0.75%) 13.72 kB → 13.82 kB
node_modules/date-fns/esm/parse/_lib/parsers/DateParser.js 📈 +14 B (+0.75%) 1.82 kB → 1.84 kB
node_modules/lodash/_castPath.js 📈 +4 B (+0.75%) 535 B → 539 B
node_modules/date-fns/esm/parse/_lib/parsers/EraParser.js 📈 +12 B (+0.75%) 1.57 kB → 1.58 kB
node_modules/dnd-core/dist/utils/coords.js 📈 +10 B (+0.73%) 1.35 kB → 1.36 kB
node_modules/date-fns/esm/_lib/toInteger/index.js 📈 +2 B (+0.72%) 278 B → 280 B
src/components/common/TextOneLine.tsx 📈 +2 B (+0.70%) 287 B → 289 B
node_modules/date-fns/esm/parse/_lib/parsers/AMPMParser.js 📈 +12 B (+0.68%) 1.72 kB → 1.73 kB
node_modules/lodash/_isFlattenable.js 📈 +4 B (+0.68%) 590 B → 594 B
node_modules/date-fns/esm/parse/_lib/parsers/DayPeriodParser.js 📈 +12 B (+0.67%) 1.74 kB → 1.76 kB
node_modules/date-fns/esm/parse/_lib/parsers/AMPMMidnightParser.js 📈 +12 B (+0.66%) 1.77 kB → 1.79 kB
node_modules/property-information/lib/util/types.js 📈 +2 B (+0.65%) 308 B → 310 B
node_modules/lodash.debounce/index.js 📈 +68 B (+0.62%) 10.66 kB → 10.73 kB
node_modules/property-information/lib/html.js 📈 +50 B (+0.62%) 7.9 kB → 7.95 kB
node_modules/d3-color/src/define.js 📈 +2 B (+0.62%) 324 B → 326 B
node_modules/is-plain-obj/index.js 📈 +2 B (+0.61%) 328 B → 330 B
src/components/rules/ConditionExpression.tsx 📈 +6 B (+0.57%) 1.03 kB → 1.03 kB
src/components/rules/RulesHeader.tsx 📈 +4 B (+0.56%) 714 B → 718 B
node_modules/lodash/isBoolean.js 📈 +4 B (+0.55%) 729 B → 733 B
node_modules/date-fns/esm/parse/_lib/parsers/LocalWeekYearParser.js 📈 +12 B (+0.55%) 2.14 kB → 2.15 kB
node_modules/lodash/_baseGetTag.js 📈 +4 B (+0.52%) 763 B → 767 B
node_modules/lodash/isString.js 📈 +4 B (+0.52%) 773 B → 777 B
node_modules/date-fns/esm/parse/_lib/parsers/QuarterParser.js 📈 +12 B (+0.52%) 2.27 kB → 2.28 kB
node_modules/date-fns/esm/parse/_lib/Parser.js 📈 +4 B (+0.51%) 781 B → 785 B
node_modules/date-fns/esm/parse/_lib/parsers/DayParser.js 📈 +12 B (+0.51%) 2.32 kB → 2.33 kB
node_modules/date-fns/esm/parse/_lib/parsers/StandAloneQuarterParser.js 📈 +12 B (+0.50%) 2.34 kB → 2.35 kB
node_modules/date-fns/esm/parse/_lib/parsers/YearParser.js 📈 +12 B (+0.50%) 2.37 kB → 2.38 kB
node_modules/lodash/isArrayLike.js 📈 +4 B (+0.49%) 818 B → 822 B
node_modules/lodash/_createFind.js 📈 +4 B (+0.49%) 823 B → 827 B
node_modules/html-parse-stringify/dist/html-parse-stringify.module.js 📈 +10 B (+0.48%) 2.02 kB → 2.03 kB
src/components/rules/ActionExpression.tsx 📈 +18 B (+0.48%) 3.65 kB → 3.67 kB
node_modules/date-fns/esm/parse/_lib/parsers/MonthParser.js 📈 +12 B (+0.48%) 2.43 kB → 2.44 kB
node_modules/date-fns/esm/parse/_lib/parsers/StandAloneMonthParser.js 📈 +12 B (+0.47%) 2.5 kB → 2.51 kB
src/components/util/DisplayId.tsx 📈 +4 B (+0.46%) 861 B → 865 B
node_modules/date-fns/esm/_lib/setUTCISODay/index.js 📈 +2 B (+0.45%) 440 B → 442 B
src/components/rules/Value.tsx 📈 +22 B (+0.45%) 4.74 kB → 4.77 kB
node_modules/throttleit/index.js 📈 +4 B (+0.45%) 889 B → 893 B
node_modules/lodash/_baseExtremum.js 📈 +4 B (+0.45%) 892 B → 896 B
node_modules/@use-gesture/core/dist/use-gesture-core.esm.js 📈 +36 B (+0.43%) 8.24 kB → 8.27 kB
node_modules/date-fns/esm/parse/_lib/parsers/ISODayParser.js 📈 +12 B (+0.42%) 2.82 kB → 2.83 kB
node_modules/date-fns/esm/parse/_lib/parsers/LocalDayParser.js 📈 +12 B (+0.41%) 2.86 kB → 2.87 kB
node_modules/date-fns/esm/parse/_lib/parsers/StandAloneLocalDayParser.js 📈 +12 B (+0.40%) 2.92 kB → 2.94 kB
node_modules/recharts/es6/util/isDomainSpecifiedByUser.js 📈 +4 B (+0.38%) 1.03 kB → 1.03 kB
src/components/spreadsheet/useFormat.ts 📈 +6 B (+0.36%) 1.63 kB → 1.63 kB
src/components/common/Stack.tsx 📈 +6 B (+0.34%) 1.74 kB → 1.75 kB
node_modules/lodash/range.js 📈 +4 B (+0.33%) 1.17 kB → 1.17 kB
src/components/budget/tracking/budgetsummary/BudgetTotal.tsx 📈 +6 B (+0.33%) 1.76 kB → 1.76 kB
node_modules/unist-util-position/lib/index.js 📈 +6 B (+0.33%) 1.79 kB → 1.8 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.31 MB → 4.16 MB (+870.06 kB) +25.65%
static/js/wide.js 225.27 kB → 228.11 kB (+2.84 kB) +1.26%

Smaller

Asset File Size % Changed
static/js/ReportRouter.js 1.5 MB → 683.15 kB (-856.8 kB) -55.64%

Unchanged

Asset File Size % Changed
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/usePreviewTransactions.js 1.64 kB 0%
static/js/narrow.js 82.1 kB 0%
static/js/AppliedFilters.js 20.97 kB 0%

Copy link
Contributor

github-actions bot commented Sep 12, 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.19 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.19 MB 0%

@Teprifer
Copy link

Correct me if I'm reading the colours wrong:

Green = budgeted
Purple = budgeted and spent in the month
Red = value of spent higher than budgeted in the month
Black = roll over from previous month

I think it's doing the maths wrong on this one, it appears to be tacking on the positive carry over to the end, instead of including it in the budgeted/spent part.
For example in this category - there was a balance of $2.54 from the previous month, and 1 transaction which zeroed out the balance, so shouldn't the spent be the whole way across since the entire balance(and goal, same value) was consumed?

#template-1 up to $207.28
image

The green only being for the budgeted this month amount and for a big goal with a small amount added each month looks a bit odd because the budgeted amount is such a small proportion of the carried over balance:

#template-50 $58 up to $x
image

Would it look better if the roll over were a different shade of green(for positive over), and be left aligned so it looks like it stacks with the this month budgeted? This would also emphasis the idea of how money carries over add you add to it each month. Excuse the bad paint edit:
image

Within the spent colour the amount carried over could also be left aligned within the spent amount, possibly a lighter purple if you want to show the source of funds otherwise no change?

I'm not really the target (hah!) for this but I think it's highly requested. I wonder what people's thoughts would be on having a rare option for this and tie its visibility to the templates feature flag? Thinking three levels, None, On Hover, Always Showing.

@Jonathan-Fang
Copy link
Contributor

Budget Bar Graph is definitely something I have been looking forward to in Actual Budget! To add to @Teprifer 's comment, the three levels I would suggest is how Notion does table properties: Hidden Always, Hide if Empty, Display Always.

I am asking in the Discord how to test edge builds because I only have Pikapods right now, but I was wondering how would the graph behave if a category has 5 months worth of money, and I want it to be kept with 5 months max and fluctuate between 4-5 months as I refill the margin?

Also @Teprifer , I appreciate the pun 🤣

@Teprifer
Copy link

Teprifer commented Sep 14, 2024

@Jonathan-Fang there's a netlify link near the top to try out this PR. I usually open it in an incognito window or another browser to have a clean environment. Then I export my budget from my regular install and import it into the netlify link, remember the app runs locally so you're not uploading your data anywhere.

Depending on the PR I might try a test or fresh budget instead.

@carkom
Copy link
Contributor Author

carkom commented Sep 16, 2024

It's not tied to templates, it's displaying budget vs spent so it's usable without any usage of templates.

Also, I don't think that adding a setting for this is necessary. It's a discovered feature that doesn't hinder or change a user's experience of the budget table. It's only shown on hover and never shown when empty.

I'd agree that colors need to be optimized.

@carkom
Copy link
Contributor Author

carkom commented Sep 16, 2024

RE: Colors

Here are all the possible outcomes (I can think of) - please excuse the rushed MS paint work...

budget bar illistration

@carkom
Copy link
Contributor Author

carkom commented Sep 16, 2024

So I have 2 questions:

  1. I have rollover showing after budgeted amount. Would it be easier to understand if it was before?
  2. Thoughts on best ways to illustrate the last 2 cases?

@MikesGlitch
Copy link
Contributor

MikesGlitch commented Sep 16, 2024

I find this quite distracting - mainly because of the hover states. I prefer to have a simplistic UI, maybe we can make this opt-in by giving an option on the category/group? Something like Show progress

From a user perspective I think the colors are not immediately obvious. My first thought was "What are purple, red, black and green supposed to mean". I think if the user has to ask that question it's too complicated.

image
image
image

My two cents for the No Rollover options
What if it was just a simple progress bar on the row? When it turns negative it goes red?

image
image

The user would have the option to turn it on for a category or group, and it would always be visible if on - no hover states.

@Teprifer
Copy link

Doh, I mis-interpreted the description.

I think a setting would still be a good idea as I can see some people wanting it on all the time(it'd look busy, but each to their own eh), as is, or not shown.
(just thought of this) - it would also create space to have an 'always show' option for mobile which doesn't have a 'hover' if this were to be ported to that UI in the future. Maybe see what other feedback comes in?

  1. I think this is a mental model thing with no firm 'right' answer, personally roll over before budgeted feels better for me because when starting the month the roll over is already there, and I'm only adding as required. Or put to it another way, what happens this month is after what happened last month. 🤷‍♂️

  2. First of all, damn that's a lot of permutations!
    I'll have to spend some time thinking them through, what is it you do/don't like about how you're mocked up the last 2 cases?

@matt-fidd
Copy link
Contributor

Big fan of this!

I find myself trying to hover for a tooltip that explains what the bar segment means, if it's possible to add then it would alleviate any confusion on what the colours mean, and would stop people having to work it out for themselves

Count me in as an advocate for a display setting, ideally in three states:

  • Always on
  • Always off (it would be nice if this could revert the height of the budget rows, for those who prefer a compact view)
  • On hover

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Walkthrough

The changes introduce a new state management system for displaying progress and controlling the visibility of hidden categories within the budget management application. The BudgetTable component now manages these states and passes them to the BudgetTotals component, which has been updated to handle this new functionality. Additionally, several components have been enhanced with hover functionality and improved data handling for budget-related metrics, including the addition of a new BarGraphVertical component for visualizing budget data.

Changes

Files Change Summary
packages/desktop-client/src/components/budget/BudgetTable.jsx Introduced showProgress state; removed old hidden categories toggle; passed new props to BudgetTotals.
packages/desktop-client/src/components/budget/BudgetTotals.tsx Modified props to manage visibility of hidden categories and progress; added a new Legend component.
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx Added hover functionality and improved budget data rendering; integrated bar graph visualization.
packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx Implemented hover state and enhanced budget calculations; added bar graph visualization based on hover state.
packages/desktop-client/src/components/reports/graphs/BarGraphVertical.tsx Introduced BarGraphVertical component for rendering vertical bar charts of budget data.
packages/loot-core/src/types/prefs.d.ts Added new boolean property 'budget.showProgress' to LocalPrefs type for managing progress display preferences.
packages/desktop-client/src/style/themes/*.ts Added new report color constants (reportsLightRed, reportsLightGreen, reportsPurple, reportsLightPurple) to enhance color palette for reports.

Possibly related PRs

Suggested labels

:sparkles: Merged

Suggested reviewers

  • MikesGlitch

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/budget/ExpenseCategory.tsx (1)

78-78: LGTM!

The addition of the height property to the Row component aligns with the PR objective of introducing visual enhancements to the budget management application. Setting a fixed height ensures consistent spacing and alignment of expense categories, which can enhance the user experience.

Please consider the following suggestions:

  • Ensure that the fixed height of 44 accommodates all necessary content within the Row component and provides sufficient padding.
  • Test the responsiveness of the Row component with the fixed height to ensure that it adapts well to different screen sizes and device orientations.
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 420aad0 and 64c685d.

Files selected for processing (9)
  • packages/desktop-client/src/components/budget/ExpenseCategory.tsx (1 hunks)
  • packages/desktop-client/src/components/budget/report/ReportComponents.tsx (4 hunks)
  • packages/desktop-client/src/components/budget/rollover/RolloverComponents.tsx (4 hunks)
  • packages/desktop-client/src/components/reports/graphs/BarGraphVertical.tsx (1 hunks)
  • packages/desktop-client/src/style/themes/dark.ts (1 hunks)
  • packages/desktop-client/src/style/themes/development.ts (1 hunks)
  • packages/desktop-client/src/style/themes/light.ts (1 hunks)
  • packages/desktop-client/src/style/themes/midnight.ts (1 hunks)
  • upcoming-release-notes/3424.md (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/desktop-client/src/style/themes/light.ts
Additional comments not posted (13)
packages/desktop-client/src/components/reports/graphs/BarGraphVertical.tsx (5)

1-8: LGTM!

The imports are correctly specified and follow the proper syntax. The imported dependencies are relevant to the functionality of the component.


9-16: LGTM!

The barGraphBudgetCategory type definition correctly specifies the fields and their corresponding data types. Exporting the type definition makes it accessible to other modules if needed.


17-112: Skipping the commented-out code segment.

The commented-out code suggests potential features that could be implemented later, such as a custom tooltip component. However, it does not affect the current functionality of the component.


113-116: LGTM!

The BarGraphVerticalProps type definition correctly specifies the expected properties and their corresponding data types. The style prop is optional, allowing flexibility in styling the component, while the data prop is required and expects an array of barGraphBudgetCategory objects.


118-181: LGTM!

The BarGraphVertical component correctly utilizes the recharts library to render a vertical bar chart. The responsive container ensures that the chart adapts to its parent dimensions, while the stacked bar configuration effectively represents the budget data, with each category represented by multiple color-coded bars. The hiding of XAxis and YAxis labels focuses the user's attention on the bars themselves. The component correctly handles the data prop and renders the chart accordingly.

packages/desktop-client/src/style/themes/development.ts (1)

193-193: LGTM!

The new color constant reportsPurple is correctly added to the theme file. It follows the existing naming convention and expands the color options available for reporting purposes.

packages/desktop-client/src/style/themes/dark.ts (1)

194-194: LGTM!

The addition of the reportsPurple color constant is a straightforward change that expands the color palette for reports. The naming convention is consistent, and the color value is sourced from the existing colorPalette object.

packages/desktop-client/src/style/themes/midnight.ts (1)

196-196: LGTM!

The addition of the reportsPurple color constant is consistent with the existing color constants used for reporting purposes. It follows the naming convention and uses a color value from the colorPalette module.

This change expands the color options available for reporting features in the application without introducing any breaking changes.

packages/desktop-client/src/components/budget/report/ReportComponents.tsx (1)

Line range hint 225-506: LGTM!

The CategoryMonth component has been enhanced with hover functionality to display a tooltip with a bar graph, providing a better visual representation of the budget data. The implementation looks solid with the following highlights:

  • The hover state is correctly managed using useCallback for pointer events and a timeout to delay the hover effect.
  • The useEffect hook is used to reset the hover state whenever the component updates, ensuring consistency.
  • The budget data fetching logic using useRolloverSheetValue and the structuring of the data array for the bar graph is implemented correctly.
  • The BarGraphVertical component is conditionally rendered based on the isHovered state, which is the expected behavior.
  • The component is using memoization with memo, which can help optimize performance by avoiding unnecessary re-renders.

Great job with the enhancements!

packages/desktop-client/src/components/budget/rollover/RolloverComponents.tsx (4)

211-234: Hover state management logic looks good!

The isHovered state variable and handlePointerEnter, handlePointerLeave functions effectively manage the hover state. The use of a timeout to delay the hover effect is a nice touch to prevent flickering on quick mouse movements. Forcing the tooltip to close whenever the component's disablement state changes ensures that the UI remains responsive.


236-260: Bar graph data calculation is comprehensive and accurate.

The bar graph data is calculated using the category's budgeted amount (catBudgeted), spent amount (catSumAmount), and balance (catBalance). The budget, spent, remaining, overBudget, and carryover metrics provide a comprehensive overview of the category's budget performance. The logic handles edge cases like overspending and negative balances correctly.


264-265: Addition of hover event handlers to the component's layout is correct.

The onMouseEnter and onMouseLeave event handlers are correctly added to the View component that wraps the category row. This ensures that the hover state is triggered when the user hovers over any part of the category row.


485-486: Rendering the bar graph component on hover is visually appealing and informative.

The BarGraphVertical component is rendered when the isHovered state is true. The styling ensures that the bar graph is positioned correctly below the category row and is visually aligned with the budget, spent, and balance columns. The flexGrow style allows the bar graph to expand to fill the available space.

upcoming-release-notes/3424.md Show resolved Hide resolved
@Jonathan-Fang
Copy link
Contributor

Thanks @Teprifer for the tip on trying out the edge build with the deploy preview link.

I'm finding all the possible permutations confusing and unintuitive at first glance, although I understand they are supposed to work with rollover.

And perhaps the use-case I was looking for is far more simplistic than what is being suggested here.

image
Note: Purple flag means that a goal has been set for this category.
I'm attaching an image here of how a "budget graph" looked like on Aspire Budgeting, defunct Google Sheets envelope budgeting solution. It was a tiny pie chart, and would change colors from green to orange, depending on how much money compared against the goal of what needed to be budgeted.

image
If we go the bar graph route, this is what I would suggest (excuse my rough MS Paint)

I'm honestly not sure how to deal with rollover, but I think that 15 different combinations of colors is much.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/budget/report/ReportComponents.tsx (1)

501-511: Consider extracting the bar graph rendering logic into a separate component.

To improve code readability and reusability, consider extracting the bar graph rendering logic into a separate component. This will help keep the CategoryMonth component focused on its primary responsibility of rendering the category's budget, spent, and balance, while delegating the bar graph rendering to a dedicated component.

Here's an example of how you can extract the bar graph rendering logic:

+const CategoryMonthBarGraph = ({ data, isHovered }: { data: barGraphBudgetCategory[], isHovered: boolean }) => {
+  return (
+    <View
+      style={{
+        height: 13,
+        marginTop: -5,
+      }}
+    >
+      {isHovered && (
+        <BarGraphVertical style={{ flexGrow: 1 }} data={data} />
+      )}
+    </View>
+  );
+};
+
// ...

return (
  <View
    // ...
  >
    // ...
    {showProgress && (
-     <View
-       style={{
-         height: 13,
-         marginTop: -5,
-       }}
-     >
-       {isHovered && (
-         <BarGraphVertical style={{ flexGrow: 1 }} data={data} />
-       )}
-     </View>
+     <CategoryMonthBarGraph data={data} isHovered={isHovered} />
    )}
  </View>
);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 64c685d and d5ab742.

Files selected for processing (7)
  • packages/desktop-client/src/components/budget/BudgetTable.jsx (2 hunks)
  • packages/desktop-client/src/components/budget/BudgetTotals.tsx (2 hunks)
  • packages/desktop-client/src/components/budget/ExpenseCategory.tsx (3 hunks)
  • packages/desktop-client/src/components/budget/report/ReportComponents.tsx (4 hunks)
  • packages/desktop-client/src/components/budget/rollover/RolloverComponents.tsx (4 hunks)
  • packages/desktop-client/src/components/common/Menu.tsx (1 hunks)
  • packages/loot-core/src/types/prefs.d.ts (1 hunks)
Files skipped from review due to trivial changes (1)
  • packages/desktop-client/src/components/common/Menu.tsx
Files skipped from review as they are similar to previous changes (2)
  • packages/desktop-client/src/components/budget/ExpenseCategory.tsx
  • packages/desktop-client/src/components/budget/rollover/RolloverComponents.tsx
Additional comments not posted (9)
packages/loot-core/src/types/prefs.d.ts (1)

73-73: LGTM!

The addition of the 'budget.showProgress': boolean; property to the LocalPrefs type is a valid change that expands the configuration options for budget-related preferences. It allows users to specify whether to display progress indicators in the budget section, providing more granular control over the user interface related to budget management.

packages/desktop-client/src/components/budget/BudgetTotals.tsx (3)

26-29: LGTM!

The BudgetTotals component has been updated to use the new props for managing the visibility of hidden categories and progress bars, which is consistent with the changes made to the BudgetTotalsProps type.


86-93: Approve the updated menu selection handling.

The menu selection handling has been updated to use the new props for managing the visibility of hidden categories and progress bars. This aligns with the changes made to the BudgetTotalsProps type and enhances the menu functionality by providing independent toggles for each feature.


104-111: LGTM!

The menu items now include toggles for both showHiddenCategories and showProgress props, allowing users to control these features directly from the menu. This enhances the user experience and is consistent with the updates made to the menu selection handling.

packages/desktop-client/src/components/budget/BudgetTable.jsx (3)

44-46: LGTM!

The introduction of the showProgress state variable using the useLocalPref hook is a good addition. It follows the existing pattern in the component and allows for persisting the user's preference for showing or hiding progress-related elements.


Line range hint 1-300: LGTM!

The removal of the onToggleHiddenCategories and toggleHiddenCategories functions is a good change. It helps to keep the component focused on its primary responsibilities and improves the separation of concerns.

As long as the responsibility of toggling the visibility of hidden categories is properly handled in the BudgetTotals component, this change should not have a negative impact on the functionality of the component.


200-203: Verify the impact on the BudgetTotals component.

The BudgetTotals component is now receiving props related to managing the visibility of hidden categories and progress. This suggests a shift in the responsibility of managing these states from the parent component to the child component.

Please ensure that the BudgetTotals component is updated to handle these new props correctly and that the overall logic and structure of the component remain cohesive.

Run the following script to verify the usage of these props in the BudgetTotals component:

Verification successful

Verification complete: Changes correctly implemented in BudgetTotals

The BudgetTotals component has been successfully updated to handle the new props related to managing the visibility of hidden categories and progress. The component is located in packages/desktop-client/src/components/budget/BudgetTotals.tsx and includes the following new props:

  • setShowHiddenCategoriesPef
  • showHiddenCategories
  • setShowProgress
  • showProgress

These props are correctly defined in the component's props type and are passed down from the BudgetTable component. The recent changes to the file, including its conversion to TypeScript and added translation support, indicate that the component is being actively maintained and improved.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new props in the `BudgetTotals` component.

# Test: Search for the usage of the new props. Expect: Usage in the `BudgetTotals` component.
rg --type jsx -A 5 $'setShowHiddenCategoriesPef|showHiddenCategories|setShowProgress|showProgress' packages/desktop-client/src/components/budget/BudgetTotals.jsx

Length of output: 190


Script:

#!/bin/bash
# Description: Locate BudgetTotals.jsx and search for new props usage

# Step 1: Find the BudgetTotals.jsx file
echo "Searching for BudgetTotals.jsx file:"
fd BudgetTotals.jsx

# Step 2: If the file is found, search for the new props
echo -e "\nSearching for new props usage:"
fd BudgetTotals.jsx --exec grep -n -A 5 'setShowHiddenCategoriesPef\|showHiddenCategories\|setShowProgress\|showProgress' {} \;

Length of output: 314


Script:

#!/bin/bash
# Description: Investigate the location and recent changes of BudgetTotals component

# Step 1: Search for any file containing "BudgetTotals" in its name
echo "Searching for files containing 'BudgetTotals' in the name:"
fd BudgetTotals

# Step 2: Search for "BudgetTotals" content in all files
echo -e "\nSearching for 'BudgetTotals' content in all files:"
rg "BudgetTotals" -n -C 2

# Step 3: Check git history for recent changes related to BudgetTotals
echo -e "\nChecking git history for BudgetTotals changes:"
git log -n 5 --pretty=format:"%h - %s" --grep="BudgetTotals"

Length of output: 6770

packages/desktop-client/src/components/budget/report/ReportComponents.tsx (2)

227-250: Hover functionality implementation looks good!

The hover functionality is implemented correctly using the isHovered state variable and hoverTimeoutRef ref. The handlePointerEnter and handlePointerLeave callbacks update the hover state with a timeout mechanism, providing a smooth user experience. The useEffect hook ensures that the hover state is reset whenever the component updates, preventing any stale state issues.


212-212: Good usage of useRolloverSheetValue and useLocalPref hooks.

The useRolloverSheetValue hook is used effectively to retrieve the necessary budget-related metrics (catSumAmount, catBudgeted, and catBalance) for rendering the bar graph. Organizing the retrieved values into a data array makes it convenient to pass the data to the BarGraphVertical component.

The useLocalPref hook is used appropriately to manage the visibility of the progress indicators based on user preferences, providing flexibility in the UI.

Also applies to: 252-276

@MikesGlitch
Copy link
Contributor

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Sep 18, 2024

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@carkom
Copy link
Contributor Author

carkom commented Sep 18, 2024

I've added a menu option and a legend in the menu tooltip.

I also, decreased permutations by about half. Only using 6 colors that follow an easy logic. (I hope - let me know)

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

Commits

Files that changed from the base of the PR and between 85d86b6 and 083058a.

Files selected for processing (1)
  • packages/desktop-client/src/components/budget/BudgetTotals.tsx (2 hunks)
Additional context used
GitHub Check: lint
packages/desktop-client/src/components/budget/BudgetTotals.tsx

[warning] 3-3:
There should be no empty line within import group


[warning] 151-151:
Delete ··

Additional comments not posted (4)
packages/desktop-client/src/components/budget/BudgetTotals.tsx (4)

10-10: LGTM!

The import statement for the Text component is valid and necessary for the component.


16-44: Approve the new Legend component.

The introduction of the Legend component is a valuable addition to the codebase. It enhances the user interface by providing clear visual cues for different categories associated with progress bars. The component's implementation is straightforward and follows the common React component structure.

The Legend component aligns well with the PR objectives of improving the user experience with visual legends.


48-51: The past review comment suggesting to fix the typo in the prop name setShowHiddenCategoriesPef is still valid.

Please apply this diff to fix the typo:

-  setShowHiddenCategoriesPef: (value: boolean) => void;
+  setShowHiddenCategoriesPref: (value: boolean) => void;

Line range hint 65-172: Approve the updates to the menu selection handling and the use of the Legend component.

The updates to the menu selection handling align well with the modifications made to the BudgetTotalsProps type and the new props for managing the visibility of hidden categories and progress bars. The inclusion of toggles for showHiddenCategories and showProgress in the menu items allows users to control these features directly from the menu, enhancing the user experience.

The use of the Legend component in the custom tooltip for the showProgress menu item is a great addition. It provides clear visual cues for different categories associated with progress bars, improving the user interface and aligning with the PR objectives.

Tools
GitHub Check: lint

[warning] 151-151:
Delete ··

@youngcw
Copy link
Member

youngcw commented Sep 22, 2024

Woah strange... It shows for me. It's coded in. What browser and os are you using so I can t/s?

Brave on Linux

@Teprifer
Copy link

Woah strange... It shows for me. It's coded in. What browser and os are you using so I can t/s?

If it helps, it shows me for in Chrome and Firefox, windows 11. A nice addition, thanks :)


green
A flip of the purples and green might work as I had a similar thought but I'd have to see it to know. I held off on commenting as I didn't feel too strongly about it and figure others would bring it up.

For positive spent value situation, I'm leaning towards just having the bar be empty, so that the user knows the bar is still working, but its a positive spent value.

Yeah empty would probably be better than no bar for the 'is it working' aspect.

@Jonathan-Fang
Copy link
Contributor

@carkom
image

Add the switch component to the "show hidden categories" line like the "show progress bars" line has

I had brought up a separate request, and this is actually a perfect solution for it! The toggle allows the user to know when it's been turned on and turned off.

Other than renaming the button as you change it.. ¯⁠\⁠_⁠(⁠ツ⁠)⁠_⁠/⁠¯

@Jonathan-Fang
Copy link
Contributor

Jonathan-Fang commented Sep 24, 2024

image

@carkom , unless I'm doing something wrong, I'm on Chrome and Microsoft Edge, Windows 11 and I don't see the toggle for "show hidden categories" like "show progress bars" has, as shown in the image above.

#3368

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

Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/budget/BudgetTotals.tsx (1)

119-172: LGTM: Enhanced Menu functionality with minor suggestion

The changes to the Menu component are well-implemented and align with the PR objectives:

  • The increased menu width accommodates the new items.
  • New menu items for visibility management are correctly implemented.
  • The custom tooltip with legends enhances user understanding of the progress bars feature.

Consider extracting the custom tooltip content into a separate component for better code organization and reusability. This would make the Menu items definition cleaner and easier to maintain.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c612a80 and a241d87.

Files selected for processing (1)
  • packages/desktop-client/src/components/budget/BudgetTotals.tsx (2 hunks)
Additional comments not posted (5)
packages/desktop-client/src/components/budget/BudgetTotals.tsx (5)

4-4: LGTM: New import for useSyncedPref

The addition of the useSyncedPref hook import is appropriate for managing synchronized preferences, which aligns with the new visibility management functionality.


16-44: LGTM: New Legend component

The Legend component is a well-structured and reusable addition that enhances the UI by providing visual cues for different categories. Its implementation is clean and follows good React practices.


48-51: LGTM: New props for visibility management

The addition of setShowHiddenCategories, showHiddenCategories, setShowProgress, and showProgress props enhances user control over the budget display, aligning well with the PR objectives. The prop names are clear and descriptive.


58-61: LGTM: Implementation of visibility management

The BudgetTotals component correctly implements the new visibility management functionality using the added props. The use of useSyncedPref for getting the budget type is appropriate and consistent with the new import.

Also applies to: 65-65


Line range hint 1-191: Overall assessment: Well-implemented feature with good attention to user experience

The changes in this file effectively implement the budget bar graph feature as described in the PR objectives. Key points:

  1. The new Legend component enhances visual understanding.
  2. Visibility management for hidden categories and progress bars is well-implemented.
  3. The menu updates provide clear user controls for the new features.
  4. The custom tooltip with legends improves user comprehension of the progress bars.

The code is clean, well-structured, and aligns with React best practices. The only suggestion is to consider extracting the custom tooltip content into a separate component for better maintainability.

Great job on implementing this feature!

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

Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/budget/BudgetTotals.tsx (1)

119-172: LGTM: Enhanced menu with new visibility options and legend tooltip

The menu has been successfully updated with new items for controlling the visibility of hidden categories and progress bars. The custom tooltip with legends for the progress bars is a great addition that enhances user understanding.

Consider extracting the legend rendering logic into a separate function to improve code organization. This would make the customTooltip prop more readable. For example:

const renderLegends = () => (
  <View style={{ padding: 10, paddingBottom: 0 }}>
    {budgetType === 'rollover' && (
      <>
        <Legend title="Rollover added" color={theme.reportsLightPurple} />
        <Legend title="Rollover spent" color={theme.reportsLightGreen} />
        <Legend title="Rollover overspent" color={theme.reportsLightRed} />
      </>
    )}
    <Legend title="Budgeted" color={theme.reportsPurple} />
    <Legend title="Spent" color={theme.reportsGreen} />
    <Legend title="Overspent" color={theme.reportsRed} />
  </View>
);

// Then in the menu items:
customTooltip: renderLegends()

This refactoring would improve the readability and maintainability of the code.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a241d87 and c84eafe.

Files selected for processing (1)
  • packages/desktop-client/src/components/budget/BudgetTotals.tsx (2 hunks)
Additional comments not posted (4)
packages/desktop-client/src/components/budget/BudgetTotals.tsx (4)

4-4: LGTM: New import for useSyncedPref

The addition of the useSyncedPref hook import is appropriate for managing synchronized preferences, which aligns with the new visibility management features.


16-44: LGTM: New Legend component enhances UI

The new Legend component is a well-structured addition that enhances the UI by providing clear visual cues for different budget categories. This aligns well with the PR objectives of improving the visual representation of budget data.


48-51: LGTM: New props for visibility management

The new props setShowHiddenCategories, showHiddenCategories, setShowProgress, and showProgress are well-named and align with the PR objectives of enhancing user control over budget visualization. The previous typo in the prop name has been correctly addressed.


58-61: LGTM: Updated component with new visibility management props

The BudgetTotals component has been correctly updated to use the new visibility management props. The addition of useSyncedPref for the budget type is a good improvement for maintaining consistent preferences across the application.

Also applies to: 65-65

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

Outside diff range and nitpick comments (2)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (1)

Line range hint 1-624: Overall improvements with some optimization opportunities

The changes to the ExpenseCategoryMonth component significantly enhance the budget management interface by introducing progress display features and improved menu interactions. The new hover functionality and conditional rendering of the BarGraphVertical component provide users with more detailed budget information.

However, there are a few areas that could be further optimized:

  1. Consider memoizing complex calculations or components to improve performance, especially if this component is rendered frequently.
  2. The file is becoming quite large and complex. Consider splitting it into smaller, more focused components for better maintainability.
  3. Ensure that all new UI elements are fully accessible, including proper ARIA labels and keyboard navigation support.

Overall, the changes are a positive improvement to the budget management functionality.

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

234-244: Simplify hover state management by removing unnecessary timeout

In the handlePointerEnter function, setTimeout is used with a delay of 0, which effectively does not delay execution. This adds unnecessary complexity without any benefit. You can simplify the hover state management by removing the setTimeout and the associated hoverTimeoutRef.

Apply this diff to simplify the code:

- const [isHovered, setIsHover] = useState(false);

- const hoverTimeoutRef = useRef<ReturnType<typeof setTimeout>>();

- const handlePointerEnter = useCallback(() => {
-   const timeout = setTimeout(() => {
-     setIsHover(true);
-   }, 0);
-   hoverTimeoutRef.current = timeout;
- }, []);

- const handlePointerLeave = useCallback(() => {
-   if (hoverTimeoutRef.current) {
-     clearTimeout(hoverTimeoutRef.current);
-   }
-   setIsHover(false);
- }, []);
+ const [isHovered, setIsHovered] = useState(false);

+ const handlePointerEnter = useCallback(() => {
+   setIsHovered(true);
+ }, []);

+ const handlePointerLeave = useCallback(() => {
+   setIsHovered(false);
+ }, []);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c84eafe and e291fe4.

Files selected for processing (3)
  • packages/desktop-client/src/components/budget/BudgetTable.jsx (2 hunks)
  • packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (4 hunks)
  • packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/desktop-client/src/components/budget/BudgetTable.jsx
Additional context used
Learnings (1)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (1)
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx:274-274
Timestamp: 2024-09-24T20:27:51.684Z
Learning: UnderKoen prefers not to include changes that would significantly alter many files in a PR focusing on specific functionality.
Additional comments not posted (5)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (4)

15-15: LGTM: New imports for progress display feature

The new imports for useLocalPref, BarGraphVertical, and barGraphBudgetCategory type are appropriate for implementing the new progress display feature and managing local preferences.

Also applies to: 23-26


247-257: LGTM: Budget calculations

The new calculations for budget-related values are correct and provide a comprehensive view of the category's financial state.


298-299: LGTM: Conditional rendering of BarGraphVertical

The conditional rendering of the BarGraphVertical component based on the showProgress preference and hover state is implemented correctly.

Also applies to: 302-302, 516-527


413-421: ⚠️ Potential issue

Remove inline hover styles

The use of inline hover styles is not supported in React. Consider moving these styles to a CSS stylesheet or using a CSS-in-JS solution that supports pseudo-classes.

Remove the inline hover styles and create a separate CSS class or styled component:

valueStyle={{
  cursor: 'default',
  margin: 1,
  padding: '0 4px',
  borderRadius: 4,
- ':hover': {
-   boxShadow: 'inset 0 0 0 1px ' + theme.mobileAccountShadow,
-   backgroundColor: theme.tableBackground,
- },
}}

Then, add these styles to a separate CSS file or use a CSS-in-JS solution that supports pseudo-classes.

Likely invalid or redundant comment.

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

Line range hint 219-223: Good implementation of user preference handling

The use of useLocalPref to retrieve and manage the showProgress preference is appropriate and correctly implemented. This allows for consistent user experience based on saved preferences.

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

Outside diff range and nitpick comments (3)
packages/desktop-client/src/components/budget/BudgetTotals.tsx (3)

16-44: LGTM: New Legend component enhances UI clarity

The Legend component is well-implemented and enhances the user interface by providing clear visual cues for the progress bars. It follows React best practices and uses appropriate styling for accessibility.

Consider making the component more flexible by allowing customization of the dot size and spacing. You could add optional props like dotSize and spacing with default values:

function Legend({ 
  title, 
  color, 
  dotSize = 14, 
  spacing = 5 
}: { 
  title: string; 
  color: string; 
  dotSize?: number; 
  spacing?: number;
}) {
  // ... use dotSize and spacing in the style objects
}

This change would make the component more reusable in different contexts.


58-61: LGTM: BudgetTotals component updated with new visibility controls

The changes to the BudgetTotals component successfully implement the new visibility control features. The use of useSyncedPref for getting the budget type and the updates to the menu selection handling are appropriate and align with the PR objectives.

To improve code clarity, consider extracting the menu selection handling logic into a separate function. This would make the component more readable and easier to maintain. For example:

const handleMenuSelect = (type: string) => {
  switch (type) {
    case 'showHiddenCategories':
      setShowHiddenCategories(!showHiddenCategories);
      break;
    case 'showProgress':
      setShowProgress(!showProgress);
      break;
    case 'expandAllCategories':
      expandAllCategories();
      setMenuOpen(false);
      break;
    case 'collapseAllCategories':
      collapseAllCategories();
      setMenuOpen(false);
      break;
  }
};

Then, you can use this function in the onMenuSelect prop:

onMenuSelect={handleMenuSelect}

This refactoring would make the component's logic easier to understand and maintain.

Also applies to: 65-65, 119-119, 123-126, 137-145


145-172: LGTM: Legend components enhance menu tooltip

The addition of Legend components in the menu tooltip significantly improves the user's understanding of the progress bar colors. The conditional rendering based on the budget type is implemented correctly and aligns well with the PR objectives.

To improve code organization and reusability, consider extracting the Legend components into a separate function or component. This would make the code more modular and easier to maintain. For example:

const RenderLegends = ({ budgetType }: { budgetType: string }) => (
  <View style={{ padding: 10, paddingBottom: 0 }}>
    {budgetType === 'rollover' && (
      <>
        <Legend title="Rollover added" color={theme.reportsLightPurple} />
        <Legend title="Rollover spent" color={theme.reportsLightGreen} />
        <Legend title="Rollover overspent" color={theme.reportsLightRed} />
      </>
    )}
    <Legend title="Budgeted" color={theme.reportsPurple} />
    <Legend title="Spent" color={theme.reportsGreen} />
    <Legend title="Overspent" color={theme.reportsRed} />
  </View>
);

Then, you can use this component in the customTooltip prop:

customTooltip: <RenderLegends budgetType={budgetType} />

This refactoring would improve code organization and make it easier to update or extend the legends in the future.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e291fe4 and 7f2b7a2.

Files selected for processing (3)
  • packages/desktop-client/src/components/budget/BudgetTotals.tsx (2 hunks)
  • packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (5 hunks)
  • packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx
  • packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx
Additional comments not posted (2)
packages/desktop-client/src/components/budget/BudgetTotals.tsx (2)

4-4: LGTM: New import for useSyncedPref

The addition of the useSyncedPref import is appropriate for managing synchronized preferences, which aligns with the new visibility management functionality.


48-51: LGTM: New props for enhanced visibility control

The addition of setShowHiddenCategories, showHiddenCategories, setShowProgress, and showProgress props aligns well with the PR objectives. These props provide granular control over the visibility of hidden categories and progress bars, enhancing the component's flexibility and user control.

The prop names are correct and consistent, addressing the typo mentioned in previous reviews.

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

🧹 Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (1)

Line range hint 314-549: LGTM: Updated JSX for new functionality

The JSX has been successfully updated to include the new progress bar feature and hover functionality. The conditional rendering of the BarGraphVertical component based on the hover state is implemented correctly.

Enhance accessibility for interactive elements

While the new functionality is well-implemented, consider improving accessibility for screen reader users.

Add appropriate ARIA attributes to the interactive elements. For example:

 <Button
   ref={budgetMenuTriggerRef}
   variant="bare"
   onPress={() => setBudgetMenuOpen(true)}
+  aria-label="Open budget menu"
   style={{
     padding: 3,
   }}
 >
   {/* ... */}
 </Button>

Also, consider adding appropriate aria-labels or aria-describedby attributes to the progress bar elements to provide context for screen reader users.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7f2b7a2 and 9dc8e6c.

📒 Files selected for processing (7)
  • packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (5 hunks)
  • packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx (5 hunks)
  • packages/desktop-client/src/style/themes/dark.ts (1 hunks)
  • packages/desktop-client/src/style/themes/development.ts (1 hunks)
  • packages/desktop-client/src/style/themes/light.ts (1 hunks)
  • packages/desktop-client/src/style/themes/midnight.ts (1 hunks)
  • packages/loot-core/src/types/prefs.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx
  • packages/desktop-client/src/style/themes/dark.ts
  • packages/desktop-client/src/style/themes/development.ts
  • packages/desktop-client/src/style/themes/light.ts
  • packages/desktop-client/src/style/themes/midnight.ts
  • packages/loot-core/src/types/prefs.d.ts
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (1)
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx:274-274
Timestamp: 2024-09-24T20:27:51.684Z
Learning: UnderKoen prefers not to include changes that would significantly alter many files in a PR focusing on specific functionality.
GitHub Check: typecheck
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx

[failure] 10-10:
Duplicate identifier 'css'.

GitHub Check: lint
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx

[warning] 10-10:
There should be no empty line within import group


[warning] 10-10:
'/home/runner/work/actual/actual/node_modules/glamor/index.d.ts' imported multiple times


[warning] 262-262:
Delete ··


[warning] 266-266:
Delete ··


[warning] 269-269:
Insert ··


[warning] 270-270:
Insert ··


[warning] 271-271:
Insert ··


[warning] 272-272:
Insert ··

🔇 Additional comments not posted (3)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (3)

19-30: LGTM: New imports for progress bar feature

The new imports for useLocalPref, BarGraphVertical, and barGraphBudgetCategory are correctly added and necessary for the new progress bar feature.


300-312: LGTM: Data structure for bar graph

The data structure for the bar graph is well-defined and includes all necessary information for rendering the progress bar.


Line range hint 1-649: Summary of changes and suggestions

The changes in this file introduce a new progress bar feature to the budget management system, enhancing the visual representation of budget data. The implementation is generally well-done, with appropriate state management and conditional rendering.

Key points and suggestions:

  1. Remove the duplicate import of css.
  2. Consider memoizing the showProgress value for optimization.
  3. Optimize hover state management by simplifying the handlePointerEnter function and adding dependencies to the useEffect hook.
  4. Refactor complex calculations into separate functions for better maintainability.
  5. Enhance accessibility by adding appropriate ARIA attributes to interactive elements.

These improvements will help optimize performance, increase maintainability, and improve accessibility of the new feature.

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

🧹 Outside diff range and nitpick comments (1)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (1)

Line range hint 312-545: Enhanced UI with improved interactivity and visual representation

The UI changes in the ExpenseCategoryMonth component significantly improve the user experience:

  1. Added hover functionality for better interactivity.
  2. Implemented a conditional rendering of the BarGraphVertical component for visual budget representation.
  3. Updated budget menu and balance menu functionality for easier budget management.

These changes provide users with more intuitive ways to interact with and understand their budget data.

However, there's room for improvement in terms of accessibility:

Enhance accessibility for the budget menu button by adding an aria-label:

<Button
  ref={budgetMenuTriggerRef}
  variant="bare"
  onPress={() => setBudgetMenuOpen(true)}
+ aria-label="Open budget menu"
  style={{
    padding: 3,
  }}
>
  <SvgCheveronDown
    width={14}
    height={14}
    className="hover-visible"
    style={budgetMenuOpen ? { opacity: 1 } : {}}
  />
</Button>

This will make it easier for users relying on screen readers to understand the purpose of the button.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9dc8e6c and ccd5f42.

📒 Files selected for processing (3)
  • packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (5 hunks)
  • packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx (5 hunks)
  • packages/desktop-client/src/components/reports/graphs/BarGraphVertical.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx
  • packages/desktop-client/src/components/reports/graphs/BarGraphVertical.tsx
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (1)
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx:274-274
Timestamp: 2024-09-24T20:27:51.684Z
Learning: UnderKoen prefers not to include changes that would significantly alter many files in a PR focusing on specific functionality.
🔇 Additional comments not posted (3)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (3)

17-17: New imports added for enhanced functionality

The following new imports have been added:

  1. useLocalPref hook from '../../../hooks/useLocalPref'
  2. barGraphBudgetCategory type and BarGraphVertical component from '../../reports/graphs/BarGraphVertical'

These imports suggest the addition of local preference management and a new graphical representation of budget data.

Also applies to: 25-28


298-310: Well-structured data for bar graph representation

The data array of type barGraphBudgetCategory[] is well-organized and includes all necessary information for the bar graph representation. This structure will make it easier to render the graph and manage the budget data visually.


Line range hint 1-645: Summary: Significant improvements to budget management functionality

This update to the EnvelopeBudgetComponents.tsx file, particularly the ExpenseCategoryMonth component, brings substantial enhancements to the budget management feature:

  1. Improved interactivity with hover states and dynamic visual representations.
  2. Added a bar graph for clearer budget visualization.
  3. Enhanced menu functionality for easier budget adjustments.

While the implementation is generally well-done, consider the following minor improvements:

  1. Refactor complex budget calculations into separate functions for better readability.
  2. Enhance accessibility of the budget menu button.
  3. Optimize the hover state management by removing unnecessary timeouts.

These changes significantly improve the user experience while maintaining code quality. Great work overall!

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

🧹 Outside diff range and nitpick comments (2)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (1)

299-300: Implement hover functionality and progress bar

The changes successfully implement the new hover functionality and progress bar feature. The conditional rendering of the BarGraphVertical component when hovered aligns well with the PR objectives.

Consider adding an aria-label to the main View component to improve accessibility:

 <View
   onMouseEnter={handlePointerEnter}
   onMouseLeave={handlePointerLeave}
+  aria-label="Budget category details"
   style={{
     // ...existing styles
   }}
 >
   {/* ... */}
 </View>

Also applies to: 303-303, 519-530

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

216-216: Rename showProgress to showProgressBar for clarity.

The name showProgress is a bit ambiguous. Renaming it to showProgressBar would make it clearer that it specifically controls the visibility of the progress bar.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ccd5f42 and 6146d00.

📒 Files selected for processing (2)
  • packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (5 hunks)
  • packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx (5 hunks)
🧰 Additional context used
📓 Learnings (1)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (1)
Learnt from: UnderKoen
PR: actualbudget/actual#3381
File: packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx:274-274
Timestamp: 2024-09-24T20:27:51.684Z
Learning: UnderKoen prefers not to include changes that would significantly alter many files in a PR focusing on specific functionality.
🪛 GitHub Check: typecheck
packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx

[failure] 510-510:
Type '{ disabled: boolean; carryover: "carryover"; balance: "leftover"; goal: "goal"; budgeted: "budget"; longGoal: "long-goal"; }' is not assignable to type 'IntrinsicAttributes & Omit<CellValueProps<SheetNames, SheetFields>, "children" | "binding"> & { ...; }'.

🔇 Additional comments (10)
packages/desktop-client/src/components/budget/envelope/EnvelopeBudgetComponents.tsx (3)

17-17: New feature: Budget progress bar graph

The addition of useLocalPref and BarGraphVertical imports, along with the showProgress preference, indicates the implementation of a new budget progress bar graph feature. This aligns well with the PR objectives.

Also applies to: 25-28, 206-206


283-295: Well-structured data for budget bar graph

The data structure is well-organized and contains all the necessary information for the budget bar graph. This implementation aligns perfectly with the PR objectives.


364-398: Comprehensive BudgetMenu implementation

The BudgetMenu component provides useful functionality for managing budgets, including options to copy last month's average, set months average, and apply budget templates. This implementation enhances user experience and aligns well with the PR objectives.

packages/desktop-client/src/components/budget/tracking/TrackingBudgetComponents.tsx (7)

241-244: ****


246-307: Simplify complex nested ternary expressions for better readability.

The nested ternary expressions in the data object can be difficult to read and maintain. Refactoring these expressions into descriptive helper functions or variables will enhance code clarity and maintainability.


334-460: LGTM!

The budget cell rendering logic looks good. The editing state is properly handled, and the menu actions are wired up correctly.


461-493: Ensure accessibility by adding aria-label to interactive elements.

The <span> element used as a button does not have an aria-label, which can hinder accessibility for screen readers. Consider adding an aria-label or using a button element to improve accessibility.


495-535: LGTM!

The balance cell rendering logic looks good. The BalanceWithCarryover component is used correctly, and the menu actions are wired up properly.

🧰 Tools
🪛 GitHub Check: typecheck

[failure] 510-510:
Type '{ disabled: boolean; carryover: "carryover"; balance: "leftover"; goal: "goal"; budgeted: "budget"; longGoal: "long-goal"; }' is not assignable to type 'IntrinsicAttributes & Omit<CellValueProps<SheetNames, SheetFields>, "children" | "binding"> & { ...; }'.


538-548: Optimize rendering performance of the bar graph.

Rendering BarGraphVertical conditionally on hover may lead to performance issues if the component is complex or if there are many instances of CategoryMonth. Consider memoizing the BarGraphVertical component or rendering it unconditionally but controlling its visibility with CSS to improve performance.


509-515: ⚠️ Potential issue

Fix the type error in BalanceWithCarryover props.

The static analysis tool reported a type error in the BalanceWithCarryover component's props. The prop types seem to be incorrectly defined.

To verify the type error, run the following script:

If the script confirms the type mismatch, update the BalanceWithCarryover component's prop types to match the usage:

type BalanceWithCarryoverProps = {
  disabled: boolean;
  carryover: Binding<'tracking-budget', 'carryover'>;
  balance: Binding<'tracking-budget', 'leftover'>;
  goal: Binding<'tracking-budget', 'goal'>;
  budgeted: Binding<'tracking-budget', 'budget'>;
  longGoal: Binding<'tracking-budget', 'long-goal'>;
};
🧰 Tools
🪛 GitHub Check: typecheck

[failure] 510-510:
Type '{ disabled: boolean; carryover: "carryover"; balance: "leftover"; goal: "goal"; budgeted: "budget"; longGoal: "long-goal"; }' is not assignable to type 'IntrinsicAttributes & Omit<CellValueProps<SheetNames, SheetFields>, "children" | "binding"> & { ...; }'.

Comment on lines +234 to +282
const catSumAmount = useEnvelopeSheetValue(
envelopeBudget.catSumAmount(category.id),
);
const catBudgeted = useEnvelopeSheetValue(
envelopeBudget.catBudgeted(category.id),
);
const catBalance = useEnvelopeSheetValue(
envelopeBudget.catBalance(category.id),
);
const carryover = catBalance - catSumAmount - catBudgeted;
const overSpent = Math.abs(catSumAmount) > catBudgeted + carryover;

const isCarryoverNegative = carryover < 0;
const absCatSumAmount = Math.abs(catSumAmount);
const totalBudget = catBudgeted + carryover;

// Calculate carryoverSpent
const carryoverSpent = isCarryoverNegative
? null
: absCatSumAmount < carryover
? absCatSumAmount
: carryover;

// Calculate carryoverRemaining
const carryoverRemaining =
absCatSumAmount < carryover ? carryover + catSumAmount : null;

// Calculate spent
const spent = isCarryoverNegative
? absCatSumAmount > catBudgeted
? null
: absCatSumAmount < totalBudget
? absCatSumAmount
: totalBudget
: absCatSumAmount < carryover
? null
: absCatSumAmount < totalBudget
? absCatSumAmount - carryover
: catBudgeted;

// Calculate remaining
const remaining = isCarryoverNegative
? absCatSumAmount > catBudgeted
? null
: !overSpent && catBudgeted + catSumAmount + carryover
: absCatSumAmount < carryover
? catBudgeted
: !overSpent && catBudgeted + catSumAmount + carryover;

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

Simplify complex budget calculations

The budget calculations are correct but use complex nested ternary operators, making the code hard to read and maintain.

Consider refactoring these calculations into separate functions for better readability and maintainability. For example:

function calculateCarryoverSpent(carryover: number, absCatSumAmount: number): number | null {
  if (carryover < 0) {
    return null;
  }
  return absCatSumAmount < carryover ? absCatSumAmount : carryover;
}

// Usage in the component
const carryoverSpent = calculateCarryoverSpent(carryover, absCatSumAmount);

Apply similar refactoring to other complex calculations in this section.

Comment on lines +401 to +448
<EnvelopeSheetCell
name="budget"
exposed={editing}
focused={editing}
width="flex"
onExpose={() => onEdit(category.id, month)}
style={{
borderBottomWidth: showProgress ? 0 : 1,
...(editing && { zIndex: 100 }),
...styles.tnum,
}}
textAlign="right"
valueStyle={{
cursor: 'default',
margin: 1,
padding: '0 4px',
borderRadius: 4,
':hover': {
boxShadow: 'inset 0 0 0 1px ' + theme.mobileAccountShadow,
backgroundColor: theme.tableBackground,
},
}}
valueProps={{
binding: envelopeBudget.catBudgeted(category.id),
type: 'financial',
getValueStyle: makeAmountGrey,
formatExpr: expr => {
return integerToCurrency(expr);
},
unformatExpr: expr => {
return amountToInteger(evalArithmetic(expr, 0));
},
}}
inputProps={{
onBlur: () => {
onEdit(null);
},
style: {
backgroundColor: theme.tableBackground,
},
}}
onSave={amount => {
onBudgetAction(month, 'budget-amount', {
category: category.id,
amount,
});
}}
/>
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve hover effects in EnvelopeSheetCell

The EnvelopeSheetCell component has been updated with new styling and improved functionality for financial values. However, the use of inline styles for hover effects may not work as expected in React.

Consider moving the hover styles to a CSS stylesheet or using a CSS-in-JS library that supports pseudo-classes. For example, using styled-components:

import styled from 'styled-components';

const StyledCellValueText = styled(CellValueText)`
  cursor: default;
  margin: 1px;
  padding: 0 4px;
  border-radius: 4px;

  &:hover {
    box-shadow: inset 0 0 0 1px ${props => props.theme.mobileAccountShadow};
    background-color: ${props => props.theme.tableBackground};
  }
`;

// Then use `StyledCellValueText` instead of `CellValueText`

This will ensure that the hover effects work as intended.

Comment on lines +219 to +232
const [isHovered, setIsHover] = useState(false);

const handlePointerEnter = useCallback(() => {
setIsHover(true);
}, []);

const handlePointerLeave = useCallback(() => {
setIsHover(false);
}, []);

// Force closing the tooltip whenever the disablement state changes
useEffect(() => {
setIsHover(false);
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Improve useEffect dependency array

The hover state management is well-implemented. However, the useEffect hook is missing dependencies, which may lead to unexpected behavior.

Consider adding relevant dependencies to the useEffect hook:

 useEffect(() => {
   setIsHover(false);
- }, []);
+ }, [/* Add relevant dependencies here */]);

This will ensure that the effect runs when necessary, improving the reliability of the hover state management.

Committable suggestion was skipped due to low confidence.

Comment on lines +231 to +239
const [isHovered, setIsHover] = useState(false);

const handlePointerEnter = useCallback(() => {
setIsHover(true);
}, []);

const handlePointerLeave = useCallback(() => {
setIsHover(false);
}, []);
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

Consider extracting hover state logic into a custom hook.

The hover state logic using useState, useCallback, and useEffect is duplicated in multiple components. Extract it into a reusable custom hook to improve code maintainability and readability.

Here's an example custom hook:

function useHover() {
  const [isHovered, setIsHovered] = useState(false);

  const handleMouseEnter = useCallback(() => {
    setIsHovered(true);
  }, []);

  const handleMouseLeave = useCallback(() => {
    setIsHovered(false);
  }, []);

  return {
    isHovered,
    handleMouseEnter,
    handleMouseLeave,
  };
}

Then use it in the component:

const { isHovered, handleMouseEnter, handleMouseLeave } = useHover();

Copy link
Contributor

github-actions bot commented Oct 6, 2024

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Oct 6, 2024
@Redbox3070
Copy link

Redbox3070 commented Oct 9, 2024

Hi I finally had the chance to try this with my budget. First of all I probably misunderstood what this does, as I was expecting a visual way to see how far i am from a budget goal template.

Now that I think I understood the various colors to me this feels very complex (also brilliant honestly). To me it is simpler just looking at numbers if I want to have that much insight. Personally (and this is just my budget philosophy, maybe others have different view), I do not find useful knowing that my balance is made up of rollover from the previous month or amount budgeted this month. Same for the spent, I do not find it is useful knowing that I spent the rollover or the portion I budgeted this month.

My suggestion (based on my use case) would be to focus on providing less information:

  • Entire bar is green and represents budgeted + rollover, red portion grows and is the amount spent. If the entire bar is red you have 0 balance. Negative rollover could be considered as an already spent portion, so if it is 30 from the previous month and you have budgeted 30, the entire bar is red, showing that you have 0 balance. If you had budgeted 60, half the bar is red and the half is green, were green is the remainder balance. Overspent might be ignored, just the entire bar is red or overlap with a darker red.
  • I tried aspire in the past and I like @Jonathan-Fang so maybe consider using a similar graphic way to show how far you are from a budget goal template

@github-actions github-actions bot removed the Stale label Oct 10, 2024
Copy link
Contributor

👋 Hi! It looks like this PR has not had any changes for a week now. Would you like someone to review this PR? If so - please remove the "[WIP]" prefix from the PR title. That will let the community know that this PR is open for a review.

@github-actions github-actions bot added the Stale label Oct 17, 2024
Copy link
Contributor

This PR was closed because it has been stalled for 5 days with no activity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants