From 564875c32ebc06d812031bd8fd67c12c39a07b19 Mon Sep 17 00:00:00 2001 From: Jan Prochazka Date: Sat, 25 Jan 2020 21:13:53 +0100 Subject: [PATCH] fix --- web/package.json | 1 + web/src/tabs/TableDataTab.js | 104 ++++++++++++++++++++++++++++++----- web/src/utility/useFetch.js | 3 +- 3 files changed, 93 insertions(+), 15 deletions(-) diff --git a/web/package.json b/web/package.json index b3d553d4..f72fdbe8 100644 --- a/web/package.json +++ b/web/package.json @@ -11,6 +11,7 @@ "eslint": "^6.8.0", "eslint-plugin-react": "^7.17.0", "formik": "^2.1.0", + "json-stable-stringify": "^1.0.1", "react": "^16.12.0", "react-dom": "^16.12.0", "react-modal": "^3.11.1", diff --git a/web/src/tabs/TableDataTab.js b/web/src/tabs/TableDataTab.js index bc90d8fd..cbc27b3e 100644 --- a/web/src/tabs/TableDataTab.js +++ b/web/src/tabs/TableDataTab.js @@ -1,9 +1,77 @@ import React from 'react'; import useFetch from '../utility/useFetch'; -import { scryRenderedComponentsWithType } from 'react-dom/test-utils'; +import styled from 'styled-components'; +import theme from '../theme'; + +// const Table = styled.table` +// position: absolute; +// left:0; +// top:0: +// bottom:0; +// right:0; +// overflow: scroll; +// `; +// const TableHead = styled.thead` +// // display: block; +// // width: 300px; +// `; +// const TableBody = styled.tbody` +// // display: block; +// // overflow: auto; +// // height: 100px; +// `; +// const TableHeaderRow = styled.tr` +// height: 35px; +// `; +// const TableBodyRow = styled.tr` +// height: 35px; +// `; +// const TableHeaderCell = styled.td` +// font-weight: bold; +// `; +// const TableBodyCell = styled.td` +// white-space: nowrap; +// `; + +const Table = styled.div` + overflow-x: scroll; + width: 500px; + position: absolute; + left:0; + top:0: + bottom:0; + right:0; +`; +const TableHead = styled.div` + // display: block; + // width: 300px; + // width:700px; +`; +const TableBody = styled.div` + // display: block; + overflow-y: scroll; + height: 200px; +`; +const TableHeaderRow = styled.div` + display: flex; + height: 35px; +`; +const TableBodyRow = styled.div` + display: flex; + height: 35px; +`; +const TableHeaderCell = styled.div` + font-weight: bold; + width: 160px; + overflow: hidden; +`; +const TableBodyCell = styled.div` + white-space: nowrap; + width: 160px; + overflow: hidden; +`; export default function TableDataTab({ conid, database, schemaName, pureName }) { - // return pureName; const data = useFetch({ url: 'tables/table-data', params: { @@ -16,19 +84,27 @@ export default function TableDataTab({ conid, database, schemaName, pureName }) const { rows, columns } = data || {}; if (!columns || !rows) return null; return ( - - - {columns.map(col => ( - - ))} - - {rows.map((row, index) => ( - +
{col.name}
+ + {columns.map(col => ( - + + {col.name} + ))} - - ))} -
{row[col.name]}
+ + + + {rows.map((row, index) => ( + + {columns.map(col => ( + + {row[col.name]} + + ))} + + ))} + + ); } diff --git a/web/src/utility/useFetch.js b/web/src/utility/useFetch.js index b030b9a7..87883f7b 100644 --- a/web/src/utility/useFetch.js +++ b/web/src/utility/useFetch.js @@ -1,6 +1,7 @@ import React from 'react'; import axios from './axios'; import useSocket from './SocketProvider'; +import stableStringify from 'json-stable-stringify'; export default function useFetch({ url, @@ -34,7 +35,7 @@ export default function useFetch({ socket.off(reloadTrigger, handleReload); }; } - }, [url, params, socket, loadCounter]); + }, [url, stableStringify(params), socket, loadCounter]); return value; }