Skip to content

fix(views): use queryOptions.start for +1 week button (closes #817)#819

Open
TimeToBuildBob wants to merge 2 commits intoActivityWatch:masterfrom
TimeToBuildBob:bob/issue-817-search-extend-week
Open

fix(views): use queryOptions.start for +1 week button (closes #817)#819
TimeToBuildBob wants to merge 2 commits intoActivityWatch:masterfrom
TimeToBuildBob:bob/issue-817-search-extend-week

Conversation

@TimeToBuildBob
Copy link
Copy Markdown
Contributor

Summary

Fixes the `TypeError: Cannot read properties of undefined (reading 'subtract')` reported in #817 when clicking the +1 week button on the Search page (and also affects the Report and Graph views).

Root cause

The button's inline expression was:

```pug
@click="start = start.subtract(1, 'week'); search()"
```

But `start` is not a top-level data field — it lives at `queryOptions.start`. Clicking the button accessed an undefined identifier and threw immediately. @realsudarshan diagnosed this exactly in the issue.

Fix

Replace the inline expression with an `extendByWeek()` method per affected view:

```js
extendByWeek() {
this.queryOptions.start = moment(this.queryOptions.start).subtract(1, 'week');
this.generate(); // or this.search() in Search.vue
}
```

The extra `moment(...)` wrapper handles the case where `queryOptions.start` was emitted by the QueryOptions datepicker as a `YYYY-MM-DD` string (it would otherwise still throw on subsequent clicks even after fixing the identifier).

Affected views

  • `src/views/Search.vue` (the one in the bug report) — calls `search()`
  • `src/views/Report.vue` (same pattern, calls `generate()`)
  • `src/views/Graph.vue` (same pattern, calls `generate()`)

Verification

  • `npm run lint` — passes (only pre-existing warnings in vite.config.js / vue.config.js)
  • `npm test` — 14 suites / 61 tests passing
  • Build/manual click-test still recommended; the moment-wrapped subtract handles both the moment-object initial state and the date-string state from the datepicker.

Closes #817.

…yWatch#817)

The '+1 week' button on the Search, Report, and Graph views referenced a
non-existent top-level `start` data field, throwing
`TypeError: Cannot read properties of undefined (reading 'subtract')`
when clicked.

Replace the inline expression with an `extendByWeek()` method that:
- subtracts a week from `queryOptions.start` (the actual data path), and
- wraps with `moment()` so it works whether the value is a moment object
  (initial state) or a date string (after the QueryOptions datepicker
  emits a string).

Reported by @realsudarshan in ActivityWatch#817 with the exact root-cause diagnosis.
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 9, 2026

Greptile Summary

This PR fixes a TypeError crash when clicking the +1 week button on the Search, Report, and Graph views by replacing the broken inline start = start.subtract(...) expression with a proper extendByWeek() method that correctly references this.queryOptions.start and wraps it in moment() to handle both moment-object and date-string inputs from the datepicker.

  • Search.vue, Report.vue, Graph.vue: The inline @click handler (which referenced an undefined start variable) is replaced with a call to the new extendByWeek() method in each component.
  • extendByWeek(): Assigns this.queryOptions.start = moment(this.queryOptions.start).subtract(1, 'week'), then triggers a fresh query via search() or generate(). The moment() wrapper is consistent with how fetchEvents() and search() already consume queryOptions.start elsewhere in each file.

Confidence Score: 5/5

Safe to merge — the change correctly fixes the crash by routing the button click through a properly scoped method in all three views.

The fix is minimal and targeted: it replaces three broken inline handlers with a consistent extendByWeek() method that reads the correct data path. The moment() wrapper is already the established pattern in fetchEvents() and search() for handling queryOptions.start, so no new assumptions are introduced. All three files are touched symmetrically with no new side effects.

No files require special attention.

Important Files Changed

Filename Overview
src/views/Search.vue Adds extendByWeek() method that correctly reads this.queryOptions.start and wraps it in moment() before subtracting; calls search() to refresh results.
src/views/Report.vue Adds extendByWeek() method mirroring Search.vue but calling generate(); pattern is consistent with how fetchEvents already uses moment(this.queryOptions.start).
src/views/Graph.vue Adds extendByWeek() method mirroring Report.vue; consistent with the existing fetchEvents() pattern that already wraps queryOptions.start in moment().

Reviews (2): Last reviewed commit: "style(views): use ES6 method shorthand f..." | Re-trigger Greptile

Comment thread src/views/Search.vue Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented May 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 30.76%. Comparing base (f4b9379) to head (a94ced0).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #819   +/-   ##
=======================================
  Coverage   30.76%   30.76%           
=======================================
  Files          33       33           
  Lines        1973     1973           
  Branches      368      368           
=======================================
  Hits          607      607           
+ Misses       1345     1288   -57     
- Partials       21       78   +57     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@realsudarshan
Copy link
Copy Markdown

Thanks for extending the fix to Report and Graph views too — I only caught it in Search. Happy to close my PR #818.

@TimeToBuildBob
Copy link
Copy Markdown
Contributor Author

CI is green across all checks and Greptile reviewed as 5/5 safe to merge. Ready for a maintainer to merge when convenient.

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.

TypeError: Cannot read properties of undefined (reading 'subtract') on Search page

2 participants