Added error boundary to the ByAsset page. Added useRef to the SimpleTable utility.
This commit is contained in:
@@ -30,6 +30,7 @@ import Tab from '@mui/material/Tab';
|
|||||||
import TabContext from '@mui/lab/TabContext';
|
import TabContext from '@mui/lab/TabContext';
|
||||||
import TabList from '@mui/lab/TabList';
|
import TabList from '@mui/lab/TabList';
|
||||||
import TabPanel from '@mui/lab/TabPanel';
|
import TabPanel from '@mui/lab/TabPanel';
|
||||||
|
import {ErrorBoundary} from "react-error-boundary";
|
||||||
|
|
||||||
const cssTwoColumnContainer = {
|
const cssTwoColumnContainer = {
|
||||||
display: 'grid',
|
display: 'grid',
|
||||||
@@ -174,7 +175,8 @@ const AssignmentsByAsset = () => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ul>
|
<ul>
|
||||||
{data.map((next, i) => (
|
<ErrorBoundary fallback={<li>Error</li>}>
|
||||||
|
{data && data.map && data.map((next, i) => (
|
||||||
<li key={next._id}>
|
<li key={next._id}>
|
||||||
{next.person && (
|
{next.person && (
|
||||||
<>
|
<>
|
||||||
@@ -198,6 +200,7 @@ const AssignmentsByAsset = () => {
|
|||||||
{/*)}*/}
|
{/*)}*/}
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
|
</ErrorBoundary>
|
||||||
</ul>
|
</ul>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, {useRef, useState} from 'react';
|
||||||
import Table from '@mui/material/Table';
|
import Table from '@mui/material/Table';
|
||||||
import TableBody from '@mui/material/TableBody';
|
import TableBody from '@mui/material/TableBody';
|
||||||
import TableCell from '@mui/material/TableCell';
|
import TableCell from '@mui/material/TableCell';
|
||||||
@@ -48,6 +48,7 @@ const cssTopControls = {
|
|||||||
*/
|
*/
|
||||||
export default ({columns, rows, options}) => {
|
export default ({columns, rows, options}) => {
|
||||||
const [selected, setSelected] = useState(undefined);
|
const [selected, setSelected] = useState(undefined);
|
||||||
|
const tableContainer = useRef(null)
|
||||||
|
|
||||||
let selectRow = (e, row) => {
|
let selectRow = (e, row) => {
|
||||||
setSelected(row);
|
setSelected(row);
|
||||||
@@ -67,6 +68,7 @@ export default ({columns, rows, options}) => {
|
|||||||
|
|
||||||
const addRow = () => {
|
const addRow = () => {
|
||||||
setEdited({});
|
setEdited({});
|
||||||
|
setTimeout(() => tableContainer.current.scrollTo({top: 0, left: 0, behavior: "smooth"}),0)
|
||||||
}
|
}
|
||||||
|
|
||||||
let containerStyle = options.maxHeight ? {maxHeight: options.maxHeight} : {}
|
let containerStyle = options.maxHeight ? {maxHeight: options.maxHeight} : {}
|
||||||
@@ -131,7 +133,7 @@ export default ({columns, rows, options}) => {
|
|||||||
{options.add && <Button variant="text" className="button" onClick={addRow}>Add</Button>}
|
{options.add && <Button variant="text" className="button" onClick={addRow}>Add</Button>}
|
||||||
{options.remove && _.isFunction(options.remove) && <Button disabled={!selected} variant='text' className='button' onClick={() => {selected && options.remove(selected)}}>Remove</Button>}
|
{options.remove && _.isFunction(options.remove) && <Button disabled={!selected} variant='text' className='button' onClick={() => {selected && options.remove(selected)}}>Remove</Button>}
|
||||||
</div>
|
</div>
|
||||||
<TableContainer className="simpleTable" component={Paper} style={containerStyle}>
|
<TableContainer ref={tableContainer} className="simpleTable" component={Paper} style={containerStyle}>
|
||||||
<Table size="small" aria-label="Table" tabIndex="0" onKeyDown={keyHandler}>
|
<Table size="small" aria-label="Table" tabIndex="0" onKeyDown={keyHandler}>
|
||||||
<TableHead className="sticky">
|
<TableHead className="sticky">
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
"mongodb": "^4.4.1",
|
"mongodb": "^4.4.1",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
|
"react-error-boundary": "^4.0.11",
|
||||||
"react-router-dom": "^6.3.0",
|
"react-router-dom": "^6.3.0",
|
||||||
"typescript": "^4.8.4",
|
"typescript": "^4.8.4",
|
||||||
"umbrellajs": "^3.3.1",
|
"umbrellajs": "^3.3.1",
|
||||||
|
|||||||
Reference in New Issue
Block a user