Skip to content
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

Conversation

timifasubaa
Copy link
Contributor

@timifasubaa timifasubaa commented Oct 1, 2018

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
screen shot 2018-10-09 at 12 26 52 am

@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch 4 times, most recently from 120826e to ee89873 Compare October 1, 2018 18:47
@codecov-io
Copy link

codecov-io commented Oct 1, 2018

Codecov Report

Merging #6013 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a71e6eb...3879751. Read the comment docs.

$.ajax({
dataType: 'json',
url,
timeout: 3000,

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.

Copy link
Contributor Author

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);

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.

@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch from ee89873 to b3ef68f Compare October 3, 2018 20:10
@timifasubaa timifasubaa changed the title [Sqllab] add timeout and refresh for failed backend polling [Sqllab] Add offline state to sqllab Oct 3, 2018
@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch 7 times, most recently from da86a1f to f079f04 Compare October 9, 2018 07:34
@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch 2 times, most recently from 70774eb to 34b1453 Compare October 11, 2018 08:49
@timifasubaa
Copy link
Contributor Author

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;
Copy link

@graceguo-supercat graceguo-supercat Oct 4, 2018

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also corrected.

@@ -20,6 +20,7 @@ initJQueryAjax();

const appContainer = document.getElementById('app');
const bootstrapData = JSON.parse(appContainer.getAttribute('data-bootstrap'));
bootstrapData.offline = false;

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

Copy link
Contributor Author

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

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?

Copy link
Contributor Author

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);

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?

Copy link
Contributor Author

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

@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch 5 times, most recently from ced2f09 to 78f66fe Compare October 12, 2018 00:39
@timifasubaa
Copy link
Contributor Author

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';
Copy link
Contributor

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.

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userOffline => setUserOffline

@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch from 78f66fe to b459143 Compare October 12, 2018 01:06
@@ -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';

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];

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

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

@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch from b459143 to 734bcdb Compare October 12, 2018 17:46
@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch 5 times, most recently from b6fd18e to 46009c3 Compare October 18, 2018 04:28
@timifasubaa
Copy link
Contributor Author

Ready for review

@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch from 46009c3 to 7221cc5 Compare October 18, 2018 04:57
@@ -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 });

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)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch 2 times, most recently from 2c1be7e to 81c4be4 Compare October 20, 2018 00:38
@timifasubaa
Copy link
Contributor Author

Ready for stamp!

@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch from 81c4be4 to 3879751 Compare October 20, 2018 01:26
@timifasubaa timifasubaa force-pushed the sqllab_timeout_when_disconnected_from_server branch from 3879751 to 573ebac Compare October 22, 2018 23:47
Copy link

@graceguo-supercat graceguo-supercat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@timifasubaa timifasubaa reopened this Oct 23, 2018
@timifasubaa timifasubaa reopened this Oct 23, 2018
@timifasubaa timifasubaa merged commit fc3b68e into apache:master Oct 23, 2018
bipinsoniguavus pushed a commit to ThalesGroup/incubator-superset that referenced this pull request Dec 26, 2018
* add timeout and refresh for failed backend

* show offline state instead of refreshing

* add southpane tests
@mistercrunch
Copy link
Member

FYI #6782

@mistercrunch
Copy link
Member

@timifasubaa I'm not sure why, but in some cases when queries that return errors are executed, I see offline flash on the UI

@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants