From 4079fc5728475dd77c6c36fe97f805834c198850 Mon Sep 17 00:00:00 2001 From: Kira Pilot Date: Fri, 14 Apr 2023 08:48:05 -0700 Subject: [PATCH 1/7] feat(UI): add workspace restart button (#7137) * Refactor primary buttons * refactor(site): Always show the main actions * Remove tests that are testes on Storybook * Fix tests * Fix keys * added restart btn --------- Co-authored-by: BrunoQuaresma --- site/src/components/Workspace/Workspace.tsx | 3 ++ .../components/WorkspaceActions/Buttons.tsx | 33 +++++++++++++++---- .../WorkspaceActions.stories.tsx | 1 + .../WorkspaceActions/WorkspaceActions.tsx | 4 +++ .../components/WorkspaceActions/constants.ts | 3 +- site/src/i18n/en/workspacePage.json | 1 + .../WorkspacePage/WorkspaceReadyPage.tsx | 1 + 7 files changed, 38 insertions(+), 8 deletions(-) diff --git a/site/src/components/Workspace/Workspace.tsx b/site/src/components/Workspace/Workspace.tsx index b0377eeb29847..f7090b45b4eec 100644 --- a/site/src/components/Workspace/Workspace.tsx +++ b/site/src/components/Workspace/Workspace.tsx @@ -41,6 +41,7 @@ export interface WorkspaceProps { } handleStart: () => void handleStop: () => void + handleRestart: () => void handleDelete: () => void handleUpdate: () => void handleCancel: () => void @@ -72,6 +73,7 @@ export const Workspace: FC> = ({ scheduleProps, handleStart, handleStop, + handleRestart, handleDelete, handleUpdate, handleCancel, @@ -132,6 +134,7 @@ export const Workspace: FC> = ({ isOutdated={workspace.outdated} handleStart={handleStart} handleStop={handleStop} + handleRestart={handleRestart} handleDelete={handleDelete} handleUpdate={handleUpdate} handleCancel={handleCancel} diff --git a/site/src/components/WorkspaceActions/Buttons.tsx b/site/src/components/WorkspaceActions/Buttons.tsx index b8c38469df68f..d6207952a4ac8 100644 --- a/site/src/components/WorkspaceActions/Buttons.tsx +++ b/site/src/components/WorkspaceActions/Buttons.tsx @@ -3,8 +3,9 @@ import BlockIcon from "@material-ui/icons/Block" import CloudQueueIcon from "@material-ui/icons/CloudQueue" import CropSquareIcon from "@material-ui/icons/CropSquare" import PlayCircleOutlineIcon from "@material-ui/icons/PlayCircleOutline" +import ReplayIcon from "@material-ui/icons/Replay" import { LoadingButton } from "components/LoadingButton/LoadingButton" -import { FC } from "react" +import { FC, PropsWithChildren } from "react" import { useTranslation } from "react-i18next" import { makeStyles } from "@material-ui/core/styles" @@ -12,7 +13,7 @@ interface WorkspaceAction { handleAction: () => void } -export const UpdateButton: FC> = ({ +export const UpdateButton: FC> = ({ handleAction, }) => { const { t } = useTranslation("workspacePage") @@ -30,7 +31,7 @@ export const UpdateButton: FC> = ({ ) } -export const StartButton: FC> = ({ +export const StartButton: FC> = ({ handleAction, }) => { const { t } = useTranslation("workspacePage") @@ -48,7 +49,7 @@ export const StartButton: FC> = ({ ) } -export const StopButton: FC> = ({ +export const StopButton: FC> = ({ handleAction, }) => { const { t } = useTranslation("workspacePage") @@ -66,7 +67,25 @@ export const StopButton: FC> = ({ ) } -export const CancelButton: FC> = ({ +export const RestartButton: FC> = ({ + handleAction, +}) => { + const { t } = useTranslation("workspacePage") + const styles = useStyles() + + return ( + + ) +} + +export const CancelButton: FC> = ({ handleAction, }) => { return ( @@ -80,7 +99,7 @@ interface DisabledProps { label: string } -export const DisabledButton: FC> = ({ +export const DisabledButton: FC> = ({ label, }) => { return ( @@ -94,7 +113,7 @@ interface LoadingProps { label: string } -export const ActionLoadingButton: FC> = ({ +export const ActionLoadingButton: FC> = ({ label, }) => { const styles = useStyles() diff --git a/site/src/components/WorkspaceActions/WorkspaceActions.stories.tsx b/site/src/components/WorkspaceActions/WorkspaceActions.stories.tsx index 090e81cb2bb03..b2b2526811d0d 100644 --- a/site/src/components/WorkspaceActions/WorkspaceActions.stories.tsx +++ b/site/src/components/WorkspaceActions/WorkspaceActions.stories.tsx @@ -15,6 +15,7 @@ const Template: Story = (args) => ( const defaultArgs = { handleStart: action("start"), handleStop: action("stop"), + handleRestart: action("restart"), handleDelete: action("delete"), handleUpdate: action("update"), handleCancel: action("cancel"), diff --git a/site/src/components/WorkspaceActions/WorkspaceActions.tsx b/site/src/components/WorkspaceActions/WorkspaceActions.tsx index d7508ed64405b..2cc4bbfcac203 100644 --- a/site/src/components/WorkspaceActions/WorkspaceActions.tsx +++ b/site/src/components/WorkspaceActions/WorkspaceActions.tsx @@ -12,6 +12,7 @@ import { DisabledButton, StartButton, StopButton, + RestartButton, UpdateButton, } from "./Buttons" import { @@ -28,6 +29,7 @@ export interface WorkspaceActionsProps { isOutdated: boolean handleStart: () => void handleStop: () => void + handleRestart: () => void handleDelete: () => void handleUpdate: () => void handleCancel: () => void @@ -43,6 +45,7 @@ export const WorkspaceActions: FC = ({ isOutdated, handleStart, handleStop, + handleRestart, handleDelete, handleUpdate, handleCancel, @@ -91,6 +94,7 @@ export const WorkspaceActions: FC = ({ key={ButtonTypesEnum.stopping} /> ), + [ButtonTypesEnum.restart]: , [ButtonTypesEnum.deleting]: ( = { canAcceptJobs: false, }, running: { - actions: [ButtonTypesEnum.stop], + actions: [ButtonTypesEnum.stop, ButtonTypesEnum.restart], canCancel: false, canAcceptJobs: true, }, diff --git a/site/src/i18n/en/workspacePage.json b/site/src/i18n/en/workspacePage.json index fa5e9f8335021..fdcfc6ea31a65 100644 --- a/site/src/i18n/en/workspacePage.json +++ b/site/src/i18n/en/workspacePage.json @@ -21,6 +21,7 @@ "actionButton": { "start": "Start", "stop": "Stop", + "restart": "Restart", "delete": "Delete", "cancel": "Cancel", "update": "Update", diff --git a/site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx b/site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx index 6066b75e64b8e..1a910a8a0c6ff 100644 --- a/site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx +++ b/site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx @@ -123,6 +123,7 @@ export const WorkspaceReadyPage = ({ workspace={workspace} handleStart={() => workspaceSend({ type: "START" })} handleStop={() => workspaceSend({ type: "STOP" })} + handleRestart={() => workspaceSend({ type: "START" })} handleDelete={() => workspaceSend({ type: "ASK_DELETE" })} handleUpdate={() => workspaceSend({ type: "UPDATE" })} handleCancel={() => workspaceSend({ type: "CANCEL" })} From a6cbf3486f571b7e64f8e3b4cc50b34903cbc048 Mon Sep 17 00:00:00 2001 From: Kira Pilot Date: Tue, 25 Apr 2023 18:27:25 +0000 Subject: [PATCH 2/7] added restart hook --- site/src/components/Workspace/Workspace.tsx | 2 +- .../components/WorkspaceActions/Buttons.tsx | 6 +- .../WorkspaceActions/WorkspaceActions.tsx | 8 ++- .../WorkspacePage/WorkspaceReadyPage.tsx | 11 +++- site/src/pages/WorkspacePage/hooks.ts | 64 +++++++++++++++++++ 5 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 site/src/pages/WorkspacePage/hooks.ts diff --git a/site/src/components/Workspace/Workspace.tsx b/site/src/components/Workspace/Workspace.tsx index f7090b45b4eec..b79f0dc455d68 100644 --- a/site/src/components/Workspace/Workspace.tsx +++ b/site/src/components/Workspace/Workspace.tsx @@ -41,7 +41,7 @@ export interface WorkspaceProps { } handleStart: () => void handleStop: () => void - handleRestart: () => void + handleRestart: any handleDelete: () => void handleUpdate: () => void handleCancel: () => void diff --git a/site/src/components/WorkspaceActions/Buttons.tsx b/site/src/components/WorkspaceActions/Buttons.tsx index d6207952a4ac8..f4bc83a81afb0 100644 --- a/site/src/components/WorkspaceActions/Buttons.tsx +++ b/site/src/components/WorkspaceActions/Buttons.tsx @@ -8,6 +8,8 @@ import { LoadingButton } from "components/LoadingButton/LoadingButton" import { FC, PropsWithChildren } from "react" import { useTranslation } from "react-i18next" import { makeStyles } from "@material-ui/core/styles" +// import { UseMutateFunction } from "@tanstack/react-query" +// import { WorkspaceBuild } from "api/typesGenerated" interface WorkspaceAction { handleAction: () => void @@ -67,9 +69,7 @@ export const StopButton: FC> = ({ ) } -export const RestartButton: FC> = ({ - handleAction, -}) => { +export const RestartButton: FC> = ({ handleAction }) => { const { t } = useTranslation("workspacePage") const styles = useStyles() diff --git a/site/src/components/WorkspaceActions/WorkspaceActions.tsx b/site/src/components/WorkspaceActions/WorkspaceActions.tsx index 2cc4bbfcac203..8c0e552b3856e 100644 --- a/site/src/components/WorkspaceActions/WorkspaceActions.tsx +++ b/site/src/components/WorkspaceActions/WorkspaceActions.tsx @@ -5,7 +5,7 @@ import { makeStyles } from "@material-ui/core/styles" import MoreVertOutlined from "@material-ui/icons/MoreVertOutlined" import { FC, ReactNode, useRef, useState } from "react" import { useTranslation } from "react-i18next" -import { WorkspaceStatus } from "../../api/typesGenerated" +import { WorkspaceStatus } from "api/typesGenerated" import { ActionLoadingButton, CancelButton, @@ -29,7 +29,7 @@ export interface WorkspaceActionsProps { isOutdated: boolean handleStart: () => void handleStop: () => void - handleRestart: () => void + handleRestart: any handleDelete: () => void handleUpdate: () => void handleCancel: () => void @@ -133,7 +133,9 @@ export const WorkspaceActions: FC = ({ (isUpdating ? buttonMapping[ButtonTypesEnum.updating] : buttonMapping[ButtonTypesEnum.update])} - {actionsByStatus.map((action) => buttonMapping[action])} + {actionsByStatus.map((action) => ( + {buttonMapping[action]} + ))} {canCancel && }