Skip to content

feat: add control to execute forget command for an export #1552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 hideSeverity data={error.data} />;
}
if (error.status === 403) {
return criticalActionDialogKeyset('no-rights-error');
}
Expand Down
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
106 changes: 102 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 {ActionTooltip, Flex, Icon, Text} 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 createToast from '../../utils/createToast';
import {formatDateTime} from '../../utils/dataFormatters/dataFormatters';
import {parseProtobufTimestampToMs} from '../../utils/timeParsers';

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

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,91 @@ 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 (
<Flex gap="2">
<ActionTooltip title={i18n('header_forget')} placement={['left', 'auto']}>
<div>
<ButtonWithConfirmDialog
buttonView="outlined"
dialogHeader={i18n('header_forget')}
dialogText={i18n('text_forget')}
onConfirmAction={() =>
forgetOperation({id, database})
.unwrap()
.then(() => {
createToast({
name: 'Forgotten',
title: i18n('text_forgotten', {id}),
type: 'success',
});
refreshTable();
})
}
buttonDisabled={isLoadingCancel}
>
<Icon data={Ban} />
</ButtonWithConfirmDialog>
</div>
</ActionTooltip>
<ActionTooltip title={i18n('header_cancel')} placement={['right', 'auto']}>
<div>
<ButtonWithConfirmDialog
buttonView="outlined"
dialogHeader={i18n('header_cancel')}
dialogText={i18n('text_cancel')}
onConfirmAction={() =>
cancelOperation({id, database})
.unwrap()
.then(() => {
createToast({
name: 'Cancelled',
title: i18n('text_cancelled', {id}),
type: 'success',
});
refreshTable();
})
}
buttonDisabled={isForgetLoading}
>
<Icon data={CircleStop} />
</ButtonWithConfirmDialog>
</div>
</ActionTooltip>
</Flex>
);
}
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
9 changes: 8 additions & 1 deletion src/containers/Operations/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@
"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?",
"text_forgotten": "The operation {{id}} has been forgotten",
"text_cancelled": "The operation {{id}} has been cancelled"
}
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
9 changes: 7 additions & 2 deletions src/containers/Tablets/TabletsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ function TabletActions(tablet: TTabletStateInfo) {
}}
buttonDisabled={isDisabledRestart || !isUserAllowedToMakeChanges}
withPopover
popoverContent={i18n('controls.kill-not-allowed')}
popoverDisabled={isUserAllowedToMakeChanges}
popoverContent={
isUserAllowedToMakeChanges
? i18n('dialog.kill-header')
: i18n('controls.kill-not-allowed')
}
popoverPlacement={['right', 'auto']}
popoverDisabled={false}
>
<Icon data={ArrowRotateLeft} />
</ButtonWithConfirmDialog>
Expand Down
34 changes: 27 additions & 7 deletions src/containers/Tenant/Query/Issues/Issues.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ const blockIssue = cn('kv-issue');

interface ResultIssuesProps {
data: ErrorResponse | string;
hideSeverity?: boolean;
}

export function ResultIssues({data}: ResultIssuesProps) {
export function ResultIssues({data, hideSeverity}: ResultIssuesProps) {
const [showIssues, setShowIssues] = React.useState(false);

const issues = typeof data === 'string' ? undefined : data?.issues;
Expand All @@ -41,7 +42,11 @@ export function ResultIssues({data}: ResultIssuesProps) {
const severity = getSeverity(data?.error?.severity);
content = (
<React.Fragment>
<IssueSeverity severity={severity} />{' '}
{hideSeverity ? null : (
<React.Fragment>
<IssueSeverity severity={severity} />{' '}
</React.Fragment>
)}
<span className={blockWrapper('error-message-text')}>
{data?.error?.message}
</span>
Expand All @@ -62,29 +67,44 @@ export function ResultIssues({data}: ResultIssuesProps) {
</Button>
)}
</div>
{hasIssues && showIssues && <Issues issues={issues} />}
{hasIssues && showIssues && <Issues hideSeverity={hideSeverity} issues={issues} />}
</div>
);
}

interface IssuesProps {
issues: IssueMessage[] | null | undefined;
hideSeverity?: boolean;
}
export function Issues({issues}: IssuesProps) {
export function Issues({issues, hideSeverity}: IssuesProps) {
const mostSevereIssue = issues?.reduce((result, issue) => {
const severity = issue.severity ?? 10;
return Math.min(result, severity);
}, 10);
return (
<div className={blockIssues(null)}>
{issues?.map((issue, index) => (
<Issue key={index} issue={issue} expanded={issue === mostSevereIssue} />
<Issue
key={index}
hideSeverity={hideSeverity}
issue={issue}
expanded={issue === mostSevereIssue}
/>
))}
</div>
);
}

function Issue({issue, level = 0}: {issue: IssueMessage; expanded?: boolean; level?: number}) {
function Issue({
issue,
hideSeverity,
level = 0,
}: {
issue: IssueMessage;
expanded?: boolean;
hideSeverity?: boolean;
level?: number;
}) {
const [isExpand, setIsExpand] = React.useState(true);
const severity = getSeverity(issue.severity);
const position = getIssuePosition(issue);
Expand All @@ -111,7 +131,7 @@ function Issue({issue, level = 0}: {issue: IssueMessage; expanded?: boolean; lev
<ArrowToggle direction={arrowDirection} size={16} />
</Button>
)}
<IssueSeverity severity={severity} />
{hideSeverity ? null : <IssueSeverity severity={severity} />}

<span className={blockIssue('message')}>
{position && (
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 @@ -887,6 +892,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.

Loading
Loading