| 1 |
import { Table, Thead, Tr, Th, Tbody, Td } from '@patternfly/react-table'; |
| 2 |
import t_global_background_color_secondary_default from '@patternfly/react-tokens/dist/esm/t_global_background_color_secondary_default'; |
| 3 |
|
| 4 |
interface Repository { |
| 5 |
name: string; |
| 6 |
branches: string | null; |
| 7 |
prs: string | null; |
| 8 |
workspaces: string; |
| 9 |
lastCommit: string; |
| 10 |
} |
| 11 |
|
| 12 |
export const TableMisc: React.FunctionComponent = () => { |
| 13 |
// In real usage, this data would come from some external source like an API via props. |
| 14 |
const repositories: Repository[] = [ |
| 15 |
{ name: 'one', branches: 'two', prs: 'three', workspaces: 'four', lastCommit: 'five' }, |
| 16 |
{ name: 'one - 2', branches: null, prs: null, workspaces: 'four - 2', lastCommit: 'five - 2' }, |
| 17 |
{ name: 'one - 3', branches: 'two - 3', prs: 'three - 3', workspaces: 'four - 3', lastCommit: 'five - 3' } |
| 18 |
]; |
| 19 |
|
| 20 |
const columnNames = { |
| 21 |
name: 'Repositories', |
| 22 |
branches: 'Branches', |
| 23 |
prs: 'Pull requests', |
| 24 |
workspaces: 'Workspaces', |
| 25 |
lastCommit: 'Last commit' |
| 26 |
}; |
| 27 |
|
| 28 |
return ( |
| 29 |
<Table aria-label="Misc table"> |
| 30 |
<Thead noWrap> |
| 31 |
<Tr> |
| 32 |
<Th |
| 33 |
info={{ |
| 34 |
tooltip: 'More information about repositories', |
| 35 |
className: 'repositories-info-tip', |
| 36 |
tooltipProps: { |
| 37 |
isContentLeftAligned: true |
| 38 |
} |
| 39 |
}} |
| 40 |
> |
| 41 |
{columnNames.name} |
| 42 |
</Th> |
| 43 |
<Th>{columnNames.branches}</Th> |
| 44 |
<Th |
| 45 |
info={{ |
| 46 |
popover: ( |
| 47 |
<div> |
| 48 |
More <strong>information</strong> on pull requests |
| 49 |
</div> |
| 50 |
), |
| 51 |
ariaLabel: 'More information on pull requests', |
| 52 |
popoverProps: { |
| 53 |
headerContent: columnNames.prs, |
| 54 |
footerContent: <a href="#">Click here for even more info</a> |
| 55 |
} |
| 56 |
}} |
| 57 |
> |
| 58 |
{columnNames.prs} |
| 59 |
</Th> |
| 60 |
<Th>{columnNames.workspaces}</Th> |
| 61 |
<Th textCenter>{columnNames.lastCommit}</Th> |
| 62 |
</Tr> |
| 63 |
</Thead> |
| 64 |
<Tbody> |
| 65 |
{repositories.map((repo, rowIndex) => { |
| 66 |
const isOddRow = (rowIndex + 1) % 2; |
| 67 |
const customStyle = { |
| 68 |
backgroundColor: t_global_background_color_secondary_default.var |
| 69 |
}; |
| 70 |
// Some arbitrary logic to demonstrate that cell styles can be based on anything |
| 71 |
const nameColSpan = repo.branches === null && repo.prs === null ? 3 : 1; |
| 72 |
const lastCommitTextCenter = rowIndex !== 2; |
| 73 |
return ( |
| 74 |
<Tr |
| 75 |
key={repo.name} |
| 76 |
className={isOddRow ? 'odd-row-class' : 'even-row-class'} |
| 77 |
style={isOddRow ? customStyle : {}} |
| 78 |
> |
| 79 |
<Td dataLabel={columnNames.name} colSpan={nameColSpan}> |
| 80 |
{repo.name} |
| 81 |
</Td> |
| 82 |
<Td dataLabel={columnNames.branches}>{repo.branches}</Td> |
| 83 |
<Td dataLabel={columnNames.prs}></Td> |
| 84 |
<Td dataLabel={columnNames.workspaces}></Td> |
| 85 |
<Td dataLabel={columnNames.lastCommit} textCenter={lastCommitTextCenter}></Td> |
| 86 |
</Tr> |
| 87 |
); |
| 88 |
})} |
| 89 |
</Tbody> |
| 90 |
</Table> |
| 91 |
); |
| 92 |
}; |