Skip to content

Commit

Permalink
Add cancel_query_on_windows_unload option to database
Browse files Browse the repository at this point in the history
  • Loading branch information
koszti committed Jul 11, 2021
1 parent e1fc4b3 commit e5223ec
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
5 changes: 4 additions & 1 deletion superset-frontend/src/SqlLab/components/SqlEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,10 @@ class SqlEditor extends React.PureComponent {
}

onBeforeUnload(event) {
if (this.props.latestQuery?.state === 'running') {
if (
this.props.database?.extra_json?.cancel_query_on_windows_unload &&
this.props.latestQuery?.state === 'running'
) {
event.preventDefault();
this.stopQuery();
}
Expand Down
5 changes: 4 additions & 1 deletion superset-frontend/src/SqlLab/reducers/sqlLab.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,10 @@ export default function sqlLabReducer(state = {}, action) {
[actions.SET_DATABASES]() {
const databases = {};
action.databases.forEach(db => {
databases[db.id] = db;
databases[db.id] = {
...db,
extra_json: JSON.parse(db.extra || ''),
};
});
return { ...state, databases };
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,24 @@ const ExtraOptions = ({
/>
</div>
</StyledInputContainer>
<StyledInputContainer css={{ no_margin_bottom }}>
<div className="input-container">
<IndeterminateCheckbox
id="cancel_query_on_windows_unload"
indeterminate={false}
checked={!!db?.extra_json?.cancel_query_on_windows_unload}
onChange={onExtraInputChange}
labelText={t('Cancel query on window unload event')}
/>
<InfoTooltip
tooltip={t(
'Terminate running queries when browser window closed or navigated ' +
'to another page. Available for Presto, Hive, MySQL, Postgres and ' +
'Snowflake databases.',
)}
/>
</div>
</StyledInputContainer>
</Collapse.Panel>
<Collapse.Panel
header={
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/views/CRUD/data/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export type DatabaseObject = {
}; // No field, holds schema and table timeout
allows_virtual_table_explore?: boolean; // in SQL Lab
schemas_allowed_for_csv_upload?: [] | string; // in Security
cancel_query_on_windows_unload?: boolean; // in Performance
version?: string;

// todo: ask beto where this should live
Expand Down
1 change: 1 addition & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
"database_name",
"explore_database_id",
"expose_in_sqllab",
"extra",
"force_ctas_schema",
"id",
]
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/databases/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def test_get_items(self):
"database_name",
"explore_database_id",
"expose_in_sqllab",
"extra",
"force_ctas_schema",
"id",
]
Expand Down

0 comments on commit e5223ec

Please sign in to comment.