Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -15,7 +15,6 @@ interface ButtonWithConfirmDialogProps<T, K> {
retryButtonText?: string;
buttonDisabled?: ButtonProps['disabled'];
buttonView?: ButtonProps['view'];
buttonTitle?: ButtonProps['title'];
buttonClassName?: ButtonProps['className'];
withPopover?: boolean;
popoverContent?: PopoverProps['content'];
Expand All @@ -32,7 +31,6 @@ export function ButtonWithConfirmDialog<T, K>({
retryButtonText,
buttonDisabled = false,
buttonView = 'action',
buttonTitle,
buttonClassName,
withPopover = false,
popoverContent,
Expand Down Expand Up @@ -71,7 +69,6 @@ export function ButtonWithConfirmDialog<T, K>({
disabled={buttonDisabled}
loading={!buttonDisabled && buttonLoading}
className={buttonClassName}
title={buttonTitle}
>
{children}
</Button>
Expand All @@ -86,7 +83,7 @@ export function ButtonWithConfirmDialog<T, K>({
placement={popoverPlacement}
disabled={popoverDisabled}
>
{renderButton()}
<span>{renderButton()}</span>
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need this span?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need the because the button can be disabled, and a disabled native does not receive pointer/hover/focus events in the browser. The popover wont'be shown on disabled buttons, but we need it (tooltip for followers for example). So if we wrap the button in a non-disabled element (the ), we can attach the popover to the wrapper and keep the button disabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice work! Let's add a comment so nobody remove this wrapper "to simplify the code".

</Popover>
);
}
Expand Down
12 changes: 7 additions & 5 deletions src/containers/Tablets/TabletsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ function getColumns({nodeId}: {nodeId?: string | number}) {
}

function TabletActions(tablet: TTabletStateInfo) {
const isDisabledRestart = tablet.State === ETabletState.Stopped;
const isFollower = tablet.Leader === false;
Copy link
Contributor

Choose a reason for hiding this comment

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

This logic is used twice in this file. Lets make a helper not to duplicate code.

const isDisabledRestart = tablet.State === ETabletState.Stopped || isFollower;
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const [killTablet] = tabletApi.useKillTabletMutation();

Expand All @@ -150,7 +151,6 @@ function TabletActions(tablet: TTabletStateInfo) {
return (
<ButtonWithConfirmDialog
buttonView="outlined"
buttonTitle={i18n('dialog.kill-header')}
dialogHeader={i18n('dialog.kill-header')}
dialogText={i18n('dialog.kill-text')}
onConfirmAction={() => {
Expand All @@ -159,9 +159,11 @@ function TabletActions(tablet: TTabletStateInfo) {
buttonDisabled={isDisabledRestart || !isUserAllowedToMakeChanges}
withPopover
popoverContent={
isUserAllowedToMakeChanges
? i18n('dialog.kill-header')
: i18n('controls.kill-not-allowed')
isFollower
Copy link
Contributor

Choose a reason for hiding this comment

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

let's now use multi-level ternaries, it's hard to read

? i18n('controls.kill-impossible-follower')
: isUserAllowedToMakeChanges
? i18n('dialog.kill-header')
: i18n('controls.kill-not-allowed')
}
popoverPlacement={['right', 'bottom']}
popoverDisabled={false}
Expand Down
1 change: 1 addition & 0 deletions src/containers/Tablets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dialog.kill-header": "Restart tablet",
"dialog.kill-text": "The tablet will be restarted. Do you want to proceed?",
"controls.kill-not-allowed": "You don't have enough rights to restart tablet",
"controls.kill-impossible-follower": "It's impossible to restart a follower",
"controls.search-placeholder": "Tablet ID",
"controls.entities-count-label": "Tablets"
}
Loading