Skip to content

feat: make template pages responsive #3232

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 1 commit into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
16 changes: 0 additions & 16 deletions site/src/components/TableContainer/TableContainer.tsx

This file was deleted.

125 changes: 64 additions & 61 deletions site/src/components/TemplateResourcesTable/TemplateResourcesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,70 +27,72 @@ export const TemplateResourcesTable: FC<TemplateResourcesProps> = ({ resources }
const styles = useStyles()

return (
<Table className={styles.table}>
<TableHead>
<TableHeaderRow>
<TableCell>
<Stack direction="row" spacing={0.5} alignItems="center">
{Language.resourceLabel}
<ResourcesHelpTooltip />
</Stack>
</TableCell>
<TableCell className={styles.agentColumn}>
<Stack direction="row" spacing={0.5} alignItems="center">
{Language.agentLabel}
<AgentHelpTooltip />
</Stack>
</TableCell>
</TableHeaderRow>
</TableHead>
<TableBody>
{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) {
<TableContainer className={styles.tableContainer}>
<Table>
<TableHead>
<TableHeaderRow>
<TableCell>
<Stack direction="row" spacing={0.5} alignItems="center">
{Language.resourceLabel}
<ResourcesHelpTooltip />
</Stack>
</TableCell>
<TableCell className={styles.agentColumn}>
<Stack direction="row" spacing={0.5} alignItems="center">
{Language.agentLabel}
<AgentHelpTooltip />
</Stack>
</TableCell>
</TableHeaderRow>
</TableHead>
<TableBody>
{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 (
<TableRow>
<TableCell className={styles.resourceNameCell}>
<AvatarData
title={resource.name}
subtitle={resource.type}
highlightTitle
avatar={<ResourceAvatar type={resource.type} />}
/>
</TableCell>
<TableCell colSpan={3}></TableCell>
</TableRow>
)
}

return (
<TableRow>
<TableCell className={styles.resourceNameCell}>
<AvatarData
title={resource.name}
subtitle={resource.type}
highlightTitle
avatar={<ResourceAvatar type={resource.type} />}
/>
<TableRow key={`${resource.id}-${agent.id}`}>
{/* 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 && (
<TableCell className={styles.resourceNameCell} rowSpan={agents.length}>
<AvatarData
title={resource.name}
subtitle={resource.type}
highlightTitle
avatar={<ResourceAvatar type={resource.type} />}
/>
</TableCell>
)}

<TableCell className={styles.agentColumn}>
{agent.name}
<span className={styles.operatingSystem}>{agent.operating_system}</span>
</TableCell>
<TableCell colSpan={3}></TableCell>
</TableRow>
)
}

return (
<TableRow key={`${resource.id}-${agent.id}`}>
{/* 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 && (
<TableCell className={styles.resourceNameCell} rowSpan={agents.length}>
<AvatarData
title={resource.name}
subtitle={resource.type}
highlightTitle
avatar={<ResourceAvatar type={resource.type} />}
/>
</TableCell>
)}

<TableCell className={styles.agentColumn}>
{agent.name}
<span className={styles.operatingSystem}>{agent.operating_system}</span>
</TableCell>
</TableRow>
)
})
})}
</TableBody>
</Table>
})
})}
</TableBody>
</Table>
</TableContainer>
)
}

Expand All @@ -98,7 +101,7 @@ const useStyles = makeStyles((theme) => ({
margin: 0,
},

table: {
tableContainer: {
border: 0,
},

Expand Down
2 changes: 1 addition & 1 deletion site/src/components/UsersTable/UsersTable.tsx
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
85 changes: 44 additions & 41 deletions site/src/components/VersionsTable/VersionsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -27,48 +28,50 @@ export const VersionsTable: FC<VersionsTableProps> = ({ versions }) => {
const theme: Theme = useTheme()

return (
<Table data-testid="versions-table">
<TableHead>
<TableRow>
<TableCell width="30%">{Language.nameLabel}</TableCell>
<TableCell width="30%">{Language.createdAtLabel}</TableCell>
<TableCell width="40%">{Language.createdByLabel}</TableCell>
</TableRow>
</TableHead>
<TableBody>
{isLoading && <TableLoader />}
{versions &&
versions
.slice()
.reverse()
.map((version) => {
return (
<TableRow key={version.id} data-testid={`version-${version.id}`}>
<TableCell>{version.name}</TableCell>
<TableCell>
<span style={{ color: theme.palette.text.secondary }}>
{new Date(version.created_at).toLocaleString()}
</span>
</TableCell>
<TableCell>
<span style={{ color: theme.palette.text.secondary }}>
{version.created_by_name}
</span>
</TableCell>
</TableRow>
)
})}

{versions && versions.length === 0 && (
<TableContainer>
<Table data-testid="versions-table">
<TableHead>
<TableRow>
<TableCell colSpan={999}>
<Box p={4}>
<EmptyState message={Language.emptyMessage} />
</Box>
</TableCell>
<TableCell width="30%">{Language.nameLabel}</TableCell>
<TableCell width="30%">{Language.createdAtLabel}</TableCell>
<TableCell width="40%">{Language.createdByLabel}</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</TableHead>
<TableBody>
{isLoading && <TableLoader />}
{versions &&
versions
.slice()
.reverse()
.map((version) => {
return (
<TableRow key={version.id} data-testid={`version-${version.id}`}>
<TableCell>{version.name}</TableCell>
<TableCell>
<span style={{ color: theme.palette.text.secondary }}>
{new Date(version.created_at).toLocaleString()}
</span>
</TableCell>
<TableCell>
<span style={{ color: theme.palette.text.secondary }}>
{version.created_by_name}
</span>
</TableCell>
</TableRow>
)
})}

{versions && versions.length === 0 && (
<TableRow>
<TableCell colSpan={999}>
<Box p={4}>
<EmptyState message={Language.emptyMessage} />
</Box>
</TableCell>
</TableRow>
)}
</TableBody>
</Table>
</TableContainer>
)
}
8 changes: 8 additions & 0 deletions site/src/pages/TemplatesPage/TemplatesPageView.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading