From 9c2b8180bc2736aab798ff2ff2e358b81cc6a7dc Mon Sep 17 00:00:00 2001 From: Abhineet Jain Date: Tue, 26 Jul 2022 20:10:45 +0000 Subject: [PATCH] feat: make template pages responsive --- .../TableContainer/TableContainer.tsx | 16 --- .../TemplateResourcesTable.tsx | 125 ++++++++--------- site/src/components/UsersTable/UsersTable.tsx | 2 +- .../VersionsTable/VersionsTable.tsx | 85 ++++++------ .../TemplatesPageView.stories.tsx | 8 ++ .../pages/TemplatesPage/TemplatesPageView.tsx | 129 +++++++++--------- .../pages/UsersPage/UsersPageView.stories.tsx | 8 ++ 7 files changed, 192 insertions(+), 181 deletions(-) delete mode 100644 site/src/components/TableContainer/TableContainer.tsx diff --git a/site/src/components/TableContainer/TableContainer.tsx b/site/src/components/TableContainer/TableContainer.tsx deleted file mode 100644 index 989b26490b60a..0000000000000 --- a/site/src/components/TableContainer/TableContainer.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { makeStyles } from "@material-ui/core/styles" -import { FC } from "react" - -export const TableContainer: FC = ({ children }) => { - const styles = useStyles() - - return
{children}
-} - -const useStyles = makeStyles((theme) => ({ - wrapper: { - overflowX: "auto", - borderRadius: theme.shape.borderRadius, - border: `1px solid ${theme.palette.divider}`, - }, -})) diff --git a/site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx b/site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx index 3c7c50eb9c8d5..221dfaf864498 100644 --- a/site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx +++ b/site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx @@ -2,6 +2,7 @@ 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" +import TableContainer from "@material-ui/core/TableContainer" import TableHead from "@material-ui/core/TableHead" import TableRow from "@material-ui/core/TableRow" import { AvatarData } from "components/AvatarData/AvatarData" @@ -26,70 +27,72 @@ export const TemplateResourcesTable: FC = ({ resources } const styles = useStyles() return ( - - - - - - {Language.resourceLabel} - - - - - - {Language.agentLabel} - - - - - - - {resources.map((resource) => { - // We need to initialize the agents to display the resource - const agents = resource.agents ?? [null] - return agents.map((agent, agentIndex) => { - // If there is no agent, just display the resource name - if (!agent) { + +
+ + + + + {Language.resourceLabel} + + + + + + {Language.agentLabel} + + + + + + + {resources.map((resource) => { + // We need to initialize the agents to display the resource + const agents = resource.agents ?? [null] + return agents.map((agent, agentIndex) => { + // If there is no agent, just display the resource name + if (!agent) { + return ( + + + } + /> + + + + ) + } + return ( - - - } - /> + + {/* We only want to display the name in the first row because we are using rowSpan */} + {/* The rowspan should be the same than the number of agents */} + {agentIndex === 0 && ( + + } + /> + + )} + + + {agent.name} + {agent.operating_system} - ) - } - - return ( - - {/* We only want to display the name in the first row because we are using rowSpan */} - {/* The rowspan should be the same than the number of agents */} - {agentIndex === 0 && ( - - } - /> - - )} - - - {agent.name} - {agent.operating_system} - - - ) - }) - })} - -
+ }) + })} + + + ) } @@ -98,7 +101,7 @@ const useStyles = makeStyles((theme) => ({ margin: 0, }, - table: { + tableContainer: { border: 0, }, diff --git a/site/src/components/UsersTable/UsersTable.tsx b/site/src/components/UsersTable/UsersTable.tsx index 556a64d47946b..0275ea08cfc91 100644 --- a/site/src/components/UsersTable/UsersTable.tsx +++ b/site/src/components/UsersTable/UsersTable.tsx @@ -1,9 +1,9 @@ import Table from "@material-ui/core/Table" import TableBody from "@material-ui/core/TableBody" import TableCell from "@material-ui/core/TableCell" +import TableContainer from "@material-ui/core/TableContainer" import TableHead from "@material-ui/core/TableHead" import TableRow from "@material-ui/core/TableRow" -import { TableContainer } from "components/TableContainer/TableContainer" import { FC } from "react" import * as TypesGen from "../../api/typesGenerated" import { UsersTableBody } from "./UsersTableBody" diff --git a/site/src/components/VersionsTable/VersionsTable.tsx b/site/src/components/VersionsTable/VersionsTable.tsx index 8e6801fcb200c..9e9ffe9c8c898 100644 --- a/site/src/components/VersionsTable/VersionsTable.tsx +++ b/site/src/components/VersionsTable/VersionsTable.tsx @@ -3,6 +3,7 @@ import { Theme } 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" +import TableContainer from "@material-ui/core/TableContainer" import TableHead from "@material-ui/core/TableHead" import TableRow from "@material-ui/core/TableRow" import useTheme from "@material-ui/styles/useTheme" @@ -27,48 +28,50 @@ export const VersionsTable: FC = ({ versions }) => { const theme: Theme = useTheme() return ( - - - - {Language.nameLabel} - {Language.createdAtLabel} - {Language.createdByLabel} - - - - {isLoading && } - {versions && - versions - .slice() - .reverse() - .map((version) => { - return ( - - {version.name} - - - {new Date(version.created_at).toLocaleString()} - - - - - {version.created_by_name} - - - - ) - })} - - {versions && versions.length === 0 && ( + +
+ - - - - - + {Language.nameLabel} + {Language.createdAtLabel} + {Language.createdByLabel} - )} - -
+ + + {isLoading && } + {versions && + versions + .slice() + .reverse() + .map((version) => { + return ( + + {version.name} + + + {new Date(version.created_at).toLocaleString()} + + + + + {version.created_by_name} + + + + ) + })} + + {versions && versions.length === 0 && ( + + + + + + + + )} + + + ) } diff --git a/site/src/pages/TemplatesPage/TemplatesPageView.stories.tsx b/site/src/pages/TemplatesPage/TemplatesPageView.stories.tsx index c4d2e57ac7a0b..a72c8024503f8 100644 --- a/site/src/pages/TemplatesPage/TemplatesPageView.stories.tsx +++ b/site/src/pages/TemplatesPage/TemplatesPageView.stories.tsx @@ -26,6 +26,14 @@ AllStates.args = { ], } +export const SmallViewport = Template.bind({}) +SmallViewport.args = { + ...AllStates.args, +} +SmallViewport.parameters = { + chromatic: { viewports: [600] }, +} + export const EmptyCanCreate = Template.bind({}) EmptyCanCreate.args = { canCreateTemplate: true, diff --git a/site/src/pages/TemplatesPage/TemplatesPageView.tsx b/site/src/pages/TemplatesPage/TemplatesPageView.tsx index ce822af401b24..5c35fd8d3e18d 100644 --- a/site/src/pages/TemplatesPage/TemplatesPageView.tsx +++ b/site/src/pages/TemplatesPage/TemplatesPageView.tsx @@ -3,6 +3,7 @@ import { fade, 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" +import TableContainer from "@material-ui/core/TableContainer" import TableHead from "@material-ui/core/TableHead" import TableRow from "@material-ui/core/TableRow" import KeyboardArrowRight from "@material-ui/icons/KeyboardArrowRight" @@ -94,73 +95,77 @@ export const TemplatesPageView: FC = (props) => { )} - - - - {Language.nameLabel} - {Language.usedByLabel} - {Language.lastUpdatedLabel} - {Language.createdByLabel} - - - - - {props.loading && } - {!props.loading && !props.templates?.length && ( + +
+ - - } - /> - + {Language.nameLabel} + {Language.usedByLabel} + {Language.lastUpdatedLabel} + {Language.createdByLabel} + - )} - {props.templates?.map((template) => { - const templatePageLink = `/templates/${template.name}` - return ( - { - if (event.key === "Enter") { - navigate(templatePageLink) - } - }} - className={styles.clickableTableRow} - > - - + + {props.loading && } + {!props.loading && !props.templates?.length && ( + + + } /> - + + + )} + {props.templates?.map((template) => { + const templatePageLink = `/templates/${template.name}` + return ( + { + if (event.key === "Enter") { + navigate(templatePageLink) + } + }} + className={styles.clickableTableRow} + > + + + - - {Language.developerCount(template.workspace_owner_count)} - + + {Language.developerCount(template.workspace_owner_count)} + - - {createDayString(template.updated_at)} - - {template.created_by_name} - -
- -
-
-
- ) - })} - -
+ + {createDayString(template.updated_at)} + + {template.created_by_name} + +
+ +
+
+ + ) + })} + + + ) } diff --git a/site/src/pages/UsersPage/UsersPageView.stories.tsx b/site/src/pages/UsersPage/UsersPageView.stories.tsx index 12fe898c05848..5ade0167ac163 100644 --- a/site/src/pages/UsersPage/UsersPageView.stories.tsx +++ b/site/src/pages/UsersPage/UsersPageView.stories.tsx @@ -17,6 +17,14 @@ Admin.args = { canEditUsers: true, } +export const SmallViewport = Template.bind({}) +SmallViewport.args = { + ...Admin.args, +} +SmallViewport.parameters = { + chromatic: { viewports: [600] }, +} + export const Member = Template.bind({}) Member.args = { ...Admin.args, canCreateUser: false, canEditUsers: false }