Skip to content

Commit

Permalink
feat(#19): add table components
Browse files Browse the repository at this point in the history
- add a basic table component
- add a tree table component
  • Loading branch information
mari1912 committed Jun 28, 2024
1 parent dc1e326 commit 4ec322b
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 2 deletions.
31 changes: 31 additions & 0 deletions dashboard/src/components/Table/BaseTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { ReactElement } from "react";

import { FormattedMessage } from "react-intl";

import { Table, TableHead, TableHeader, TableRow } from "../ui/table"

interface IBaseTable {
headers: string[];
body: ReactElement;
}

const BaseTable = ({headers, body}: IBaseTable) : JSX.Element => {
return (
<div>
<Table className="rounded-lg text-black bg-white w-full">
<TableHeader className="bg-mediumGray">
<TableRow>
{headers.map((column) => (
<TableHead className="text-black border-b" key={column}>
<FormattedMessage id={column}/>
</TableHead>
))}
</TableRow>
</TableHeader>
{body}
</Table>
</div>
);
};

export default BaseTable;
94 changes: 94 additions & 0 deletions dashboard/src/components/Table/TreeTable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { useMemo } from "react";

import { TableRow, TableCell } from "../ui/table";

import BaseTable from "./BaseTable";

interface ITreeTableBody {
name: string;
branch: string;
commit: string;
buildStatus: string;
testStatus: string;
}

const treeTableColumnsLabelId = [
'treeTable.tree',
'treeTable.branch',
'treeTable.commit',
'treeTable.build',
'treeTable.test'
];

const treeTableRows: ITreeTableBody[] = [
{
name: "stable-rc",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "150 completed",
testStatus: "80 completed"
},
{
name: "stable-rc",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
}
];

const TreeTableRow = (row: ITreeTableBody): JSX.Element => {
return (
<TableRow>
<TableCell>{row.name}</TableCell>
<TableCell>{row.branch}</TableCell>
<TableCell>{row.commit}</TableCell>
<TableCell><div className="bg-lightGray w-fit h-fit p-1 rounded-lg">{row.buildStatus}</div></TableCell>
<TableCell><div className="bg-lightGray w-fit h-fit p-1 rounded-lg">{row.testStatus}</div></TableCell>
</TableRow>
);
};

const TreeTable = () : JSX.Element => {
const treeTableBody = useMemo(() => {
return (
treeTableRows.map((row: ITreeTableBody) => (
<TreeTableRow
key={row.commit}
name={row.name}
branch={row.branch}
commit={row.commit}
buildStatus={row.buildStatus}
testStatus={row.testStatus}/>
))
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [treeTableRows]);

return(
<BaseTable headers={treeTableColumnsLabelId} body={<>{treeTableBody}</>} />
);
}

export default TreeTable;
2 changes: 1 addition & 1 deletion dashboard/src/components/ui/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const Table = React.forwardRef<
HTMLTableElement,
React.HTMLAttributes<HTMLTableElement>
>(({ className, ...props }, ref) => (
<div className="relative w-full overflow-auto">
<div className="relative w-full overflow-auto rounded-lg border-t border-x border-darkGray">
<table
ref={ref}
className={cn("w-full caption-bottom text-sm", className)}
Expand Down
7 changes: 7 additions & 0 deletions dashboard/src/locales/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,12 @@ export const messages = {
deviceMonitor: "Device Monitor",
labsMonitor: "Labs Monitor",
},
treeTable: {
tree: "Tree",
branch: "Branch",
commit: "Commit/tag",
build: "Build Status",
test: "Test Status",
}
},
};
1 change: 0 additions & 1 deletion dashboard/tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ module.exports = {
},
colors: {
'bgSecondary' : '#343638',
'onSecondary' : '#FFFFFF',
'lightBlue': '#11B3E6',
'onSecondary-10': '#FFFFFF1A',
"white": '#FFFFFF',
Expand Down

0 comments on commit 4ec322b

Please sign in to comment.