-
Notifications
You must be signed in to change notification settings - Fork 978
feat: Add the template page #1754
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
Changes from 1 commit
0764df3
b8ff946
02747cf
f63f04c
fac8e3e
792ee73
2822db0
b42f3e9
728c270
c011edb
5eb55cc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,8 @@ export const Resources: React.FC<ResourcesProps> = ({ resources, getResourcesErr | |
)} | ||
|
||
<TableCell className={styles.agentColumn}> | ||
<span style={{ color: theme.palette.text.secondary }}>{agent.name}</span> | ||
{agent.name} | ||
<span className={styles.operatingSystem}>{agent.operating_system}</span> | ||
</TableCell> | ||
<TableCell> | ||
<span style={{ color: getDisplayAgentStatus(theme, agent).color }}> | ||
|
@@ -143,4 +144,12 @@ const useStyles = makeStyles((theme) => ({ | |
marginRight: theme.spacing(1.5), | ||
}, | ||
}, | ||
|
||
operatingSystem: { | ||
fontSize: 14, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we try to use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably yes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there are more styles involved I will keep it right now. |
||
color: theme.palette.text.secondary, | ||
marginTop: theme.spacing(0.5), | ||
display: "block", | ||
textTransform: "capitalize", | ||
}, | ||
})) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
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 TableHead from "@material-ui/core/TableHead" | ||
import TableRow from "@material-ui/core/TableRow" | ||
import React from "react" | ||
import { WorkspaceResource } from "../../api/typesGenerated" | ||
import { TableHeaderRow } from "../TableHeaders/TableHeaders" | ||
|
||
const Language = { | ||
resourceLabel: "Resource", | ||
agentLabel: "Agent", | ||
} | ||
|
||
interface TemplateResourcesProps { | ||
resources: WorkspaceResource[] | ||
} | ||
|
||
export const TemplateResourcesTable: React.FC<TemplateResourcesProps> = ({ resources }) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<Table className={styles.table}> | ||
<TableHead> | ||
<TableHeaderRow> | ||
<TableCell>{Language.resourceLabel}</TableCell> | ||
<TableCell className={styles.agentColumn}>{Language.agentLabel}</TableCell> | ||
</TableHeaderRow> | ||
</TableHead> | ||
<TableBody> | ||
{resources.map((resource) => { | ||
{ | ||
/* We need to initialize the agents to display the resource */ | ||
} | ||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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} | ||
<span className={styles.resourceType}>{resource.type}</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}> | ||
{resource.name} | ||
<span className={styles.resourceType}>{resource.type}</span> | ||
</TableCell> | ||
)} | ||
|
||
<TableCell className={styles.agentColumn}> | ||
{agent.name} | ||
<span className={styles.operatingSystem}>{agent.operating_system}</span> | ||
</TableCell> | ||
</TableRow> | ||
) | ||
}) | ||
})} | ||
</TableBody> | ||
</Table> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
sectionContents: { | ||
margin: 0, | ||
}, | ||
|
||
table: { | ||
border: 0, | ||
}, | ||
|
||
resourceNameCell: { | ||
borderRight: `1px solid ${theme.palette.divider}`, | ||
}, | ||
|
||
resourceType: { | ||
fontSize: 14, | ||
color: theme.palette.text.secondary, | ||
marginTop: theme.spacing(0.5), | ||
display: "block", | ||
}, | ||
|
||
// Adds some left spacing | ||
agentColumn: { | ||
paddingLeft: `${theme.spacing(2)}px !important`, | ||
}, | ||
|
||
operatingSystem: { | ||
fontSize: 14, | ||
color: theme.palette.text.secondary, | ||
marginTop: theme.spacing(0.5), | ||
display: "block", | ||
textTransform: "capitalize", | ||
}, | ||
})) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { makeStyles } from "@material-ui/core/styles" | ||
import dayjs from "dayjs" | ||
import React from "react" | ||
import { Template, TemplateVersion } from "../../api/typesGenerated" | ||
import { CardRadius, MONOSPACE_FONT_FAMILY } from "../../theme/constants" | ||
|
||
const Language = { | ||
usedByLabel: "Used by", | ||
activeVersionLabel: "Active version", | ||
lastUpdateLabel: "Last updated", | ||
userPlural: "users", | ||
userSingular: "user", | ||
} | ||
|
||
export interface TemplateStatsProps { | ||
template: Template | ||
activeVersion: TemplateVersion | ||
} | ||
|
||
export const TemplateStats: React.FC<TemplateStatsProps> = ({ template, activeVersion }) => { | ||
const styles = useStyles() | ||
|
||
return ( | ||
<div className={styles.stats}> | ||
<div className={styles.statItem}> | ||
<span className={styles.statsLabel}>{Language.usedByLabel}</span> | ||
|
||
<span className={styles.statsValue}> | ||
{template.workspace_owner_count}{" "} | ||
{template.workspace_owner_count === 1 ? Language.userSingular : Language.userPlural} | ||
</span> | ||
</div> | ||
<div className={styles.statsDivider} /> | ||
<div className={styles.statItem}> | ||
<span className={styles.statsLabel}>{Language.activeVersionLabel}</span> | ||
<span className={styles.statsValue}>{activeVersion.name}</span> | ||
</div> | ||
<div className={styles.statsDivider} /> | ||
<div className={styles.statItem}> | ||
<span className={styles.statsLabel}>{Language.lastUpdateLabel}</span> | ||
<span className={styles.statsValue} data-chromatic="ignore"> | ||
{dayjs().to(dayjs(template.updated_at))} | ||
</span> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const useStyles = makeStyles((theme) => ({ | ||
stats: { | ||
paddingLeft: theme.spacing(2), | ||
paddingRight: theme.spacing(2), | ||
backgroundColor: theme.palette.background.paper, | ||
borderRadius: CardRadius, | ||
display: "flex", | ||
alignItems: "center", | ||
color: theme.palette.text.secondary, | ||
fontFamily: MONOSPACE_FONT_FAMILY, | ||
border: `1px solid ${theme.palette.divider}`, | ||
}, | ||
|
||
statItem: { | ||
minWidth: theme.spacing(20), | ||
padding: theme.spacing(2), | ||
paddingTop: theme.spacing(1.75), | ||
}, | ||
|
||
statsLabel: { | ||
fontSize: 12, | ||
textTransform: "uppercase", | ||
display: "block", | ||
fontWeight: 600, | ||
}, | ||
|
||
statsValue: { | ||
fontSize: 16, | ||
marginTop: theme.spacing(0.25), | ||
display: "inline-block", | ||
}, | ||
|
||
statsDivider: { | ||
width: 1, | ||
height: theme.spacing(5), | ||
backgroundColor: theme.palette.divider, | ||
marginRight: theme.spacing(2), | ||
}, | ||
})) |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||
import { useActor } from "@xstate/react" | ||||
import { useContext } from "react" | ||||
import { XServiceContext } from "../xServices/StateContext" | ||||
|
||||
export const useOrganizationID = (): string => { | ||||
BrunoQuaresma marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
const xServices = useContext(XServiceContext) | ||||
const [authState] = useActor(xServices.authXService) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is getting authentication data which is a global state I would use the XServiceContext. About the selector for organization Id, I think it is a good idea. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh you're right, we don't need
|
||||
const organizationId = authState.context.me?.organization_ids[0] | ||||
|
||||
if (!organizationId) { | ||||
throw new Error("No organization ID found") | ||||
} | ||||
|
||||
return organizationId | ||||
} |
Uh oh!
There was an error while loading. Please reload this page.