Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import {CircleXmarkFill, TriangleExclamationFill} from '@gravity-ui/icons';
import {Checkbox, Dialog, Icon} from '@gravity-ui/uikit';

import {ResultIssues} from '../../containers/Tenant/Query/Issues/Issues';
import type {IResponseError} from '../../types/api/error';
import {cn} from '../../utils/cn';

Expand All @@ -13,6 +14,9 @@ import './CriticalActionDialog.scss';
const b = cn('ydb-critical-dialog');

const parseError = (error: IResponseError) => {
if (error.data && 'issues' in error.data && error.data.issues) {
return <ResultIssues data={error.data} />;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks strange... What if we remove ydb-critical-dialog__error-icon in case when we show issues tree?
Screenshot 2024-10-29 at 11 45 53

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is seems formatting is broken when expand issues
Screenshot 2024-10-31 at 12 35 04

}
if (error.status === 403) {
return criticalActionDialogKeyset('no-rights-error');
}
Expand Down
5 changes: 5 additions & 0 deletions src/containers/Operations/Operations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
&__search {
width: 220px;
}

&__buttons-container {
display: flex;
gap: var(--g-spacing-2);
}
}
6 changes: 3 additions & 3 deletions src/containers/Operations/Operations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {isAccessError} from '../../components/Errors/PageError/PageError';
import {ResponseError} from '../../components/Errors/ResponseError';
import {ResizeableDataTable} from '../../components/ResizeableDataTable/ResizeableDataTable';
import {TableWithControlsLayout} from '../../components/TableWithControlsLayout/TableWithControlsLayout';
import {operationListApi} from '../../store/reducers/operationList';
import {operationsApi} from '../../store/reducers/operations';
import {useAutoRefreshInterval} from '../../utils/hooks';

import {OperationsControls} from './OperationsControls';
Expand All @@ -24,7 +24,7 @@ export function Operations({database}: OperationsProps) {
const {kind, searchValue, pageSize, pageToken, handleKindChange, handleSearchChange} =
useOperationsQueryParams();

const {data, isFetching, error} = operationListApi.useGetOperationListQuery(
const {data, isFetching, error, refetch} = operationsApi.useGetOperationListQuery(
{database, kind, page_size: pageSize, page_token: pageToken},
{
pollingInterval: autoRefreshInterval,
Expand Down Expand Up @@ -61,7 +61,7 @@ export function Operations({database}: OperationsProps) {
<TableWithControlsLayout.Table loading={isFetching} className={b('table')}>
{data ? (
<ResizeableDataTable
columns={getColumns()}
columns={getColumns({database, refreshTable: refetch})}
data={filteredOperations}
emptyDataMessage={i18n('title_empty')}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/containers/Operations/OperationsControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Select} from '@gravity-ui/uikit';

import {EntitiesCount} from '../../components/EntitiesCount';
import {Search} from '../../components/Search';
import type {OperationKind} from '../../types/api/operationList';
import type {OperationKind} from '../../types/api/operations';

import {OPERATION_KINDS} from './constants';
import i18n from './i18n';
Expand Down
92 changes: 88 additions & 4 deletions src/containers/Operations/columns.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import {duration} from '@gravity-ui/date-utils';
import {Ban, CircleStop} from '@gravity-ui/icons';
import type {Column as DataTableColumn} from '@gravity-ui/react-data-table';
import {Text} from '@gravity-ui/uikit';
import {Icon, Text, Tooltip} from '@gravity-ui/uikit';

import {ButtonWithConfirmDialog} from '../../components/ButtonWithConfirmDialog/ButtonWithConfirmDialog';
import {CellWithPopover} from '../../components/CellWithPopover/CellWithPopover';
import type {TOperation} from '../../types/api/operationList';
import {EStatusCode} from '../../types/api/operationList';
import {operationsApi} from '../../store/reducers/operations';
import type {TOperation} from '../../types/api/operations';
import {EStatusCode} from '../../types/api/operations';
import {EMPTY_DATA_PLACEHOLDER, HOUR_IN_SECONDS, SECOND_IN_MS} from '../../utils/constants';
import {formatDateTime} from '../../utils/dataFormatters/dataFormatters';
import {parseProtobufTimestampToMs} from '../../utils/timeParsers';

import {COLUMNS_NAMES, COLUMNS_TITLES} from './constants';
import i18n from './i18n';
import {b} from './shared';

export function getColumns(): DataTableColumn<TOperation>[] {
import './Operations.scss';

export function getColumns({
database,
refreshTable,
}: {
database: string;
refreshTable: VoidFunction;
}): DataTableColumn<TOperation>[] {
return [
{
name: COLUMNS_NAMES.ID,
Expand Down Expand Up @@ -114,5 +126,77 @@ export function getColumns(): DataTableColumn<TOperation>[] {
return Date.now() - createTime;
},
},
{
name: 'Actions',
sortable: false,
resizeable: false,
header: '',
render: ({row}) => {
return (
<OperationsActions
operation={row}
database={database}
refreshTable={refreshTable}
/>
);
},
},
];
}

interface OperationsActionsProps {
operation: TOperation;
database: string;
refreshTable: VoidFunction;
}

function OperationsActions({operation, database, refreshTable}: OperationsActionsProps) {
const [cancelOperation, {isLoading: isLoadingCancel}] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for me it would be nice to show success toast if action is completed. What do you think?

operationsApi.useCancelOperationMutation();
const [forgetOperation, {isLoading: isForgetLoading}] =
operationsApi.useForgetOperationMutation();

const id = operation.id;
if (!id) {
return null;
}

return (
<div className={b('buttons-container')}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets use Flex from uikit?

<Tooltip openDelay={0} content={i18n('header_forget')} placement="right">
<div>
<ButtonWithConfirmDialog
buttonView="outlined"
dialogHeader={i18n('header_forget')}
dialogText={i18n('text_forget')}
onConfirmAction={() =>
forgetOperation({id, database})
.unwrap()
.then(() => refreshTable())
}
buttonDisabled={isLoadingCancel}
>
<Icon data={Ban} />
</ButtonWithConfirmDialog>
</div>
</Tooltip>
<Tooltip openDelay={0} content={i18n('header_cancel')} placement="right">
<div>
<ButtonWithConfirmDialog
buttonView="outlined"
dialogHeader={i18n('header_cancel')}
dialogText={i18n('text_cancel')}
onConfirmAction={() =>
cancelOperation({id, database})
.unwrap()
.then(() => refreshTable())
}
buttonDisabled={isForgetLoading}
>
<Icon data={CircleStop} />
</ButtonWithConfirmDialog>
</div>
</Tooltip>
</div>
);
}
2 changes: 1 addition & 1 deletion src/containers/Operations/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {OperationKind} from '../../types/api/operationList';
import type {OperationKind} from '../../types/api/operations';

import i18n from './i18n';

Expand Down
7 changes: 6 additions & 1 deletion src/containers/Operations/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@
"column_createTime": "Create Time",
"column_endTime": "End Time",
"column_duration": "Duration",
"label_duration-ongoing": "{{value}} (ongoing)"
"label_duration-ongoing": "{{value}} (ongoing)",

"header_cancel": "Cancel operation",
"header_forget": "Forget operation",
"text_cancel": "The operation will be cancelled. Do you want to proceed?",
"text_forget": "The operation will be forgotten. Do you want to proceed?"
}
2 changes: 1 addition & 1 deletion src/containers/Operations/useOperationsQueryParams.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {NumberParam, StringParam, useQueryParams} from 'use-query-params';
import {z} from 'zod';

import type {OperationKind} from '../../types/api/operationList';
import type {OperationKind} from '../../types/api/operations';

const operationKindSchema = z.enum(['ss/backgrounds', 'export', 'buildindex']).catch('buildindex');

Expand Down
37 changes: 36 additions & 1 deletion src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ import type {ModifyDiskResponse} from '../types/api/modifyDisk';
import type {TNetInfo} from '../types/api/netInfo';
import type {NodesRequestParams, TNodesInfo} from '../types/api/nodes';
import type {TEvNodesInfo} from '../types/api/nodesList';
import type {OperationListRequestParams, TOperationList} from '../types/api/operationList';
import type {
OperationCancelRequestParams,
OperationForgetRequestParams,
OperationListRequestParams,
TOperationList,
} from '../types/api/operations';
import type {EDecommitStatus, TEvPDiskStateResponse, TPDiskInfoResponse} from '../types/api/pdisk';
import type {
Actions,
Expand Down Expand Up @@ -886,6 +891,36 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
);
}

cancelOperation(
params: OperationCancelRequestParams,
{concurrentId, signal}: AxiosOptions = {},
) {
return this.post<TOperationList>(
this.getPath('/operation/cancel'),
{},
{...params},
{
concurrentId,
requestConfig: {signal},
},
);
}

forgetOperation(
params: OperationForgetRequestParams,
{concurrentId, signal}: AxiosOptions = {},
) {
return this.post<TOperationList>(
this.getPath('/operation/forget'),
{},
{...params},
{
concurrentId,
requestConfig: {signal},
},
);
}

getClusterBaseInfo(
_clusterName: string,
_opts: AxiosOptions = {},
Expand Down
20 changes: 0 additions & 20 deletions src/store/reducers/operationList.ts

This file was deleted.

44 changes: 44 additions & 0 deletions src/store/reducers/operations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type {
OperationCancelRequestParams,
OperationForgetRequestParams,
OperationListRequestParams,
} from '../../types/api/operations';

import {api} from './api';

export const operationsApi = api.injectEndpoints({
endpoints: (build) => ({
getOperationList: build.query({
queryFn: async (params: OperationListRequestParams, {signal}) => {
try {
const data = await window.api.getOperationList(params, {signal});
return {data};
} catch (error) {
return {error};
}
},
providesTags: ['All'],
}),
cancelOperation: build.mutation({
queryFn: async (params: OperationCancelRequestParams, {signal}) => {
try {
const data = await window.api.cancelOperation(params, {signal});
return {data};
} catch (error) {
return {error};
}
},
}),
forgetOperation: build.mutation({
queryFn: async (params: OperationForgetRequestParams, {signal}) => {
try {
const data = await window.api.forgetOperation(params, {signal});
return {data};
} catch (error) {
return {error};
}
},
}),
}),
overrideExisting: 'throw',
});
7 changes: 6 additions & 1 deletion src/types/api/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export interface IResponseError<T = unknown> {
import type {TIssueMessage} from './operations';

// TODO: extend with other error types
type ResponseErrorData = TIssueMessage;

export interface IResponseError<T = ResponseErrorData> {
data?: T;
status?: number;
statusText?: string;
Expand Down
10 changes: 10 additions & 0 deletions src/types/api/operationList.ts → src/types/api/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,13 @@ export interface OperationListRequestParams {
page_size?: number;
page_token?: string;
}

export interface OperationCancelRequestParams {
database: string;
id: string;
}

export interface OperationForgetRequestParams {
database: string;
id: string;
}
Loading