Skip to content

Commit da8bd12

Browse files
committed
reduce button explosion
1 parent 1c703ca commit da8bd12

File tree

3 files changed

+44
-59
lines changed

3 files changed

+44
-59
lines changed

site/src/modules/workspaces/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import type { Workspace } from "api/typesGenerated";
66
const actionTypes = [
77
"start",
88
"starting",
9-
// Replaces start when an update is available.
9+
// Appears beside start when an update is available.
1010
"updateAndStart",
1111
// Replaces start when an update is required.
1212
"updateAndStartRequireActiveVersion",
1313
"stop",
1414
"stopping",
1515
"restart",
1616
"restarting",
17-
// Replaces restart when an update is available.
17+
// Appears beside restart when an update is available.
1818
"updateAndRestart",
1919
// Replaces restart when an update is required.
2020
"updateAndRestartRequireActiveVersion",

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

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,33 @@ export interface ActionButtonProps {
1818
handleAction: (buildParameters?: WorkspaceBuildParameter[]) => void;
1919
disabled?: boolean;
2020
tooltipText?: string;
21+
isRunning?: boolean;
22+
requireActiveVersion?: boolean;
2123
}
2224

23-
export const UpdateAndStartButton: FC<ActionButtonProps> = ({
25+
export const UpdateButton: FC<ActionButtonProps> = ({
2426
handleAction,
2527
loading,
28+
isRunning,
29+
requireActiveVersion,
2630
}) => {
2731
return (
28-
<Tooltip title="Start workspace with the latest template version.">
32+
<Tooltip
33+
title={
34+
requireActiveVersion
35+
? "This template requires automatic updates on workspace startup. Contact your administrator if you want to preserve the template version."
36+
: isRunning
37+
? "Stop workspace and restart it with the latest template version."
38+
: "Start workspace with the latest template version."
39+
}
40+
>
2941
<TopbarButton
30-
disabled={loading}
3142
data-testid="workspace-update-button"
32-
onClick={() => handleAction()}
33-
>
34-
<CirclePlayIcon />
35-
{loading ? <>Updating&hellip;</> : <>Update&hellip;</>}
36-
</TopbarButton>
37-
</Tooltip>
38-
);
39-
};
40-
41-
export const UpdateAndRestartButton: FC<ActionButtonProps> = ({
42-
handleAction,
43-
loading,
44-
}) => {
45-
return (
46-
<Tooltip title="Stop workspace, if running, and restart it with the latest template version.">
47-
<TopbarButton
4843
disabled={loading}
49-
data-testid="workspace-update-and-restart-button"
5044
onClick={() => handleAction()}
5145
>
52-
<RotateCcwIcon />
53-
{loading ? <>Updating&hellip;</> : <>Update and restart&hellip;</>}
46+
{isRunning ? <RotateCcwIcon /> : <CirclePlayIcon />}
47+
{loading ? <>Updating&hellip;</> : <>Update&hellip;</>}
5448
</TopbarButton>
5549
</Tooltip>
5650
);
@@ -103,19 +97,6 @@ export const StartButton: FC<ActionButtonPropsWithWorkspace> = ({
10397
);
10498
};
10599

106-
export const UpdateAndStartButtonRequireActiveVersion: FC<
107-
ActionButtonProps
108-
> = ({ handleAction }) => {
109-
return (
110-
<Tooltip title="This template requires automatic updates on workspace startup. Contact your administrator if you want to preserve the template version.">
111-
<TopbarButton onClick={() => handleAction()}>
112-
<CirclePlayIcon />
113-
Update and start&hellip;
114-
</TopbarButton>
115-
</Tooltip>
116-
);
117-
};
118-
119100
export const StopButton: FC<ActionButtonProps> = ({
120101
handleAction,
121102
loading,
@@ -157,19 +138,6 @@ export const RestartButton: FC<ActionButtonPropsWithWorkspace> = ({
157138
);
158139
};
159140

160-
export const UpdateAndRestartButtonRequireActiveVersion: FC<
161-
ActionButtonProps
162-
> = ({ handleAction }) => {
163-
return (
164-
<Tooltip title="This template requires automatic updates on workspace startup. Contact your administrator if you want to preserve the template version.">
165-
<TopbarButton onClick={() => handleAction()}>
166-
<RotateCcwIcon />
167-
Update and restart&hellip;
168-
</TopbarButton>
169-
</Tooltip>
170-
);
171-
};
172-
173141
export const CancelButton: FC<ActionButtonProps> = ({ handleAction }) => {
174142
return (
175143
<TopbarButton onClick={() => handleAction()}>

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ import {
1818
RestartButton,
1919
StartButton,
2020
StopButton,
21-
UpdateAndRestartButton,
22-
UpdateAndRestartButtonRequireActiveVersion,
23-
UpdateAndStartButton,
24-
UpdateAndStartButtonRequireActiveVersion,
21+
UpdateButton,
2522
} from "./Buttons";
2623
import { DebugButton } from "./DebugButton";
2724
import { RetryButton } from "./RetryButton";
@@ -82,15 +79,35 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
8279

8380
// A mapping of button type to the corresponding React component
8481
const buttonMapping: Record<ActionType, ReactNode> = {
85-
updateAndStart: <UpdateAndStartButton handleAction={handleUpdate} />,
82+
updateAndStart: (
83+
<UpdateButton
84+
handleAction={handleUpdate}
85+
isRunning={false}
86+
requireActiveVersion={false}
87+
/>
88+
),
8689
updateAndStartRequireActiveVersion: (
87-
<UpdateAndStartButtonRequireActiveVersion handleAction={handleUpdate} />
90+
<UpdateButton
91+
handleAction={handleUpdate}
92+
isRunning={false}
93+
requireActiveVersion={true}
94+
/>
95+
),
96+
updateAndRestart: (
97+
<UpdateButton
98+
handleAction={handleUpdate}
99+
isRunning={true}
100+
requireActiveVersion={false}
101+
/>
88102
),
89-
updateAndRestart: <UpdateAndRestartButton handleAction={handleUpdate} />,
90103
updateAndRestartRequireActiveVersion: (
91-
<UpdateAndRestartButtonRequireActiveVersion handleAction={handleUpdate} />
104+
<UpdateButton
105+
handleAction={handleUpdate}
106+
isRunning={true}
107+
requireActiveVersion={true}
108+
/>
92109
),
93-
updating: <UpdateAndStartButton loading handleAction={handleUpdate} />,
110+
updating: <UpdateButton loading handleAction={handleUpdate} />,
94111
start: (
95112
<StartButton
96113
workspace={workspace}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy