1
- import { FC , Fragment , ReactNode } from "react" ;
1
+ import { type FC , type ReactNode , Fragment } from "react" ;
2
2
import { Workspace , WorkspaceBuildParameter } from "api/typesGenerated" ;
3
3
import { useWorkspaceDuplication } from "pages/CreateWorkspacePage/useWorkspaceDuplication" ;
4
4
import {
@@ -10,12 +10,9 @@ import {
10
10
RestartButton ,
11
11
UpdateButton ,
12
12
ActivateButton ,
13
+ RetryButton ,
13
14
} from "./Buttons" ;
14
- import {
15
- ButtonMapping ,
16
- ButtonTypesEnum ,
17
- actionsByWorkspaceStatus ,
18
- } from "./constants" ;
15
+ import { type ButtonType , actionsByWorkspaceStatus } from "./constants" ;
19
16
20
17
import Divider from "@mui/material/Divider" ;
21
18
import DuplicateIcon from "@mui/icons-material/FileCopyOutlined" ;
@@ -41,6 +38,7 @@ export interface WorkspaceActionsProps {
41
38
handleCancel : ( ) => void ;
42
39
handleSettings : ( ) => void ;
43
40
handleChangeVersion : ( ) => void ;
41
+ handleRetry : ( ) => void ;
44
42
handleDormantActivate : ( ) => void ;
45
43
isUpdating : boolean ;
46
44
isRestarting : boolean ;
@@ -57,81 +55,72 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
57
55
handleUpdate,
58
56
handleCancel,
59
57
handleSettings,
58
+ handleRetry,
60
59
handleChangeVersion,
61
60
handleDormantActivate : handleDormantActivate ,
62
61
isUpdating,
63
62
isRestarting,
64
63
canChangeVersions,
65
64
} ) => {
66
- const {
67
- canCancel,
68
- canAcceptJobs,
69
- actions : actionsByStatus ,
70
- } = actionsByWorkspaceStatus (
71
- workspace ,
72
- workspace . latest_build . status ,
73
- canChangeVersions ,
74
- ) ;
75
- const canBeUpdated = workspace . outdated && canAcceptJobs ;
76
65
const { duplicateWorkspace, isDuplicationReady } =
77
66
useWorkspaceDuplication ( workspace ) ;
78
67
79
- // A mapping of button type to the corresponding React component
80
- const buttonMapping : ButtonMapping = {
81
- [ ButtonTypesEnum . update ] : < UpdateButton handleAction = { handleUpdate } /> ,
82
- [ ButtonTypesEnum . updating ] : (
83
- < UpdateButton loading handleAction = { handleUpdate } />
84
- ) ,
85
- [ ButtonTypesEnum . start ] : (
86
- < StartButton workspace = { workspace } handleAction = { handleStart } />
87
- ) ,
88
- [ ButtonTypesEnum . starting ] : (
68
+ // A mapping of button type to their corresponding React components
69
+ const buttonMapping : Record < ButtonType , ReactNode > = {
70
+ update : < UpdateButton handleAction = { handleUpdate } /> ,
71
+ updating : < UpdateButton loading handleAction = { handleUpdate } /> ,
72
+ start : < StartButton workspace = { workspace } handleAction = { handleStart } /> ,
73
+ starting : (
89
74
< StartButton loading workspace = { workspace } handleAction = { handleStart } />
90
75
) ,
91
- [ ButtonTypesEnum . stop ] : < StopButton handleAction = { handleStop } /> ,
92
- [ ButtonTypesEnum . stopping ] : (
93
- < StopButton loading handleAction = { handleStop } />
94
- ) ,
95
- [ ButtonTypesEnum . restart ] : (
76
+ stop : < StopButton handleAction = { handleStop } /> ,
77
+ stopping : < StopButton loading handleAction = { handleStop } /> ,
78
+ restart : (
96
79
< RestartButton workspace = { workspace } handleAction = { handleRestart } />
97
80
) ,
98
- [ ButtonTypesEnum . restarting ] : (
81
+ restarting : (
99
82
< RestartButton
100
83
loading
101
84
workspace = { workspace }
102
85
handleAction = { handleRestart }
103
86
/>
104
87
) ,
105
- [ ButtonTypesEnum . deleting ] : < ActionLoadingButton label = "Deleting" /> ,
106
- [ ButtonTypesEnum . canceling ] : < DisabledButton label = "Canceling..." /> ,
107
- [ ButtonTypesEnum . deleted ] : < DisabledButton label = "Deleted" /> ,
108
- [ ButtonTypesEnum . pending ] : < ActionLoadingButton label = "Pending..." /> ,
109
- [ ButtonTypesEnum . activate ] : (
110
- < ActivateButton handleAction = { handleDormantActivate } />
111
- ) ,
112
- [ ButtonTypesEnum . activating ] : (
113
- < ActivateButton loading handleAction = { handleDormantActivate } />
114
- ) ,
88
+ deleting : < ActionLoadingButton label = "Deleting" /> ,
89
+ canceling : < DisabledButton label = "Canceling..." /> ,
90
+ deleted : < DisabledButton label = "Deleted" /> ,
91
+ pending : < ActionLoadingButton label = "Pending..." /> ,
92
+ activate : < ActivateButton handleAction = { handleDormantActivate } /> ,
93
+ activating : < ActivateButton loading handleAction = { handleDormantActivate } /> ,
94
+ retry : < RetryButton handleAction = { handleRetry } /> ,
115
95
} ;
116
96
97
+ const { actions, canCancel, canAcceptJobs } = actionsByWorkspaceStatus (
98
+ workspace ,
99
+ workspace . latest_build . status ,
100
+ canChangeVersions ,
101
+ ) ;
102
+ const canBeUpdated = workspace . outdated && canAcceptJobs ;
103
+
117
104
return (
118
105
< div
119
106
css = { { display : "flex" , alignItems : "center" , gap : 12 } }
120
107
data-testid = "workspace-actions"
121
108
>
109
+ { /*
110
+ * Parentheses important – if canBeUpdated is false, nothing should
111
+ * appear in the UI
112
+ */ }
122
113
{ canBeUpdated &&
123
- ( isUpdating
124
- ? buttonMapping [ ButtonTypesEnum . updating ]
125
- : buttonMapping [ ButtonTypesEnum . update ] ) }
114
+ ( isUpdating ? buttonMapping . updating : buttonMapping . update ) }
126
115
127
- { isRestarting && buttonMapping [ ButtonTypesEnum . restarting ] }
128
-
129
- { ! isRestarting &&
130
- actionsByStatus . map ( ( action ) => (
131
- < Fragment key = { action } > { buttonMapping [ action ] } </ Fragment >
132
- ) ) }
116
+ { isRestarting
117
+ ? buttonMapping . restarting
118
+ : actions . map ( ( action ) => (
119
+ < Fragment key = { action } > { buttonMapping [ action ] } </ Fragment >
120
+ ) ) }
133
121
134
122
{ canCancel && < CancelButton handleAction = { handleCancel } /> }
123
+
135
124
< MoreMenu >
136
125
< MoreMenuTrigger >
137
126
< ThreeDotsButton
0 commit comments