Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor: Improve the load state for the list pages #1428

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 10 commits into from
May 13, 2022
Prev Previous commit
Next Next commit
Improve empty state
  • Loading branch information
BrunoQuaresma committed May 13, 2022
commit 40afc475a50b97d08b138691a616ca576c8e4adc
41 changes: 18 additions & 23 deletions site/src/components/EmptyState/EmptyState.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Box from "@material-ui/core/Box"
import Button, { ButtonProps } from "@material-ui/core/Button"
import { makeStyles } from "@material-ui/core/styles"
import Typography from "@material-ui/core/Typography"
import React from "react"
Expand All @@ -8,8 +7,8 @@ export interface EmptyStateProps {
/** Text Message to display, placed inside Typography component */
message: string
/** Longer optional description to display below the message */
description?: React.ReactNode
button?: ButtonProps
description?: string
cta?: React.ReactNode
}

/**
Expand All @@ -21,17 +20,22 @@ export interface EmptyStateProps {
* that you can directly pass props through to to customize the shape and layout of it.
*/
export const EmptyState: React.FC<EmptyStateProps> = (props) => {
const { message, description, button, ...boxProps } = props
const { message, description, cta, ...boxProps } = props
const styles = useStyles()
const buttonClassName = `${styles.button} ${button && button.className ? button.className : ""}`

return (
<Box className={styles.root} {...boxProps}>
<Typography variant="h5" color="textSecondary" className={styles.header}>
{message}
</Typography>
{description && <div className={styles.description}>{description}</div>}
{button && <Button variant="contained" color="primary" {...button} className={buttonClassName} />}
<div className={styles.header}>
<Typography variant="h5" className={styles.title}>
{message}
</Typography>
{description && (
<Typography variant="body2" color="textSecondary" className={styles.description}>
{description}
</Typography>
)}
</div>
{cta}
</Box>
)
}
Expand All @@ -48,22 +52,13 @@ const useStyles = makeStyles(
padding: theme.spacing(3),
},
header: {
marginBottom: theme.spacing(3),
},
title: {
fontWeight: 400,
},
description: {
marginTop: theme.spacing(2),
marginBottom: theme.spacing(1),
color: theme.palette.text.secondary,
fontSize: theme.typography.body2.fontSize,
},
button: {
marginTop: theme.spacing(2),
},
icon: {
fontSize: theme.typography.h2.fontSize,
color: theme.palette.text.secondary,
marginBottom: theme.spacing(1),
opacity: 0.5,
marginTop: theme.spacing(1),
},
}),
{ name: "EmptyState" },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Button from "@material-ui/core/Button"
import React from "react"
import { Link, useNavigate, useParams } from "react-router-dom"
import useSWR from "swr"
Expand Down Expand Up @@ -53,12 +54,13 @@ export const TemplatePage: React.FC = () => {

const emptyState = (
<EmptyState
button={{
children: "Create Workspace",
onClick: createWorkspace,
}}
message="No workspaces have been created yet"
description="Create a workspace to get started"
cta={
<Button variant="contained" color="primary" onClick={createWorkspace}>
Create workspace
</Button>
}
/>
)

Expand Down
16 changes: 2 additions & 14 deletions site/src/pages/TemplatesPages/TemplatesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import Box from "@material-ui/core/Box"
import { makeStyles } from "@material-ui/core/styles"
import Table from "@material-ui/core/Table"
import TableBody from "@material-ui/core/TableBody"
import TableCell from "@material-ui/core/TableCell"
Expand Down Expand Up @@ -29,7 +28,6 @@ export const Language = {
}

export const TemplatesPage: React.FC = () => {
const styles = useStyles()
const { data: orgs, error: orgsError } = useSWR<TypesGen.Organization[], Error>("/api/v2/users/me/organizations")
const { data: templates, error } = useSWR<TypesGen.Template[] | null, Error>(
orgs ? `/api/v2/organizations/${orgs[0].id}/templates` : null,
Expand Down Expand Up @@ -81,12 +79,8 @@ export const TemplatesPage: React.FC = () => {
<Box p={4}>
<EmptyState
message={Language.emptyMessage}
description={
<div>
<div className={styles.descriptionLabel}>{Language.emptyDescription}</div>
<CodeExample code="coder templates create" />
</div>
}
description={Language.emptyDescription}
cta={<CodeExample code="coder templates create" />}
/>
</Box>
</TableCell>
Expand All @@ -99,9 +93,3 @@ export const TemplatesPage: React.FC = () => {
</Stack>
)
}

const useStyles = makeStyles((theme) => ({
descriptionLabel: {
marginBottom: theme.spacing(1),
},
}))