diff --git a/web/pgadmin/static/js/sqleditor/execute_query.js b/web/pgadmin/static/js/sqleditor/execute_query.js index 9aa025b..cb9420e 100644 --- a/web/pgadmin/static/js/sqleditor/execute_query.js +++ b/web/pgadmin/static/js/sqleditor/execute_query.js @@ -240,12 +240,10 @@ class ExecuteQuery { enableSQLEditorButtons() { this.sqlServerObject.disable_tool_buttons(false); - $('#btn-cancel-query').prop('disabled', true); } disableSQLEditorButtons() { this.sqlServerObject.disable_tool_buttons(true); - $('#btn-cancel-query').prop('disabled', false); } static wasConnectionLostToPythonServer(httpResponse) { diff --git a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js index ce39769..c360421 100644 --- a/web/pgadmin/tools/sqleditor/static/js/sqleditor.js +++ b/web/pgadmin/tools/sqleditor/static/js/sqleditor.js @@ -3370,6 +3370,10 @@ define('tools.querytool', [ $('#btn-edit-dropdown').prop('disabled', disabled); $('#btn-edit').prop('disabled', disabled); $('#btn-load-file').prop('disabled', disabled); + if (this.is_query_tool) { + // Cancel query tool needs opposite behaviour + $('#btn-cancel-query').prop('disabled', !disabled); + } }, // This function will fetch the sql query from the text box @@ -3461,8 +3465,6 @@ define('tools.querytool', [ // This function will cancel the running query. _cancel_query: function() { var self = this; - - $('#btn-cancel-query').prop('disabled', true); $.ajax({ url: url_for('sqleditor.cancel_transaction', { 'trans_id': self.transId, @@ -3470,12 +3472,10 @@ define('tools.querytool', [ method: 'POST', contentType: 'application/json', success: function(res) { - if (res.data.status) { - self.disable_tool_buttons(false); - } else { - self.disable_tool_buttons(false); + if (!res.data.status) { alertify.alert(gettext('Cancel Query Error'), res.data.result); } + self.disable_tool_buttons(false); is_query_running = false; setTimeout(() => { self.gridView.query_tool_obj.focus(); }, 200); }, diff --git a/web/regression/javascript/sqleditor/execute_query_spec.js b/web/regression/javascript/sqleditor/execute_query_spec.js index 0c0953c..7f42a9a 100644 --- a/web/regression/javascript/sqleditor/execute_query_spec.js +++ b/web/regression/javascript/sqleditor/execute_query_spec.js @@ -228,15 +228,6 @@ describe('ExecuteQuery', () => { done(); }, 0); }); - - it('should disable the cancel button', (done) => { - setTimeout( - () => { - expect(cancelButtonSpy) - .toHaveBeenCalledWith('disabled', true); - done(); - }, 0); - }); }); describe('when query was cancelled', () => { @@ -333,15 +324,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should disable the cancel button', (done) => { - setTimeout( - () => { - expect(cancelButtonSpy) - .toHaveBeenCalledWith('disabled', true); - done(); - }, 0); - }); - it('should not login is displayed', (done) => { setTimeout( () => { @@ -406,15 +388,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should disable the cancel button', (done) => { - setTimeout( - () => { - expect(cancelButtonSpy) - .toHaveBeenCalledWith('disabled', true); - done(); - }, 0); - }); - it('should login is displayed', (done) => { setTimeout( () => { @@ -483,15 +456,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should disable the cancel button', (done) => { - setTimeout( - () => { - expect(cancelButtonSpy) - .toHaveBeenCalledWith('disabled', true); - done(); - }, 0); - }); - it('should login is not displayed', (done) => { setTimeout( () => { @@ -558,15 +522,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should disable the cancel button', (done) => { - setTimeout( - () => { - expect(cancelButtonSpy) - .toHaveBeenCalledWith('disabled', true); - done(); - }, 0); - }); - it('should login is displayed', (done) => { setTimeout( () => { @@ -630,15 +585,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should disable the cancel button', (done) => { - setTimeout( - () => { - expect(cancelButtonSpy) - .toHaveBeenCalledWith('disabled', true); - done(); - }, 0); - }); - it('should login is not displayed', (done) => { setTimeout( () => { @@ -970,14 +916,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should not disable the cancel button', (done) => { - setTimeout( - () => { - expect(cancelButtonSpy).not - .toHaveBeenCalled(); - done(); - }, 0); - }); }); describe('when cannot reach the Python Server', () => { @@ -1251,15 +1189,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('disable the cancel query button', (done) => { - setTimeout(() => { - let buttonFlash = $('#btn-cancel-query'); - - expect(buttonFlash.prop('disabled')).toEqual(true); - done(); - }, 0); - }); - it('enable the query tool buttons', (done) => { setTimeout(() => { expect(sqlEditorMock.disable_tool_buttons).toHaveBeenCalledWith(false); @@ -1369,16 +1298,6 @@ describe('ExecuteQuery', () => { done(); }, 0); }); - - it('should disable the cancel button', (done) => { - setTimeout( - () => { - let buttonFlash = $('#btn-cancel-query'); - - expect(buttonFlash.prop('disabled')).toEqual(true); - done(); - }, 0); - }); }); describe('when error is returned by the server', () => { @@ -1428,16 +1347,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should disable the cancel button', (done) => { - setTimeout( - () => { - let buttonFlash = $('#btn-cancel-query'); - - expect(buttonFlash.prop('disabled')).toEqual(true); - done(); - }, 0); - }); - it('should not save the state', () => { setTimeout(() => { expect(sqlEditorMock.saveState).not.toHaveBeenCalled(); @@ -1496,16 +1405,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should disable the cancel button', (done) => { - setTimeout( - () => { - let buttonFlash = $('#btn-cancel-query'); - - expect(buttonFlash.prop('disabled')).toEqual(true); - done(); - }, 0); - }); - it('should save the state', () => { setTimeout(() => { expect(sqlEditorMock.saveState).toHaveBeenCalledWith( @@ -1567,16 +1466,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should disable the cancel button', (done) => { - setTimeout( - () => { - let buttonFlash = $('#btn-cancel-query'); - - expect(buttonFlash.prop('disabled')).toEqual(true); - done(); - }, 0); - }); - it('should not save the state', () => { setTimeout(() => { expect(sqlEditorMock.saveState).not.toHaveBeenCalled(); @@ -1641,16 +1530,6 @@ describe('ExecuteQuery', () => { }, 0); }); - it('should disable the cancel button', (done) => { - setTimeout( - () => { - let buttonFlash = $('#btn-cancel-query'); - - expect(buttonFlash.prop('disabled')).toEqual(true); - done(); - }, 0); - }); - it('should save the state', () => { setTimeout(() => { expect(sqlEditorMock.saveState).toHaveBeenCalledWith(