Skip to content

Commit

Permalink
feat(#38): add tree monitoring list page component
Browse files Browse the repository at this point in the history
- add filters button
- add table information
- add table pagination
  • Loading branch information
mari1912 committed Jul 2, 2024
1 parent d15f7a8 commit 766458b
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 44 deletions.
6 changes: 3 additions & 3 deletions dashboard/src/components/Dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import SideMenu from "../SideMenu/SideMenu";
import TreeTable from "../Table/TreeTable";
import TopBar from "../TopBar/TopBar";
import TreeMonitorListingPage from "../TreeMonitorListingPage/TreeMonitorListingPage";

const Dashboard = () : JSX.Element => {
return (
<div className="w-full h-full">
<div className="flex flex-row w-full justify-between">
<SideMenu />
<TopBar />
<div className="w-full px-16 pt-64 bg-lightGray">
<TreeTable />
<div className="w-full px-16 pt-24 bg-lightGray">
<TreeMonitorListingPage />
</div>
</div>
</div>
Expand Down
46 changes: 6 additions & 40 deletions dashboard/src/components/Table/TreeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import { TableRow, TableCell } from "../ui/table";

import BaseTable from "./BaseTable";

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

interface ITreeTable {
treeTableRows: ITreeTableBody[];
}

const treeTableColumnsLabelId = [
'treeTable.tree',
'treeTable.branch',
Expand All @@ -20,44 +24,6 @@ const treeTableColumnsLabelId = [
'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>
Expand All @@ -70,7 +36,7 @@ const TreeTableRow = (row: ITreeTableBody): JSX.Element => {
);
};

const TreeTable = () : JSX.Element => {
const TreeTable = ({treeTableRows}: ITreeTable) : JSX.Element => {
const treeTableBody = useMemo(() => {
return (
treeTableRows.map((row: ITreeTableBody) => (
Expand Down
3 changes: 2 additions & 1 deletion dashboard/src/components/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const TopBar = (): JSX.Element => {
</span>
<div className="flex w-2/3 px-6 items-center">
{/* placeholder for search */}
<Input className="w-2/3" type="text" placeholder="Search" />
{/* TODO: use i18n for the input placeholder */}
<Input className="w-2/3" type="text" placeholder="Search by tree, branch or tag" />
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
import { FormattedMessage } from "react-intl";

import { MdArrowBackIos, MdArrowForwardIos, MdExpandMore } from "react-icons/md";

import { useCallback, useState } from "react";

import TreeTable, { ITreeTableBody } from "../Table/TreeTable";
import { Button } from "../ui/button";


interface ITableInformation {
startIndex: number;
endIndex: number;
totalTrees: number;
itemsPerPage: number;
onClickForward: () => void;
onClickBack: () => void;
}

const TableInfo = ({
startIndex,
endIndex,
totalTrees,
itemsPerPage,
onClickForward,
onClickBack,
}: ITableInformation): JSX.Element => {
const buttonsClassName = "text-lightBlue font-bold"
const groupsClassName = "flex flex-row items-center gap-2"
return (
<div className="flex flex-row gap-4 text-sm">
<div className={groupsClassName}>
<FormattedMessage id="table.showing"/>
<span className="font-bold">{startIndex} - {endIndex}</span>
<FormattedMessage id="table.of"/>
<span className="font-bold">{totalTrees}</span>
<FormattedMessage id="table.tree"/>
</div>
<div className={groupsClassName}>
<FormattedMessage id="table.itemsPerPage"/>
<span className="font-bold">{itemsPerPage}</span>
<MdExpandMore className={buttonsClassName}/>
</div>
<div className="flex flex-row gap-2 items-center">
<Button variant="outline" onClick={onClickBack}>
<MdArrowBackIos className={buttonsClassName}/>
</Button>
<Button variant="outline" onClick={onClickForward}>
<MdArrowForwardIos className={buttonsClassName}/>
</Button>
</div>
</div>
);
};

const TreeMonitorListingPage = (): JSX.Element => {
const listItems = treeTableRows;
const itemsPerPage = 10;
const [startIndex, setStartIndex] = useState(0);
const [endIndex, setEndIndex] = useState(listItems.length+1 > itemsPerPage ? itemsPerPage : listItems.length+1);

const onClickGoForward = useCallback(() => {
setStartIndex(endIndex);
setEndIndex(endIndex+itemsPerPage >= listItems.length ? listItems.length : endIndex+itemsPerPage)
}, [endIndex, listItems]);

const onClickGoBack = useCallback(() => {
setStartIndex(startIndex-itemsPerPage);
setEndIndex(endIndex % itemsPerPage !== 0 ? endIndex - endIndex % itemsPerPage : endIndex - itemsPerPage);
}, [startIndex, endIndex]);

return (
<div className="flex flex-col gap-6">
<div className="flex flex-col items-end gap-4">
<Button variant="outline" className="rounded-full w-[128px] border-black">
<div className="flex flex-row gap-1 items-center">
<FormattedMessage id="global.filters" />
<MdExpandMore />
</div>
</Button>
<TableInfo
startIndex={startIndex+1}
endIndex={endIndex}
totalTrees={listItems.length}
itemsPerPage={itemsPerPage}
onClickBack={onClickGoBack}
onClickForward={onClickGoForward}
/>
</div>
<TreeTable treeTableRows={listItems.slice(startIndex, endIndex)}/>
<div className="flex flex-col items-end">
<TableInfo
startIndex={startIndex+1}
endIndex={endIndex}
totalTrees={listItems.length}
itemsPerPage={itemsPerPage}
onClickBack={onClickGoBack}
onClickForward={onClickGoForward}
/>
</div>
</div>
);
};

const treeTableRows: ITreeTableBody[] = [
{
name: "stable-rc1",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "150 completed",
testStatus: "80 completed"
},
{
name: "stable-rc2",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc3",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc4",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc5",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc6",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "150 completed",
testStatus: "80 completed"
},
{
name: "stable-rc7",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc8",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc9",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc10",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc11",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
},
{
name: "stable-rc12",
branch: "linux-5.15",
commit: "asidnasidn-oqiwejeoij-oaidnosdnk",
buildStatus: "10 completed",
testStatus: "150 completed"
}
];

export default TreeMonitorListingPage;

0 comments on commit 766458b

Please sign in to comment.