@@ -17,18 +17,19 @@ type VisibleDialogType = EVisibleDialogType | null;
1717
1818interface 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' ) }
0 commit comments