|
1 | 1 | import {duration} from '@gravity-ui/date-utils';
|
| 2 | +import {Ban, CircleStop} from '@gravity-ui/icons'; |
2 | 3 | import type {Column as DataTableColumn} from '@gravity-ui/react-data-table';
|
3 |
| -import {Text} from '@gravity-ui/uikit'; |
| 4 | +import {ActionTooltip, Flex, Icon, Text} from '@gravity-ui/uikit'; |
4 | 5 |
|
| 6 | +import {ButtonWithConfirmDialog} from '../../components/ButtonWithConfirmDialog/ButtonWithConfirmDialog'; |
5 | 7 | import {CellWithPopover} from '../../components/CellWithPopover/CellWithPopover';
|
6 |
| -import type {TOperation} from '../../types/api/operationList'; |
7 |
| -import {EStatusCode} from '../../types/api/operationList'; |
| 8 | +import {operationsApi} from '../../store/reducers/operations'; |
| 9 | +import type {TOperation} from '../../types/api/operations'; |
| 10 | +import {EStatusCode} from '../../types/api/operations'; |
8 | 11 | import {EMPTY_DATA_PLACEHOLDER, HOUR_IN_SECONDS, SECOND_IN_MS} from '../../utils/constants';
|
| 12 | +import createToast from '../../utils/createToast'; |
9 | 13 | import {formatDateTime} from '../../utils/dataFormatters/dataFormatters';
|
10 | 14 | import {parseProtobufTimestampToMs} from '../../utils/timeParsers';
|
11 | 15 |
|
12 | 16 | import {COLUMNS_NAMES, COLUMNS_TITLES} from './constants';
|
13 | 17 | import i18n from './i18n';
|
14 | 18 |
|
15 |
| -export function getColumns(): DataTableColumn<TOperation>[] { |
| 19 | +import './Operations.scss'; |
| 20 | + |
| 21 | +export function getColumns({ |
| 22 | + database, |
| 23 | + refreshTable, |
| 24 | +}: { |
| 25 | + database: string; |
| 26 | + refreshTable: VoidFunction; |
| 27 | +}): DataTableColumn<TOperation>[] { |
16 | 28 | return [
|
17 | 29 | {
|
18 | 30 | name: COLUMNS_NAMES.ID,
|
@@ -114,5 +126,91 @@ export function getColumns(): DataTableColumn<TOperation>[] {
|
114 | 126 | return Date.now() - createTime;
|
115 | 127 | },
|
116 | 128 | },
|
| 129 | + { |
| 130 | + name: 'Actions', |
| 131 | + sortable: false, |
| 132 | + resizeable: false, |
| 133 | + header: '', |
| 134 | + render: ({row}) => { |
| 135 | + return ( |
| 136 | + <OperationsActions |
| 137 | + operation={row} |
| 138 | + database={database} |
| 139 | + refreshTable={refreshTable} |
| 140 | + /> |
| 141 | + ); |
| 142 | + }, |
| 143 | + }, |
117 | 144 | ];
|
118 | 145 | }
|
| 146 | + |
| 147 | +interface OperationsActionsProps { |
| 148 | + operation: TOperation; |
| 149 | + database: string; |
| 150 | + refreshTable: VoidFunction; |
| 151 | +} |
| 152 | + |
| 153 | +function OperationsActions({operation, database, refreshTable}: OperationsActionsProps) { |
| 154 | + const [cancelOperation, {isLoading: isLoadingCancel}] = |
| 155 | + operationsApi.useCancelOperationMutation(); |
| 156 | + const [forgetOperation, {isLoading: isForgetLoading}] = |
| 157 | + operationsApi.useForgetOperationMutation(); |
| 158 | + |
| 159 | + const id = operation.id; |
| 160 | + if (!id) { |
| 161 | + return null; |
| 162 | + } |
| 163 | + |
| 164 | + return ( |
| 165 | + <Flex gap="2"> |
| 166 | + <ActionTooltip title={i18n('header_forget')} placement={['left', 'auto']}> |
| 167 | + <div> |
| 168 | + <ButtonWithConfirmDialog |
| 169 | + buttonView="outlined" |
| 170 | + dialogHeader={i18n('header_forget')} |
| 171 | + dialogText={i18n('text_forget')} |
| 172 | + onConfirmAction={() => |
| 173 | + forgetOperation({id, database}) |
| 174 | + .unwrap() |
| 175 | + .then(() => { |
| 176 | + createToast({ |
| 177 | + name: 'Forgotten', |
| 178 | + title: i18n('text_forgotten', {id}), |
| 179 | + type: 'success', |
| 180 | + }); |
| 181 | + refreshTable(); |
| 182 | + }) |
| 183 | + } |
| 184 | + buttonDisabled={isLoadingCancel} |
| 185 | + > |
| 186 | + <Icon data={Ban} /> |
| 187 | + </ButtonWithConfirmDialog> |
| 188 | + </div> |
| 189 | + </ActionTooltip> |
| 190 | + <ActionTooltip title={i18n('header_cancel')} placement={['right', 'auto']}> |
| 191 | + <div> |
| 192 | + <ButtonWithConfirmDialog |
| 193 | + buttonView="outlined" |
| 194 | + dialogHeader={i18n('header_cancel')} |
| 195 | + dialogText={i18n('text_cancel')} |
| 196 | + onConfirmAction={() => |
| 197 | + cancelOperation({id, database}) |
| 198 | + .unwrap() |
| 199 | + .then(() => { |
| 200 | + createToast({ |
| 201 | + name: 'Cancelled', |
| 202 | + title: i18n('text_cancelled', {id}), |
| 203 | + type: 'success', |
| 204 | + }); |
| 205 | + refreshTable(); |
| 206 | + }) |
| 207 | + } |
| 208 | + buttonDisabled={isForgetLoading} |
| 209 | + > |
| 210 | + <Icon data={CircleStop} /> |
| 211 | + </ButtonWithConfirmDialog> |
| 212 | + </div> |
| 213 | + </ActionTooltip> |
| 214 | + </Flex> |
| 215 | + ); |
| 216 | +} |
0 commit comments