@@ -5,7 +5,16 @@ import { FC, ReactNode, useEffect, useMemo, useRef, useState } from "react"
5
5
import { Workspace } from "../../api/typesGenerated"
6
6
import { getWorkspaceStatus , WorkspaceStatus } from "../../util/workspace"
7
7
import { CloseDropdown , OpenDropdown } from "../DropdownArrows/DropdownArrows"
8
- import { CancelButton , DeleteButton , StartButton , StopButton , UpdateButton } from "./ActionCtas"
8
+ import {
9
+ ActionLoadingButton ,
10
+ CancelButton ,
11
+ DeleteButton ,
12
+ DisabledButton ,
13
+ Language ,
14
+ StartButton ,
15
+ StopButton ,
16
+ UpdateButton ,
17
+ } from "./ActionCtas"
9
18
import { ButtonTypesEnum , WorkspaceStateActions , WorkspaceStateEnum } from "./constants"
10
19
11
20
/**
@@ -69,12 +78,6 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
69
78
}
70
79
} , [ workspaceStatus ] )
71
80
72
- const disabledButton = (
73
- < Button disabled className = { styles . actionButton } >
74
- { workspaceState }
75
- </ Button >
76
- )
77
-
78
81
type ButtonMapping = {
79
82
[ key in ButtonTypesEnum ] : ReactNode
80
83
}
@@ -83,60 +86,68 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
83
86
const buttonMapping : ButtonMapping = {
84
87
[ ButtonTypesEnum . update ] : < UpdateButton handleAction = { handleUpdate } /> ,
85
88
[ ButtonTypesEnum . start ] : < StartButton handleAction = { handleStart } /> ,
89
+ [ ButtonTypesEnum . starting ] : < ActionLoadingButton label = { Language . starting } /> ,
86
90
[ ButtonTypesEnum . stop ] : < StopButton handleAction = { handleStop } /> ,
91
+ [ ButtonTypesEnum . stopping ] : < ActionLoadingButton label = { Language . stopping } /> ,
87
92
[ ButtonTypesEnum . delete ] : < DeleteButton handleAction = { handleDelete } /> ,
93
+ [ ButtonTypesEnum . deleting ] : < ActionLoadingButton label = { Language . deleting } /> ,
88
94
[ ButtonTypesEnum . cancel ] : < CancelButton handleAction = { handleCancel } /> ,
89
- [ ButtonTypesEnum . canceling ] : disabledButton ,
90
- [ ButtonTypesEnum . disabled ] : disabledButton ,
91
- [ ButtonTypesEnum . queued ] : disabledButton ,
92
- [ ButtonTypesEnum . error ] : disabledButton ,
93
- [ ButtonTypesEnum . loading ] : disabledButton ,
95
+ [ ButtonTypesEnum . canceling ] : < DisabledButton workspaceState = { workspaceState } /> ,
96
+ [ ButtonTypesEnum . disabled ] : < DisabledButton workspaceState = { workspaceState } /> ,
97
+ [ ButtonTypesEnum . queued ] : < DisabledButton workspaceState = { workspaceState } /> ,
98
+ [ ButtonTypesEnum . error ] : < DisabledButton workspaceState = { workspaceState } /> ,
99
+ [ ButtonTypesEnum . loading ] : < DisabledButton workspaceState = { workspaceState } /> ,
94
100
}
95
101
96
102
return (
97
103
< span className = { styles . buttonContainer } >
98
104
{ /* primary workspace CTA */ }
99
105
< span data-testid = "primary-cta" > { buttonMapping [ actions . primary ] } </ span >
100
-
101
- { /* popover toggle button */ }
102
- < Button
103
- data-testid = "workspace-actions-button"
104
- aria-controls = "workspace-actions-menu"
105
- aria-haspopup = "true"
106
- className = { styles . dropdownButton }
107
- ref = { anchorRef }
108
- disabled = { ! actions . secondary . length }
109
- onClick = { ( ) => {
110
- setIsOpen ( true )
111
- } }
112
- >
113
- { isOpen ? < CloseDropdown /> : < OpenDropdown /> }
114
- </ Button >
115
-
116
- < Popover
117
- classes = { { paper : styles . popoverPaper } }
118
- id = { id }
119
- open = { isOpen }
120
- anchorEl = { anchorRef . current }
121
- onClose = { ( ) => setIsOpen ( false ) }
122
- anchorOrigin = { {
123
- vertical : "bottom" ,
124
- horizontal : "right" ,
125
- } }
126
- transformOrigin = { {
127
- vertical : "top" ,
128
- horizontal : "right" ,
129
- } }
130
- >
131
- { /* secondary workspace CTAs */ }
132
- < span data-testid = "secondary-ctas" >
133
- { actions . secondary . map ( ( action ) => (
134
- < div key = { action } className = { styles . popoverActionButton } >
135
- { buttonMapping [ action ] }
136
- </ div >
137
- ) ) }
138
- </ span >
139
- </ Popover >
106
+ { actions . canCancel ? (
107
+ // cancel CTA
108
+ < > { buttonMapping [ ButtonTypesEnum . cancel ] } </ >
109
+ ) : (
110
+ < >
111
+ { /* popover toggle button */ }
112
+ < Button
113
+ data-testid = "workspace-actions-button"
114
+ aria-controls = "workspace-actions-menu"
115
+ aria-haspopup = "true"
116
+ className = { styles . dropdownButton }
117
+ ref = { anchorRef }
118
+ disabled = { ! actions . secondary . length }
119
+ onClick = { ( ) => {
120
+ setIsOpen ( true )
121
+ } }
122
+ >
123
+ { isOpen ? < CloseDropdown /> : < OpenDropdown /> }
124
+ </ Button >
125
+ < Popover
126
+ classes = { { paper : styles . popoverPaper } }
127
+ id = { id }
128
+ open = { isOpen }
129
+ anchorEl = { anchorRef . current }
130
+ onClose = { ( ) => setIsOpen ( false ) }
131
+ anchorOrigin = { {
132
+ vertical : "bottom" ,
133
+ horizontal : "right" ,
134
+ } }
135
+ transformOrigin = { {
136
+ vertical : "top" ,
137
+ horizontal : "right" ,
138
+ } }
139
+ >
140
+ { /* secondary workspace CTAs */ }
141
+ < span data-testid = "secondary-ctas" >
142
+ { actions . secondary . map ( ( action ) => (
143
+ < div key = { action } className = { styles . popoverActionButton } >
144
+ { buttonMapping [ action ] }
145
+ </ div >
146
+ ) ) }
147
+ </ span >
148
+ </ Popover >
149
+ </ >
150
+ ) }
140
151
</ span >
141
152
)
142
153
}
@@ -152,18 +163,11 @@ const useStyles = makeStyles((theme) => ({
152
163
borderLeft : `1px solid ${ theme . palette . divider } ` ,
153
164
borderRadius : `0px ${ theme . shape . borderRadius } px ${ theme . shape . borderRadius } px 0px` ,
154
165
minWidth : "unset" ,
155
- width : "35px" ,
166
+ width : "63px" , // matching cancel button so button grouping doesn't grow in size
156
167
"& .MuiButton-label" : {
157
168
marginRight : "8px" ,
158
169
} ,
159
170
} ,
160
- actionButton : {
161
- // Set fixed width for the action buttons so they will not change the size
162
- // during the transitions
163
- width : theme . spacing ( 16 ) ,
164
- border : "none" ,
165
- borderRadius : `${ theme . shape . borderRadius } px 0px 0px ${ theme . shape . borderRadius } px` ,
166
- } ,
167
171
popoverActionButton : {
168
172
"& .MuiButtonBase-root" : {
169
173
backgroundColor : "unset" ,
0 commit comments