|
| 1 | +import{makeStyles,Theme}from"@material-ui/core/styles" |
| 2 | +importTablefrom"@material-ui/core/Table" |
| 3 | +importTableBodyfrom"@material-ui/core/TableBody" |
| 4 | +importTableCellfrom"@material-ui/core/TableCell" |
| 5 | +importTableHeadfrom"@material-ui/core/TableHead" |
| 6 | +importTableRowfrom"@material-ui/core/TableRow" |
| 7 | +importuseThemefrom"@material-ui/styles/useTheme" |
| 8 | +importReactfrom"react" |
| 9 | +import{WorkspaceResource}from"../../api/typesGenerated" |
| 10 | +import{getDisplayAgentStatus}from"../../util/workspace" |
| 11 | +import{TableHeaderRow}from"../TableHeaders/TableHeaders" |
| 12 | +import{WorkspaceSection}from"../WorkspaceSection/WorkspaceSection" |
| 13 | + |
| 14 | +constLanguage={ |
| 15 | +resources:"Resources", |
| 16 | +resourceLabel:"Resource", |
| 17 | +agentsLabel:"Agents", |
| 18 | +agentLabel:"Agent", |
| 19 | +statusLabel:"Status", |
| 20 | +} |
| 21 | + |
| 22 | +interfaceResourcesProps{ |
| 23 | +resources?:WorkspaceResource[] |
| 24 | +getResourcesError?:Error |
| 25 | +} |
| 26 | + |
| 27 | +exportconstResources:React.FC<ResourcesProps>=({ resources, getResourcesError})=>{ |
| 28 | +conststyles=useStyles() |
| 29 | +consttheme:Theme=useTheme() |
| 30 | + |
| 31 | +return( |
| 32 | +<WorkspaceSectiontitle={Language.resources}contentsProps={{className:styles.sectionContents}}> |
| 33 | +{getResourcesError ?( |
| 34 | +{ getResourcesError} |
| 35 | +) :( |
| 36 | +<TableclassName={styles.table}> |
| 37 | +<TableHead> |
| 38 | +<TableHeaderRow> |
| 39 | +<TableCell>{Language.resourceLabel}</TableCell> |
| 40 | +<TableCellclassName={styles.agentColumn}>{Language.agentLabel}</TableCell> |
| 41 | +<TableCell>{Language.statusLabel}</TableCell> |
| 42 | +</TableHeaderRow> |
| 43 | +</TableHead> |
| 44 | +<TableBody> |
| 45 | +{resources?.map((resource)=>{ |
| 46 | +{ |
| 47 | +/* We need to initialize the agents to display the resource */ |
| 48 | +} |
| 49 | +constagents=resource.agents??[null] |
| 50 | +returnagents.map((agent,agentIndex)=>{ |
| 51 | +{ |
| 52 | +/* If there is no agent, just display the resource name */ |
| 53 | +} |
| 54 | +if(!agent){ |
| 55 | +return( |
| 56 | +<TableRow> |
| 57 | +<TableCellclassName={styles.resourceNameCell}>{resource.name}</TableCell> |
| 58 | +<TableCellcolSpan={2}></TableCell> |
| 59 | +</TableRow> |
| 60 | +) |
| 61 | +} |
| 62 | + |
| 63 | +return( |
| 64 | +<TableRowkey={`${resource.id}-${agent.id}`}> |
| 65 | +{/* We only want to display the name in the first row because we are using rowSpan */} |
| 66 | +{/* The rowspan should be the same than the number of agents */} |
| 67 | +{agentIndex===0&&( |
| 68 | +<TableCellclassName={styles.resourceNameCell}rowSpan={agents.length}> |
| 69 | +{resource.name} |
| 70 | +</TableCell> |
| 71 | +)} |
| 72 | + |
| 73 | +<TableCellclassName={styles.agentColumn}> |
| 74 | +<spanstyle={{color:theme.palette.text.secondary}}>{agent.name}</span> |
| 75 | +</TableCell> |
| 76 | +<TableCell> |
| 77 | +<spanstyle={{color:getDisplayAgentStatus(theme,agent).color}}> |
| 78 | +{getDisplayAgentStatus(theme,agent).status} |
| 79 | +</span> |
| 80 | +</TableCell> |
| 81 | +</TableRow> |
| 82 | +) |
| 83 | +}) |
| 84 | +})} |
| 85 | +</TableBody> |
| 86 | +</Table> |
| 87 | +)} |
| 88 | +</WorkspaceSection> |
| 89 | +) |
| 90 | +} |
| 91 | + |
| 92 | +constuseStyles=makeStyles((theme)=>({ |
| 93 | +sectionContents:{ |
| 94 | +margin:0, |
| 95 | +}, |
| 96 | + |
| 97 | +table:{ |
| 98 | +border:0, |
| 99 | +}, |
| 100 | + |
| 101 | +resourceNameCell:{ |
| 102 | +borderRight:`1px solid${theme.palette.divider}`, |
| 103 | +}, |
| 104 | + |
| 105 | +// Adds some left spacing |
| 106 | +agentColumn:{ |
| 107 | +paddingLeft:`${theme.spacing(2)}px !important`, |
| 108 | +}, |
| 109 | +})) |