working stream table

This commit is contained in:
karl.hudgell 2021-02-21 11:22:57 +00:00
parent c4700137f4
commit f32a949f25
3 changed files with 88 additions and 43 deletions

View File

@ -1,12 +1,10 @@
import React from "react"; import React from "react";
import MTable from "./accountTable"; import MTable from "./accountTable";
function About() { function About() {
return ( return (
<div style={{ padding: "30px" }}> <div style={{ padding: "30px" }}>
<h1>Material Table Example</h1> <MTable/>
<MTable />
</div> </div>
); );
} }

View File

@ -1,42 +1,88 @@
import { useState } from "react"; import React, { Component } from "react";
import axios from "axios"; // npm instal axios
import { forwardRef } from "react";
import MaterialTable from "material-table"; import MaterialTable from "material-table";
import { data } from "../data"; import ArrowDownward from "@material-ui/icons/ArrowDownward";
import ChevronLeft from "@material-ui/icons/ChevronLeft";
import ChevronRight from "@material-ui/icons/ChevronRight";
import Clear from "@material-ui/icons/Clear";
import FilterList from "@material-ui/icons/FilterList";
import FirstPage from "@material-ui/icons/FirstPage";
import LastPage from "@material-ui/icons/LastPage";
import Search from "@material-ui/icons/Search";
const MTable = () => { const tableIcons = {
// let res // DetailPanel: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
// try { Filter: forwardRef((props, ref) => <FilterList {...props} ref={ref} />),
// res = axios.get("/getUserAccounts", { FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
// data: { LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
// username: "Duly", NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
// }, PreviousPage: forwardRef((props, ref) => (
// }); <ChevronLeft {...props} ref={ref} />
// } catch (error) { )),
// console.log(error); ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
// } Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
const [selectedRow, setSelectedRow] = useState(null); SortArrow: forwardRef((props, ref) => <ArrowDownward {...props} ref={ref} />),
const columns = [ };
{ title: "UserName", field: "username" },
{ title: "Stream Name", field: "streamName" }, export default class MatDataTable extends Component {
{ title: "Stream URL", field: "streamURL" }, constructor(props) {
]; super(props);
return ( this.state = { person: [] };
<div style={{ maxWidth: "100%" }}>
<MaterialTable
columns={columns}
data={res}
title="Books Directory"
onRowClick={(evt, selectedRow) =>
setSelectedRow(selectedRow.tableData.id)
} }
componentDidMount(prevProps) {
const user = "Karl";
const url = `/getUserAccounts?userName=${user}`;
axios.get(url).then((results) => {
console.log(results);
console.log(results.data);
this.setState({ person: results.data });
var newArr = results.data.map(function (val) {
return {
username: val.username,
streamName: val.streamName,
streamURL: val.streamURL,
expiaryDate: val.expiaryDate
};
});
console.log(results.data.results);
this.setState(
{
tableArray: newArr, //set state of the weather5days
},
() => {
console.log(this.state.tableArray);
console.log("this.tableArray ", this.state.tableArray);
}
);
});
}
render() {
return (
<div style={{ maxWidth: "100%", marginLeft: "50px", marginRight: "50px" }}>
<MaterialTable
icons={tableIcons}
options={{ options={{
search: false, grouping: false,
rowStyle: (rowData) => ({
backgroundColor:
selectedRow === rowData.tableData.id ? "#67aeae" : "#FFF",
}),
}} }}
columns={[
{
title: "userName",
field: "username",
type: "numeric",
align: "left",
},
{ title: "streamName", field: "streamName" },
{ title: "streamURL", field: "streamURL" },
{ title: "Expires", field: "expiaryDate", type: "numeric" },
]}
data={this.state.tableArray}
title="Stream Details"
/> />
</div> </div>
); );
}; }
export default MTable; }

View File

@ -4,7 +4,8 @@ function getUserAccounts(user) {
let data = sql.query(`SELECT let data = sql.query(`SELECT
userAccounts.username, userAccounts.username,
streams.streamName, streams.streamName,
streams.streamURL streams.streamURL,
userAccounts.expiaryDate
FROM users FROM users
INNER JOIN userAccounts INNER JOIN userAccounts
ON users.idusers = userAccounts.userID ON users.idusers = userAccounts.userID