App icon indicating copy to clipboard operation
App copied to clipboard

[$175] In Insights, the custom date range year picker lists about 100 future years before any past year

Open m-natarajan opened this issue 1 week ago • 12 comments

If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.


Version Number: 9.5.53-0 Reproducible in staging?: Y Reproducible in production?: Y If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @abzokhattab Slack conversation (hyperlinked to channel name): #Expensify Bugs

Action Performed:

  1. Go to Insights (any tab, e.g. Compliance)
  2. Click Date > Custom range
  3. In the From calendar, click the year (2026) to open the year picker
  4. Scroll the year list

Expected Result:

Insights only covers past dates, so the list should show the current year and then earlier years, nearest first (2026, 2025, 2024, …). Future years shouldn’t appear.

Actual Result:

The list shows 2026 pinned at the top, then 2027 through 2126 in ascending order, and only then 2025, 2024 … 1926. To pick a past year, you have to scroll past about 100 future years or search for it.

Workaround:

Unknown

Platforms:

Select the officially supported platforms where the issue was reproduced:

  • [ ] Android: App
  • [ ] Android: mWeb Chrome
  • [ ] iOS: App
  • [ ] iOS: mWeb Safari
  • [ ] iOS: mWeb Chrome
  • [x] Windows: Chrome
  • [x] MacOS: Chrome / Safari

Screenshots/Videos

https://github.com/user-attachments/assets/7a3718e7-90e2-4bd8-b88c-d8e4489e2247

https://github.com/user-attachments/assets/f8e23cc5-9b41-4059-a395-edd1f7932500

View all open jobs on GitHub

Upwork Automation - Do Not Edit

m-natarajan avatar Nov 24 '26 12:11 m-natarajan

Triggered auto assignment to Contributor-plus team member for initial proposal review - @abdulrahuman5196 (External)

Job added to Upwork: https://www.upwork.com/jobs/~022125210834804254856

Proposal

What is the root cause of that problem?

Insights inherits the shared calendar’s 100-years-back/100-years-forward bounds without restricting future years. For long lists, the year picker intentionally places future years before past years, then moves the initially displayed year to the top.

Together, these produce exactly the reported sequence: 2026 → 2027…2126 → 2025…1926.

Confidence: Medium. The code explains the complete sequence, and existing tests explicitly expect this ordering. Browser reproduction was not performed.

Code evidence

This is client-side option generation; server logs are not needed to explain the reported list.

What changes do you think we should make in order to solve the problem?

Add Insights-only configuration that:

  1. Limits custom-range year options to the current year and earlier.
  2. Orders years strictly descending.
  3. Keeps the selected year highlighted without moving it ahead of newer years.

Pass this configuration through the shared date controls to both From and To calendars, including wide and narrow layouts. Preserve existing defaults for Search and other calendar consumers.

Implementation scope and regression coverage

Forward the configuration from Insights through both responsive branches of DateSelectPopup, its narrow-layout branch, and the range branch in DatePresetFilterBase.tsx:479–493.

Why a maximum date alone is insufficient: reopening on a selected year such as 2020 would still produce 2020, 2021…2026, 2019…. Strict descending mode must bypass both around-selection sorting and initial-year pinning.

Regression coverage should verify:

  • From and To show 2026, 2025, 2024…, with no future years.
  • Selecting an older year and reopening does not change that order.
  • Year search and From ≤ To validation still work.
  • Both responsive layouts receive the configuration.
  • Unconfigured shared consumers retain their current behavior.

If the requirement also forbids future days, cap at today; excluding future years alone does not require that broader behavior change.

What alternative solutions did you explore?

Changing the shared defaults globally would affect unrelated date pickers. Restricting selectable days alone would leave the unwanted year rows visible.

Related issues—not confirmed duplicates:


Next Steps for Contributor+ team: To accept: @MelvinBot implement [this](https://github.com/Expensify/App/issues/107841) to create a draft PR. To refine: @MelvinBot <your feedback> To reject: Explain why you are rejecting Melvin's proposal.


view run

MelvinBot avatar Nov 24 '26 12:11 MelvinBot

@abdulrahuman5196 Melvin's fix forwards the year cap only to the From and To calendars of the Custom range branch, but the Insights Date control also offers Custom date (INSIGHTS_ALLOWED_CUSTOM_DATE_MODIFIERS is [ON]), and that path renders a separate CalendarPicker with no maxDate:

https://github.com/Expensify/App/blob/b7bd2e60a86738b411cb0b766ecabd0b34c6351c/src/components/Search/FilterComponents/DatePresetFilterBase.tsx#L497-L503

So after that fix, opening the year picker from Insights > Date > Custom date still lists 2026, then 2027 through 2126, then 2025. Passing a current-year maxDate from InsightsDateControl down to every CalendarPicker in DatePresetFilterBase caps both entry points, since CalendarPicker already derives maxYear from maxDate.

Happy to put up a full proposal for this if that's useful.

yusufdeveloper2903 avatar Nov 24 '26 12:11 yusufdeveloper2903

Proposal

Please re-state the problem that we are trying to solve in this issue.

In Insights, opening the year picker for the date control (the Custom date option, and the From / To calendars of a Custom range) shows about 100 future years before any past year: the list starts at 2026, then runs upward to 2126, and only after that runs downward through the past years. The user has to scroll through a century of future years to reach a year they can actually use, because Insights only covers past dates. The expected behavior is a list that starts at the current year and runs downward through past years only.

What is the root cause of that problem?

Two interacting causes, both verified on baseline e91964cb:

  1. The shared calendar picker has no year cap on the Insights path, so it defaults to a 201-year window. CONST.CALENDAR_PICKER.MIN_YEAR is the current year minus 100 and MAX_YEAR is the current year plus 100 (src/CONST/index.ts:736-737). CalendarPicker (src/components/DatePicker/CalendarPicker/index.tsx:88-89) builds its bounds with getBound(maxDateProp, CONST.CALENDAR_PICKER.MAX_YEAR), and Insights passes no maxDate at all, so the picker shows 1926 to 2126. DatePresetFilterBase (src/components/Search/FilterComponents/DatePresetFilterBase.tsx) forwards no maxDate to either the Custom range branch (RangeDatePicker) or the Custom single-date branch (the single CalendarPicker), and RangeDatePicker (src/components/Search/FilterComponents/RangeDatePicker.tsx) has no maxDate prop to forward in the first place.

  2. Even with a cap, the list would still open in the wrong order. YearPickerModal (src/components/DatePicker/CalendarPicker/YearPickerModal.tsx:70-71) sorts with compareAroundInitialYear and then pins the initial selection to the top whenever shouldMoveInitialSelectionToTop(years.length) is true, which it is for any list of 12 or more years. A capped list of 101 years (1926 to 2026) still has 12 or more entries, so on reopening after selecting 2020 it would show 2020 first, then 2021 upward to 2026, then 2019 downward. Capping the years alone does not produce a newest-first list.

What changes do you think we should make in order to solve the problem?

Two changes, plumbed through the whole Insights date chain so all three pickers (From, To, and the single Custom date picker) behave the same way:

  1. Cap the year list at the end of the current year. InsightsDateControl (src/pages/Insights/controls/InsightsDateControl.tsx:28) computes INSIGHTS_MAX_DATE = endOfYear(new Date()) once at module load and passes it as maxDate. The value is the last day of the current year, not today: using today would wrongly disable future days inside the current year, while end of year keeps every day inside the current year selectable. Days in later years become unselectable, which is intended because Insights covers past dates. maxDate is forwarded through DateSelectPopup (both the wide and narrow branches, src/components/Search/FilterDropdowns/DateSelectPopup/index.tsx:163,227), DatePresetFilterBase (both the range branch and the single-date branch, :466,478), and RangeDatePicker (both the From and To calendars, :49,64) into CalendarPicker, where the existing getBound logic turns it into maxYear equal to the current year. The list becomes exactly 101 years: current year down to current year minus 100.

  2. Add an explicit opt-in prop shouldSortYearsDescending that sorts the year list newest-first and skips the pin-to-top step. In YearPickerModal (:70-71), when the prop is true the list is sorted with compareNewestFirst and moveInitialSelectionToTop is skipped entirely, so reopening after selecting 2020 still shows the strict newest-first order. The prop defaults to false everywhere and is passed only by InsightsDateControl, so every other consumer keeps its current ordering: the date-of-birth picker keeps its pinned initial selection, and any other picker that already passes its own maxDate is untouched. The prop is forwarded along the same four levels as maxDate.

The fix is on branch fix-107841-insights-year-picker (baseline e91964cb), 6 source files, +54/-4. No schema change, no new Onyx subscriptions, and no change to any other date control.

What alternative solutions did you explore? (Optional)

  1. Capping maxDate only, with no sort change: rejected. As shown in root cause (2), a 101-year list still triggers the pin-to-top ordering, so reopening the picker after a selection would not show a newest-first list.
  2. Setting maxDate to today instead of end of year: rejected. Today would disable every day after today inside the current year, even though those dates are valid for Insights. End of year caps only the year list.
  3. Sorting descending automatically whenever the capped maxYear is at or below the current year: rejected. That trigger is global, so it would also reorder every other picker whose maxDate caps at or below the current year. The date-of-birth picker, for example, passes maxDate equal to today minus 18 years; a global trigger would silently change its pinned ordering and break the behavior its tests assert. An explicit opt-in prop passed only on the Insights path avoids that.
  4. Inferring the sort from the maxDate value instead of adding a prop: rejected for the same reason as (3). The sort is a display choice for one screen, not a property of the cap, so it should be an explicit prop rather than a side effect of the date value.

Tests added and run on baseline e91964cb (all passing):

  • tests/ui/YearPickerModalTest.tsx (3 new tests): with the opt-in on, the list is exactly the current year down to current year minus 100 when reopened after selecting 2020; the same descending order holds under search; with the prop off, a DOB-style picker (min 1876, max 2008, current 1990) keeps its pinned ordering. 11/11 pass in the suite.
  • tests/unit/CalendarPickerTest.tsx (4 new tests): passing maxDate caps the year list at the current year; the sort prop is forwarded to the modal; the list is not sorted descending by default; Dec 31 of the current year stays selectable. 79/79 pass in the suite.
  • tests/unit/RangeDatePickerTest.tsx (3 new tests): both the From and To calendars are capped at the current year and both receive the sort prop. 15/15 pass in the suite.
  • tests/ui/DatePresetFilterBaseCustomDateModifiersTest.tsx (3 new tests): the range branch and the single-date branch are both capped and sorted, and the uncapped default is unchanged. 8/8 pass in the suite.

113/113 tests pass across the four suites. 8 of the 13 new tests fail on the clean baseline, which confirms they exercise the new behavior; the 5 that pass on baseline are by-design regression guards (DOB pinning, the uncapped default, the pre-existing CalendarPicker maxDate cap, Dec 31 selectability, and the default no-sort behavior).

Lint: direct oxlint on all 10 touched files reports 8 errors, all pre-existing on lines outside this diff (pre-existing new Date() calls, a restricted import, a setState-in-effect, and deprecated MenuItem usages); this change adds zero new lint errors. The React Compiler compliance concern on the first version of the change (new Date() during render) was fixed by moving the computation to a module-level constant, which matches the existing module-level CONST.CALENDAR_PICKER.MIN_YEAR / MAX_YEAR pattern.

Full typecheck was attempted once on this machine and did not finish (the run was interrupted before producing diagnostics); it was not retried. The changed files pass the type-aware lint rules, and the changes add no any and no new type assertions.

Peer review: independent reviewer, PASS 92/100. The reviewer traced the full prop chain, verified that no non-Insights consumer receives either prop, verified the exact 101-year list and the pinned-ordering regression guard, and confirmed the lint result. Its only findings were non-blocking: an end-to-end test through InsightsDateControl would be stronger than the current composition of plumbing tests plus the exact-list modal test, and the day-selectability wording above is the tightened version it asked for.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~013b564a690d9bcdab

dankezo avatar Nov 24 '26 14:11 dankezo

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 24 '26 14:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue?

In Insights, opening the year picker for the date filter (both for the Custom date option and the From/To calendars of Custom range) displays ~100 future years (e.g. 2026, then 2027 through 2126) before any past years. Users must scroll past a century of irrelevant future years or type to search to select past years, even though Insights is an analytical reporting dashboard that only covers past/existing expenses.

What is the root cause of that problem?

In src/pages/Insights/controls/InsightsDateControl.tsx and src/components/Search/FilterComponents/DatePresetFilterBase.tsx:

  1. InsightsDateControl renders DateSelectPopup without passing an explicit maxDate prop.

  2. In DatePresetFilterBase.tsx (lines 481–503), neither the RangeDatePicker (From/To calendars) nor the single-date CalendarPicker receives a maxDate constraint.

  3. In CalendarPicker/index.tsx (line 85), when maxDateProp is omitted, it falls back to:

const maxDate = getBound(maxDateProp, CONST.CALENDAR_PICKER.MAX_YEAR);

where CONST.CALENDAR_PICKER.MAX_YEAR is currentYear + 100 (e.g. 2126).

  1. CalendarPicker passes minYear = 1926 and maxYear = 2126 to YearPickerModal.tsx.

  2. In YearPickerModal.tsx (lines 45–68), because years.length (201) exceeds CONST.CALENDAR_PICKER.SHORT_YEAR_LIST_THRESHOLD (10), shouldMoveInitialSelectionToTop applies compareAroundInitialYear:

const compareAroundInitialYear = (a: CalendarPickerListItem, b: CalendarPickerListItem) => {
    const isAUpcoming = a.value > initialYear;
    const isBUpcoming = b.value > initialYear;
    if (isAUpcoming !== isBUpcoming) {
        return isAUpcoming ? -1 : 1;
    }
    return isAUpcoming ? a.value - b.value : b.value - a.value;
};

This intentionally sorts all upcoming future years (value > 2026: 2027...2126) first in ascending order, followed by past years descending (2025...1926), and pins the selected year (2026) at the top. This produces the exact sequence: 2026 → 2027...2126 → 2025...1926.

What changes do you think we should make in order to solve the problem?

  1. In src/pages/Insights/controls/InsightsDateControl.tsx: Pass maxDate to DateSelectPopup. Because Insights only applies to past dates up to the end of the current year (or today), pass maxDate:
const maxDate = endOfYear(new Date());

(or a memoized/module-level date instance).

  1. Forward maxDate?: Date through the component chain:
  • In src/components/Search/FilterDropdowns/DateSelectPopup/index.tsx: accept maxDate?: Date and pass it to DatePresetFilterBase.
  • In src/components/Search/FilterComponents/DatePresetFilterBase.tsx: accept maxDate?: Date and forward it to both <RangeDatePicker maxDate={maxDate} ... /> and <CalendarPicker maxDate={maxDate} ... />.
  • In src/components/Search/FilterComponents/RangeDatePicker.tsx: accept maxDate?: Date and pass it to both the From and To <CalendarPicker maxDate={maxDate} ... /> instances.
  1. Natural sorting resolution in YearPickerModal.tsx: When maxDate is capped at the current year (maxYear === currentYear):
  • years contains only years 1926...2026.
  • There are no future years (value > initialYear is always false).
  • In compareAroundInitialYear, isAUpcoming is false for all years, so the comparison naturally sorts descending: b.value - a.value.
  • moveInitialSelectionToTop pins the current year (2026) at the top, followed naturally by 2025, 2024, 2023, ... 1926.

This elegantly solves the issue using standard maxDate props already supported by CalendarPicker, without requiring custom sort flags, without breaking DOB pickers, and covering both Custom range and Custom date paths.

What alternative solutions did you explore? (Optional)?

  • Adding an explicit shouldSortDescending boolean prop: Rejected as unnecessary overhead. CalendarPicker already natively supports maxDate. Capping maxDate to the current year naturally eliminates future years and produces the desired newest-first ordering across all years.

Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~0131dae36abcf59374

kevinjosh10 avatar Nov 25 '26 06:11 kevinjosh10

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 25 '26 06:11 melvin-bot[bot]

Proposal

Please re-state the problem that we are trying to solve in this issue.

In Insights, opening the year picker from the Date control (both Custom range From/To calendars and Custom date) shows ~100 future years before any past year (2026, 2027..2126, then 2025..1926). Because Insights only covers past dates, the list should omit future years and display years strictly newest-first starting with the current year (2026, 2025, 2024, ...).

What is the root cause of that problem?

Two separate pieces of logic combine to produce the bug:

  1. No upper year bound on the Insights date chain: InsightsDateControl does not pass a maxDate into DateSelectPopup, and neither DateSelectPopup, DatePresetFilterBase, nor RangeDatePicker forwards maxDate to CalendarPicker. As a result, CalendarPicker falls back to CONST.CALENDAR_PICKER.MAX_YEAR (currentYear + 100, e.g. 2126).
  2. Default year ordering pins and groups around initialYear for lists ≥ 12 years: In src/components/DatePicker/CalendarPicker/YearPickerModal.tsx, whenever shouldMoveInitialSelectionToTop(years.length) is true, the list sorts with compareAroundInitialYear and calls moveInitialSelectionToTop. Even after capping maxYear to the current year, the list still has 101 years (>= 12), so reopening the picker after choosing a past year (e.g. 2020) would still display 2020, 2021..2026, 2019..1926 instead of 2026, 2025, ....

What changes do you think we should make in order to solve the problem?

  1. Compute a fresh current-year cap in src/pages/Insights/controls/InsightsDateControl.tsx
    • Inside the datePopover render callback, pass maxDate={endOfYear(new Date())} and an opt-in shouldSortYearsDescending flag to DateSelectPopup.
    • Computing endOfYear(new Date()) when the popover opens avoids freezing a stale year in a module-level constant across a year rollover (Dec 31 → Jan 1), while keeping all days within the current year selectable and disabling navigation beyond the current year (isAtMaxYear in CalendarPicker).
  2. Forward maxDate and shouldSortYearsDescending through the shared Insights date controls
    • src/components/Search/FilterDropdowns/DateSelectPopup/index.tsx: accept both optional props and forward them to DatePresetFilterBase in both the wide (!isSmallScreenWidth) and narrow (isSmallScreenWidth) render branches.
    • src/components/Search/FilterComponents/DatePresetFilterBase.tsx: accept both optional props and forward them to both <RangeDatePicker /> (Custom range) and the single <CalendarPicker /> (Custom date ON modifier).
    • src/components/Search/FilterComponents/RangeDatePicker.tsx: accept both optional props and forward them to both the From and To <CalendarPicker /> instances.
    • src/components/DatePicker/CalendarPicker/index.tsx: accept shouldSortYearsDescending?: boolean (default false) and forward it to <YearPickerModal /> (where maxDate already derives maxYear).
  3. Add strict descending mode in src/components/DatePicker/CalendarPicker/YearPickerModal.tsx
    • Accept shouldSortYearsDescending = false.
    • When shouldSortYearsDescending is true, sort with compareNewestFirst and skip moveInitialSelectionToTop (leaving isSelected highlighted on currentYear and keeping shouldScrollToFocusedIndexOnMount={false} so the list always opens at the current year at the top).
    • When false (default), preserve the existing compareAroundInitialYear + moveInitialSelectionToTop behavior untouched for all other consumers (such as Search and DOB pickers).

What specific scenarios should we cover in automated tests?

  • YearPickerModal: with shouldSortYearsDescending, verify 2026, 2025, ... order holds even when reopening with currentYear={2020} and while searching; with default false, verify existing pinned ordering (e.g. DOB picker) is unchanged.
  • CalendarPicker, RangeDatePicker, DatePresetFilterBase, and DateSelectPopup (wide + narrow): verify maxDate and shouldSortYearsDescending reach From, To, and Custom date calendars, no future years appear, and non-Insights callers keep their defaults.

What alternative solutions did you explore? (Optional)

  • Only passing maxDate without updating YearPickerModal: Incomplete — reopening after selecting a past year like 2020 still shows 2020, 2021..2026, 2019... because 101 years still exceeds the pin-to-top threshold.
  • Using a module-level endOfYear(new Date()) constant: Goes stale if a long-lived web/desktop session stays open past midnight on Dec 31.
  • Using endOfDay(new Date()) instead of endOfYear(new Date()): Would also block selecting future days inside the current year; if product wants future days in the current year disabled too, switching endOfYear to endOfDay is a one-line adjustment.

ductai05 avatar Nov 27 '26 06:11 ductai05

@abdulrahuman5196 Whoops! This issue is 2 days overdue. Let's get this updated quick!

Proposal

Please re-state the problem that we are trying to solve in this issue.

In Insights, opening the year picker inside the date filter (both the Custom range From/To calendars and the single Custom date calendar) shows ~100 future years (2027..2126) in ascending order before past years (2025..1926). Because Insights only covers historical/current-year expense data, users must scroll past a century of unusable future years to pick an earlier year.

What is the root cause of that problem?

  1. InsightsDateControl passes no explicit maxDate to DateSelectPopup, and neither DateSelectPopup, DatePresetFilterBase, nor RangeDatePicker forwards maxDate to CalendarPicker. As a result, CalendarPicker falls back to CONST.CALENDAR_PICKER.MAX_YEAR (currentYear + 100).
  2. Even with maxDate capped at the current year (leaving 101 years), YearPickerModal sorts with compareAroundInitialYear + moveInitialSelectionToTop whenever years.length > SHORT_YEAR_LIST_THRESHOLD (10), which pins a previously chosen earlier year (e.g. 2020) to the top and lists 2021..2026 ahead of 2019..1926.

What changes do you think we should make in order to solve the problem?

  1. In src/pages/Insights/controls/InsightsDateControl.tsx, pass maxDate={endOfYear(new Date())} inside datePopover (avoiding a stale module-level constant across year rollover while keeping all days in the current year selectable) along with shouldSortYearsDescending to DateSelectPopup.
  2. Forward maxDate?: Date and shouldSortYearsDescending?: boolean through DateSelectPopup (both desktop and narrow-screen branches), DatePresetFilterBase (both RangeDatePicker and single CalendarPicker branches), RangeDatePicker (both From and To calendars), and CalendarPicker (to YearPickerModal).
  3. In src/components/DatePicker/CalendarPicker/YearPickerModal.tsx, when shouldSortYearsDescending is true, sort strictly with compareNewestFirst and skip moveInitialSelectionToTop, keeping the selected year highlighted via isSelected while leaving default behavior unchanged for non-Insights callers (e.g. DOB pickers).
  4. Add unit tests in tests/ui/YearPickerModalTest.tsx verifying strict descending order when reopening on an earlier year and while filtering via search.

What alternative solutions did you explore?

  • Passing maxDate alone without shouldSortYearsDescending: leaves reopening after selecting an earlier year (e.g. 2020) showing 2020, 2021..2026, 2019..1926.
  • Freezing endOfYear(new Date()) at module load: would go stale if a long-lived session stays open across midnight on Dec 31.

ryancooper312 avatar Nov 29 '26 15:11 ryancooper312

📣 @ryancooper312! 📣 Hey, it seems we don’t have your contributor details yet! You'll only have to do this once, and this is how we'll hire you on Upwork. Please follow these steps:

  1. Make sure you've read and understood the contributing guidelines.
  2. Get the email address used to login to your Expensify account. If you don't already have an Expensify account, create one here. If you have multiple accounts (e.g. one for testing), please use your main account email.
  3. Get the link to your Upwork profile. It's necessary because we only pay via Upwork. You can access it by logging in, and then clicking on your name. It'll look like this. If you don't already have an account, sign up for one here.
  4. Copy the format below and paste it in a comment on this issue. Replace the placeholder text with your actual details. Screen Shot 2022-11-16 at 4 42 54 PM Format:
Contributor details
Your Expensify account email: <REPLACE EMAIL HERE>
Upwork Profile Link: <REPLACE LINK HERE>

melvin-bot[bot] avatar Nov 29 '26 15:11 melvin-bot[bot]