Skip to content

fix(search): fix TypeError when extending search range by a week#818

Closed
realsudarshan wants to merge 2 commits intoActivityWatch:masterfrom
realsudarshan:fix/search-subtract-undefined
Closed

fix(search): fix TypeError when extending search range by a week#818
realsudarshan wants to merge 2 commits intoActivityWatch:masterfrom
realsudarshan:fix/search-subtract-undefined

Conversation

@realsudarshan
Copy link
Copy Markdown

Description

Fixes a crash on the Search page that occurred when clicking the "+1 week" button to expand the search scope.

The Problem

  • The "+1 week" button's click handler was trying to call .subtract() on start, which was undefined (it should have been queryOptions.start).
  • Even when pointing to queryOptions.start, it threw a TypeError because the date returned by the b-form-datepicker is a formatted string, not a moment object.

The Solution

fix.mp4

@realsudarshan realsudarshan force-pushed the fix/search-subtract-undefined branch from 39b800c to 51fbea5 Compare May 9, 2026 12:32
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 9, 2026

Greptile Summary

This PR fixes a TypeError that crashed the Search page when the "+1 week" button was clicked. The inline handler referenced an undefined start variable and, even when corrected to queryOptions.start, failed because b-form-datepicker stores the value as a plain date string rather than a moment object.

  • Replaces the broken inline @click handler with a dedicated addWeek() method that explicitly parses queryOptions.start using moment(value, 'YYYY-MM-DD'), subtracts one week, formats the result back to a 'YYYY-MM-DD' string, and then calls search().
  • The explicit format argument in moment(this.queryOptions.start, 'YYYY-MM-DD') ensures correct parsing regardless of whether queryOptions.start is still the initial moment object or has already been set to a date string by the datepicker or a prior addWeek() call.

Confidence Score: 5/5

The fix is a targeted, self-contained method addition that correctly handles both the moment-object and date-string states of queryOptions.start; safe to merge.

The change is minimal — one new four-line method replaces a broken inline handler. The moment(value, 'YYYY-MM-DD') call with an explicit format handles all reachable states of queryOptions.start (initial moment object, datepicker-produced string, or a string from a previous addWeek() call), and the rest of the search flow is unchanged.

No files require special attention.

Important Files Changed

Filename Overview
src/views/Search.vue Adds a dedicated addWeek() method that correctly parses queryOptions.start (either a moment object or a date string) with an explicit format before subtracting one week and re-assigning as a formatted string; fixes the original TypeError.

Sequence Diagram

sequenceDiagram
    actor User
    participant Button as "+1 week Button"
    participant addWeek as addWeek()
    participant moment as moment.js
    participant search as search()
    participant API as $aw.query()

    User->>Button: click
    Button->>addWeek: addWeek()
    addWeek->>moment: moment(queryOptions.start, 'YYYY-MM-DD')
    moment-->>addWeek: parsed moment object
    addWeek->>moment: .subtract(1, 'week').format('YYYY-MM-DD')
    moment-->>addWeek: date string
    addWeek->>addWeek: "queryOptions.start = date string"
    addWeek->>search: search()
    search->>moment: moment(queryOptions.start).format()
    moment-->>search: ISO timestamp
    search->>API: query(timeperiods, query_array)
    API-->>search: events[]
    search-->>User: display results
Loading

Reviews (2): Last reviewed commit: "fix(search): specify format hint to avoi..." | Re-trigger Greptile

Comment thread src/views/Search.vue Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@realsudarshan
Copy link
Copy Markdown
Author

Closing in favor of #819 which also covers Report and Graph views. Thanks for the thorough fix @TimeToBuildBob!

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

1 participant