-
Notifications
You must be signed in to change notification settings - Fork 14.1k
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
[Sqllab] Add offline state to sqllab #6013
[Sqllab] Add offline state to sqllab #6013
Conversation
120826e
to
ee89873
Compare
Codecov Report
@@ Coverage Diff @@
## master #6013 +/- ##
=======================================
Coverage 76.91% 76.91%
=======================================
Files 47 47
Lines 9362 9362
=======================================
Hits 7201 7201
Misses 2161 2161 Continue to review full report at Codecov.
|
$.ajax({ | ||
dataType: 'json', | ||
url, | ||
timeout: 3000, |
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 line will make all long query (>3 seconds) abort.
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.
Okay, I will remove the timeout option.
}, | ||
error: (XMLHttpRequest) => { | ||
if (XMLHttpRequest.readyState === 0) { | ||
document.location.reload(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.
i will prefer show error message not force refresh user's browser.
ee89873
to
b3ef68f
Compare
da86a1f
to
f079f04
Compare
70774eb
to
34b1453
Compare
Ready for review |
@@ -38,12 +38,22 @@ class QueryAutoRefresh extends React.PureComponent { | |||
} | |||
stopwatch() { | |||
// only poll /superset/queries/ if there are started or running queries | |||
const self = this; |
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.
you don't need self
variable. see the exist code.
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.
also corrected.
superset/assets/src/SqlLab/App.jsx
Outdated
@@ -20,6 +20,7 @@ initJQueryAjax(); | |||
|
|||
const appContainer = document.getElementById('app'); | |||
const bootstrapData = JSON.parse(appContainer.getAttribute('data-bootstrap')); | |||
bootstrapData.offline = false; |
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 logic (set initial value for offline state) should be in function getInitialState
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.
Fixed!
@@ -21,9 +21,11 @@ const propTypes = { | |||
tabHistory: PropTypes.array.isRequired, | |||
tables: PropTypes.array.isRequired, | |||
getHeight: PropTypes.func.isRequired, | |||
offline: PropTypes.func |
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.
what is offline
prop type?
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.
Oops. Corrected.
SqlEditorLeftBar.propTypes = propTypes; | ||
SqlEditorLeftBar.defaultProps = defaultProps; | ||
|
||
export default SqlEditorLeftBar; | ||
export default connect(mapStateToProps)(SqlEditorLeftBar); |
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.
is adding redux connect for this component necessary? where do you need to check state?
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.
it's necessary because I ensure it is online before the ajax calls
ced2f09
to
78f66fe
Compare
All concerns addressed. |
@@ -34,6 +34,7 @@ export const SET_DATABASES = 'SET_DATABASES'; | |||
export const SET_ACTIVE_QUERY_EDITOR = 'SET_ACTIVE_QUERY_EDITOR'; | |||
export const SET_ACTIVE_SOUTHPANE_TAB = 'SET_ACTIVE_SOUTHPANE_TAB'; | |||
export const REFRESH_QUERIES = 'REFRESH_QUERIES'; | |||
export const USER_OFFLINE = 'USER_OFFLINE'; |
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.
Rename this to SET_USER_OFFLINE
to make verb like other action names.
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.
very good catch!
@@ -373,6 +374,10 @@ export function refreshQueries(alteredQueries) { | |||
return { type: REFRESH_QUERIES, alteredQueries }; | |||
} | |||
|
|||
export function userOffline(offline) { |
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.
userOffline
=> setUserOffline
78f66fe
to
b459143
Compare
@@ -34,6 +34,7 @@ export const SET_DATABASES = 'SET_DATABASES'; | |||
export const SET_ACTIVE_QUERY_EDITOR = 'SET_ACTIVE_QUERY_EDITOR'; | |||
export const SET_ACTIVE_SOUTHPANE_TAB = 'SET_ACTIVE_SOUTHPANE_TAB'; | |||
export const REFRESH_QUERIES = 'REFRESH_QUERIES'; | |||
export const USER_OFFLINE = 'USER_OFFLINE'; |
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.
very good catch!
@@ -39,6 +42,12 @@ class SouthPane extends React.PureComponent { | |||
latestQuery = props.editorQueries[props.editorQueries.length - 1]; |
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.
if it is in offline state, you don't need to run these logic, you just render offline and exit early, right? so you can move offline check before this line.
if (this.props.offline){ | ||
return ( | ||
<Label className="m-r-3" bsStyle={STATE_BSSTYLE_MAP['offline']}> | ||
offline |
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.
instead of create a hard-coded text here, you should create new entry in STATUS_OPTIONS in constants.js
b459143
to
734bcdb
Compare
b6fd18e
to
46009c3
Compare
Ready for review |
46009c3
to
7221cc5
Compare
@@ -166,4 +166,9 @@ describe('TabbedSqlEditors', () => { | |||
const lastTab = wrapper.find(Tab).last(); | |||
expect(lastTab.props().eventKey).toContain('add_tab'); | |||
}); | |||
it('should disable new tab when offline', () => { | |||
wrapper = getWrapper(); | |||
wrapper.setProps({ offline: 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.
before .setProps
, can you add an expect that disabled
props toBe(false)
?
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.
done
2c1be7e
to
81c4be4
Compare
Ready for stamp! |
81c4be4
to
3879751
Compare
3879751
to
573ebac
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.
LGTM
* add timeout and refresh for failed backend * show offline state instead of refreshing * add southpane tests
FYI #6782 |
@timifasubaa I'm not sure why, but in some cases when queries that return errors are executed, I see |
This is a user experience improvement in sqllab. Historically, if the user was disconnected from the internet or the backed was down, sqllab continues to poll from the backend. All the while showing the user they are in the pending state. This is confusing to the user as they would keep thinking their query is pending for a long time when the request hasn't been sent to the backend.
This PR makes it show
offline
when the ajax request cannot connect to the backend to avoid confusion .@graceguo-supercat @kristw