Skip to content

Commit f1d71c5

Browse files
fix(Tablet): fetch data on action finish (#405)
1 parent 53afcf4 commit f1d71c5

File tree

5 files changed

+30
-29
lines changed

5 files changed

+30
-29
lines changed

src/components/CriticalActionDialog/CriticalActionDialog.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ interface CriticalActionDialogProps {
1313
text: string;
1414
onClose: VoidFunction;
1515
onConfirm: () => Promise<unknown>;
16+
onConfirmActionFinish: VoidFunction;
1617
}
1718

1819
export const CriticalActionDialog = ({
1920
visible,
2021
text,
2122
onClose,
2223
onConfirm,
24+
onConfirmActionFinish,
2325
}: CriticalActionDialogProps) => {
2426
const [isLoading, setIsLoading] = useState(false);
2527

@@ -28,6 +30,7 @@ export const CriticalActionDialog = ({
2830
setIsLoading(true);
2931

3032
return onConfirm().then(() => {
33+
onConfirmActionFinish();
3134
setIsLoading(false);
3235
onClose();
3336
});

src/containers/Tablet/Tablet.scss

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@
5252
text-transform: uppercase;
5353
}
5454

55+
&__loader {
56+
width: 25px;
57+
}
58+
5559
.info-viewer__items {
5660
grid-template-columns: auto;
5761
}

src/containers/Tablet/Tablet.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ export const Tablet = () => {
108108
<Icon name="external" />
109109
</a>
110110
{Leader && <Tag text="Leader" type="blue" />}
111+
<span className={b('loader')}>{loading && <Loader size="s" />}</span>
111112
</div>
112113
<TabletInfo tablet={tablet} tenantPath={tenantPath} />
113-
<TabletControls tablet={tablet} />
114+
<TabletControls tablet={tablet} fetchData={fetchData} />
114115
</div>
115116
<div className={b('rigth-pane')}>
116117
<TabletTable history={history} />

src/containers/Tablet/TabletControls/TabletControls.tsx

+19-27
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@ type VisibleDialogType = EVisibleDialogType | null;
1717

1818
interface TabletControlsProps {
1919
tablet: TTabletStateInfo;
20+
fetchData: VoidFunction;
2021
}
2122

22-
export const TabletControls = ({tablet}: TabletControlsProps) => {
23+
export const TabletControls = ({tablet, fetchData}: TabletControlsProps) => {
2324
const {TabletId, HiveId} = tablet;
2425

2526
const [isDialogVisible, setIsDialogVisible] = useState(false);
2627
const [visibleDialogType, setVisibleDialogType] = useState<VisibleDialogType>(null);
27-
const [isTabletActionsDisabled, setIsTabletActionsDisabled] = useState(false);
28+
const [isTabletActionLoading, setIsTabletActionLoading] = useState(false);
2829

2930
// Enable controls after data update
3031
useEffect(() => {
31-
setIsTabletActionsDisabled(false);
32+
setIsTabletActionLoading(false);
3233
}, [tablet]);
3334

3435
const makeShowDialog = (type: VisibleDialogType) => () => {
@@ -46,41 +47,27 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
4647
};
4748

4849
const _onKillClick = () => {
49-
setIsTabletActionsDisabled(true);
50+
setIsTabletActionLoading(true);
5051
return window.api.killTablet(TabletId);
5152
};
5253
const _onStopClick = () => {
53-
setIsTabletActionsDisabled(true);
54+
setIsTabletActionLoading(true);
5455
return window.api.stopTablet(TabletId, HiveId);
5556
};
5657
const _onResumeClick = () => {
57-
setIsTabletActionsDisabled(true);
58+
setIsTabletActionLoading(true);
5859
return window.api.resumeTablet(TabletId, HiveId);
5960
};
6061

6162
const hasHiveId = () => {
6263
return HiveId && HiveId !== '0';
6364
};
6465

65-
const isDisabledResume = () => {
66-
if (isTabletActionsDisabled) {
67-
return true;
68-
}
69-
70-
return tablet.State !== ETabletState.Stopped && tablet.State !== ETabletState.Dead;
71-
};
72-
73-
const isDisabledKill = () => {
74-
return isTabletActionsDisabled;
75-
};
76-
77-
const isDisabledStop = () => {
78-
if (isTabletActionsDisabled) {
79-
return true;
80-
}
66+
const isDisabledResume =
67+
tablet.State !== ETabletState.Stopped && tablet.State !== ETabletState.Dead;
8168

82-
return tablet.State === ETabletState.Stopped || tablet.State === ETabletState.Deleted;
83-
};
69+
const isDisabledStop =
70+
tablet.State === ETabletState.Stopped || tablet.State === ETabletState.Deleted;
8471

8572
const renderDialog = () => {
8673
if (!isDialogVisible) {
@@ -95,6 +82,7 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
9582
text={i18n('dialog.kill')}
9683
onClose={hideDialog}
9784
onConfirm={_onKillClick}
85+
onConfirmActionFinish={fetchData}
9886
/>
9987
);
10088
}
@@ -105,6 +93,7 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
10593
text={i18n('dialog.stop')}
10694
onClose={hideDialog}
10795
onConfirm={_onStopClick}
96+
onConfirmActionFinish={fetchData}
10897
/>
10998
);
11099
}
@@ -115,6 +104,7 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
115104
text={i18n('dialog.resume')}
116105
onClose={hideDialog}
117106
onConfirm={_onResumeClick}
107+
onConfirmActionFinish={fetchData}
118108
/>
119109
);
120110
}
@@ -128,7 +118,7 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
128118
<Button
129119
onClick={showKillDialog}
130120
view="action"
131-
disabled={isDisabledKill()}
121+
loading={isTabletActionLoading}
132122
className={b('control')}
133123
>
134124
{i18n('controls.kill')}
@@ -138,15 +128,17 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
138128
<Button
139129
onClick={showStopDialog}
140130
view="action"
141-
disabled={isDisabledStop()}
131+
disabled={isDisabledStop}
132+
loading={!isDisabledStop && isTabletActionLoading}
142133
className={b('control')}
143134
>
144135
{i18n('controls.stop')}
145136
</Button>
146137
<Button
147138
onClick={showResumeDialog}
148139
view="action"
149-
disabled={isDisabledResume()}
140+
disabled={isDisabledResume}
141+
loading={!isDisabledResume && isTabletActionLoading}
150142
className={b('control')}
151143
>
152144
{i18n('controls.resume')}

src/utils/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ export const formatDateTime = (value) => {
9797

9898
export const calcUptimeInSeconds = (milliseconds) => {
9999
const currentDate = new Date();
100-
return (currentDate - Number(milliseconds)) / 1000;
100+
const diff = currentDate - Number(milliseconds);
101+
return diff <= 0 ? 0 : diff / 1000;
101102
};
102103

103104
export const calcUptime = (milliseconds) => {

0 commit comments

Comments
 (0)