Skip to content

Fix Spending Analysis preset date range refresh flow#10

Merged
niyazmft merged 2 commits intomainfrom
fix-spending-analysis-preset-dates-v20260320-1415-16626626647949589162
Mar 21, 2026
Merged

Fix Spending Analysis preset date range refresh flow#10
niyazmft merged 2 commits intomainfrom
fix-spending-analysis-preset-dates-v20260320-1415-16626626647949589162

Conversation

@niyazmft
Copy link
Copy Markdown
Owner

Fixed a bug where using preset date ranges (e.g., 'Last 30 Days', 'This Year') on the Spending Analysis page caused a runtime crash ('date.toISOString is not a function'). The crash occurred because the shared DateRangePicker emits YYYY-MM-DD strings for presets, while the page logic expected Date objects.

The fix involved updating SpendingAnalysisView.vue to detect and normalize both string and Date object inputs before passing them to the API fetch logic. I also added a comprehensive test suite to ensure this scenario is covered and remains stable. All frontend tests pass.

Fixes #8


PR created automatically by Jules for task 16626626647949589162 started by @niyazmft

- Updated `handleDateRangeUpdate` in `SpendingAnalysisView.vue` to safely handle both `Date` objects (from manual picker) and `YYYY-MM-DD` strings (from preset selections).
- Reverted redundant call to `formatDateForInput` in `fetchData` as inputs are guaranteed strings.
- Added a new unit test suite `frontend/tests/views/SpendingAnalysisView.spec.js` to verify both selection paths.
- Verified that all frontend tests pass, including `DateRangePicker.spec.js` and the new test.

This fixes the runtime error 'date.toISOString is not a function' when clicking presets like 'Last 30 Days' or 'This Year' on the Spending Analysis page.

Co-authored-by: niyazmft <9331133+niyazmft@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the Spending Analysis page where selecting preset date ranges led to a runtime crash. The fix enhances the date range handling mechanism to gracefully accept various input formats (both strings and Date objects), ensuring the feature functions reliably. Comprehensive tests have been added to validate the solution and maintain stability.

Highlights

  • Bug Fix: Resolved a runtime crash on the Spending Analysis page that occurred when using preset date ranges, specifically when date.toISOString was called on a string instead of a Date object.
  • Date Handling Improvement: Modified the SpendingAnalysisView.vue component to correctly process date inputs from the DateRangePicker, accommodating both YYYY-MM-DD string formats and Date objects before passing them to the API fetch logic.
  • Test Coverage: Introduced a new, comprehensive test suite (SpendingAnalysisView.spec.js) to validate the updated date range handling logic, ensuring stability and preventing future regressions for both string and Date object inputs.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses a crash on the Spending Analysis page by correctly handling different date input types. The addition of a comprehensive test suite is a valuable contribution that improves the stability of this component. I have one suggestion to simplify the implementation in SpendingAnalysisView.vue by removing redundant logic, which will enhance maintainability.

Comment on lines +130 to +132
const startStr = typeof start === 'string' ? start : utils.formatDateForInput(start);
const endStr = typeof end === 'string' ? end : utils.formatDateForInput(end);
fetchData(startStr, endStr);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While this change correctly fixes the issue, the explicit typeof check here is redundant. The utils.formatDateForInput function already contains logic to safely handle both string and Date inputs, so this implementation introduces unnecessary code duplication.

To improve maintainability and centralize the type-handling logic, it's best to rely on the utility function's existing capabilities. I recommend simplifying this back to a direct call to the utility function.

    fetchData(utils.formatDateForInput(start), utils.formatDateForInput(end));

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I think the main fix should be in the shared DateRangePicker, not handled separately in each page. Since multiple views consume the same component, fixing only SpendingAnalysisView.vue is too narrow for the updated scope of issue #8. This PR helps that page, but I wouldn’t treat it as the complete fix unless the shared picker contract is normalized.

- Updated `applyRange` in `DateRangePicker.vue` to always emit `Date` objects for both manual and preset selections, providing a consistent contract for all consumers.
- Reverted manual type checking in `SpendingAnalysisView.vue` as the picker now guarantees `Date` objects.
- Updated `DateRangePicker.spec.js` to verify `Date` object emission and fixed existing assertions.
- Added a new unit test suite `frontend/tests/views/SpendingAnalysisView.spec.js` using timezone-agnostic `Date.UTC` to verify the view correctly triggers data refreshes.
- Verified that all 13 frontend tests pass correctly.

This fixes the runtime error 'date.toISOString is not a function' on the Spending Analysis page when selecting presets like 'Last 30 Days' or 'This Year'.

Co-authored-by: niyazmft <9331133+niyazmft@users.noreply.github.com>
@niyazmft niyazmft merged commit 5e31f27 into main Mar 21, 2026
2 checks passed
@niyazmft niyazmft deleted the fix-spending-analysis-preset-dates-v20260320-1415-16626626647949589162 branch March 21, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: shared date range picker can break pages using preset or calendar selection

1 participant