Skip to content

fix: make workspace buttons less confusing when errors happen #10609

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

Closed
wants to merge 16 commits into from
Closed
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
Prev Previous commit
Next Next commit
refactor: clean up Workspace
  • Loading branch information
Parkreiner committed Nov 8, 2023
commit 33bd41232121b595e4b5961bedc4671424aef0a5
55 changes: 26 additions & 29 deletions site/src/pages/WorkspacePage/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,31 +113,13 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
hasMoreBuilds,
}) => {
const navigate = useNavigate();
const serverVersion = buildInfo?.version || "";
const { saveLocal, getLocal } = useLocalStorage();

const buildError = Boolean(workspaceErrors[WorkspaceErrors.BUILD_ERROR]) && (
<ErrorAlert
error={workspaceErrors[WorkspaceErrors.BUILD_ERROR]}
dismissible
/>
);

const cancellationError = Boolean(
workspaceErrors[WorkspaceErrors.CANCELLATION_ERROR],
) && (
<ErrorAlert
error={workspaceErrors[WorkspaceErrors.CANCELLATION_ERROR]}
dismissible
/>
);

let transitionStats: TypesGen.TransitionStats | undefined = undefined;
if (template !== undefined) {
transitionStats = ActiveTransition(template, workspace);
}

const [showAlertPendingInQueue, setShowAlertPendingInQueue] = useState(false);

// 2023-11-08 - MES - This effect will be called every single render because
// "now" will always change and invalidate the dependency array. Need to
// figure out if this effect should run every render (possibly meaning no
// dependency array at all), or how to get the array stabilized (more ideal)
const now = dayjs();
useEffect(() => {
if (
Expand All @@ -164,10 +146,12 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
setShowAlertPendingInQueue(true);
}, t);

return () => {
clearTimeout(showTimer);
};
return () => clearTimeout(showTimer);
}, [workspace, now, showAlertPendingInQueue]);

const transitionStats =
template !== undefined ? ActiveTransition(template, workspace) : undefined;

return (
<>
<FullWidthPageHeader>
Expand Down Expand Up @@ -226,8 +210,21 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
{updateMessage && <AlertDetail>{updateMessage}</AlertDetail>}
</Alert>
)}
{buildError}
{cancellationError}

{Boolean(workspaceErrors[WorkspaceErrors.BUILD_ERROR]) && (
<ErrorAlert
error={workspaceErrors[WorkspaceErrors.BUILD_ERROR]}
dismissible
/>
)}

{Boolean(workspaceErrors[WorkspaceErrors.CANCELLATION_ERROR]) && (
<ErrorAlert
error={workspaceErrors[WorkspaceErrors.CANCELLATION_ERROR]}
dismissible
/>
)}

{workspace.latest_build.status === "running" &&
!workspace.health.healthy && (
<Alert
Expand Down Expand Up @@ -334,7 +331,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
showBuiltinApps={canUpdateWorkspace}
hideSSHButton={hideSSHButton}
hideVSCodeDesktopButton={hideVSCodeDesktopButton}
serverVersion={serverVersion}
serverVersion={buildInfo?.version || ""}
onUpdateAgent={handleUpdate} // On updating the workspace the agent version is also updated
/>
)}
Expand Down