|
| 1 | +import Avatar from "@material-ui/core/Avatar" |
| 2 | +import Button from "@material-ui/core/Button" |
| 3 | +import Link from "@material-ui/core/Link" |
| 4 | +import { makeStyles, Theme } from "@material-ui/core/styles" |
| 5 | +import Table from "@material-ui/core/Table" |
| 6 | +import TableBody from "@material-ui/core/TableBody" |
| 7 | +import TableCell from "@material-ui/core/TableCell" |
| 8 | +import TableHead from "@material-ui/core/TableHead" |
| 9 | +import TableRow from "@material-ui/core/TableRow" |
| 10 | +import AddCircleOutline from "@material-ui/icons/AddCircleOutline" |
| 11 | +import useTheme from "@material-ui/styles/useTheme" |
| 12 | +import dayjs from "dayjs" |
| 13 | +import relativeTime from "dayjs/plugin/relativeTime" |
1 | 14 | import React from "react"
|
| 15 | +import { Link as RouterLink } from "react-router-dom" |
| 16 | +import * as TypesGen from "../../api/typesGenerated" |
| 17 | +import { Margins } from "../../components/Margins/Margins" |
| 18 | +import { Stack } from "../../components/Stack/Stack" |
| 19 | +import { firstLetter } from "../../util/firstLetter" |
2 | 20 |
|
3 |
| -export const TemplatesPageView: React.FC = () => { |
4 |
| - return <div>testing</div> |
| 21 | +dayjs.extend(relativeTime) |
| 22 | + |
| 23 | +export const Language = { |
| 24 | + createButton: "Create Template", |
| 25 | + emptyView: "so you can check out your repositories, edit your source code, and build and test your software.", |
| 26 | +} |
| 27 | + |
| 28 | +export interface TemplatesPageViewProps { |
| 29 | + loading?: boolean |
| 30 | + templates?: TypesGen.Template[] |
| 31 | + error?: unknown |
5 | 32 | }
|
| 33 | + |
| 34 | +export const TemplatesPageView: React.FC<TemplatesPageViewProps> = (props) => { |
| 35 | + const styles = useStyles() |
| 36 | + const theme: Theme = useTheme() |
| 37 | + return ( |
| 38 | + <Stack spacing={4}> |
| 39 | + <Margins> |
| 40 | + <div className={styles.actions}> |
| 41 | + <Button startIcon={<AddCircleOutline />}>{Language.createButton}</Button> |
| 42 | + </div> |
| 43 | + <Table> |
| 44 | + <TableHead> |
| 45 | + <TableRow> |
| 46 | + <TableCell>Name</TableCell> |
| 47 | + <TableCell>Description</TableCell> |
| 48 | + <TableCell>Last Updated</TableCell> |
| 49 | + <TableCell>Provisioner</TableCell> |
| 50 | + <TableCell>Developers</TableCell> |
| 51 | + </TableRow> |
| 52 | + </TableHead> |
| 53 | + <TableBody> |
| 54 | + {!props.loading && !props.templates?.length && ( |
| 55 | + <TableRow> |
| 56 | + <TableCell colSpan={999}> |
| 57 | + <div className={styles.welcome}> |
| 58 | + <span> |
| 59 | + <Link component={RouterLink} to="/templates/new"> |
| 60 | + Create a template |
| 61 | + </Link> |
| 62 | + {Language.emptyView} |
| 63 | + </span> |
| 64 | + </div> |
| 65 | + </TableCell> |
| 66 | + </TableRow> |
| 67 | + )} |
| 68 | + {props.templates?.map((template) => { |
| 69 | + return ( |
| 70 | + <TableRow key={template.id} className={styles.templateRow}> |
| 71 | + <TableCell> |
| 72 | + <div className={styles.templateName}> |
| 73 | + <Avatar variant="square" className={styles.templateAvatar}> |
| 74 | + {firstLetter(template.name)} |
| 75 | + </Avatar> |
| 76 | + <Link component={RouterLink} to={`/templates/${template.id}`} className={styles.templateLink}> |
| 77 | + <b>{template.name}</b> |
| 78 | + </Link> |
| 79 | + </div> |
| 80 | + </TableCell> |
| 81 | + <TableCell>{template.description}</TableCell> |
| 82 | + <TableCell>{dayjs().to(dayjs(template.updated_at))}</TableCell> |
| 83 | + <TableCell> |
| 84 | + <img alt="Terraform" src="/terraform-logo.svg" /> |
| 85 | + </TableCell> |
| 86 | + <TableCell>{template.workspace_owner_count}</TableCell> |
| 87 | + </TableRow> |
| 88 | + ) |
| 89 | + })} |
| 90 | + </TableBody> |
| 91 | + </Table> |
| 92 | + </Margins> |
| 93 | + </Stack> |
| 94 | + ) |
| 95 | +} |
| 96 | + |
| 97 | +const useStyles = makeStyles((theme) => ({ |
| 98 | + actions: { |
| 99 | + marginTop: theme.spacing(3), |
| 100 | + marginBottom: theme.spacing(3), |
| 101 | + display: "flex", |
| 102 | + height: theme.spacing(6), |
| 103 | + |
| 104 | + "& button": { |
| 105 | + marginLeft: "auto", |
| 106 | + }, |
| 107 | + }, |
| 108 | + welcome: { |
| 109 | + paddingTop: theme.spacing(12), |
| 110 | + paddingBottom: theme.spacing(12), |
| 111 | + display: "flex", |
| 112 | + flexDirection: "column", |
| 113 | + alignItems: "center", |
| 114 | + justifyContent: "center", |
| 115 | + "& span": { |
| 116 | + maxWidth: 600, |
| 117 | + textAlign: "center", |
| 118 | + fontSize: theme.spacing(2), |
| 119 | + lineHeight: `${theme.spacing(3)}px`, |
| 120 | + }, |
| 121 | + }, |
| 122 | + templateRow: { |
| 123 | + "& > td": { |
| 124 | + paddingTop: theme.spacing(2), |
| 125 | + paddingBottom: theme.spacing(2), |
| 126 | + }, |
| 127 | + }, |
| 128 | + templateAvatar: { |
| 129 | + borderRadius: 2, |
| 130 | + marginRight: theme.spacing(1), |
| 131 | + width: 24, |
| 132 | + height: 24, |
| 133 | + fontSize: 16, |
| 134 | + }, |
| 135 | + templateName: { |
| 136 | + display: "flex", |
| 137 | + alignItems: "center", |
| 138 | + }, |
| 139 | + templateLink: { |
| 140 | + display: "flex", |
| 141 | + flexDirection: "column", |
| 142 | + color: theme.palette.text.primary, |
| 143 | + textDecoration: "none", |
| 144 | + "&:hover": { |
| 145 | + textDecoration: "underline", |
| 146 | + }, |
| 147 | + "& span": { |
| 148 | + fontSize: 12, |
| 149 | + color: theme.palette.text.secondary, |
| 150 | + }, |
| 151 | + }, |
| 152 | +})) |
0 commit comments