Fix crash on car table (#158) (#159)

This commit is contained in:
John Wu
2022-05-23 15:26:36 -07:00
committed by GitHub
parent 23111f9c3a
commit 7c7f3889de

View File

@@ -48,7 +48,15 @@ const tableColumns = [
]; ];
const CarSelectionTable = (props) => { const CarSelectionTable = (props) => {
const { token, classes, search, multiSelect, selected, onSelect, onSelectAll } = props; const {
token,
classes,
search,
multiSelect,
selected,
onSelect,
onSelectAll,
} = props;
const [pageSize, setPageSize] = useState(10); const [pageSize, setPageSize] = useState(10);
const [pageIndex, setPageIndex] = useState(0); const [pageIndex, setPageIndex] = useState(0);
const [orderBy, setOrderBy] = useState("vin"); const [orderBy, setOrderBy] = useState("vin");
@@ -126,19 +134,23 @@ const CarSelectionTable = (props) => {
multiSelect={multiSelect} multiSelect={multiSelect}
onSelectAll={handleSelectAll} onSelectAll={handleSelectAll}
selectCount={selected ? selected.length : 0} selectCount={selected ? selected.length : 0}
rowCount={vehicles.length} rowCount={vehicles ? vehicles.length : 0}
/> />
<TableBody> <TableBody>
{vehicles.map((row) => { {vehicles.map((row) => {
const isSelected = selected ? selected.indexOf(row.vin) !== -1 : false; const isSelected = selected
? selected.indexOf(row.vin) !== -1
: false;
return ( return (
<TableRow key={row.vin}> <TableRow key={row.vin}>
{multiSelect && (<TableCell padding="checkbox"> {multiSelect && (
<TableCell padding="checkbox">
<Checkbox <Checkbox
checked={isSelected} checked={isSelected}
onChange={(event) => handleSelect(event, row.vin)} onChange={(event) => handleSelect(event, row.vin)}
/> />
</TableCell>)} </TableCell>
)}
<TableCell align="center"> <TableCell align="center">
<ConnectedIcon <ConnectedIcon
connected={row.connected} connected={row.connected}