-
Notifications
You must be signed in to change notification settings - Fork 13.8k
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
chore: Convert QueryAutoRefresh to TypeScript functional React component [sc-48362] #20179
chore: Convert QueryAutoRefresh to TypeScript functional React component [sc-48362] #20179
Conversation
superset-frontend/src/SqlLab/components/QueryAutoRefresh/index.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/src/SqlLab/components/QueryAutoRefresh/index.tsx
Outdated
Show resolved
Hide resolved
superset-frontend/src/SqlLab/components/QueryAutoRefresh/index.tsx
Outdated
Show resolved
Hide resolved
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.
Thanks @eric-briscoe, this is great! The comments make it very readable, too.
Removes unneeded props and state tracking of offline, adds finally block to simplify clearing pending request, simplifies value comparison in array by using includes in place of indexOf
…esh-to-functional-component
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! Does it need an ephemeral for testing?
Codecov Report
@@ Coverage Diff @@
## master #20179 +/- ##
=======================================
Coverage 66.74% 66.75%
=======================================
Files 1739 1740 +1
Lines 65130 65135 +5
Branches 6898 6898
=======================================
+ Hits 43472 43480 +8
+ Misses 19908 19906 -2
+ Partials 1750 1749 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Original implementation had string literals used in multiple places representing Query.state value options. This commit creates a formal TypeScript enum for QueryState so we can remove string literals and ensure better consistency
…esh-to-functional-component
This commit resolves an issue why the TypeScript typing for queryList was marked as a Query[] but was actually a Dictionary (associative array) or Queries. A new type QueryDictionary has been added and the QueryAutoRefresh code was adjusted to use QueryDictionary instead of Query[] in appropriate places as well as unit tests. Commit also removes QueryAutoRefreshContainer by making the once component using QueryAutoRefresh (which is already redux connected) pass the needed values on props. this simplifies the code base and reduce files that need unit testing while keeping QueryAutoRefresh out of needing a redux connection directly.
…esh-to-functional-component
…List [sc-48362] In previous implementation 'scheduled' was not included int he list of Query States. Further investigation shows it should be added to as a running state.
@eric-briscoe do you have the pre-commit hook installed? We have it in a makefile. The command is There is also a way to make prettier run on save, which I forget how to do, but I think we have documented somewhere. Elizabeth definitely knows. |
…wrapper object [sc-48362]
…esh-to-functional-component
* The useInterval function solves this issue. | ||
* more info: https://overreacted.io/making-setinterval-declarative-with-react-hooks/ | ||
*/ | ||
function useInterval(callback: Function, delay: number | null): void { |
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: can we set delay as an optional and = to 0
function useInterval(callback: Function, delay: number = 0): void {
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.
@hughhhh I'm thinking it may be dangerous to run the function continuously without any delay interval (or the minimum interval that the browser allows). If you forget to pass a delay, this could be problematic. I think @eric-briscoe has a good idea about doing nothing (returning a noop). WDYT?
…esh-to-functional-component
Merges in updates from master and resolves conflicts from relocation of some of the Query TypeScript definitions into core
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.
Thanks @eric-briscoe, looks great! There are just some tests and checks that aren't passing still.
…esh-to-functional-component
… message [sc-48362]
…ent [sc-48362] (apache#20179) * git commit -m 'Convert QueryAutoRefresh to functional component [sc-48362]' * addressing PR comments [sc-48362] Removes unneeded props and state tracking of offline, adds finally block to simplify clearing pending request, simplifies value comparison in array by using includes in place of indexOf * Address PR comment to use enum for QueryState [sc-48362] Original implementation had string literals used in multiple places representing Query.state value options. This commit creates a formal TypeScript enum for QueryState so we can remove string literals and ensure better consistency * Address PR comments for object type validation [sc-48362] This commit resolves an issue why the TypeScript typing for queryList was marked as a Query[] but was actually a Dictionary (associative array) or Queries. A new type QueryDictionary has been added and the QueryAutoRefresh code was adjusted to use QueryDictionary instead of Query[] in appropriate places as well as unit tests. Commit also removes QueryAutoRefreshContainer by making the once component using QueryAutoRefresh (which is already redux connected) pass the needed values on props. this simplifies the code base and reduce files that need unit testing while keeping QueryAutoRefresh out of needing a redux connection directly. * Addresses PR comment to add QueryState.SCHEDULED to runningQueryStateList [sc-48362] In previous implementation 'scheduled' was not included int he list of Query States. Further investigation shows it should be added to as a running state. * Fix prettier lint error [sc-48362] * Adjust unit tests for props update hoisting callbacks out of actions wrapper object [sc-48362] * Update with changes from master [sc-48362] Merges in updates from master and resolves conflicts from relocation of some of the Query TypeScript definitions into core * Removes logic setting user offline and relying on results panel error message [sc-48362] * Fixes bad import after some TypeScript definitions were relocated to core [sc-48362] * Fixes TypeScript errors [sc-48362]
Convert QueryAutoRefresh to TypeScript functional React component
SUMMARY
This PR converts QueryAutoRefresh from es6 class component to TypeScript functional component as part of bigger effort to migrate frontend code to TypeScript and functional React components defined in: #18388
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
There should be no visual change to the application
TESTING INSTRUCTIONS
Changes to http requests for getting Query statuses:
If you watch the dev tools network tab you should see less network traffic as the execution now ensures only one outstanding http call to check query status is made at a time to avoid http response race conditions that can lead to incorrect application state and to reduce tandem network calls on slower connections. If the call fails, the offline state change will be triggered but the interval timer will continue attempting to reconnect and set user online and show results once the connection is restored. This can be tested by:
QueryAutoRefresh was separated into two files to separate Redux knowledge from the simple functional component:
IMPORTANT:
When changing QueryAutoRefresh to a functional component the behavior of setInterval no longer worked correctly. This is a known issue with functional React components using setInterval can provide stale state / props in the interval callback creating undesired, hard to debug / fix behavior. A new utility hook (SqlLab/utils/useInterval.ts) was introduced in this PR to handle this based on this very helpful article by Dan Abramov (thank you!): https://overreacted.io/making-setinterval-declarative-with-react-hooks/
ADDITIONAL INFORMATION