Skip to content

Commit

Permalink
Merge pull request #270 from carlosms/cancel-disable
Browse files Browse the repository at this point in the history
Disable cancel button for older browsers
  • Loading branch information
carlosms authored Oct 11, 2018
2 parents 30eca23 + 7a4361b commit c8a2d39
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
7 changes: 5 additions & 2 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ FROM ( SELECT MONTH(committer_when) as month,

loadQuery(key, sql) {
const { history } = this.state;
const abortController = new window.AbortController();
const abortController = window.AbortController
? new window.AbortController()
: undefined;

const loadingResults = new Map(this.state.results);
loadingResults.set(key, { sql, loading: true, abortController });
Expand All @@ -220,8 +222,9 @@ FROM ( SELECT MONTH(committer_when) as month,
() => this.handleSetActiveResult(key)
);

const signal = abortController ? abortController.signal : undefined;
api
.query(sql, abortController.signal)
.query(sql, signal)
.then(response => {
this.setResult(key, { sql, response });

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/TabbedResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ class TabbedResults extends Component {
const { codeModalShow, codeModalContent } = this.state;
const { showUAST, history, languages } = this.props;

const cancelDisabled = window.AbortController === undefined;

return (
<div className="results-padding full-height full-width">
<DivTabs
Expand Down Expand Up @@ -242,6 +244,7 @@ class TabbedResults extends Component {
<Button
className="animation-action cancel"
bsStyle="gbpl-tertiary"
disabled={cancelDisabled}
onClick={() => this.props.handleAbortQuery(key)}
>
CANCEL
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import 'abortcontroller-polyfill/dist/polyfill-patch-fetch';
import 'bootstrap/dist/css/bootstrap.css';
import './variables.less';
import App from './App';

ReactDOM.render(<App />, document.getElementById('root'));

if (!window.AbortController) {
// eslint-disable-next-line no-console
console.warn(`Cancelling gitbase queries is disabled; your browser does not support the AbortController interface.
Please check for compatibility here: https://developer.mozilla.org/en-US/docs/Web/API/AbortController#Browser_compatibility`);
}

0 comments on commit c8a2d39

Please sign in to comment.