Skip to content

Commit

Permalink
[QuerySearch] Add loading status to QuerySearch page (apache#1657)
Browse files Browse the repository at this point in the history
* Add loading state to QuerySearch
 * Move ajax call to ComponentDidMount
 * Show loading image during ajax call
  • Loading branch information
vera-liu authored Nov 21, 2016
1 parent c90dd49 commit bd6a439
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions superset/assets/javascripts/SqlLab/components/QuerySearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ class QuerySearch extends React.PureComponent {
to: null,
status: 'success',
queriesArray: [],
queriesLoading: true,
};
}
componentWillMount() {
this.fetchUsers();
}
componentDidMount() {
this.refreshQueries();
}
onUserClicked(userId) {
Expand Down Expand Up @@ -100,6 +103,7 @@ class QuerySearch extends React.PureComponent {
});
}
refreshQueries() {
this.setState({ queriesLoading: true });
const params = [
this.state.userId ? `user_id=${this.state.userId}` : '',
this.state.databaseId ? `database_id=${this.state.databaseId}` : '',
Expand All @@ -116,7 +120,7 @@ class QuerySearch extends React.PureComponent {
for (const id in data) {
newQueriesArray.push(data[id]);
}
this.setState({ queriesArray: newQueriesArray });
this.setState({ queriesArray: newQueriesArray, queriesLoading: false });
}
});
}
Expand Down Expand Up @@ -185,16 +189,20 @@ class QuerySearch extends React.PureComponent {
Search
</Button>
</div>
<QueryTable
columns={[
'state', 'db', 'user', 'date',
'progress', 'rows', 'sql', 'querylink',
]}
onUserClicked={this.onUserClicked.bind(this)}
onDbClicked={this.onDbClicked.bind(this)}
queries={this.state.queriesArray}
actions={this.props.actions}
/>
{this.state.queriesLoading ?
(<img className="loading" alt="Loading..." src="/static/assets/images/loading.gif" />)
:
(<QueryTable
columns={[
'state', 'db', 'user', 'date',
'progress', 'rows', 'sql', 'querylink',
]}
onUserClicked={this.onUserClicked.bind(this)}
onDbClicked={this.onDbClicked.bind(this)}
queries={this.state.queriesArray}
actions={this.props.actions}
/>)
}
</div>
);
}
Expand Down

0 comments on commit bd6a439

Please sign in to comment.