Skip to content

refactor(site): improve first workspace creation time #10510

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 2 commits into from
Nov 3, 2023
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
refactor(site): improve first workspace creation time
  • Loading branch information
BrunoQuaresma committed Nov 3, 2023
commit 712ee0329adede46ae4bd9e976c0102280b01717
94 changes: 94 additions & 0 deletions site/src/pages/WorkspacesPage/WorkspacesEmpty.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import ArrowForwardOutlined from "@mui/icons-material/ArrowForwardOutlined";
import Button from "@mui/material/Button";
import { Template } from "api/typesGenerated";
import { Avatar } from "components/Avatar/Avatar";
import { TableEmpty } from "components/TableEmpty/TableEmpty";
import { Link } from "react-router-dom";

export const WorkspacesEmpty = (props: {
isUsingFilter: boolean;
templates?: Template[];
}) => {
const { isUsingFilter, templates } = props;
const totalFeaturedTemplates = 6;
const featuredTemplates = templates?.slice(0, totalFeaturedTemplates);

if (isUsingFilter) {
return <TableEmpty message="No results matched your search" />;
}

return (
<TableEmpty
message="Create a workspace"
description="A workspace is your personal, customizable development environment in the cloud. Select one template below to start."
cta={
<div>
<div
css={(theme) => ({
display: "grid",
gridTemplateColumns: "repeat(2, 320px)",
gap: theme.spacing(2),
marginBottom: theme.spacing(3),
})}
>
{featuredTemplates?.map((t) => (
<Link
to={`/templates/${t.name}/workspace`}
key={t.id}
css={(theme) => ({
padding: theme.spacing(2),
borderRadius: 6,
border: `1px solid ${theme.palette.divider}`,
textAlign: "left",
display: "flex",
gap: theme.spacing(2),
textDecoration: "none",
color: "inherit",

"&:hover": {
backgroundColor: theme.palette.background.paperLight,
},
})}
>
<div css={{ flexShrink: 0, paddingTop: 4 }}>
<Avatar
variant={t.icon ? "square" : undefined}
fitImage={Boolean(t.icon)}
src={t.icon}
size="sm"
>
{t.name}
</Avatar>
</div>
<div>
<h4 css={{ fontSize: 14, fontWeight: 600, margin: 0 }}>
{t.display_name}
</h4>
<span
css={(theme) => ({
fontSize: 13,
color: theme.palette.text.secondary,
lineHeight: "0.5",
})}
>
{t.description}
</span>
</div>
</Link>
))}
</div>
{templates && templates.length > totalFeaturedTemplates && (
<Button
component={Link}
to="/templates"
variant="contained"
startIcon={<ArrowForwardOutlined />}
>
See all templates
</Button>
)}
</div>
}
/>
);
};
2 changes: 1 addition & 1 deletion site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export interface WorkspacesPageViewProps {
onCheckChange: (checkedWorkspaces: Workspace[]) => void;
onDeleteAll: () => void;
canCheckWorkspaces: boolean;

templatesFetchStatus: TemplateQuery["status"];
templates: TemplateQuery["data"];
}
Expand Down Expand Up @@ -156,6 +155,7 @@ export const WorkspacesPageView: FC<
checkedWorkspaces={checkedWorkspaces}
onCheckChange={onCheckChange}
canCheckWorkspaces={canCheckWorkspaces}
templates={templates}
/>
{count !== undefined && (
<PaginationWidgetBase
Expand Down
59 changes: 9 additions & 50 deletions site/src/pages/WorkspacesPage/WorkspacesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ import TableCell from "@mui/material/TableCell";
import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import { Workspace } from "api/typesGenerated";
import { Template, Workspace } from "api/typesGenerated";
import { FC, ReactNode } from "react";
import { TableEmpty } from "components/TableEmpty/TableEmpty";
import {
TableLoaderSkeleton,
TableRowSkeleton,
} from "components/TableLoader/TableLoader";
import AddOutlined from "@mui/icons-material/AddOutlined";
import Button from "@mui/material/Button";
import { Link as RouterLink, useNavigate } from "react-router-dom";
import { useNavigate } from "react-router-dom";
import { useClickableTableRow } from "hooks/useClickableTableRow";
import KeyboardArrowRight from "@mui/icons-material/KeyboardArrowRight";
import Box from "@mui/material/Box";
Expand All @@ -28,8 +25,7 @@ import Checkbox from "@mui/material/Checkbox";
import { AvatarDataSkeleton } from "components/AvatarData/AvatarDataSkeleton";
import Skeleton from "@mui/material/Skeleton";
import { InfoTooltip } from "components/InfoTooltip/InfoTooltip";
import { css } from "@emotion/react";
import { useTheme } from "@mui/system";
import { WorkspacesEmpty } from "./WorkspacesEmpty";

export interface WorkspacesTableProps {
workspaces?: Workspace[];
Expand All @@ -39,6 +35,7 @@ export interface WorkspacesTableProps {
onUpdateWorkspace: (workspace: Workspace) => void;
onCheckChange: (checkedWorkspaces: Workspace[]) => void;
canCheckWorkspaces: boolean;
templates?: Template[];
}

export const WorkspacesTable: FC<WorkspacesTableProps> = ({
Expand All @@ -48,9 +45,8 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
onUpdateWorkspace,
onCheckChange,
canCheckWorkspaces,
templates,
}) => {
const theme = useTheme();

return (
<TableContainer>
<Table>
Expand Down Expand Up @@ -93,47 +89,10 @@ export const WorkspacesTable: FC<WorkspacesTableProps> = ({
<TableLoader canCheckWorkspaces={canCheckWorkspaces} />
)}
{workspaces && workspaces.length === 0 && (
<>
{isUsingFilter ? (
<TableEmpty message="No results matched your search" />
) : (
<TableEmpty
css={{
paddingBottom: 0,
}}
message="Create a workspace"
description="A workspace is your personal, customizable development environment in the cloud"
cta={
<Button
component={RouterLink}
to="/templates"
startIcon={<AddOutlined />}
variant="contained"
data-testid="button-select-template"
>
Select a Template
</Button>
}
image={
<div
css={css`
max-width: 50%;
height: ${theme.spacing(34)};
overflow: hidden;
margin-top: ${theme.spacing(6)};
opacity: 0.85;

& img {
max-width: 100%;
}
`}
>
<img src="/featured/workspaces.webp" alt="" />
</div>
}
/>
)}
</>
<WorkspacesEmpty
templates={templates}
isUsingFilter={isUsingFilter}
/>
)}
{workspaces &&
workspaces.map((workspace) => {
Expand Down