Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
7 changes: 7 additions & 0 deletions site/src/components/Workspace/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ export const WithoutUpdateAccess: Story = {
},
}

export const PendingInQueue: Story = {
args: {
...Running.args,
workspace: Mocks.MockPendingWorkspace,
},
}

export const Starting: Story = {
args: {
...Running.args,
Expand Down
27 changes: 27 additions & 0 deletions site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { ImpendingDeletionBanner } from "components/WorkspaceDeletion"
import { useLocalStorage } from "hooks"
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
import AlertTitle from "@mui/material/AlertTitle"
import { Maybe } from "components/Conditionals/Maybe"

export enum WorkspaceErrors {
GET_BUILDS_ERROR = "getBuildsError",
Expand Down Expand Up @@ -207,6 +208,28 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({

<TemplateVersionWarnings warnings={templateWarnings} />

<Maybe
condition={
workspace.latest_build.status === "pending" &&
workspace.latest_build.job.queue_size > 0
}
>
<Alert severity="info">
<AlertTitle>Workspace build is pending</AlertTitle>
<AlertDetail>
<div className={styles.alertPendingInQueue}>
This build job is waiting for a provisioner to become
available. If you have been waiting for an extended period,
contact your administrator for assistance.
</div>
<div>
Position in queue:{" "}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the {" "} necessary here? I would imagine the newline becomes a space but maybe not in React-land.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to be necessary. Otherwise, it's merged together: Position in queue:3 (no space).

<strong>{workspace.latest_build.job.queue_position}</strong>
</div>
</AlertDetail>
</Alert>
</Maybe>

{failedBuildLogs && (
<Stack>
<Alert
Expand Down Expand Up @@ -319,5 +342,9 @@ export const useStyles = makeStyles((theme) => {
fullWidth: {
width: "100%",
},

alertPendingInQueue: {
marginBottom: 12,
},
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const WorkspaceStatusBadge: FC<
> = ({ workspace, className }) => {
const { text, icon, type } = getDisplayWorkspaceStatus(
workspace.latest_build.status,
workspace.latest_build.job,
)
return (
<ChooseOne>
Expand All @@ -42,6 +43,8 @@ export const WorkspaceStatusText: FC<
workspace.latest_build.status,
)

workspace.latest_build.job.queue_size

return (
<ChooseOne>
{/* <ImpendingDeletionText/> determines its own visibility */}
Expand Down
1 change: 0 additions & 1 deletion site/src/components/WorkspacesTable/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const Language = {
template: "Template",
lastUsed: "Last Used",
status: "Status",
lastBuiltBy: "Last Built By",
}

export interface WorkspacesTableProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MockExperiments,
mockApiError,
MockUser,
MockPendingProvisionerJob,
} from "testHelpers/entities"
import { WorkspacesPageView } from "./WorkspacesPageView"
import { DashboardProviderContext } from "components/Dashboard/DashboardProvider"
Expand All @@ -33,6 +34,10 @@ const createWorkspace = (
latest_build: {
...MockWorkspace.latest_build,
status,
job:
status === "pending"
? MockPendingProvisionerJob
: MockWorkspace.latest_build.job,
},
last_used_at: lastUsedAt,
}
Expand Down
2 changes: 2 additions & 0 deletions site/src/testHelpers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ export const MockRunningProvisionerJob: TypesGen.ProvisionerJob = {
export const MockPendingProvisionerJob: TypesGen.ProvisionerJob = {
...MockProvisionerJob,
status: "pending",
queue_position: 2,
queue_size: 4,
}
export const MockTemplateVersion: TypesGen.TemplateVersion = {
id: "test-template-version",
Expand Down
14 changes: 13 additions & 1 deletion site/src/utils/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export const getDisplayWorkspaceTemplateName = (

export const getDisplayWorkspaceStatus = (
workspaceStatus: TypesGen.WorkspaceStatus,
provisionerJob?: TypesGen.ProvisionerJob,
) => {
const { t } = i18next

Expand Down Expand Up @@ -260,12 +261,23 @@ export const getDisplayWorkspaceStatus = (
case "pending":
return {
type: "info",
text: t("workspaceStatus.pending", { ns: "common" }),
text: getPendingWorkspaceStatusText(provisionerJob),
icon: <QueuedIcon />,
} as const
}
}

const getPendingWorkspaceStatusText = (
provisionerJob?: TypesGen.ProvisionerJob,
): string => {
const { t } = i18next

if (provisionerJob === undefined || provisionerJob.queue_size === 0) {
return t("workspaceStatus.pending", { ns: "common" })
}
return "Position in queue: " + provisionerJob.queue_position
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use t here too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I skipped this on purpose, as we are not going to implement translations. I learnt some time ago

}

const LoadingIcon = () => {
return <CircularProgress size={10} style={{ color: "#FFF" }} />
}