Skip to content

refactor(site): refactor workspace notifications #11520

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 27 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
0b28628
Refactor outdated warning
BrunoQuaresma Jan 9, 2024
ab96aab
Move unhealthy warning
BrunoQuaresma Jan 9, 2024
38f213e
Move dormant notification
BrunoQuaresma Jan 9, 2024
9ec5952
Remove mutation errors from alerts
BrunoQuaresma Jan 9, 2024
17ecf0e
Move pending in queue notification
BrunoQuaresma Jan 9, 2024
c969df5
Move deprecated notification
BrunoQuaresma Jan 9, 2024
8f6040d
Move outdated to notifications array
BrunoQuaresma Jan 9, 2024
691c028
Move unhealthy to notifications array
BrunoQuaresma Jan 9, 2024
706bbd5
Fix permissions for restart workspace
BrunoQuaresma Jan 9, 2024
d3e68fb
Move dormant notifications to notifications array
BrunoQuaresma Jan 9, 2024
2f1ac83
Structure notification pills
BrunoQuaresma Jan 9, 2024
c334031
Minor style adjustments
BrunoQuaresma Jan 9, 2024
a78d4cf
Remove bottom bar from workspace page
BrunoQuaresma Jan 9, 2024
24c7552
Display notifications under the pills
BrunoQuaresma Jan 9, 2024
b711018
Improve canAutoStart check
BrunoQuaresma Jan 11, 2024
121005c
Move css into a style
BrunoQuaresma Jan 11, 2024
3234d49
Move css into a style
BrunoQuaresma Jan 11, 2024
b30dc44
Remove unecessary boolean
BrunoQuaresma Jan 11, 2024
04994a4
Refactor props
BrunoQuaresma Jan 11, 2024
5ba0765
Improve semantics
BrunoQuaresma Jan 11, 2024
3d0d70b
Merge branch 'bq/move-alert' of https://github.com/coder/coder into b…
BrunoQuaresma Jan 11, 2024
9299c68
Merge branch 'main' of https://github.com/coder/coder into bq/move-alert
BrunoQuaresma Jan 11, 2024
6d3148b
Merge branch 'main' of https://github.com/coder/coder into bq/move-alert
BrunoQuaresma Jan 12, 2024
45be26c
Add tests
BrunoQuaresma Jan 12, 2024
d21be38
Merge branch 'main' of https://github.com/coder/coder into bq/move-alert
BrunoQuaresma Jan 12, 2024
478a333
Fix storybook
BrunoQuaresma Jan 12, 2024
d62833c
Merge branch 'main' of https://github.com/coder/coder into bq/move-alert
BrunoQuaresma Jan 12, 2024
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
Refactor outdated warning
  • Loading branch information
BrunoQuaresma committed Jan 9, 2024
commit 0b286284ebda1e5a88b289695d9b59b41abce031
2 changes: 1 addition & 1 deletion site/src/api/queries/workspaceQuota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const workspaceQuota = (username: string) => {
};
};

const getWorkspaceResolveAutostartQueryKey = (workspaceId: string) => [
export const getWorkspaceResolveAutostartQueryKey = (workspaceId: string) => [
workspaceId,
"workspaceResolveAutostart",
];
Expand Down
14 changes: 13 additions & 1 deletion site/src/pages/WorkspacePage/Workspace.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import EventSource from "eventsourcemock";
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
import { DashboardProviderContext } from "components/Dashboard/DashboardProvider";
import { WorkspaceBuildLogsSection } from "pages/WorkspacePage/WorkspaceBuildLogsSection";
import { getWorkspaceResolveAutostartQueryKey } from "api/queries/workspaceQuota";

const MockedAppearance = {
config: Mocks.MockAppearanceConfig,
Expand Down Expand Up @@ -196,9 +197,20 @@ export const Outdated: Story = {
export const CantAutostart: Story = {
args: {
...Running.args,
canAutostart: false,
workspace: Mocks.MockOutdatedRunningWorkspaceRequireActiveVersion,
},
parameters: {
queries: [
{
key: getWorkspaceResolveAutostartQueryKey(
Mocks.MockOutdatedRunningWorkspaceRequireActiveVersion.id,
),
data: {
parameter_mismatch: false,
},
},
],
},
};

export const GetBuildsError: Story = {
Expand Down
37 changes: 7 additions & 30 deletions site/src/pages/WorkspacePage/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { SidebarIconButton } from "components/FullPageLayout/Sidebar";
import HubOutlined from "@mui/icons-material/HubOutlined";
import { ResourcesSidebar } from "./ResourcesSidebar";
import { ResourceCard } from "components/Resources/ResourceCard";
import { WorkspaceNotifications } from "./WorkspaceNotifications";

export type WorkspaceError =
| "getBuildsError"
Expand All @@ -48,7 +49,6 @@ export interface WorkspaceProps {
isRestarting: boolean;
workspace: TypesGen.Workspace;
canUpdateWorkspace: boolean;
updateMessage?: string;
canChangeVersions: boolean;
hideSSHButton?: boolean;
hideVSCodeDesktopButton?: boolean;
Expand All @@ -60,7 +60,7 @@ export interface WorkspaceProps {
handleBuildRetry: () => void;
handleBuildRetryDebug: () => void;
buildLogs?: React.ReactNode;
canAutostart: boolean;
latestVersion?: TypesGen.TemplateVersion;
}

/**
Expand All @@ -80,7 +80,6 @@ export const Workspace: FC<WorkspaceProps> = ({
isUpdating,
isRestarting,
canUpdateWorkspace,
updateMessage,
canChangeVersions,
workspaceErrors,
hideSSHButton,
Expand All @@ -92,7 +91,7 @@ export const Workspace: FC<WorkspaceProps> = ({
handleBuildRetry,
handleBuildRetryDebug,
buildLogs,
canAutostart,
latestVersion,
}) => {
const navigate = useNavigate();
const { saveLocal, getLocal } = useLocalStorage();
Expand Down Expand Up @@ -135,13 +134,6 @@ export const Workspace: FC<WorkspaceProps> = ({
};
}, [workspace, now, showAlertPendingInQueue]);

const updateRequired =
(workspace.template_require_active_version ||
workspace.automatic_updates === "always") &&
workspace.outdated;
const autoStartFailing = workspace.autostart_schedule && !canAutostart;
const requiresManualUpdate = updateRequired && autoStartFailing;

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

Expand Down Expand Up @@ -244,25 +236,10 @@ export const Workspace: FC<WorkspaceProps> = ({
<div css={styles.content}>
<div css={styles.dotBackground}>
<Stack direction="column" css={styles.firstColumnSpacer} spacing={4}>
{workspace.outdated &&
(requiresManualUpdate ? (
<Alert severity="warning">
<AlertTitle>
Autostart has been disabled for your workspace.
</AlertTitle>
<AlertDetail>
Autostart is unable to automatically update your workspace.
Manually update your workspace to reenable Autostart.
</AlertDetail>
</Alert>
) : (
<Alert severity="info">
<AlertTitle>
An update is available for your workspace
</AlertTitle>
{updateMessage && <AlertDetail>{updateMessage}</AlertDetail>}
</Alert>
))}
<WorkspaceNotifications
workspace={workspace}
latestVersion={latestVersion}
/>

{Boolean(workspaceErrors.buildError) && (
<ErrorAlert error={workspaceErrors.buildError} dismissible />
Expand Down
52 changes: 52 additions & 0 deletions site/src/pages/WorkspacePage/WorkspaceNotifications.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import AlertTitle from "@mui/material/AlertTitle";
import { workspaceResolveAutostart } from "api/queries/workspaceQuota";
import { TemplateVersion, Workspace } from "api/typesGenerated";
import { Alert, AlertDetail } from "components/Alert/Alert";
import { FC } from "react";
import { useQuery } from "react-query";

type WorkspaceNotificationsProps = {
workspace: Workspace;
latestVersion?: TemplateVersion;
};

export const WorkspaceNotifications: FC<WorkspaceNotificationsProps> = (
props,
) => {
const { workspace, latestVersion } = props;

// Outdated
const canAutostartResponse = useQuery(
workspaceResolveAutostart(workspace.id),
);
const canAutostart = !canAutostartResponse.data?.parameter_mismatch ?? false;
const updateRequired =
(workspace.template_require_active_version ||
workspace.automatic_updates === "always") &&
workspace.outdated;
const autoStartFailing = workspace.autostart_schedule && !canAutostart;
const requiresManualUpdate = updateRequired && autoStartFailing;

return (
<>
{workspace.outdated &&
latestVersion &&
(requiresManualUpdate ? (
<Alert severity="warning">
<AlertTitle>
Autostart has been disabled for your workspace.
</AlertTitle>
<AlertDetail>
Autostart is unable to automatically update your workspace.
Manually update your workspace to reenable Autostart.
</AlertDetail>
</Alert>
) : (
<Alert severity="info">
<AlertTitle>An update is available for your workspace</AlertTitle>
<AlertDetail>{latestVersion.message}</AlertDetail>
</Alert>
))}
</>
);
};
10 changes: 1 addition & 9 deletions site/src/pages/WorkspacePage/WorkspaceReadyPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { getErrorMessage } from "api/errors";
import { displayError } from "components/GlobalSnackbar/utils";
import { deploymentConfig, deploymentSSHConfig } from "api/queries/deployment";
import { WorkspacePermissions } from "./permissions";
import { workspaceResolveAutostart } from "api/queries/workspaceQuota";
import { WorkspaceDeleteDialog } from "./WorkspaceDeleteDialog";
import dayjs from "dayjs";

Expand Down Expand Up @@ -83,12 +82,6 @@ export const WorkspaceReadyPage = ({
mutationFn: restartWorkspace,
});

// Auto start
const canAutostartResponse = useQuery(
workspaceResolveAutostart(workspace.id),
);
const canAutostart = !canAutostartResponse.data?.parameter_mismatch ?? false;

// SSH Prefix
const sshPrefixQuery = useQuery(deploymentSSHConfig());

Expand Down Expand Up @@ -225,7 +218,7 @@ export const WorkspaceReadyPage = ({
}
}}
canUpdateWorkspace={canUpdateWorkspace}
updateMessage={latestVersion?.message}
latestVersion={latestVersion}
canChangeVersions={canChangeVersions}
hideSSHButton={featureVisibility["browser_only"]}
hideVSCodeDesktopButton={featureVisibility["browser_only"]}
Expand All @@ -246,7 +239,6 @@ export const WorkspaceReadyPage = ({
<WorkspaceBuildLogsSection logs={buildLogs} />
)
}
canAutostart={canAutostart}
/>

<WorkspaceDeleteDialog
Expand Down