Skip to content

Commit 7a314a5

Browse files
committed
added new restart button and wrote tests
1 parent a07209e commit 7a314a5

File tree

7 files changed

+44
-10
lines changed

7 files changed

+44
-10
lines changed

site/src/components/DropdownButton/ActionCtas.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import CloudQueueIcon from "@material-ui/icons/CloudQueue"
66
import SettingsOutlined from "@material-ui/icons/SettingsOutlined"
77
import CropSquareIcon from "@material-ui/icons/CropSquare"
88
import DeleteOutlineIcon from "@material-ui/icons/DeleteOutline"
9+
import ReplayIcon from "@material-ui/icons/Replay"
910
import PlayCircleOutlineIcon from "@material-ui/icons/PlayCircleOutline"
1011
import { LoadingButton } from "components/LoadingButton/LoadingButton"
11-
import { FC } from "react"
12+
import { FC, PropsWithChildren } from "react"
1213
import { useTranslation } from "react-i18next"
1314
import { combineClasses } from "util/combineClasses"
1415
import { WorkspaceActionButton } from "../WorkspaceActionButton/WorkspaceActionButton"
@@ -17,7 +18,7 @@ interface WorkspaceAction {
1718
handleAction: () => void
1819
}
1920

20-
export const UpdateButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
21+
export const UpdateButton: FC<PropsWithChildren<WorkspaceAction>> = ({
2122
handleAction,
2223
}) => {
2324
const styles = useStyles()
@@ -35,7 +36,7 @@ export const UpdateButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
3536
)
3637
}
3738

38-
export const SettingsButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
39+
export const SettingsButton: FC<PropsWithChildren<WorkspaceAction>> = ({
3940
handleAction,
4041
}) => {
4142
const styles = useStyles()
@@ -53,7 +54,7 @@ export const SettingsButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
5354
)
5455
}
5556

56-
export const StartButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
57+
export const StartButton: FC<PropsWithChildren<WorkspaceAction>> = ({
5758
handleAction,
5859
}) => {
5960
const styles = useStyles()
@@ -69,7 +70,7 @@ export const StartButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
6970
)
7071
}
7172

72-
export const StopButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
73+
export const StopButton: FC<PropsWithChildren<WorkspaceAction>> = ({
7374
handleAction,
7475
}) => {
7576
const styles = useStyles()
@@ -85,7 +86,23 @@ export const StopButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
8586
)
8687
}
8788

88-
export const DeleteButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
89+
export const RestartButton: FC<PropsWithChildren<WorkspaceAction>> = ({
90+
handleAction,
91+
}) => {
92+
const styles = useStyles()
93+
const { t } = useTranslation("workspacePage")
94+
95+
return (
96+
<WorkspaceActionButton
97+
className={styles.actionButton}
98+
icon={<ReplayIcon />}
99+
onClick={handleAction}
100+
label={t("actionButton.restart")}
101+
/>
102+
)
103+
}
104+
105+
export const DeleteButton: FC<PropsWithChildren<WorkspaceAction>> = ({
89106
handleAction,
90107
}) => {
91108
const styles = useStyles()
@@ -101,7 +118,7 @@ export const DeleteButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
101118
)
102119
}
103120

104-
export const CancelButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
121+
export const CancelButton: FC<PropsWithChildren<WorkspaceAction>> = ({
105122
handleAction,
106123
}) => {
107124
const styles = useStyles()
@@ -128,7 +145,7 @@ interface DisabledProps {
128145
label: string
129146
}
130147

131-
export const DisabledButton: FC<React.PropsWithChildren<DisabledProps>> = ({
148+
export const DisabledButton: FC<PropsWithChildren<DisabledProps>> = ({
132149
label,
133150
}) => {
134151
const styles = useStyles()
@@ -144,7 +161,7 @@ interface LoadingProps {
144161
label: string
145162
}
146163

147-
export const ActionLoadingButton: FC<React.PropsWithChildren<LoadingProps>> = ({
164+
export const ActionLoadingButton: FC<PropsWithChildren<LoadingProps>> = ({
148165
label,
149166
}) => {
150167
const styles = useStyles()

site/src/components/Workspace/Workspace.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
125125
isOutdated={workspace.outdated}
126126
handleStart={handleStart}
127127
handleStop={handleStop}
128+
handleRestart={() => console.log("restarting!")}
128129
handleDelete={handleDelete}
129130
handleUpdate={handleUpdate}
130131
handleCancel={handleCancel}

site/src/components/WorkspaceActions/WorkspaceActions.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const Template: Story<WorkspaceActionsProps> = (args) => (
1515
const defaultArgs = {
1616
handleStart: action("start"),
1717
handleStop: action("stop"),
18+
handleRestart: action("restart"),
1819
handleDelete: action("delete"),
1920
handleUpdate: action("update"),
2021
handleCancel: action("cancel"),

site/src/components/WorkspaceActions/WorkspaceActions.test.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const renderComponent = async (props: Partial<WorkspaceActionsProps> = {}) => {
1515
isOutdated={props.isOutdated ?? false}
1616
handleStart={jest.fn()}
1717
handleStop={jest.fn()}
18+
handleRestart={jest.fn()}
1819
handleDelete={jest.fn()}
1920
handleUpdate={jest.fn()}
2021
handleCancel={jest.fn()}
@@ -33,6 +34,7 @@ const renderAndClick = async (props: Partial<WorkspaceActionsProps> = {}) => {
3334
isOutdated={props.isOutdated ?? false}
3435
handleStart={jest.fn()}
3536
handleStop={jest.fn()}
37+
handleRestart={jest.fn()}
3638
handleDelete={jest.fn()}
3739
handleUpdate={jest.fn()}
3840
handleCancel={jest.fn()}
@@ -62,7 +64,7 @@ describe("WorkspaceActions", () => {
6264
})
6365
})
6466
describe("when the workspace is started", () => {
65-
it("primary is stop; secondary is delete", async () => {
67+
it("primary is stop; secondary are delete, restart", async () => {
6668
await renderAndClick({
6769
workspaceStatus: Mocks.MockWorkspace.latest_build.status,
6870
})
@@ -72,6 +74,9 @@ describe("WorkspaceActions", () => {
7274
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(
7375
t("actionButton.delete", { ns: "workspacePage" }),
7476
)
77+
expect(screen.getByTestId("secondary-ctas")).toHaveTextContent(
78+
t("actionButton.restart", { ns: "workspacePage" }),
79+
)
7580
})
7681
})
7782
describe("when the workspace is started", () => {

site/src/components/WorkspaceActions/WorkspaceActions.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
SettingsButton,
1010
StartButton,
1111
StopButton,
12+
RestartButton,
1213
UpdateButton,
1314
} from "../DropdownButton/ActionCtas"
1415
import { ButtonMapping, ButtonTypesEnum, buttonAbilities } from "./constants"
@@ -18,6 +19,7 @@ export interface WorkspaceActionsProps {
1819
isOutdated: boolean
1920
handleStart: () => void
2021
handleStop: () => void
22+
handleRestart: () => void
2123
handleDelete: () => void
2224
handleUpdate: () => void
2325
handleCancel: () => void
@@ -31,6 +33,7 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
3133
isOutdated,
3234
handleStart,
3335
handleStop,
36+
handleRestart,
3437
handleDelete,
3538
handleUpdate,
3639
handleCancel,
@@ -58,6 +61,10 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
5861
[ButtonTypesEnum.stopping]: (
5962
<ActionLoadingButton label={t("actionButton.stopping")} />
6063
),
64+
[ButtonTypesEnum.restart]: <RestartButton handleAction={handleRestart} />,
65+
[ButtonTypesEnum.starting]: (
66+
<ActionLoadingButton label={t("actionButton.starting")} />
67+
),
6168
[ButtonTypesEnum.delete]: <DeleteButton handleAction={handleDelete} />,
6269
[ButtonTypesEnum.deleting]: (
6370
<ActionLoadingButton label={t("actionButton.deleting")} />

site/src/components/WorkspaceActions/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export enum ButtonTypesEnum {
77
starting = "starting",
88
stop = "stop",
99
stopping = "stopping",
10+
restart = "restart",
1011
delete = "delete",
1112
deleting = "deleting",
1213
update = "update",
@@ -45,6 +46,7 @@ const statusToAbilities: Record<WorkspaceStatus, WorkspaceAbilities> = {
4546
ButtonTypesEnum.stop,
4647
ButtonTypesEnum.settings,
4748
ButtonTypesEnum.delete,
49+
ButtonTypesEnum.restart,
4850
],
4951
canCancel: false,
5052
canAcceptJobs: true,

site/src/i18n/en/workspacePage.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"actionButton": {
2222
"start": "Start",
2323
"stop": "Stop",
24+
"restart": "Restart",
2425
"delete": "Delete",
2526
"cancel": "Cancel",
2627
"update": "Update",

0 commit comments

Comments
 (0)