-
Notifications
You must be signed in to change notification settings - Fork 929
feat: resources card #1627
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
feat: resources card #1627
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
448070b
Set up table
presleyp 99e63e5
Format
presleyp 7b318ee
Hook up api and test - bug assigning resources
presleyp 8cfb56a
Remove debugging code
presleyp 2a3897c
Merge branch 'main' into resources/presleyp/1031
presleyp c5b60dd
Format
presleyp c4257a2
Remove unnecessary cards
presleyp be67df8
Fix test
presleyp 85a869d
Fix assignment
presleyp 1289ad2
Fix tests
presleyp abc7703
Lint
presleyp 416be20
Merge branch 'main' into resources/presleyp/1031
presleyp c300c07
Merge branch 'main' into resources/presleyp/1031
presleyp 13ba13c
Merge branch 'main' of github.com:coder/coder into resources/presleyp…
BrunoQuaresma 85c2ac8
Refactor design
BrunoQuaresma e7b1110
Refactor resources table
BrunoQuaresma f645de3
Fix tests
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { makeStyles, 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 TableHead from "@material-ui/core/TableHead" | ||
import TableRow from "@material-ui/core/TableRow" | ||
import useTheme from "@material-ui/styles/useTheme" | ||
import React from "react" | ||
import { WorkspaceResource } from "../../api/typesGenerated" | ||
import { getDisplayAgentStatus } from "../../util/workspace" | ||
import { TableHeaderRow } from "../TableHeaders/TableHeaders" | ||
import { WorkspaceSection } from "../WorkspaceSection/WorkspaceSection" | ||
|
||
const Language = { | ||
resources: "Resources", | ||
resourceLabel: "Resource", | ||
agentsLabel: "Agents", | ||
agentLabel: "Agent", | ||
statusLabel: "Status", | ||
} | ||
|
||
interface ResourcesProps { | ||
resources?: WorkspaceResource[] | ||
getResourcesError?: Error | ||
} | ||
|
||
export const Resources: React.FC<ResourcesProps> = ({ resources, getResourcesError }) => { | ||
const styles = useStyles() | ||
const theme: Theme = useTheme() | ||
|
||
return ( | ||
<WorkspaceSection title={Language.resources} contentsProps={{ className: styles.sectionContents }}> | ||
{getResourcesError ? ( | ||
{ getResourcesError } | ||
) : ( | ||
<Table className={styles.table}> | ||
<TableHead> | ||
<TableHeaderRow> | ||
<TableCell>{Language.resourceLabel}</TableCell> | ||
<TableCell className={styles.agentColumn}>{Language.agentLabel}</TableCell> | ||
<TableCell>{Language.statusLabel}</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}>{resource.name}</TableCell> | ||
<TableCell colSpan={2}></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}> | ||
{resource.name} | ||
</TableCell> | ||
)} | ||
|
||
<TableCell className={styles.agentColumn}> | ||
<span style={{ color: theme.palette.text.secondary }}>{agent.name}</span> | ||
</TableCell> | ||
<TableCell> | ||
<span style={{ color: getDisplayAgentStatus(theme, agent).color }}> | ||
{getDisplayAgentStatus(theme, agent).status} | ||
</span> | ||
</TableCell> | ||
</TableRow> | ||
) | ||
}) | ||
})} | ||
</TableBody> | ||
</Table> | ||
)} | ||
</WorkspaceSection> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
sectionContents: { | ||
margin: 0, | ||
}, | ||
|
||
table: { | ||
border: 0, | ||
}, | ||
|
||
resourceNameCell: { | ||
borderRight: `1px solid ${theme.palette.divider}`, | ||
}, | ||
|
||
// Adds some left spacing | ||
agentColumn: { | ||
paddingLeft: `${theme.spacing(2)}px !important`, | ||
}, | ||
})) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉