diff --git a/package-lock.json b/package-lock.json index 70021c4..115561d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12700,6 +12700,11 @@ } } }, + "react-table": { + "version": "7.5.1", + "resolved": "https://registry.npmjs.org/react-table/-/react-table-7.5.1.tgz", + "integrity": "sha512-rprrUElCqvj79lyY2XbUoYLzwA5Mm4CGS8ElQ8OyzocvmkvCcmunvvfbpIg9Jm9HnMBjVZcVyPFPZ1BFelIBKw==" + }, "react-to-print": { "version": "2.10.0", "resolved": "https://registry.npmjs.org/react-to-print/-/react-to-print-2.10.0.tgz", diff --git a/package.json b/package.json index d5bc649..d2c0f1d 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,8 @@ "mui-datatables": "^3.4.1", "react": "^16.13.1", "react-dom": "^16.13.1", - "react-scripts": "3.4.1" + "react-scripts": "3.4.1", + "react-table": "^7.5.1" }, "scripts": { "start:frontend": "react-scripts start", diff --git a/src/App.js b/src/App.js index d573c3f..e1cdcf0 100644 --- a/src/App.js +++ b/src/App.js @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useState, useEffect } from "react"; import { ThemeProvider } from "@material-ui/core/styles"; import webqueueTheme from "./theme"; import { Box, makeStyles, Paper } from "@material-ui/core"; @@ -7,6 +7,7 @@ import ItemTable from "./components/ItemTable/"; import ItemViewAppBar from "./components/ItemViewAppBar/"; import ItemView from "./components/ItemView/"; import clsx from "clsx"; +import ReactTable from "./components/ItemTable/ReactTable"; function App(){ const [darkMode, setDarkMode] = useState(false); @@ -49,13 +50,69 @@ function App(){ const classes = useStyles(); + const columns = React.useMemo( + () => [ + { + Header: 'Queue', + accessor: 'queue', // accessor is the "key" in the data + }, + { + Header: 'Item #', + accessor: 'number', + }, + { + Header: 'Assigned To', + accessor: 'assignedTo', + }, + { + Header: 'Subject', + accessor: 'subject', + }, + { + Header: 'Status', + accessor: 'status', + }, + { + Header: 'Priority', + accessor: 'priority', + }, + { + Header: 'Last Updated', + accessor: 'lastUpdated', + }, + { + Header: 'Department', + accessor: 'department', + }, + { + Header: 'Building', + accessor: 'building', + }, + { + Header: 'Date Received', + accessor: 'dateReceived', + }, + + ], + [] + ); + + const [data, setData] = useState([]) + + useEffect(() => { + fetch("/api/ce").then(res => res.json()).then(queue => { + setData(queue.items) + }) + }, []); + return ( - + {/* */} + diff --git a/src/components/ItemTable/ReactTable.js b/src/components/ItemTable/ReactTable.js new file mode 100644 index 0000000..17ccdae --- /dev/null +++ b/src/components/ItemTable/ReactTable.js @@ -0,0 +1,51 @@ +import { Table, TableBody, TableCell, TableHead, TableRow, TableContainer, Paper, TextField } from "@material-ui/core"; +import React from "react"; +import { useTable } from "react-table"; + +export default function ReactTable({ columns, data }) { + // Use the useTable Hook to send the columns and data to build the table + const { + getTableProps, // table props from react-table + getTableBodyProps, // table body props from react-table + headerGroups, // headerGroups, if your table has groupings + rows, // rows for the table based on the data passed + prepareRow // Prepare the row (this function needs to be called for each row before getting the row props) + } = useTable({ + columns, + data + }); + + + + return ( + + + + + {headerGroups.map(headerGroup => ( + + {headerGroup.headers.map(column => ( + {column.render("Header")} + ))} + + ))} + + + + + {rows.map((row, i) => { + prepareRow(row); + return ( + + {row.cells.map(cell => { + return {cell.render("Cell")}; + })} + + ); + })} + +
+
+ + ); +} \ No newline at end of file