Skip to content

Commit 9edfd71

Browse files
committed
Organize code on ready page
1 parent b0fba32 commit 9edfd71

File tree

2 files changed

+62
-55
lines changed

2 files changed

+62
-55
lines changed

site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { StateFrom } from "xstate";
1414
import { DeleteDialog } from "components/Dialogs/DeleteDialog/DeleteDialog";
1515
import { Workspace, WorkspaceErrors } from "./Workspace";
1616
import { pageTitle } from "utils/page";
17-
import { getFaviconByStatus, hasJobError } from "utils/workspace";
17+
import { hasJobError } from "utils/workspace";
1818
import {
1919
WorkspaceEvent,
2020
workspaceMachine,
@@ -68,14 +68,14 @@ export const WorkspaceReadyPage = ({
6868
isLoadingMoreBuilds,
6969
hasMoreBuilds,
7070
}: WorkspaceReadyPageProps): JSX.Element => {
71+
const navigate = useNavigate();
7172
const { buildInfo } = useDashboard();
7273
const featureVisibility = useFeatureVisibility();
7374
const { buildError, cancellationError, missedParameters } =
7475
workspaceState.context;
7576
if (workspace === undefined) {
7677
throw Error("Workspace is undefined");
7778
}
78-
const deadline = getDeadline(workspace);
7979
const canUpdateWorkspace = Boolean(permissions?.updateWorkspace);
8080
const canUpdateTemplate = Boolean(permissions?.updateTemplate);
8181
const { data: deploymentValues } = useQuery({
@@ -85,15 +85,10 @@ export const WorkspaceReadyPage = ({
8585
const canRetryDebugMode = Boolean(
8686
deploymentValues?.config.enable_terraform_debug_mode,
8787
);
88-
const favicon = getFaviconByStatus(workspace.latest_build);
89-
const navigate = useNavigate();
9088
const [changeVersionDialogOpen, setChangeVersionDialogOpen] = useState(false);
9189
const [isConfirmingUpdate, setIsConfirmingUpdate] = useState(false);
92-
const [confirmingRestart, setConfirmingRestart] = useState<{
93-
open: boolean;
94-
buildParameters?: TypesGen.WorkspaceBuildParameter[];
95-
}>({ open: false });
9690

91+
// Versions
9792
const { data: allVersions } = useQuery({
9893
...templateVersions(workspace.template_id),
9994
enabled: changeVersionDialogOpen,
@@ -102,22 +97,20 @@ export const WorkspaceReadyPage = ({
10297
...templateVersion(workspace.template_active_version_id),
10398
enabled: workspace.outdated,
10499
});
105-
const [faviconTheme, setFaviconTheme] = useState<"light" | "dark">("dark");
106-
useEffect(() => {
107-
if (typeof window === "undefined" || !window.matchMedia) {
108-
return;
109-
}
110100

111-
const isDark = window.matchMedia("(prefers-color-scheme: dark)");
112-
// We want the favicon the opposite of the theme.
113-
setFaviconTheme(isDark.matches ? "light" : "dark");
114-
}, []);
101+
// Build logs
115102
const buildLogs = useWorkspaceBuildLogs(workspace.latest_build.id);
116103
const shouldDisplayBuildLogs =
117104
hasJobError(workspace) ||
118105
["canceling", "deleting", "pending", "starting", "stopping"].includes(
119106
workspace.latest_build.status,
120107
);
108+
109+
// Restart
110+
const [confirmingRestart, setConfirmingRestart] = useState<{
111+
open: boolean;
112+
buildParameters?: TypesGen.WorkspaceBuildParameter[];
113+
}>({ open: false });
121114
const {
122115
mutate: mutateRestartWorkspace,
123116
error: restartBuildError,
@@ -126,6 +119,8 @@ export const WorkspaceReadyPage = ({
126119
mutationFn: restartWorkspace,
127120
});
128121

122+
// Schedule controls
123+
const deadline = getDeadline(workspace);
129124
const onDeadlineChangeSuccess = () => {
130125
displaySuccess("Updated workspace shutdown time.");
131126
};
@@ -145,13 +140,28 @@ export const WorkspaceReadyPage = ({
145140
onError: onDeadlineChangeFails,
146141
});
147142

143+
// Auto start
148144
const canAutostartResponse = useQuery(
149145
workspaceResolveAutostart(workspace.id),
150146
);
151147
const canAutostart = !canAutostartResponse.data?.parameter_mismatch ?? false;
152148

149+
// SSH Prefix
153150
const sshPrefixQuery = useQuery(deploymentSSHConfig());
154151

152+
// Favicon
153+
const favicon = getFaviconByStatus(workspace.latest_build);
154+
const [faviconTheme, setFaviconTheme] = useState<"light" | "dark">("dark");
155+
useEffect(() => {
156+
if (typeof window === "undefined" || !window.matchMedia) {
157+
return;
158+
}
159+
160+
const isDark = window.matchMedia("(prefers-color-scheme: dark)");
161+
// We want the favicon the opposite of the theme.
162+
setFaviconTheme(isDark.matches ? "light" : "dark");
163+
}, []);
164+
155165
return (
156166
<>
157167
<Helmet>
@@ -320,3 +330,38 @@ const WarningDialog: FC<
320330
> = (props) => {
321331
return <ConfirmDialog type="info" hideCancel={false} {...props} />;
322332
};
333+
334+
// You can see the favicon designs here: https://www.figma.com/file/YIGBkXUcnRGz2ZKNmLaJQf/Coder-v2-Design?node-id=560%3A620
335+
type FaviconType =
336+
| "favicon"
337+
| "favicon-success"
338+
| "favicon-error"
339+
| "favicon-warning"
340+
| "favicon-running";
341+
342+
const getFaviconByStatus = (build: TypesGen.WorkspaceBuild): FaviconType => {
343+
switch (build.status) {
344+
case undefined:
345+
return "favicon";
346+
case "running":
347+
return "favicon-success";
348+
case "starting":
349+
return "favicon-running";
350+
case "stopping":
351+
return "favicon-running";
352+
case "stopped":
353+
return "favicon";
354+
case "deleting":
355+
return "favicon";
356+
case "deleted":
357+
return "favicon";
358+
case "canceling":
359+
return "favicon-warning";
360+
case "canceled":
361+
return "favicon";
362+
case "failed":
363+
return "favicon-error";
364+
case "pending":
365+
return "favicon";
366+
}
367+
};

site/src/utils/workspace.tsx

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -147,44 +147,6 @@ export const defaultWorkspaceExtension = (
147147
};
148148
};
149149

150-
// You can see the favicon designs here: https://www.figma.com/file/YIGBkXUcnRGz2ZKNmLaJQf/Coder-v2-Design?node-id=560%3A620
151-
152-
type FaviconType =
153-
| "favicon"
154-
| "favicon-success"
155-
| "favicon-error"
156-
| "favicon-warning"
157-
| "favicon-running";
158-
159-
export const getFaviconByStatus = (
160-
build: TypesGen.WorkspaceBuild,
161-
): FaviconType => {
162-
switch (build.status) {
163-
case undefined:
164-
return "favicon";
165-
case "running":
166-
return "favicon-success";
167-
case "starting":
168-
return "favicon-running";
169-
case "stopping":
170-
return "favicon-running";
171-
case "stopped":
172-
return "favicon";
173-
case "deleting":
174-
return "favicon";
175-
case "deleted":
176-
return "favicon";
177-
case "canceling":
178-
return "favicon-warning";
179-
case "canceled":
180-
return "favicon";
181-
case "failed":
182-
return "favicon-error";
183-
case "pending":
184-
return "favicon";
185-
}
186-
};
187-
188150
export const getDisplayWorkspaceTemplateName = (
189151
workspace: TypesGen.Workspace,
190152
): string => {

0 commit comments

Comments
 (0)