Skip to content

Commit 8757691

Browse files
committed
fix: fix workspace actions options
1 parent c587af7 commit 8757691

File tree

4 files changed

+59
-48
lines changed

4 files changed

+59
-48
lines changed

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

Lines changed: 18 additions & 6 deletions
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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,16 @@ export const RequireActiveVersionStarted: Story = {
103103
},
104104
};
105105

106+
export const RequireActiveVersionStarting: Story = {
107+
args: {
108+
workspace: {
109+
...Mocks.MockStartingWorkspace,
110+
template_require_active_version: true,
111+
},
112+
canChangeVersions: false,
113+
},
114+
};
115+
106116
export const RequireActiveVersionStopped: Story = {
107117
args: {
108118
workspace: Mocks.MockOutdatedStoppedWorkspaceRequireActiveVersion,

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

Lines changed: 15 additions & 29 deletions
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>

site/src/pages/WorkspacePage/WorkspaceActions/constants.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,26 @@ import type { Workspace } from "api/typesGenerated";
66
export const actionTypes = [
77
"start",
88
"starting",
9+
// Replaces start when an update is required.
10+
"updateAndStart",
911
"stop",
1012
"stopping",
1113
"restart",
1214
"restarting",
15+
// Replaces restart when an update is required.
16+
"updateAndRestart",
1317
"deleting",
1418
"update",
1519
"updating",
1620
"activate",
1721
"activating",
18-
"toggleFavorite",
1922

2023
// There's no need for a retrying state because retrying starts a transition
2124
// into one of the starting, stopping, or deleting states (based on the
2225
// WorkspaceTransition type)
2326
"retry",
2427
"debug",
2528

26-
// When a template requires updates, we aim to display a distinct update
27-
// button that clearly indicates a mandatory update.
28-
"updateAndStart",
29-
3029
// These are buttons that should be used with disabled UI elements
3130
"canceling",
3231
"deleted",
@@ -73,10 +72,12 @@ export const abilitiesByWorkspaceStatus = (
7372
case "running": {
7473
const actions: ActionType[] = ["stop"];
7574

76-
// If the template requires the latest version, we prevent the user from
77-
// restarting the workspace without updating it first. In the Buttons
78-
// component, we display an UpdateAndStart component to facilitate this.
79-
if (!workspace.template_require_active_version) {
75+
if (workspace.template_require_active_version && workspace.outdated) {
76+
actions.push("updateAndRestart");
77+
} else {
78+
if (workspace.outdated) {
79+
actions.unshift("update");
80+
}
8081
actions.push("restart");
8182
}
8283

@@ -96,10 +97,12 @@ export const abilitiesByWorkspaceStatus = (
9697
case "stopped": {
9798
const actions: ActionType[] = [];
9899

99-
// If the template requires the latest version, we prevent the user from
100-
// starting the workspace without updating it first. In the Buttons
101-
// component, we display an UpdateAndStart component to facilitate this.
102-
if (!workspace.template_require_active_version) {
100+
if (workspace.template_require_active_version && workspace.outdated) {
101+
actions.push("updateAndStart");
102+
} else {
103+
if (workspace.outdated) {
104+
actions.unshift("update");
105+
}
103106
actions.push("start");
104107
}
105108

0 commit comments

Comments
 (0)