1
- import { type FC } from "react" ;
2
- import type { Workspace , WorkspaceBuildParameter } from "api/typesGenerated" ;
3
- import { BuildParametersPopover } from "./BuildParametersPopover" ;
4
-
5
1
import Tooltip from "@mui/material/Tooltip" ;
6
2
import Button from "@mui/material/Button" ;
7
3
import LoadingButton from "@mui/lab/LoadingButton" ;
@@ -15,15 +11,18 @@ import OutlinedBlockIcon from "@mui/icons-material/BlockOutlined";
15
11
import PowerSettingsNewIcon from "@mui/icons-material/PowerSettingsNew" ;
16
12
import RetryIcon from "@mui/icons-material/BuildOutlined" ;
17
13
import RetryDebugIcon from "@mui/icons-material/BugReportOutlined" ;
14
+ import { type FC } from "react" ;
15
+ import type { Workspace , WorkspaceBuildParameter } from "api/typesGenerated" ;
16
+ import { BuildParametersPopover } from "./BuildParametersPopover" ;
18
17
19
- interface WorkspaceActionProps {
18
+ interface ActionButtonProps {
20
19
loading ?: boolean ;
21
- handleAction : ( ) => void ;
20
+ handleAction : ( buildParameters ?: WorkspaceBuildParameter [ ] ) => void ;
22
21
disabled ?: boolean ;
23
22
tooltipText ?: string ;
24
23
}
25
24
26
- export const UpdateButton : FC < WorkspaceActionProps > = ( {
25
+ export const UpdateButton : FC < ActionButtonProps > = ( {
27
26
handleAction,
28
27
loading,
29
28
} ) => {
@@ -33,14 +32,14 @@ export const UpdateButton: FC<WorkspaceActionProps> = ({
33
32
loadingPosition = "start"
34
33
data-testid = "workspace-update-button"
35
34
startIcon = { < CloudQueueIcon /> }
36
- onClick = { handleAction }
35
+ onClick = { ( ) => handleAction ( ) }
37
36
>
38
37
{ loading ? < > Updating…</ > : < > Update…</ > }
39
38
</ LoadingButton >
40
39
) ;
41
40
} ;
42
41
43
- export const ActivateButton : FC < WorkspaceActionProps > = ( {
42
+ export const ActivateButton : FC < ActionButtonProps > = ( {
44
43
handleAction,
45
44
loading,
46
45
} ) => {
@@ -49,30 +48,29 @@ export const ActivateButton: FC<WorkspaceActionProps> = ({
49
48
loading = { loading }
50
49
loadingPosition = "start"
51
50
startIcon = { < PowerSettingsNewIcon /> }
52
- onClick = { handleAction }
51
+ onClick = { ( ) => handleAction ( ) }
53
52
>
54
53
{ loading ? < > Activating…</ > : "Activate" }
55
54
</ LoadingButton >
56
55
) ;
57
56
} ;
58
57
59
- type StartButtonProps = Omit < WorkspaceActionProps , "handleAction" > & {
58
+ interface ActionButtonPropsWithWorkspace extends ActionButtonProps {
60
59
workspace : Workspace ;
61
- handleAction : ( buildParameters ?: WorkspaceBuildParameter [ ] ) => void ;
62
- } ;
60
+ }
63
61
64
- export const StartButton : FC < StartButtonProps > = ( {
62
+ export const StartButton : FC < ActionButtonPropsWithWorkspace > = ( {
65
63
handleAction,
66
64
workspace,
67
65
loading,
68
66
disabled,
69
67
tooltipText,
70
68
} ) => {
71
- return (
69
+ const buttonContent = (
72
70
< ButtonGroup
73
71
variant = "outlined"
74
- css = { {
75
- // Workaround to make the border transitions smmothly on button groups
72
+ sx = { {
73
+ // Workaround to make the border transitions smoothly on button groups
76
74
"& > button:hover + button" : {
77
75
borderLeft : "1px solid #FFF" ,
78
76
} ,
@@ -95,9 +93,15 @@ export const StartButton: FC<StartButtonProps> = ({
95
93
/>
96
94
</ ButtonGroup >
97
95
) ;
96
+
97
+ return tooltipText ? (
98
+ < Tooltip title = { tooltipText } > { buttonContent } </ Tooltip >
99
+ ) : (
100
+ buttonContent
101
+ ) ;
98
102
} ;
99
103
100
- export const StopButton : FC < WorkspaceActionProps > = ( {
104
+ export const StopButton : FC < ActionButtonProps > = ( {
101
105
handleAction,
102
106
loading,
103
107
} ) => {
@@ -106,31 +110,26 @@ export const StopButton: FC<WorkspaceActionProps> = ({
106
110
loading = { loading }
107
111
loadingPosition = "start"
108
112
startIcon = { < CropSquareIcon /> }
109
- onClick = { handleAction }
113
+ onClick = { ( ) => handleAction ( ) }
110
114
data-testid = "workspace-stop-button"
111
115
>
112
116
{ loading ? < > Stopping…</ > : "Stop" }
113
117
</ LoadingButton >
114
118
) ;
115
119
} ;
116
120
117
- type RestartButtonProps = Omit < WorkspaceActionProps , "handleAction" > & {
118
- workspace : Workspace ;
119
- handleAction : ( buildParameters ?: WorkspaceBuildParameter [ ] ) => void ;
120
- } ;
121
-
122
- export const RestartButton : FC < RestartButtonProps > = ( {
121
+ export const RestartButton : FC < ActionButtonPropsWithWorkspace > = ( {
123
122
handleAction,
124
123
loading,
125
124
workspace,
126
125
disabled,
127
126
tooltipText,
128
127
} ) => {
129
- return (
128
+ const buttonContent = (
130
129
< ButtonGroup
131
130
variant = "outlined"
132
131
css = { {
133
- // Workaround to make the border transitions smmothly on button groups
132
+ // Workaround to make the border transitions smoothly on button groups
134
133
"& > button:hover + button" : {
135
134
borderLeft : "1px solid #FFF" ,
136
135
} ,
@@ -154,21 +153,27 @@ export const RestartButton: FC<RestartButtonProps> = ({
154
153
/>
155
154
</ ButtonGroup >
156
155
) ;
156
+
157
+ return tooltipText ? (
158
+ < Tooltip title = { tooltipText } > { buttonContent } </ Tooltip >
159
+ ) : (
160
+ buttonContent
161
+ ) ;
157
162
} ;
158
163
159
- export const CancelButton : FC < WorkspaceActionProps > = ( { handleAction } ) => {
164
+ export const CancelButton : FC < ActionButtonProps > = ( { handleAction } ) => {
160
165
return (
161
- < Button startIcon = { < BlockIcon /> } onClick = { handleAction } >
166
+ < Button startIcon = { < BlockIcon /> } onClick = { ( ) => handleAction ( ) } >
162
167
Cancel
163
168
</ Button >
164
169
) ;
165
170
} ;
166
171
167
- interface DisabledProps {
172
+ interface DisabledButtonProps {
168
173
label : string ;
169
174
}
170
175
171
- export const DisabledButton : FC < DisabledProps > = ( { label } ) => {
176
+ export const DisabledButton : FC < DisabledButtonProps > = ( { label } ) => {
172
177
return (
173
178
< Button startIcon = { < OutlinedBlockIcon /> } disabled >
174
179
{ label }
@@ -188,7 +193,7 @@ export const ActionLoadingButton: FC<LoadingProps> = ({ label }) => {
188
193
) ;
189
194
} ;
190
195
191
- type RetryButtonProps = Omit < WorkspaceActionProps , "loading" > & {
196
+ type RetryButtonProps = Omit < ActionButtonProps , "loading" > & {
192
197
debug ?: boolean ;
193
198
} ;
194
199
@@ -199,7 +204,7 @@ export const RetryButton: FC<RetryButtonProps> = ({
199
204
return (
200
205
< Button
201
206
startIcon = { debug ? < RetryDebugIcon /> : < RetryIcon /> }
202
- onClick = { handleAction }
207
+ onClick = { ( ) => handleAction ( ) }
203
208
>
204
209
Retry{ debug && " (Debug)" }
205
210
</ Button >
0 commit comments