Skip to content
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 @@ -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,13 +69,13 @@ export function ButtonWithConfirmDialog<T, K>({
disabled={buttonDisabled}
loading={!buttonDisabled && buttonLoading}
className={buttonClassName}
title={buttonTitle}
>
{children}
</Button>
);
};

// keep <span>: if button is disabled, popover won't open without this wrapper
const renderContent = () => {
if (withPopover) {
return (
Expand All @@ -86,7 +84,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
26 changes: 18 additions & 8 deletions src/containers/Tablets/TabletsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedT

import i18n from './i18n';

function isFollowerTablet(state: TTabletStateInfo) {
return state.Leader === false;
}

function getColumns({nodeId}: {nodeId?: string | number}) {
const columns: DataTableColumn<TTabletStateInfo & {fqdn?: string}>[] = [
{
Expand All @@ -34,7 +38,7 @@ function getColumns({nodeId}: {nodeId?: string | number}) {
return i18n('Type');
},
render: ({row}) => {
const isFollower = row.Leader === false;
const isFollower = isFollowerTablet(row);
return (
<span>
{row.Type} {isFollower ? <Text color="secondary">follower</Text> : ''}
Expand Down Expand Up @@ -138,7 +142,8 @@ function getColumns({nodeId}: {nodeId?: string | number}) {
}

function TabletActions(tablet: TTabletStateInfo) {
const isDisabledRestart = tablet.State === ETabletState.Stopped;
const isFollower = isFollowerTablet(tablet);
const isDisabledRestart = tablet.State === ETabletState.Stopped || isFollower;
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
const [killTablet] = tabletApi.useKillTabletMutation();

Expand All @@ -147,22 +152,27 @@ function TabletActions(tablet: TTabletStateInfo) {
return null;
}

let popoverContent: React.ReactNode;

if (isFollower) {
popoverContent = i18n('controls.kill-impossible-follower');
} else if (!isUserAllowedToMakeChanges) {
popoverContent = i18n('controls.kill-not-allowed');
} else {
popoverContent = i18n('dialog.kill-header');
}

return (
<ButtonWithConfirmDialog
buttonView="outlined"
buttonTitle={i18n('dialog.kill-header')}
dialogHeader={i18n('dialog.kill-header')}
dialogText={i18n('dialog.kill-text')}
onConfirmAction={() => {
return killTablet({id}).unwrap();
}}
buttonDisabled={isDisabledRestart || !isUserAllowedToMakeChanges}
withPopover
popoverContent={
isUserAllowedToMakeChanges
? i18n('dialog.kill-header')
: i18n('controls.kill-not-allowed')
}
popoverContent={popoverContent}
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