Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
artemmufazalov committed Sep 3, 2024
1 parent b3815b6 commit c231322
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 81 deletions.
14 changes: 4 additions & 10 deletions src/components/ButtonWithConfirmDialog/ButtonWithConfirmDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,15 @@ export function ButtonWithConfirmDialog<T, K>({
const handleConfirmAction = async (isRetry?: boolean) => {
setButtonLoading(true);
await onConfirmAction(isRetry);
setButtonLoading(false);
};

const handleConfirmActionSuccess = async () => {
setWithRetry(false);

if (onConfirmActionSuccess) {
setButtonLoading(true);

try {
await onConfirmActionSuccess();
} catch {
} finally {
setButtonLoading(false);
}
try {
await onConfirmActionSuccess?.();
} finally {
setButtonLoading(false);
}
};

Expand Down
1 change: 0 additions & 1 deletion src/components/PDiskInfo/i18n/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"decomission-status": "Decomission Status",
"type": "Type",
"path": "Path",
"guid": "GUID",
Expand Down
133 changes: 72 additions & 61 deletions src/containers/PDiskPage/DecommissionButton/DecommissionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';

import {ChevronDown} from '@gravity-ui/icons';
import type {DropdownMenuItem, DropdownMenuProps} from '@gravity-ui/uikit';
import type {ButtonProps, DropdownMenuItem, DropdownMenuProps} from '@gravity-ui/uikit';
import {Button, DropdownMenu, Icon, Popover} from '@gravity-ui/uikit';

import {CriticalActionDialog} from '../../../components/CriticalActionDialog/CriticalActionDialog';
Expand Down Expand Up @@ -34,9 +34,41 @@ function getDecommissionWarningText(decommission?: EDecommitStatus) {
return undefined;
}

function getDecommissionButtonItems(
decommission: EDecommitStatus | undefined,
setNewDecommission: (newDecommission: EDecommitStatus | undefined) => void,
): DropdownMenuItem[] {
return [
{
text: pDiskPageKeyset('decommission-none'),
action: () => setNewDecommission('DECOMMIT_NONE'),
hidden:
!decommission ||
decommission === 'DECOMMIT_NONE' ||
decommission === 'DECOMMIT_UNSET',
},
{
text: pDiskPageKeyset('decommission-pending'),
action: () => setNewDecommission('DECOMMIT_PENDING'),
hidden: decommission === 'DECOMMIT_PENDING',
},
{
text: pDiskPageKeyset('decommission-rejected'),
action: () => setNewDecommission('DECOMMIT_REJECTED'),
hidden: decommission === 'DECOMMIT_REJECTED',
},
{
text: pDiskPageKeyset('decommission-imminent'),
theme: 'danger',
action: () => setNewDecommission('DECOMMIT_IMMINENT'),
hidden: decommission === 'DECOMMIT_IMMINENT',
},
];
}

interface DecommissionButtonProps {
decommission?: EDecommitStatus;
onConfirmAction: (newDecomissionStatus?: EDecommitStatus, isRetry?: boolean) => Promise<void>;
onConfirmAction: (newDecommissionStatus?: EDecommitStatus, isRetry?: boolean) => Promise<void>;
onConfirmActionSuccess: (() => Promise<void>) | VoidFunction;
buttonDisabled?: boolean;
popoverDisabled?: boolean;
Expand All @@ -56,25 +88,19 @@ export function DecommissionButton({
const handleConfirmAction = async (isRetry?: boolean) => {
setButtonLoading(true);
await onConfirmAction(newDecommission, isRetry);
setButtonLoading(false);
};

const handleConfirmActionSuccess = async () => {
setWithRetry(false);

if (onConfirmActionSuccess) {
setButtonLoading(true);
// Decommission needs some time to change
// Wait for some time to send request for updated data
await wait(5000);

// Decommission needs some time to change
// Wait for some time to send request for updated data
await wait(5000);

try {
await onConfirmActionSuccess();
} catch {
} finally {
setButtonLoading(false);
}
try {
await onConfirmActionSuccess();
} finally {
setButtonLoading(false);
}
};

Expand All @@ -83,52 +109,20 @@ export function DecommissionButton({
setButtonLoading(false);
};

const items: DropdownMenuItem[] = [
{
text: pDiskPageKeyset('decommission-none'),
action: () => setNewDecommission('DECOMMIT_NONE'),
hidden:
!decommission ||
decommission === 'DECOMMIT_NONE' ||
decommission === 'DECOMMIT_UNSET',
},
{
text: pDiskPageKeyset('decommission-pending'),
action: () => setNewDecommission('DECOMMIT_PENDING'),
hidden: decommission === 'DECOMMIT_PENDING',
},
{
text: pDiskPageKeyset('decommission-rejected'),
action: () => setNewDecommission('DECOMMIT_REJECTED'),
hidden: decommission === 'DECOMMIT_REJECTED',
},
{
text: pDiskPageKeyset('decommission-imminent'),
theme: 'danger',
action: () => setNewDecommission('DECOMMIT_IMMINENT'),
hidden: decommission === 'DECOMMIT_IMMINENT',
},
];
const handleClose = () => {
setNewDecommission(undefined);
};

const items = getDecommissionButtonItems(decommission, setNewDecommission);

const renderSwitcher: DropdownMenuProps<unknown>['renderSwitcher'] = (props) => {
return (
<Popover
content={pDiskPageKeyset('decommission-change-not-allowed')}
placement={'right'}
disabled={popoverDisabled}
>
<Button
view={'normal'}
className={b('button')}
loading={buttonLoading}
disabled={buttonDisabled}
{...props}
>
<Icon data={decommissionIcon} />
{pDiskPageKeyset('decommission-button')}
<Icon data={ChevronDown} />
</Button>
</Popover>
<DecommissionButtonSwitcher
popoverDisabled={popoverDisabled}
loading={buttonLoading}
disabled={buttonDisabled}
{...props}
/>
);
};

Expand All @@ -148,10 +142,27 @@ export function DecommissionButton({
onConfirm={handleConfirmAction}
onConfirmActionSuccess={handleConfirmActionSuccess}
onConfirmActionError={handleConfirmActionError}
onClose={() => {
setNewDecommission(undefined);
}}
onClose={handleClose}
/>
</React.Fragment>
);
}

function DecommissionButtonSwitcher({
popoverDisabled,
...restProps
}: ButtonProps & {popoverDisabled?: boolean}) {
return (
<Popover
content={pDiskPageKeyset('decommission-change-not-allowed')}
placement={'right'}
disabled={popoverDisabled}
>
<Button view={'normal'} className={b('button')} {...restProps}>
<Icon data={decommissionIcon} />
{pDiskPageKeyset('decommission-button')}
<Icon data={ChevronDown} />
</Button>
</Popover>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import {Label} from '@gravity-ui/uikit';
import type {EDecommitStatus} from '../../../types/api/pdisk';
import {pDiskPageKeyset} from '../i18n';

interface DecommisionLabelProps {
interface DecommissionLabelProps {
decommission?: EDecommitStatus;
}

function getDecommissionLabelText(decommission: string) {
return pDiskPageKeyset('decommission-label', {decommission});
}

export function DecommisionLabel({decommission}: DecommisionLabelProps) {
export function DecommissionLabel({decommission}: DecommissionLabelProps) {
if (decommission === 'DECOMMIT_IMMINENT') {
return (
<Label theme="danger" size="m">
Expand Down
10 changes: 5 additions & 5 deletions src/containers/PDiskPage/PDiskPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import {cn} from '../../utils/cn';
import {getPDiskId, getSeverityColor} from '../../utils/disks/helpers';
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks';

import {DecommisionLabel} from './DecommisionLabel/DecommisionLabel';
import {DecommissionButton} from './DecommissionButton/DecommissionButton';
import {DecommissionLabel} from './DecommissionLabel/DecommissionLabel';
import {PDiskGroups} from './PDiskGroups/PDiskGroups';
import {PDiskSpaceDistribution} from './PDiskSpaceDistribution/PDiskSpaceDistribution';
import {pDiskPageKeyset} from './i18n';
Expand Down Expand Up @@ -102,16 +102,16 @@ export function PDiskPage() {
};

const handleDecommissionChange = async (
newDecomissionStatus?: EDecommitStatus,
newDecommissionStatus?: EDecommitStatus,
isRetry?: boolean,
) => {
if (pDiskParamsDefined) {
return window.api
return await window.api
.changePDiskStatus({
nodeId,
pDiskId,
force: isRetry,
decommissionStatus: newDecomissionStatus,
decommissionStatus: newDecommissionStatus,
})
.then((response) => {
if (response?.result === false) {
Expand Down Expand Up @@ -171,7 +171,7 @@ export function PDiskPage() {
status={getSeverityColor(Severity)}
id={pDiskParamsDefined ? getPDiskId(nodeId, pDiskId) : null}
/>
<DecommisionLabel decommission={DecommitStatus} />
<DecommissionLabel decommission={DecommitStatus} />
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/containers/PDiskPage/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"decommission-dialog-force-change": "Change anyway",

"decommission-dialog-imminent-warning": "This will start imminent decommission. Existing slots will be moved from the disk",
"decommission-dialog-pending-warning": "This will start pending decommission. Decomission will be planned for this disk, but will not start immediatelly. Existing slots will not be moved from the disk, but no new slots will be allocated on it",
"decommission-dialog-pending-warning": "This will start pending decommission. Decommission will be planned for this disk, but will not start immediatelly. Existing slots will not be moved from the disk, but no new slots will be allocated on it",
"decommission-dialog-rejected-warning": "This will start rejected decommission. No slots from other disks are placed on this disk in the process of decommission",
"decommission-dialog-none-warning": "This will reset decommission mode, allowing the disk to be used by the storage"
}
2 changes: 1 addition & 1 deletion src/types/api/pdisk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ type EDriveStatus =

export type EDecommitStatus =
| 'DECOMMIT_UNSET'
| 'DECOMMIT_NONE' // no decomission
| 'DECOMMIT_NONE' // no decommission
| 'DECOMMIT_PENDING' // drive is going to be removed soon, but SelfHeal logic would not remove it automatically
| 'DECOMMIT_IMMINENT' // drive is going to be settled automatically
| 'DECOMMIT_REJECTED'; // drive is working as usual, but decommitted slots are not placed here
Expand Down

0 comments on commit c231322

Please sign in to comment.