1
1
import Button from "@material-ui/core/Button"
2
2
import Link from "@material-ui/core/Link"
3
3
import { makeStyles } from "@material-ui/core/styles"
4
+ import CancelIcon from "@material-ui/icons/Cancel"
4
5
import CloudDownloadIcon from "@material-ui/icons/CloudDownload"
5
6
import PlayArrowRoundedIcon from "@material-ui/icons/PlayArrowRounded"
6
- import ReplayIcon from "@material-ui/icons/Replay"
7
7
import StopIcon from "@material-ui/icons/Stop"
8
8
import React from "react"
9
9
import { Link as RouterLink } from "react-router-dom"
@@ -17,7 +17,7 @@ export const Language = {
17
17
stopping : "Stopping workspace" ,
18
18
start : "Start workspace" ,
19
19
starting : "Starting workspace" ,
20
- retry : "Retry " ,
20
+ cancel : "Cancel action " ,
21
21
update : "Update workspace" ,
22
22
}
23
23
@@ -28,20 +28,32 @@ export const Language = {
28
28
const canAcceptJobs = ( workspaceStatus : WorkspaceStatus ) =>
29
29
[ "started" , "stopped" , "deleted" , "error" , "canceled" ] . includes ( workspaceStatus )
30
30
31
+ /**
32
+ * Jobs that are in progress (queued or pending) can be canceled.
33
+ * @param workspaceStatus WorkspaceStatus
34
+ * @returns boolean
35
+ */
36
+ const canCancelJobs = ( workspaceStatus : WorkspaceStatus ) =>
37
+ [ "starting" , "stopping" , "deleting" ] . includes ( workspaceStatus )
38
+
39
+ const canStart = ( workspaceStatus : WorkspaceStatus ) => [ "stopped" , "canceled" , "error" ] . includes ( workspaceStatus )
40
+
41
+ const canStop = ( workspaceStatus : WorkspaceStatus ) => [ "started" , "canceled" , "error" ] . includes ( workspaceStatus )
42
+
31
43
export interface WorkspaceActionsProps {
32
44
workspace : Workspace
33
45
handleStart : ( ) => void
34
46
handleStop : ( ) => void
35
- handleRetry : ( ) => void
36
47
handleUpdate : ( ) => void
48
+ handleCancel : ( ) => void
37
49
}
38
50
39
51
export const WorkspaceActions : React . FC < WorkspaceActionsProps > = ( {
40
52
workspace,
41
53
handleStart,
42
54
handleStop,
43
- handleRetry,
44
55
handleUpdate,
56
+ handleCancel,
45
57
} ) => {
46
58
const styles = useStyles ( )
47
59
const workspaceStatus = getWorkspaceStatus ( workspace . latest_build )
@@ -51,31 +63,30 @@ export const WorkspaceActions: React.FC<WorkspaceActionsProps> = ({
51
63
< Link underline = "none" component = { RouterLink } to = "edit" >
52
64
< Button variant = "outlined" > Settings</ Button >
53
65
</ Link >
54
- { ( workspaceStatus === "started" || workspaceStatus === "stopping" ) && (
66
+ { canStart ( workspaceStatus ) && (
67
+ < WorkspaceActionButton
68
+ className = { styles . actionButton }
69
+ icon = { < PlayArrowRoundedIcon /> }
70
+ onClick = { handleStart }
71
+ label = { Language . start }
72
+ />
73
+ ) }
74
+ { canStop ( workspaceStatus ) && (
55
75
< WorkspaceActionButton
56
76
className = { styles . actionButton }
57
77
icon = { < StopIcon /> }
58
78
onClick = { handleStop }
59
79
label = { Language . stop }
60
- loadingLabel = { Language . stopping }
61
- isLoading = { workspaceStatus === "stopping" }
62
80
/>
63
81
) }
64
- { ( workspaceStatus === "stopped" || workspaceStatus === "starting" ) && (
82
+ { canCancelJobs ( workspaceStatus ) && (
65
83
< WorkspaceActionButton
66
84
className = { styles . actionButton }
67
- icon = { < PlayArrowRoundedIcon /> }
68
- onClick = { handleStart }
69
- label = { Language . start }
70
- loadingLabel = { Language . starting }
71
- isLoading = { workspaceStatus === "starting" }
85
+ icon = { < CancelIcon /> }
86
+ onClick = { handleCancel }
87
+ label = { Language . cancel }
72
88
/>
73
89
) }
74
- { workspaceStatus === "error" && (
75
- < Button className = { styles . actionButton } startIcon = { < ReplayIcon /> } onClick = { handleRetry } >
76
- { Language . retry }
77
- </ Button >
78
- ) }
79
90
{ workspace . outdated && canAcceptJobs ( workspaceStatus ) && (
80
91
< Button className = { styles . actionButton } startIcon = { < CloudDownloadIcon /> } onClick = { handleUpdate } >
81
92
{ Language . update }
@@ -89,6 +100,6 @@ const useStyles = makeStyles((theme) => ({
89
100
actionButton : {
90
101
// Set fixed width for the action buttons so they will not change the size
91
102
// during the transitions
92
- width : theme . spacing ( 30 ) ,
103
+ width : theme . spacing ( 27 ) ,
93
104
} ,
94
105
} ) )
0 commit comments