-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix card filter connected to a field not causing an update #36206
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
Conversation
8661ca2 to
25dc512
Compare
|
No failed tests 🎉 |
997cd59 to
5e49fc2
Compare
|
|
||
| if ( | ||
| !_.isEqual(prevProps.parameterValues, this.props.parameterValues) || | ||
| (!prevProps.dashboard && this.props.dashboard) |
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.
We do initially render Dashboard with dashboard={null}. However, this conditional never works as it's superseded by the first one in this method: prevProps.dashboardId !== this.props.dashboardId.
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 was wrong, so reverting this. Won't be committing after working hours anymore.
| if ( | ||
| !_.isEqual(prevProps.parameterValues, this.props.parameterValues) || | ||
| (!prevProps.dashboard && this.props.dashboard) | ||
| !_.isEqual(prevProps.parameters, this.props.parameters) |
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 actual bug fix.
| const canWrite = dashboard?.can_write ?? false; | ||
|
|
||
| const dashboardHasCards = dashboard?.dashcards.length > 0 ?? false; | ||
| shouldRenderAsNightMode() { |
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 have extracted this as a method as it was used in two different methods.
| } | ||
|
|
||
| renderContent = () => { | ||
| const p = this.props; |
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.
Everything that's happening here is removing destructured props as they are essentially slag.
| const shouldRenderAsNightMode = isNightMode && isFullscreen; | ||
|
|
||
| const visibleParameters = getVisibleParameters(parameters); | ||
| const p = this.props; |
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.
Same here: instead of wasting lines on avoiding writing this.props, I am putting it into a one-char variable (which is still ugly) that's almost invisible to the eye and removes this unnecessary cruft.
|
|
||
| const TEST_CARD = createMockCard(); | ||
|
|
||
| const TEST_TABLE = createMockTable(); |
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.
Same cruft as everywhere else. We don't need "constants" when they're not exported or at least used multiple times, and absolutely certainly we don't need them at the top of the file — it's ugly and useless albeit quite common.
| } | ||
|
|
||
| async function setup({ dashboard }: Options = {}) { | ||
| const TEST_COLLECTION = createMockCollection(); |
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 where they belong. I don't use this SHOUT_CASE for every constant but here I left it as is.
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.
Convert to regular camel case straight away?
5e49fc2 to
be4b7b0
Compare
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.
Good overall. Somewhat inconsistent with other integration tests (naming etc).
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.
nit: We usually call it SetupOpts
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.
nit: We usually omit the return type in setup function
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.
nit: We usually name callbacks as onFetch... and return them as it is
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 am not sure it's correct in this case since these aren't really "event handlers", which on* would suggest, but rather callbacks or action dispatchers or whatever you call them. So I'll leave as is if you don't object. I think it reads well.
| } | ||
|
|
||
| async function setup({ dashboard }: Options = {}) { | ||
| const TEST_COLLECTION = createMockCollection(); |
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.
Convert to regular camel case straight away?
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.
We usually use these props in setup function so we don't need to deal with spreading
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.
That's actually a very good catch, thanks!
be4b7b0 to
f0a9240
Compare
6682b22 to
d5de9b7
Compare
| p.addCardToDashboard({ | ||
| dashId: p.dashboardId, | ||
| cardId: p.addCardOnLoad, | ||
| tabId: p.dashboard?.tabs[0]?.id ?? null, |
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.
Notice ? after dashboard. This was causing exceptions (and failed e2e tests) when dashboard is null.
* Rename DashboardHeaderView to match filename * Fix non updating cards on filter mapping to a field * Clean up DashboardApp tests a bit * Clean up Dashboard.jsx cruft * Add Dashboard componentDidUpdate "unit tests" * Simplify setup code as per feedback * Add test for changing dashboard prop in componentDidMount * Change constant names * Fix optional chaining in Dashboard
…36419) * Rename DashboardHeaderView to match filename * Fix non updating cards on filter mapping to a field * Clean up DashboardApp tests a bit * Clean up Dashboard.jsx cruft * Add Dashboard componentDidUpdate "unit tests" * Simplify setup code as per feedback * Add test for changing dashboard prop in componentDidMount * Change constant names * Fix optional chaining in Dashboard Co-authored-by: Oleg Gromov <mail@oleggromov.com>
* Rename DashboardHeaderView to match filename * Fix non updating cards on filter mapping to a field * Clean up DashboardApp tests a bit * Clean up Dashboard.jsx cruft * Add Dashboard componentDidUpdate "unit tests" * Simplify setup code as per feedback * Add test for changing dashboard prop in componentDidMount * Change constant names * Fix optional chaining in Dashboard
* Rename DashboardHeaderView to match filename * Fix non updating cards on filter mapping to a field * Clean up DashboardApp tests a bit * Clean up Dashboard.jsx cruft * Add Dashboard componentDidUpdate "unit tests" * Simplify setup code as per feedback * Add test for changing dashboard prop in componentDidMount * Change constant names * Fix optional chaining in Dashboard
Fixes #35503
Description
The problem was that for some reason in
Dashboard.componentDidUpdate, the method that decides whether to fetch new data, only parameter values where checked — but not parameters themselves.I have fixed that, removing garbage code along the way, and added "unit tests" for the
Dashboardcomponent. Net change (without the test code) is-46sloc, which I think is worth it.Test approach evolution
PS Certainly the tests we produce with react testing library aren't unit tests because they require a rich environment, so much mocking, and are slow.
How to verify
Repeat after what I do in the screencast.
Before it didn't work
287385786-a0544210-58b4-486f-95ca-c81d8b26e5e8.mov
Now it works
287386102-4a8010f3-09e5-4660-b07e-09076d263189.mov
Checklist