Skip to content

Commit 9ca4400

Browse files
fix: disable restart for followers and remove duplicate tooltip (#3036)
1 parent 44dd3b4 commit 9ca4400

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/components/ButtonWithConfirmDialog/ButtonWithConfirmDialog.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ interface ButtonWithConfirmDialogProps<T, K> {
1515
retryButtonText?: string;
1616
buttonDisabled?: ButtonProps['disabled'];
1717
buttonView?: ButtonProps['view'];
18-
buttonTitle?: ButtonProps['title'];
1918
buttonClassName?: ButtonProps['className'];
2019
withPopover?: boolean;
2120
popoverContent?: PopoverProps['content'];
@@ -32,7 +31,6 @@ export function ButtonWithConfirmDialog<T, K>({
3231
retryButtonText,
3332
buttonDisabled = false,
3433
buttonView = 'action',
35-
buttonTitle,
3634
buttonClassName,
3735
withPopover = false,
3836
popoverContent,
@@ -71,13 +69,13 @@ export function ButtonWithConfirmDialog<T, K>({
7169
disabled={buttonDisabled}
7270
loading={!buttonDisabled && buttonLoading}
7371
className={buttonClassName}
74-
title={buttonTitle}
7572
>
7673
{children}
7774
</Button>
7875
);
7976
};
8077

78+
// keep <span>: if button is disabled, popover won't open without this wrapper
8179
const renderContent = () => {
8280
if (withPopover) {
8381
return (
@@ -86,7 +84,7 @@ export function ButtonWithConfirmDialog<T, K>({
8684
placement={popoverPlacement}
8785
disabled={popoverDisabled}
8886
>
89-
{renderButton()}
87+
<span>{renderButton()}</span>
9088
</Popover>
9189
);
9290
}

src/containers/Tablets/TabletsTable.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ import {useIsUserAllowedToMakeChanges} from '../../utils/hooks/useIsUserAllowedT
2525

2626
import i18n from './i18n';
2727

28+
function isFollowerTablet(state: TTabletStateInfo) {
29+
return state.Leader === false;
30+
}
31+
2832
function getColumns({nodeId}: {nodeId?: string | number}) {
2933
const columns: DataTableColumn<TTabletStateInfo & {fqdn?: string}>[] = [
3034
{
@@ -34,7 +38,7 @@ function getColumns({nodeId}: {nodeId?: string | number}) {
3438
return i18n('Type');
3539
},
3640
render: ({row}) => {
37-
const isFollower = row.Leader === false;
41+
const isFollower = isFollowerTablet(row);
3842
return (
3943
<span>
4044
{row.Type} {isFollower ? <Text color="secondary">follower</Text> : ''}
@@ -138,7 +142,8 @@ function getColumns({nodeId}: {nodeId?: string | number}) {
138142
}
139143

140144
function TabletActions(tablet: TTabletStateInfo) {
141-
const isDisabledRestart = tablet.State === ETabletState.Stopped;
145+
const isFollower = isFollowerTablet(tablet);
146+
const isDisabledRestart = tablet.State === ETabletState.Stopped || isFollower;
142147
const isUserAllowedToMakeChanges = useIsUserAllowedToMakeChanges();
143148
const [killTablet] = tabletApi.useKillTabletMutation();
144149

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

155+
let popoverContent: React.ReactNode;
156+
157+
if (isFollower) {
158+
popoverContent = i18n('controls.kill-impossible-follower');
159+
} else if (!isUserAllowedToMakeChanges) {
160+
popoverContent = i18n('controls.kill-not-allowed');
161+
} else {
162+
popoverContent = i18n('dialog.kill-header');
163+
}
164+
150165
return (
151166
<ButtonWithConfirmDialog
152167
buttonView="outlined"
153-
buttonTitle={i18n('dialog.kill-header')}
154168
dialogHeader={i18n('dialog.kill-header')}
155169
dialogText={i18n('dialog.kill-text')}
156170
onConfirmAction={() => {
157171
return killTablet({id}).unwrap();
158172
}}
159173
buttonDisabled={isDisabledRestart || !isUserAllowedToMakeChanges}
160174
withPopover
161-
popoverContent={
162-
isUserAllowedToMakeChanges
163-
? i18n('dialog.kill-header')
164-
: i18n('controls.kill-not-allowed')
165-
}
175+
popoverContent={popoverContent}
166176
popoverPlacement={['right', 'bottom']}
167177
popoverDisabled={false}
168178
>

src/containers/Tablets/i18n/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"dialog.kill-header": "Restart tablet",
1111
"dialog.kill-text": "The tablet will be restarted. Do you want to proceed?",
1212
"controls.kill-not-allowed": "You don't have enough rights to restart tablet",
13+
"controls.kill-impossible-follower": "It's impossible to restart a follower",
1314
"controls.search-placeholder": "Tablet ID",
1415
"controls.entities-count-label": "Tablets"
1516
}

0 commit comments

Comments
 (0)