-
Notifications
You must be signed in to change notification settings - Fork 86
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
LF-4746(1) FinancesDateRangeSelector minor refactors and bugfixes #3708
LF-4746(1) FinancesDateRangeSelector minor refactors and bugfixes #3708
Conversation
…nnected to the finance redux store
…date picker) when the component first mounts
…to clearOldFarmStateSaga() In fetchAllSaga() it was being called each time the transaction list page was loaded
@@ -67,11 +67,18 @@ export default function DateRangeSelector({ | |||
} | |||
}, [isValid, isCustomDatePickerOpen]); | |||
|
|||
const isInitialRender = useRef(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This useEffect hook was added in this PR:
to solve a crash we used to see in finances, but I think we all (mostly myself as reviewer on that PR 😅🙇 ) missed that it also triggered buggy behaviour on custom date range by clearing and opening the picker on every navigation within Finances.
The bug happens because the ReactSelect's .onChange()
is called after this useEffect runs on the initial render, and that opens the date picker and clears the value. I believe that the initial render should be safely covered by the defaultValue
prop on the ReactSelect, which is why I think it's okay to skip it and have done so here, but @antsgar please let me know if you remember more context about how this contributed to the crash and if I just reverted something important! 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update Mar 12: in tech daily we decided to remove this useEffect()
entirely.
@@ -516,7 +514,6 @@ export function* fetchAllDataSaga() { | |||
]); | |||
yield put(setSelectedExpenseTypes([])); | |||
yield put(resetTransactionsFilter()); | |||
yield put(setDateRange({ option: dateRangeOptions.YEAR_TO_DATE })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the cause of the Finances date range resetting to Year to Date each time transactions list is loaded. I have moved the same call to clearOldFarmStateSaga()
below, since it was switching between farms I believe we were finding problematic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels amazing! I was expecting it would need more changes to fix the behaviour, but the fixes seem effective and powerful! ❤️
The one thing I couldn't spot just from reviewing the code is that the custom range persists when switching farms. (set a custom range -> switch farms (no need to go to finances, though I did in the recording)-> switch back to the original farm and go to finances) Are you able to reproduce it?
Screen.Recording.2025-03-07.at.10.19.07.AM.mov
@SayakaOno thank you so much for spotting that!! ❤️ 🙏 It wasn't even just the custom dates, but everything other than the Edit: actually since that action call was in the original code too there may even be an additional bug ticket I can track down related to this. Found one! https://lite-farm.atlassian.net/browse/LF-3958 |
endDate?: string | Moment; | ||
} | ||
|
||
export interface DateRangeSelection { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated to anything else in the PR, do you have any suggestions for this type? 😅 I'm not loving the name I picked here -- but is DateRange
too unspecific? Maybe DateRangeData
? It's the shape of the date range data that the hooks and components act on.
It could be stored in Redux or in component state, dependent on use case... maybe DateRangeState
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I usually go with data or info, but both data and state sound good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I'll update all to DateRangeData
in the sensors PR 🙏
a032055
to
7886133
Compare
I found another bug in the finance date range filters that seemed an easy fix so I had initially added it as well:
However, I'll just open it as a separate ticket since it's not dependent on the others and it's still a bit mysterious to me. Apologies for the force-pushing 🙇 |
7886133
to
a5f8a30
Compare
Calling sequentially when closing picker was passing stale state in the second call
I'm embarrassed to admit how long it took me to debug why the dates were not setting properly within the
Thank you in advance for your re-reviews 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Looks good, thank you for all the improvements to the component! ❤️ |
Description
This PR is a preparation PR for the creation of the
<SensorsDateRangeSelector />
filter + hook.It prepares the existing
Finances/DateRangeSelector
implementation for re-use in a general way by some renaming and conversion to TypeScript. In looking at this, I found a few bugs in Finances and fixed them. Most of the code changes are just renames! That is the only reason so many files are touched.Changes in this PR:
Finances/DateRangeSelector
component toFinancesDateRangeSelector
throughout the app. It was sometimes imported as such and sometimes as<DateRangeSelector />
which made code search more difficult. We also have a different componentcomponents/DateRangeSelector
so I wanted to avoid the naming conflict.useDateRangeSelector.js
imports and uses the action and selector for the Finances Redux store. To make this dependency clear I have renamed it touseFinancesDateRange.ts
and moved it intoFinances/
. It was previously co-located withcomponents/DateRangeSelector
but that component is redux-store agnostic.onChange()
handler of the base<DateRangeSelector />
being called upon first load by a call tosetSelectedDateRangeOption
.#ux_ui
about it. To me it felt quite buggy and I have removed it. At some point a proper implementation of resetting when leaving finances can be added.Jira links:
Bug tickets related to the custom range behaviour (the reset + open picker)
Bug tickets related to incomplete reset of Redux state as spotted by @SayakaOno 🙏
Type of change
How Has This Been Tested?
Checklist: