Skip to content

feat: Change workspace version using the UI #5158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add change versions
  • Loading branch information
BrunoQuaresma committed Nov 22, 2022
commit 27645b75575818ed80aacdd08b9184e8f1b544f8
18 changes: 18 additions & 0 deletions site/src/components/DropdownButton/ActionCtas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Button from "@material-ui/core/Button"
import { makeStyles } from "@material-ui/core/styles"
import BlockIcon from "@material-ui/icons/Block"
import CloudQueueIcon from "@material-ui/icons/CloudQueue"
import UpdateOutlined from "@material-ui/icons/UpdateOutlined"
import CropSquareIcon from "@material-ui/icons/CropSquare"
import DeleteOutlineIcon from "@material-ui/icons/DeleteOutline"
import PlayCircleOutlineIcon from "@material-ui/icons/PlayCircleOutline"
Expand Down Expand Up @@ -33,6 +34,23 @@ export const UpdateButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
)
}

export const ChangeVersionButton: FC<
React.PropsWithChildren<WorkspaceAction>
> = ({ handleAction }) => {
const styles = useStyles()
const { t } = useTranslation("workspacePage")

return (
<Button
className={styles.actionButton}
startIcon={<UpdateOutlined />}
onClick={handleAction}
>
{t("actionButton.changeVersion")}
</Button>
)
}

export const StartButton: FC<React.PropsWithChildren<WorkspaceAction>> = ({
handleAction,
}) => {
Expand Down
3 changes: 3 additions & 0 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface WorkspaceProps {
handleDelete: () => void
handleUpdate: () => void
handleCancel: () => void
handleChangeVersion: () => void
isUpdating: boolean
workspace: TypesGen.Workspace
resources?: TypesGen.WorkspaceResource[]
Expand All @@ -68,6 +69,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
handleDelete,
handleUpdate,
handleCancel,
handleChangeVersion,
workspace,
isUpdating,
resources,
Expand Down Expand Up @@ -143,6 +145,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
handleDelete={handleDelete}
handleUpdate={handleUpdate}
handleCancel={handleCancel}
handleChangeVersion={handleChangeVersion}
isUpdating={isUpdating}
/>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const renderComponent = async (props: Partial<WorkspaceActionsProps> = {}) => {
handleDelete={jest.fn()}
handleUpdate={jest.fn()}
handleCancel={jest.fn()}
handleChangeVersion={jest.fn()}
isUpdating={false}
/>,
)
Expand All @@ -35,6 +36,7 @@ const renderAndClick = async (props: Partial<WorkspaceActionsProps> = {}) => {
handleDelete={jest.fn()}
handleUpdate={jest.fn()}
handleCancel={jest.fn()}
handleChangeVersion={jest.fn()}
isUpdating={false}
/>,
)
Expand Down
6 changes: 6 additions & 0 deletions site/src/components/WorkspaceActions/WorkspaceActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next"
import { WorkspaceStatus } from "../../api/typesGenerated"
import {
ActionLoadingButton,
ChangeVersionButton,
DeleteButton,
DisabledButton,
StartButton,
Expand All @@ -20,6 +21,7 @@ export interface WorkspaceActionsProps {
handleDelete: () => void
handleUpdate: () => void
handleCancel: () => void
handleChangeVersion: () => void
isUpdating: boolean
children?: ReactNode
}
Expand All @@ -32,6 +34,7 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
handleDelete,
handleUpdate,
handleCancel,
handleChangeVersion,
isUpdating,
}) => {
const { t } = useTranslation("workspacePage")
Expand All @@ -45,6 +48,9 @@ export const WorkspaceActions: FC<WorkspaceActionsProps> = ({
[ButtonTypesEnum.updating]: (
<ActionLoadingButton label={t("actionButton.updating")} />
),
[ButtonTypesEnum.changeVersion]: (
<ChangeVersionButton handleAction={handleChangeVersion} />
),
[ButtonTypesEnum.start]: <StartButton handleAction={handleStart} />,
[ButtonTypesEnum.starting]: (
<ActionLoadingButton label={t("actionButton.starting")} />
Expand Down
20 changes: 17 additions & 3 deletions site/src/components/WorkspaceActions/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum ButtonTypesEnum {
deleting = "deleting",
update = "update",
updating = "updating",
changeVersion = "changeVersion",
// disabled buttons
canceling = "canceling",
deleted = "deleted",
Expand All @@ -34,7 +35,11 @@ export const statusToAbilities: Record<WorkspaceStatus, WorkspaceAbilities> = {
canAcceptJobs: false,
},
running: {
actions: [ButtonTypesEnum.stop, ButtonTypesEnum.delete],
actions: [
ButtonTypesEnum.stop,
ButtonTypesEnum.changeVersion,
ButtonTypesEnum.delete,
],
canCancel: false,
canAcceptJobs: true,
},
Expand All @@ -44,22 +49,31 @@ export const statusToAbilities: Record<WorkspaceStatus, WorkspaceAbilities> = {
canAcceptJobs: false,
},
stopped: {
actions: [ButtonTypesEnum.start, ButtonTypesEnum.delete],
actions: [
ButtonTypesEnum.start,
ButtonTypesEnum.changeVersion,
ButtonTypesEnum.delete,
],
canCancel: false,
canAcceptJobs: true,
},
canceled: {
actions: [
ButtonTypesEnum.start,
ButtonTypesEnum.stop,
ButtonTypesEnum.changeVersion,
ButtonTypesEnum.delete,
],
canCancel: false,
canAcceptJobs: true,
},
// in the case of an error
failed: {
actions: [ButtonTypesEnum.start, ButtonTypesEnum.delete],
actions: [
ButtonTypesEnum.start,
ButtonTypesEnum.changeVersion,
ButtonTypesEnum.delete,
],
canCancel: false,
canAcceptJobs: true,
},
Expand Down
3 changes: 2 additions & 1 deletion site/src/i18n/en/workspacePage.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"updating": "Updating",
"starting": "Starting...",
"stopping": "Stopping...",
"deleting": "Deleting..."
"deleting": "Deleting...",
"changeVersion": "Change version"
},
"disabledButton": {
"canceling": "Canceling",
Expand Down
3 changes: 3 additions & 0 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dayjs from "dayjs"
import { useContext } from "react"
import { Helmet } from "react-helmet-async"
import { useTranslation } from "react-i18next"
import { useNavigate } from "react-router-dom"
import {
getMaxDeadline,
getMaxDeadlineChange,
Expand Down Expand Up @@ -63,6 +64,7 @@ export const WorkspaceReadyPage = ({
const canUpdateWorkspace = Boolean(permissions?.updateWorkspace)
const { t } = useTranslation("workspacePage")
const favicon = getFaviconByStatus(workspace.latest_build)
const navigate = useNavigate()

return (
<>
Expand Down Expand Up @@ -114,6 +116,7 @@ export const WorkspaceReadyPage = ({
handleDelete={() => workspaceSend({ type: "ASK_DELETE" })}
handleUpdate={() => workspaceSend({ type: "UPDATE" })}
handleCancel={() => workspaceSend({ type: "CANCEL" })}
handleChangeVersion={() => navigate("/change-version")}
resources={workspace.latest_build.resources}
builds={builds}
canUpdateWorkspace={canUpdateWorkspace}
Expand Down