Skip to content

Commit 07cd9ac

Browse files
authored
fix: fix workspace actions options (#13572)
1 parent eed9794 commit 07cd9ac

File tree

5 files changed

+138
-102
lines changed

5 files changed

+138
-102
lines changed

site/src/pages/WorkspacePage/WorkspaceActions/Buttons.tsx

+18-6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ export const StartButton: FC<ActionButtonPropsWithWorkspace> = ({
9999
);
100100
};
101101

102+
export const UpdateAndStartButton: FC<ActionButtonProps> = ({
103+
handleAction,
104+
}) => {
105+
return (
106+
<Tooltip title="This template requires automatic updates on workspace startup. Contact your administrator if you want to preserve the template version.">
107+
<TopbarButton
108+
startIcon={<PlayCircleOutlineIcon />}
109+
onClick={() => handleAction()}
110+
>
111+
Update and start&hellip;
112+
</TopbarButton>
113+
</Tooltip>
114+
);
115+
};
116+
102117
export const StopButton: FC<ActionButtonProps> = ({
103118
handleAction,
104119
loading,
@@ -148,16 +163,13 @@ export const RestartButton: FC<ActionButtonPropsWithWorkspace> = ({
148163
);
149164
};
150165

151-
export const UpdateAndStartButton: FC<ActionButtonProps> = ({
166+
export const UpdateAndRestartButton: FC<ActionButtonProps> = ({
152167
handleAction,
153168
}) => {
154169
return (
155170
<Tooltip title="This template requires automatic updates on workspace startup. Contact your administrator if you want to preserve the template version.">
156-
<TopbarButton
157-
startIcon={<PlayCircleOutlineIcon />}
158-
onClick={() => handleAction()}
159-
>
160-
Update and start&hellip;
171+
<TopbarButton startIcon={<ReplayIcon />} onClick={() => handleAction()}>
172+
Update and restart&hellip;
161173
</TopbarButton>
162174
</Tooltip>
163175
);

site/src/pages/WorkspacePage/WorkspaceActions/WorkspaceActions.stories.tsx

+69-33
Original file line numberDiff line numberDiff line change
@@ -34,93 +34,128 @@ export const Running: Story = {
3434
},
3535
};
3636

37-
export const Stopping: Story = {
37+
export const RunningUpdateAvailable: Story = {
38+
name: "Running (Update available)",
3839
args: {
39-
workspace: Mocks.MockStoppingWorkspace,
40+
workspace: {
41+
...Mocks.MockWorkspace,
42+
outdated: true,
43+
},
4044
},
4145
};
4246

43-
export const Stopped: Story = {
47+
export const RunningRequireActiveVersion: Story = {
48+
name: "Running (No required update)",
4449
args: {
45-
workspace: Mocks.MockStoppedWorkspace,
50+
workspace: {
51+
...Mocks.MockWorkspace,
52+
template_require_active_version: true,
53+
},
4654
},
4755
};
4856

49-
export const Canceling: Story = {
57+
export const RunningUpdateRequired: Story = {
58+
name: "Running (Update Required)",
5059
args: {
51-
workspace: Mocks.MockCancelingWorkspace,
60+
workspace: {
61+
...Mocks.MockWorkspace,
62+
template_require_active_version: true,
63+
outdated: true,
64+
},
5265
},
5366
};
5467

55-
export const Canceled: Story = {
68+
export const Stopping: Story = {
5669
args: {
57-
workspace: Mocks.MockCanceledWorkspace,
70+
workspace: Mocks.MockStoppingWorkspace,
5871
},
5972
};
6073

61-
export const Deleting: Story = {
74+
export const Stopped: Story = {
6275
args: {
63-
workspace: Mocks.MockDeletingWorkspace,
76+
workspace: Mocks.MockStoppedWorkspace,
6477
},
6578
};
6679

67-
export const Deleted: Story = {
80+
export const StoppedUpdateAvailable: Story = {
81+
name: "Stopped (Update available)",
6882
args: {
69-
workspace: Mocks.MockDeletedWorkspace,
83+
workspace: {
84+
...Mocks.MockStoppedWorkspace,
85+
outdated: true,
86+
},
7087
},
7188
};
7289

73-
export const Outdated: Story = {
90+
export const StoppedRequireActiveVersion: Story = {
91+
name: "Stopped (No required update)",
92+
args: {
93+
workspace: {
94+
...Mocks.MockStoppedWorkspace,
95+
template_require_active_version: true,
96+
},
97+
},
98+
};
99+
100+
export const StoppedUpdateRequired: Story = {
101+
name: "Stopped (Update Required)",
102+
args: {
103+
workspace: {
104+
...Mocks.MockStoppedWorkspace,
105+
template_require_active_version: true,
106+
outdated: true,
107+
},
108+
},
109+
};
110+
111+
export const Updating: Story = {
74112
args: {
75113
workspace: Mocks.MockOutdatedWorkspace,
114+
isUpdating: true,
76115
},
77116
};
78117

79-
export const Failed: Story = {
118+
export const Restarting: Story = {
80119
args: {
81-
workspace: Mocks.MockFailedWorkspace,
120+
workspace: Mocks.MockStoppingWorkspace,
121+
isRestarting: true,
82122
},
83123
};
84124

85-
export const FailedWithDebug: Story = {
125+
export const Canceling: Story = {
86126
args: {
87-
workspace: Mocks.MockFailedWorkspace,
88-
canDebug: true,
127+
workspace: Mocks.MockCancelingWorkspace,
89128
},
90129
};
91130

92-
export const Updating: Story = {
131+
export const Deleting: Story = {
93132
args: {
94-
isUpdating: true,
95-
workspace: Mocks.MockOutdatedWorkspace,
133+
workspace: Mocks.MockDeletingWorkspace,
96134
},
97135
};
98136

99-
export const RequireActiveVersionStarted: Story = {
137+
export const Deleted: Story = {
100138
args: {
101-
workspace: Mocks.MockOutdatedRunningWorkspaceRequireActiveVersion,
102-
canChangeVersions: false,
139+
workspace: Mocks.MockDeletedWorkspace,
103140
},
104141
};
105142

106-
export const RequireActiveVersionStopped: Story = {
143+
export const Outdated: Story = {
107144
args: {
108-
workspace: Mocks.MockOutdatedStoppedWorkspaceRequireActiveVersion,
109-
canChangeVersions: false,
145+
workspace: Mocks.MockOutdatedWorkspace,
110146
},
111147
};
112148

113-
export const AlwaysUpdateStarted: Story = {
149+
export const Failed: Story = {
114150
args: {
115-
workspace: Mocks.MockOutdatedRunningWorkspaceAlwaysUpdate,
116-
canChangeVersions: true,
151+
workspace: Mocks.MockFailedWorkspace,
117152
},
118153
};
119154

120-
export const AlwaysUpdateStopped: Story = {
155+
export const FailedWithDebug: Story = {
121156
args: {
122-
workspace: Mocks.MockOutdatedStoppedWorkspaceAlwaysUpdate,
123-
canChangeVersions: true,
157+
workspace: Mocks.MockFailedWorkspace,
158+
canDebug: true,
124159
},
125160
};
126161

@@ -133,6 +168,7 @@ export const CancelShownForOwner: Story = {
133168
isOwner: true,
134169
},
135170
};
171+
136172
export const CancelShownForUser: Story = {
137173
args: {
138174
workspace: Mocks.MockStartingWorkspace,

site/src/pages/WorkspacePage/WorkspaceActions/WorkspaceActions.tsx

+15-29
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
ActivateButton,
2727
FavoriteButton,
2828
UpdateAndStartButton,
29+
UpdateAndRestartButton,
2930
} from "./Buttons";
3031
import { type ActionType, abilitiesByWorkspaceStatus } from "./constants";
3132
import { DebugButton } from "./DebugButton";
@@ -89,12 +90,12 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
8990

9091
const mustUpdate = mustUpdateWorkspace(workspace, canChangeVersions);
9192
const tooltipText = getTooltipText(workspace, mustUpdate, canChangeVersions);
92-
const canBeUpdated = workspace.outdated && canAcceptJobs;
9393

9494
// A mapping of button type to the corresponding React component
9595
const buttonMapping: Record<ActionType, ReactNode> = {
9696
update: <UpdateButton handleAction={handleUpdate} />,
9797
updateAndStart: <UpdateAndStartButton handleAction={handleUpdate} />,
98+
updateAndRestart: <UpdateAndRestartButton handleAction={handleUpdate} />,
9899
updating: <UpdateButton loading handleAction={handleUpdate} />,
99100
start: (
100101
<StartButton
@@ -152,44 +153,29 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
152153
enableBuildParameters={workspace.latest_build.transition === "start"}
153154
/>
154155
),
155-
toggleFavorite: (
156-
<FavoriteButton
157-
workspaceID={workspace.id}
158-
isFavorite={workspace.favorite}
159-
onToggle={handleToggleFavorite}
160-
/>
161-
),
162156
};
163157

164158
return (
165159
<div
166160
css={{ display: "flex", alignItems: "center", gap: 8 }}
167161
data-testid="workspace-actions"
168162
>
169-
{canBeUpdated && (
170-
<>
171-
{isUpdating
172-
? buttonMapping.updating
173-
: workspace.template_require_active_version
174-
? buttonMapping.updateAndStart
175-
: buttonMapping.update}
176-
</>
177-
)}
178-
179-
{!canBeUpdated &&
180-
!isUpdating &&
181-
workspace.template_require_active_version &&
182-
buttonMapping.start}
183-
184-
{isRestarting
185-
? buttonMapping.restarting
186-
: actions.map((action) => (
187-
<Fragment key={action}>{buttonMapping[action]}</Fragment>
188-
))}
163+
{/* Restarting must be handled separately, because it otherwise would appear as stopping */}
164+
{isUpdating
165+
? buttonMapping.updating
166+
: isRestarting
167+
? buttonMapping.restarting
168+
: actions.map((action) => (
169+
<Fragment key={action}>{buttonMapping[action]}</Fragment>
170+
))}
189171

190172
{showCancel && <CancelButton handleAction={handleCancel} />}
191173

192-
{buttonMapping.toggleFavorite}
174+
<FavoriteButton
175+
workspaceID={workspace.id}
176+
isFavorite={workspace.favorite}
177+
onToggle={handleToggleFavorite}
178+
/>
193179

194180
<MoreMenu>
195181
<MoreMenuTrigger>

0 commit comments

Comments
 (0)