| 109 | }; |
| 110 | |
| 111 | function getTerminateCell(pgAdmin, sid, did, canTakeAction, onSuccess) { |
| 112 | function TerminateCell({row}) { |
| 113 | let terminate_session_url = |
| 114 | url_for('dashboard.index') + 'terminate_session' + '/' + sid, |
| 115 | title = gettext('Terminate Session?'), |
| 116 | txtConfirm = gettext( |
| 117 | 'Are you sure you wish to terminate the session?' |
| 118 | ), |
| 119 | txtSuccess = gettext('Session terminated successfully.'), |
| 120 | txtError = gettext( |
| 121 | 'An error occurred whilst terminating the active query.' |
| 122 | ); |
| 123 | const action_url = did |
| 124 | ? terminate_session_url + '/' + did |
| 125 | : terminate_session_url; |
| 126 | |
| 127 | const api = getApiInstance(); |
| 128 | |
| 129 | return ( |
| 130 | <PgIconButton |
| 131 | size="xs" |
| 132 | noBorder |
| 133 | icon={<BlockRoundedIcon />} |
| 134 | className='Dashboard-terminateButton' |
| 135 | onClick={() => { |
| 136 | if ( |
| 137 | !canTakeAction(row, 'terminate') |
| 138 | ) |
| 139 | return; |
| 140 | let url = action_url + '/' + row.original.pid; |
| 141 | pgAdmin.Browser.notifier.confirm( |
| 142 | title, |
| 143 | txtConfirm, |
| 144 | function () { |
| 145 | api |
| 146 | .delete(url) |
| 147 | .then(function (res) { |
| 148 | if (res.data == gettext('Success')) { |
| 149 | pgAdmin.Browser.notifier.success(txtSuccess); |
| 150 | onSuccess?.(); |
| 151 | } else { |
| 152 | pgAdmin.Browser.notifier.error(txtError); |
| 153 | } |
| 154 | }) |
| 155 | .catch(function (error) { |
| 156 | pgAdmin.Browser.notifier.alertText( |
| 157 | gettext('Failed to perform the operation.'), |
| 158 | parseApiError(error) |
| 159 | ); |
| 160 | }); |
| 161 | }, |
| 162 | function () { |
| 163 | return true; |
| 164 | } |
| 165 | ); |
| 166 | }} |
| 167 | aria-label="Terminate Session?" |
| 168 | title={gettext('Terminate Session?')} |