@@ -5,7 +5,16 @@ import { FC, ReactNode, useEffect, useMemo, useRef, useState } from "react"
55import { Workspace } from "../../api/typesGenerated"
66import { getWorkspaceStatus , WorkspaceStatus } from "../../util/workspace"
77import { 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"
918import { ButtonTypesEnum , WorkspaceStateActions , WorkspaceStateEnum } from "./constants"
1019
1120/**
@@ -69,12 +78,6 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
6978 }
7079 } , [ workspaceStatus ] )
7180
72- const disabledButton = (
73- < Button disabled className = { styles . actionButton } >
74- { workspaceState }
75- </ Button >
76- )
77-
7881 type ButtonMapping = {
7982 [ key in ButtonTypesEnum ] : ReactNode
8083 }
@@ -83,60 +86,68 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
8386 const buttonMapping : ButtonMapping = {
8487 [ ButtonTypesEnum . update ] : < UpdateButton handleAction = { handleUpdate } /> ,
8588 [ ButtonTypesEnum . start ] : < StartButton handleAction = { handleStart } /> ,
89+ [ ButtonTypesEnum . starting ] : < ActionLoadingButton label = { Language . starting } /> ,
8690 [ ButtonTypesEnum . stop ] : < StopButton handleAction = { handleStop } /> ,
91+ [ ButtonTypesEnum . stopping ] : < ActionLoadingButton label = { Language . stopping } /> ,
8792 [ ButtonTypesEnum . delete ] : < DeleteButton handleAction = { handleDelete } /> ,
93+ [ ButtonTypesEnum . deleting ] : < ActionLoadingButton label = { Language . deleting } /> ,
8894 [ 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 } /> ,
94100 }
95101
96102 return (
97103 < span className = { styles . buttonContainer } >
98104 { /* primary workspace CTA */ }
99105 < 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+ ) }
140151 </ span >
141152 )
142153}
@@ -152,18 +163,11 @@ const useStyles = makeStyles((theme) => ({
152163 borderLeft : `1px solid ${ theme . palette . divider } ` ,
153164 borderRadius : `0px ${ theme . shape . borderRadius } px ${ theme . shape . borderRadius } px 0px` ,
154165 minWidth : "unset" ,
155- width : "35px" ,
166+ width : "63px" , // matching cancel button so button grouping doesn't grow in size
156167 "& .MuiButton-label" : {
157168 marginRight : "8px" ,
158169 } ,
159170 } ,
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- } ,
167171 popoverActionButton : {
168172 "& .MuiButtonBase-root" : {
169173 backgroundColor : "unset" ,
0 commit comments