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

Skip to content

Commit 584d3a3

Browse files
committed
Add empty states
1 parent 08069d3 commit 584d3a3

File tree

3 files changed

+55
-20
lines changed

3 files changed

+55
-20
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { ComponentMeta, Story } from "@storybook/react"
2+
import React from "react"
3+
import { MockTemplate } from "../../testHelpers/entities"
4+
import { TemplatesPageView, TemplatesPageViewProps } from "./TemplatesPageView"
5+
6+
export default {
7+
title: "pages/TemplatesPageView",
8+
component: TemplatesPageView,
9+
} as ComponentMeta<typeof TemplatesPageView>
10+
11+
const Template: Story<TemplatesPageViewProps> = (args) => <TemplatesPageView {...args} />
12+
13+
export const AllStates = Template.bind({})
14+
AllStates.args = {
15+
canCreateTemplate: true,
16+
templates: [
17+
MockTemplate,
18+
{
19+
...MockTemplate,
20+
description: "🚀 Some magical template that does some magical things!",
21+
},
22+
{
23+
...MockTemplate,
24+
workspace_owner_count: 150,
25+
description: "😮 Wow, this one has a bunch of usage!"
26+
}
27+
],
28+
}
29+
30+
export const EmptyCanCreate = Template.bind({})
31+
EmptyCanCreate.args = {
32+
canCreateTemplate: true,
33+
}
34+
35+
export const EmptyCannotCreate = Template.bind({})
36+
EmptyCannotCreate.args = {}

site/src/pages/TemplatesPage/TemplatesPageView.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
11
import Avatar from "@material-ui/core/Avatar"
22
import Button from "@material-ui/core/Button"
33
import Link from "@material-ui/core/Link"
4-
import { makeStyles, Theme } from "@material-ui/core/styles"
4+
import { makeStyles } from "@material-ui/core/styles"
55
import Table from "@material-ui/core/Table"
66
import TableBody from "@material-ui/core/TableBody"
77
import TableCell from "@material-ui/core/TableCell"
88
import TableHead from "@material-ui/core/TableHead"
99
import TableRow from "@material-ui/core/TableRow"
1010
import AddCircleOutline from "@material-ui/icons/AddCircleOutline"
11-
import useTheme from "@material-ui/styles/useTheme"
1211
import dayjs from "dayjs"
1312
import relativeTime from "dayjs/plugin/relativeTime"
1413
import React from "react"
1514
import { Link as RouterLink } from "react-router-dom"
1615
import * as TypesGen from "../../api/typesGenerated"
1716
import { Margins } from "../../components/Margins/Margins"
1817
import { Stack } from "../../components/Stack/Stack"
19-
import { combineClasses } from "../../util/combineClasses"
2018
import { firstLetter } from "../../util/firstLetter"
2119

2220
dayjs.extend(relativeTime)
2321

2422
export const Language = {
2523
createButton: "Create Template",
26-
emptyView: "so you can check out your repositories, edit your source code, and build and test your software.",
24+
emptyView: "to standardize development workspaces for your team.",
2725
}
2826

2927
export interface TemplatesPageViewProps {
@@ -35,14 +33,11 @@ export interface TemplatesPageViewProps {
3533

3634
export const TemplatesPageView: React.FC<TemplatesPageViewProps> = (props) => {
3735
const styles = useStyles()
38-
const theme: Theme = useTheme()
3936
return (
4037
<Stack spacing={4}>
4138
<Margins>
4239
<div className={styles.actions}>
43-
{props.canCreateTemplate && (
44-
<Button startIcon={<AddCircleOutline />}>{Language.createButton}</Button>
45-
)}
40+
{props.canCreateTemplate && <Button startIcon={<AddCircleOutline />}>{Language.createButton}</Button>}
4641
</div>
4742
<Table>
4843
<TableHead>
@@ -57,12 +52,16 @@ export const TemplatesPageView: React.FC<TemplatesPageViewProps> = (props) => {
5752
<TableRow>
5853
<TableCell colSpan={999}>
5954
<div className={styles.welcome}>
60-
<span>
61-
<Link component={RouterLink} to="/templates/new">
62-
Create a template
63-
</Link>
64-
&nbsp;{Language.emptyView}
65-
</span>
55+
{props.canCreateTemplate ? (
56+
<span>
57+
<Link component={RouterLink} to="/templates/new">
58+
Create a template
59+
</Link>
60+
&nbsp;{Language.emptyView}
61+
</span>
62+
) : (
63+
<span>No templates have been created! Contact your Coder administrator.</span>
64+
)}
6665
</div>
6766
</TableCell>
6867
</TableRow>
@@ -77,13 +76,13 @@ export const TemplatesPageView: React.FC<TemplatesPageViewProps> = (props) => {
7776
</Avatar>
7877
<Link component={RouterLink} to={`/templates/${template.id}`} className={styles.templateLink}>
7978
<b>{template.name}</b>
80-
<span>
81-
{template.description}
82-
</span>
79+
<span>{template.description}</span>
8380
</Link>
8481
</div>
8582
</TableCell>
86-
<TableCell>{template.workspace_owner_count} developer{template.workspace_owner_count !== 1 && "s"}</TableCell>
83+
<TableCell>
84+
{template.workspace_owner_count} developer{template.workspace_owner_count !== 1 && "s"}
85+
</TableCell>
8786
<TableCell>{dayjs().to(dayjs(template.updated_at))}</TableCell>
8887
</TableRow>
8988
)

site/src/testHelpers/entities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ export const MockRunningProvisionerJob = { ...MockProvisionerJob, status: "runni
8080

8181
export const MockTemplate: TypesGen.Template = {
8282
id: "test-template",
83-
created_at: "",
84-
updated_at: "",
83+
created_at: new Date().toString(),
84+
updated_at: new Date().toString(),
8585
organization_id: MockOrganization.id,
8686
name: "Test Template",
8787
provisioner: MockProvisioner.id,

0 commit comments

Comments
 (0)