@@ -17,18 +17,19 @@ type VisibleDialogType = EVisibleDialogType | null;
17
17
18
18
interface TabletControlsProps {
19
19
tablet : TTabletStateInfo ;
20
+ fetchData : VoidFunction ;
20
21
}
21
22
22
- export const TabletControls = ( { tablet} : TabletControlsProps ) => {
23
+ export const TabletControls = ( { tablet, fetchData } : TabletControlsProps ) => {
23
24
const { TabletId, HiveId} = tablet ;
24
25
25
26
const [ isDialogVisible , setIsDialogVisible ] = useState ( false ) ;
26
27
const [ visibleDialogType , setVisibleDialogType ] = useState < VisibleDialogType > ( null ) ;
27
- const [ isTabletActionsDisabled , setIsTabletActionsDisabled ] = useState ( false ) ;
28
+ const [ isTabletActionLoading , setIsTabletActionLoading ] = useState ( false ) ;
28
29
29
30
// Enable controls after data update
30
31
useEffect ( ( ) => {
31
- setIsTabletActionsDisabled ( false ) ;
32
+ setIsTabletActionLoading ( false ) ;
32
33
} , [ tablet ] ) ;
33
34
34
35
const makeShowDialog = ( type : VisibleDialogType ) => ( ) => {
@@ -46,41 +47,27 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
46
47
} ;
47
48
48
49
const _onKillClick = ( ) => {
49
- setIsTabletActionsDisabled ( true ) ;
50
+ setIsTabletActionLoading ( true ) ;
50
51
return window . api . killTablet ( TabletId ) ;
51
52
} ;
52
53
const _onStopClick = ( ) => {
53
- setIsTabletActionsDisabled ( true ) ;
54
+ setIsTabletActionLoading ( true ) ;
54
55
return window . api . stopTablet ( TabletId , HiveId ) ;
55
56
} ;
56
57
const _onResumeClick = ( ) => {
57
- setIsTabletActionsDisabled ( true ) ;
58
+ setIsTabletActionLoading ( true ) ;
58
59
return window . api . resumeTablet ( TabletId , HiveId ) ;
59
60
} ;
60
61
61
62
const hasHiveId = ( ) => {
62
63
return HiveId && HiveId !== '0' ;
63
64
} ;
64
65
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 ;
81
68
82
- return tablet . State === ETabletState . Stopped || tablet . State === ETabletState . Deleted ;
83
- } ;
69
+ const isDisabledStop =
70
+ tablet . State === ETabletState . Stopped || tablet . State === ETabletState . Deleted ;
84
71
85
72
const renderDialog = ( ) => {
86
73
if ( ! isDialogVisible ) {
@@ -95,6 +82,7 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
95
82
text = { i18n ( 'dialog.kill' ) }
96
83
onClose = { hideDialog }
97
84
onConfirm = { _onKillClick }
85
+ onConfirmActionFinish = { fetchData }
98
86
/>
99
87
) ;
100
88
}
@@ -105,6 +93,7 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
105
93
text = { i18n ( 'dialog.stop' ) }
106
94
onClose = { hideDialog }
107
95
onConfirm = { _onStopClick }
96
+ onConfirmActionFinish = { fetchData }
108
97
/>
109
98
) ;
110
99
}
@@ -115,6 +104,7 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
115
104
text = { i18n ( 'dialog.resume' ) }
116
105
onClose = { hideDialog }
117
106
onConfirm = { _onResumeClick }
107
+ onConfirmActionFinish = { fetchData }
118
108
/>
119
109
) ;
120
110
}
@@ -128,7 +118,7 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
128
118
< Button
129
119
onClick = { showKillDialog }
130
120
view = "action"
131
- disabled = { isDisabledKill ( ) }
121
+ loading = { isTabletActionLoading }
132
122
className = { b ( 'control' ) }
133
123
>
134
124
{ i18n ( 'controls.kill' ) }
@@ -138,15 +128,17 @@ export const TabletControls = ({tablet}: TabletControlsProps) => {
138
128
< Button
139
129
onClick = { showStopDialog }
140
130
view = "action"
141
- disabled = { isDisabledStop ( ) }
131
+ disabled = { isDisabledStop }
132
+ loading = { ! isDisabledStop && isTabletActionLoading }
142
133
className = { b ( 'control' ) }
143
134
>
144
135
{ i18n ( 'controls.stop' ) }
145
136
</ Button >
146
137
< Button
147
138
onClick = { showResumeDialog }
148
139
view = "action"
149
- disabled = { isDisabledResume ( ) }
140
+ disabled = { isDisabledResume }
141
+ loading = { ! isDisabledResume && isTabletActionLoading }
150
142
className = { b ( 'control' ) }
151
143
>
152
144
{ i18n ( 'controls.resume' ) }
0 commit comments