Skip to content

Commit d3e5f70

Browse files
feat(PDiskPage): add decommission button (#1168)
1 parent c79ccbc commit d3e5f70

File tree

25 files changed

+445
-103
lines changed

25 files changed

+445
-103
lines changed

src/assets/icons/decommission.svg

Lines changed: 6 additions & 0 deletions
Loading

src/components/ButtonWithConfirmDialog/ButtonWithConfirmDialog.tsx

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import React from 'react';
33
import {Button, Popover} from '@gravity-ui/uikit';
44
import type {ButtonProps, PopoverProps} from '@gravity-ui/uikit';
55

6-
import {CriticalActionDialog} from '../CriticalActionDialog';
6+
import {CriticalActionDialog} from '../CriticalActionDialog/CriticalActionDialog';
7+
import {isErrorWithRetry} from '../CriticalActionDialog/utils';
78

89
interface ButtonWithConfirmDialogProps<T, K> {
910
children: React.ReactNode;
1011
onConfirmAction: (isRetry?: boolean) => Promise<T>;
1112
onConfirmActionSuccess?: (() => Promise<K>) | VoidFunction;
12-
dialogContent: string;
13+
dialogHeader: string;
14+
dialogText: string;
1315
retryButtonText?: string;
1416
buttonDisabled?: ButtonProps['disabled'];
1517
buttonView?: ButtonProps['view'];
@@ -24,7 +26,8 @@ export function ButtonWithConfirmDialog<T, K>({
2426
children,
2527
onConfirmAction,
2628
onConfirmActionSuccess,
27-
dialogContent,
29+
dialogHeader,
30+
dialogText,
2831
retryButtonText,
2932
buttonDisabled = false,
3033
buttonView = 'action',
@@ -41,29 +44,20 @@ export function ButtonWithConfirmDialog<T, K>({
4144
const handleConfirmAction = async (isRetry?: boolean) => {
4245
setButtonLoading(true);
4346
await onConfirmAction(isRetry);
44-
setButtonLoading(false);
4547
};
4648

4749
const handleConfirmActionSuccess = async () => {
4850
setWithRetry(false);
4951

50-
if (onConfirmActionSuccess) {
51-
setButtonLoading(true);
52-
53-
try {
54-
await onConfirmActionSuccess();
55-
} catch {
56-
} finally {
57-
setButtonLoading(false);
58-
}
52+
try {
53+
await onConfirmActionSuccess?.();
54+
} finally {
55+
setButtonLoading(false);
5956
}
6057
};
6158

6259
const handleConfirmActionError = (error: unknown) => {
63-
const isWithRetry = Boolean(
64-
error && typeof error === 'object' && 'retryPossible' in error && error.retryPossible,
65-
);
66-
setWithRetry(isWithRetry);
60+
setWithRetry(isErrorWithRetry(error));
6761
setButtonLoading(false);
6862
};
6963

@@ -101,7 +95,8 @@ export function ButtonWithConfirmDialog<T, K>({
10195
<React.Fragment>
10296
<CriticalActionDialog
10397
visible={isConfirmDialogVisible}
104-
text={dialogContent}
98+
header={dialogHeader}
99+
text={dialogText}
105100
withRetry={withRetry}
106101
retryButtonText={retryButtonText}
107102
onConfirm={handleConfirmAction}

src/components/CriticalActionDialog/CriticalActionDialog.scss

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.ydb-critical-dialog {
2-
padding-top: var(--g-spacing-7);
2+
padding-top: var(--g-spacing-3);
33

44
&__warning-icon {
55
margin-right: 16px;
@@ -15,7 +15,29 @@
1515
}
1616

1717
&__body {
18+
display: flex;
19+
flex-direction: column;
20+
gap: var(--g-spacing-6);
21+
}
22+
23+
&__body-message {
1824
display: flex;
1925
align-items: center;
26+
27+
&_warning,
28+
&_error {
29+
padding: var(--g-spacing-4) var(--g-spacing-5);
30+
31+
border: 1px solid;
32+
border-radius: var(--g-modal-border-radius, 5px);
33+
}
34+
35+
&_warning {
36+
border-color: var(--ydb-color-status-yellow);
37+
}
38+
39+
&_error {
40+
border-color: var(--ydb-color-status-red);
41+
}
2042
}
2143
}

src/components/CriticalActionDialog/CriticalActionDialog.tsx

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const parseError = (error: IResponseError) => {
2525

2626
interface CriticalActionDialogProps<T> {
2727
visible: boolean;
28-
text: string;
28+
header?: React.ReactNode;
29+
text?: string;
2930
withRetry?: boolean;
3031
retryButtonText?: string;
3132
onClose: VoidFunction;
@@ -36,6 +37,7 @@ interface CriticalActionDialogProps<T> {
3637

3738
export function CriticalActionDialog<T>({
3839
visible,
40+
header,
3941
text,
4042
withRetry,
4143
retryButtonText,
@@ -64,15 +66,22 @@ export function CriticalActionDialog<T>({
6466
});
6567
};
6668

69+
const handleTransitionExited = () => {
70+
setError(undefined);
71+
};
72+
6773
const renderDialogContent = () => {
6874
if (error) {
6975
return (
7076
<React.Fragment>
77+
<Dialog.Header caption={header} />
7178
<Dialog.Body className={b('body')}>
72-
<span className={b('error-icon')}>
73-
<CircleXmarkFill width="24" height="22" />
74-
</span>
75-
{parseError(error)}
79+
<div className={b('body-message', {error: true})}>
80+
<span className={b('error-icon')}>
81+
<CircleXmarkFill width="24" height="22" />
82+
</span>
83+
{parseError(error)}
84+
</div>
7685
</Dialog.Body>
7786

7887
<Dialog.Footer
@@ -93,11 +102,15 @@ export function CriticalActionDialog<T>({
93102

94103
return (
95104
<React.Fragment>
105+
<Dialog.Header caption={header} />
106+
96107
<Dialog.Body className={b('body')}>
97-
<span className={b('warning-icon')}>
98-
<Icon data={TriangleExclamationFill} size={24} />
99-
</span>
100-
{text}
108+
<div className={b('body-message', {warning: true})}>
109+
<span className={b('warning-icon')}>
110+
<Icon data={TriangleExclamationFill} size={24} />
111+
</span>
112+
{text}
113+
</div>
101114
</Dialog.Body>
102115

103116
<Dialog.Footer
@@ -120,7 +133,7 @@ export function CriticalActionDialog<T>({
120133
className={b()}
121134
size="s"
122135
onClose={onClose}
123-
onTransitionExited={() => setError(undefined)}
136+
onTransitionExited={handleTransitionExited}
124137
>
125138
{renderDialogContent()}
126139
</Dialog>

src/components/CriticalActionDialog/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface ErrorWithRetry {
2+
retryPossible: boolean;
3+
}
4+
5+
export const isErrorWithRetry = (error: unknown): error is ErrorWithRetry => {
6+
return Boolean(
7+
error && typeof error === 'object' && 'retryPossible' in error && error.retryPossible,
8+
);
9+
};

src/components/EntityPageTitle/EntityPageTitle.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,14 @@ interface EntityPageTitleProps {
1111
status: EFlag;
1212
id: React.ReactNode;
1313
className?: string;
14-
children?: React.ReactNode;
1514
}
1615

17-
export function EntityPageTitle({
18-
entityName,
19-
status,
20-
id,
21-
className,
22-
children,
23-
}: EntityPageTitleProps) {
16+
export function EntityPageTitle({entityName, status, id, className}: EntityPageTitleProps) {
2417
return (
2518
<div className={b(null, className)}>
2619
<span className={b('prefix')}>{entityName}</span>
2720
<StatusIcon className={b('icon')} status={status} size="s" />
2821
{id}
29-
{children}
3022
</div>
3123
);
3224
}

src/components/PDiskInfo/PDiskInfo.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ function getPDiskInfo<T extends PreparedPDisk>({
4646
SerialNumber,
4747
TotalSize,
4848
AllocatedSize,
49-
DecommitStatus,
5049
StatusV2,
5150
NumActiveSlots,
5251
ExpectedSlotCount,
@@ -58,12 +57,6 @@ function getPDiskInfo<T extends PreparedPDisk>({
5857

5958
const generalInfo: InfoViewerItem[] = [];
6059

61-
if (valueIsDefined(DecommitStatus)) {
62-
generalInfo.push({
63-
label: pDiskInfoKeyset('decomission-status'),
64-
value: DecommitStatus.replace('DECOMMIT_', ''),
65-
});
66-
}
6760
if (valueIsDefined(Category)) {
6861
generalInfo.push({label: pDiskInfoKeyset('type'), value: Type});
6962
}

src/components/PDiskInfo/i18n/en.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"decomission-status": "Decomission Status",
32
"type": "Type",
43
"path": "Path",
54
"guid": "GUID",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.ydb-pdisk-decommission-button {
2+
&__button,
3+
&__popup {
4+
width: 160px;
5+
}
6+
}

0 commit comments

Comments
 (0)