Merge branch 'development' into main

This commit is contained in:
jwu-fisker
2021-06-02 11:37:41 -07:00
22 changed files with 4794 additions and 3414 deletions

View File

@@ -91,6 +91,10 @@ describe("App", () => {
await check("/vehicles-command", "span.MuiButton-label", "Sign In");
});
it("Route /dashboard unauthenticated", async () => {
await check("/dashboard", "span.MuiButton-label", "Sign In");
});
it("Route / authenticated", async () => {
setToken(TEST_AUTH_OBJECT);
await check("/", "h1", "Welcome John!");
@@ -154,4 +158,10 @@ describe("App", () => {
setToken(TEST_AUTH_OBJECT);
await check("/carupdate-deploy/1", "h6", "Deploy ");
});
it("Route /dashboard authenticated", async () => {
setToken(TEST_AUTH_OBJECT);
await check("/dashboard", "h6", "Dashboard");
});
});

File diff suppressed because it is too large Load Diff

View File

@@ -1,15 +1,17 @@
import React, { useEffect, useState } from "react";
import { useParams, Redirect } from "react-router";
import { Button, Typography } from "@material-ui/core";
import { Button, Grid, Typography } from "@material-ui/core";
import {
UpdatesProvider,
useUpdatesContext,
} from "../../Contexts/UpdatesContext";
import { VehicleProvider } from "../../Contexts/VehicleContext";
import { useUserContext } from "../../Contexts/UserContext";
import { useStatusContext } from "../../Contexts/StatusContext";
import CarSelection from "../../Cars/CarSelection";
import useStyles from "../../useStyles";
import { tsLocalDateTimeString } from "../../../utils/dates";
import SearchField from "../../Controls/SearchField";
import CarSelectionTable from "../../Cars/CarSelectionTable";
const MainForm = () => {
const { packageid } = useParams();
@@ -24,20 +26,41 @@ const MainForm = () => {
const [version, setVersion] = useState("");
const [description, setDescription] = useState("");
const [createDate, setCreateDate] = useState("");
const [selectedVehicles, setSelectedVehicles] = useState([]);
const [selected, setSelected] = useState([]);
const [search, setSearch] = useState("");
const [redirect, setRedirect] = useState("");
const classes = useStyles();
const handleSearch = (search) => {
setSelected([]);
setSearch(search);
};
const handleSelectAll = (cars) => {
setSelected(cars);
};
const handleSelect = (event, key) => {
let newSelected;
if (event.target.checked) {
newSelected = [...selected];
newSelected.push(key);
} else {
newSelected = selected.filter((vin) => vin !== key);
}
setSelected(newSelected);
};
const onSubmit = async (event) => {
try {
event.preventDefault();
const data = {
package_id: parseInt(packageid),
vins: selectedVehicles,
vins: selected,
};
await createCarUpdates(data, token);
setMessage(
`Deployed ${packageName} ${version} to ${selectedVehicles.length} cars`
`Deployed ${packageName} ${version} to ${selected.length} cars`
);
setRedirect(`/carupdate-status/${packageid}`);
} catch (e) {
@@ -80,30 +103,48 @@ const MainForm = () => {
<div className={classes.paper}>
<form className={classes.form} noValidate action="{onSubmit}">
<Typography variant="body2">
Created {createDate}. {description}
Created {createDate}. {description || "No description"}
</Typography>
<hr style={{ marginBottom: 30, marginTop: 30 }} />
<CarSelection onSelection={setSelectedVehicles} />
<Button
type="submit"
disabled={busy}
fullWidth
variant="contained"
color="primary"
className={classes.submit}
onClick={onSubmit}
>
{busy ? "Deploying..." : "Deploy"}
</Button>
<Grid container className={classes.root} spacing={2}>
<Grid item md={10}>
<SearchField classes={classes} onSearch={handleSearch} />
<div
className={classes.labelInline}
>{`${selected.length} Selected`}</div>
</Grid>
<Grid item md={2} style={{ textAlign: "right" }}>
<Button
type="submit"
disabled={busy || selected.length === 0}
fullWidth
variant="contained"
color="primary"
className={classes.formControl}
onClick={onSubmit}
>
{busy ? "Deploying..." : "Deploy"}
</Button>
</Grid>
</Grid>
<CarSelectionTable
classes={classes}
token={token}
search={{ search }}
selected={selected}
onSelect={handleSelect}
onSelectAll={handleSelectAll}
/>
</form>
</div>
);
};
const UpdatePackageDeployForm = () => (
<UpdatesProvider>
<MainForm />
</UpdatesProvider>
<VehicleProvider>
<UpdatesProvider>
<MainForm />
</UpdatesProvider>
</VehicleProvider>
);
export default UpdatePackageDeployForm;

View File

@@ -1,11 +1,11 @@
import React, { useEffect, useState } from "react";
import { useParams } from "react-router";
import { Link } from "react-router-dom";
import {
LinearProgress,
Table,
TableBody,
TableCell,
TableContainer,
TableFooter,
TableHead,
TablePagination,
@@ -20,14 +20,12 @@ import { useUserContext } from "../../Contexts/UserContext";
import { useStatusContext } from "../../Contexts/StatusContext";
import useStyles from "../../useStyles";
import { LocalDateTimeString } from "../../../utils/dates";
import VehicleStatus from "../../Cars/StatusModal";
const MainForm = () => {
const { packageid } = useParams();
const classes = useStyles();
const [pageSize, setPageSize] = useState(10);
const [pageIndex, setPageIndex] = useState(0);
const [viewVIN, setViewVIN] = useState(null);
const {
getCarUpdates,
carUpdates,
@@ -99,75 +97,58 @@ const MainForm = () => {
setPageIndex(0);
};
const handleViewVIN = (event) => {
event.preventDefault();
setViewVIN(event.target.innerHTML);
};
const handleCloseViewVIN = (event) => {
setViewVIN(null);
};
return (
<div className={classes.paper} style={{ height: 700, width: "100%" }}>
<TableContainer>
<Table>
<TableHead>
<TableRow>
<TableCell align="center">ID</TableCell>
<TableCell align="center">Vehicle</TableCell>
<TableCell align="center">Status</TableCell>
<TableCell align="center">Created</TableCell>
<TableCell align="center">Updated</TableCell>
<Table>
<TableHead>
<TableRow>
<TableCell align="center">ID</TableCell>
<TableCell align="center">Vehicle</TableCell>
<TableCell align="center">Status</TableCell>
<TableCell align="center">Created</TableCell>
<TableCell align="center">Updated</TableCell>
</TableRow>
</TableHead>
<TableBody>
{carUpdates.map((row) => (
<TableRow key={row.id}>
<TableCell align="center">{row.id}</TableCell>
<TableCell align="center">
<Link to={`/vehicle-status/${row.vin}`}>{row.vin}</Link>
</TableCell>
<TableCell align="center">
{row.status}
{row.progress > 0 && (
<LinearProgress variant="determinate" value={row.progress} />
)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.updated)}
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{carUpdates.map((row) => (
<TableRow key={row.id}>
<TableCell align="center">{row.id}</TableCell>
<TableCell align="center">
<span className={classes.link} onClick={handleViewVIN}>
{row.vin}
</span>
</TableCell>
<TableCell align="center">
{row.status}
{row.progress > 0 && (
<LinearProgress
variant="determinate"
value={row.progress}
/>
)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.updated)}
</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={5}
count={totalCarUpdates}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
</TableRow>
</TableFooter>
</Table>
</TableContainer>
<VehicleStatus vin={viewVIN} handleClose={handleCloseViewVIN} />
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={5}
count={totalCarUpdates}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
</TableRow>
</TableFooter>
</Table>
</div>
);
};

View File

@@ -21,6 +21,7 @@ const MainForm = () => {
const vinEl = useRef(null);
const modelEl = useRef(null);
const yearEl = useRef(null);
const trimEl = useRef(null);
useEffect(() => {
setTitle("Add Vehicle");
@@ -34,6 +35,7 @@ const MainForm = () => {
vin: vinEl.current.value,
model: modelEl.current.value,
year: parseInt(yearEl.current.value),
trim: trimEl.current.value,
};
const result = await addVehicle(formData, token);
@@ -91,6 +93,21 @@ const MainForm = () => {
fullWidth
inputRef={yearEl}
/>
<TextField
id="trim"
name="trim"
label="Trim"
defaultValue="Base"
variant="outlined"
margin="normal"
inputProps={{
maxLength: "4",
minLength: "4",
}}
required
fullWidth
inputRef={trimEl}
/>
<Button
type="submit"
disabled={busy}

View File

@@ -11,14 +11,8 @@ import useStyles from "../../useStyles";
const Control = (props) => {
const classes = useStyles();
const {
models,
years,
vehicles,
getModels,
getYears,
getVehicles,
} = useVehicleContext();
const { models, years, vehicles, getModels, getYears, getVehicles } =
useVehicleContext();
const {
token: {
idToken: { jwtToken: token },
@@ -26,6 +20,7 @@ const Control = (props) => {
} = useUserContext();
const [model, setModel] = useState("");
const [year, setYear] = useState(-1);
const [trim, setTrim] = useState("");
const handleChangeModel = (event) => {
setModel(event.target.value);
@@ -33,6 +28,9 @@ const Control = (props) => {
const handleChangeYear = (event) => {
setYear(event.target.value);
};
const handleChangeTrim = (event) => {
setTrim(event.target.value);
};
useEffect(() => {
if (!token) return;
@@ -57,9 +55,9 @@ const Control = (props) => {
useEffect(() => {
if (model === null || year === -1) return;
getVehicles({ model, year }, token);
getVehicles({ model, year, trim }, token);
// eslint-disable-next-line
}, [model, year]);
}, [model, year, trim]);
useEffect(() => {
if (!props.onSelection) return;
@@ -69,56 +67,80 @@ const Control = (props) => {
}, [vehicles]);
return (
<div className={classes.form}>
<FormControl className={classes.formControlInline} variant="outlined">
<InputLabel htmlFor="car-model" style={{ backgroundColor: "White" }}>
Model
</InputLabel>
<Select
native
value={model}
onChange={handleChangeModel}
variant="outlined"
inputProps={{
name: "car-model",
id: "car-model",
}}
>
{models.map((item) => (
<option key={item} value={item}>
{item}
</option>
))}
</Select>
</FormControl>
<FormControl className={classes.formControlInline} variant="outlined">
<InputLabel htmlFor="car-year" style={{ backgroundColor: "White" }}>
Year
</InputLabel>
<Select
native
value={year}
onChange={handleChangeYear}
variant="outlined"
inputProps={{
name: "car-year",
id: "car-year",
}}
>
{years.map((item) => (
<option key={item} value={item}>
{item}
</option>
))}
</Select>
</FormControl>
<div className={classes.labelInline}>
{vehicles.length === 0
? "No Cars Selected"
: vehicles.length === 1
? "1 Car Selected"
: `${vehicles.length} Cars Selected`}
<div className={classes.paper}>
<div className={classes.form}>
<FormControl className={classes.formControlInline} variant="outlined">
<InputLabel htmlFor="car-model" style={{ backgroundColor: "White" }}>
Model
</InputLabel>
<Select
native
value={model}
onChange={handleChangeModel}
variant="outlined"
inputProps={{
name: "car-model",
id: "car-model",
}}
>
{models.map((item) => (
<option key={item} value={item}>
{item}
</option>
))}
</Select>
</FormControl>
<FormControl className={classes.formControlInline} variant="outlined">
<InputLabel htmlFor="car-year" style={{ backgroundColor: "White" }}>
Year
</InputLabel>
<Select
native
value={year}
onChange={handleChangeYear}
variant="outlined"
inputProps={{
name: "car-year",
id: "car-year",
}}
>
{years.map((item) => (
<option key={item} value={item}>
{item}
</option>
))}
</Select>
</FormControl>
<FormControl className={classes.formControlInline} variant="outlined">
<InputLabel htmlFor="car-trim" style={{ backgroundColor: "White" }}>
Trim
</InputLabel>
<Select
native
value={year}
onChange={handleChangeTrim}
variant="outlined"
inputProps={{
name: "car-trim",
id: "car-trim",
}}
>
{years.map((item) => (
<option key={item} value={item}>
{item}
</option>
))}
</Select>
</FormControl>
<div className={classes.labelInline}>
{vehicles.length === 0
? "No Cars Selected"
: vehicles.length === 1
? "1 Car Selected"
: `${vehicles.length} Cars Selected`}
</div>
</div>
<div className={classes.form}></div>
</div>
);
};

View File

@@ -0,0 +1,182 @@
import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import PropTypes from "prop-types";
import {
Checkbox,
Table,
TableBody,
TableCell,
TableFooter,
TablePagination,
TableRow,
} from "@material-ui/core";
import { useVehicleContext } from "../../Contexts/VehicleContext";
import { useStatusContext } from "../../Contexts/StatusContext";
import { LocalDateTimeString } from "../../../utils/dates";
import TableHeaderSortable from "../../Table/HeaderSortable";
const tableColumns = [
{
id: "vin",
label: "VIN",
},
{
id: "model",
label: "Model",
},
{
id: "year",
label: "Year",
},
{
id: "trim",
label: "Trim",
},
{
id: "created_at",
label: "Created",
},
{
id: "updated_at",
label: "Updated",
},
];
const CarSelectionTable = (props) => {
const { token, classes, search, selected, onSelect, onSelectAll } = props;
const [pageSize, setPageSize] = useState(10);
const [pageIndex, setPageIndex] = useState(0);
const [orderBy, setOrderBy] = useState("vin");
const [order, setOrder] = useState("asc");
const { getVehicles, vehicles, totalVehicles } = useVehicleContext();
const { setMessage } = useStatusContext();
const sortHandler = (event, property) => {
if (property === orderBy) {
if (order === "asc") {
setOrder("desc");
} else {
setOrder("asc");
}
} else {
setOrderBy(property);
setOrder("asc");
}
};
const handleChangePageIndex = (event, newIndex) => {
setPageIndex(newIndex);
};
const handleChangePageSize = (event) => {
setPageSize(parseInt(event.target.value, 10));
setPageIndex(0);
};
const handleSelectAll = (event) => {
if (!onSelectAll) return;
const newSelected = [];
if (event.target.checked) {
vehicles.forEach((car) => {
newSelected.push(car.vin);
});
}
onSelectAll(newSelected);
};
const handleSelect = (event, key) => {
if (!onSelect) return;
onSelect(event, key);
};
useEffect(() => {
const options = {
limit: pageSize,
offset: pageSize * pageIndex,
order: `${orderBy} ${order}`,
};
try {
getVehicles(Object.assign(options, search), token);
} catch (e) {
setMessage(e.message);
}
// eslint-disable-next-line
}, [pageIndex, pageSize, orderBy, order, search, token]);
return (
<div className={classes.paper} style={{ height: 700, width: "100%" }}>
<Table>
<TableHeaderSortable
classes={classes}
orderBy={orderBy}
order={order}
columnData={tableColumns}
onSortRequest={sortHandler}
multiSelect={true}
onSelectAll={handleSelectAll}
selectCount={selected.length}
rowCount={vehicles.length}
/>
<TableBody>
{vehicles.map((row) => {
const isSelected = selected.indexOf(row.vin) !== -1;
return (
<TableRow key={row.vin}>
<TableCell padding="checkbox">
<Checkbox
checked={isSelected}
onChange={(event) => handleSelect(event, row.vin)}
/>
</TableCell>
<TableCell align="center">
<Link to={`/vehicle-status/${row.vin}`}>{row.vin}</Link>
</TableCell>
<TableCell align="center">{row.model}</TableCell>
<TableCell align="center">{row.year}</TableCell>
<TableCell align="center">{row.trim || ""}</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.updated)}
</TableCell>
</TableRow>
);
})}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={7}
count={totalVehicles}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
</TableRow>
</TableFooter>
</Table>
</div>
);
};
CarSelectionTable.propTypes = {
token: PropTypes.string.isRequired,
classes: PropTypes.object.isRequired,
search: PropTypes.object.isRequired,
selected: PropTypes.array.isRequired,
onSelect: PropTypes.func.isRequired,
onSelectAll: PropTypes.func.isRequired,
};
export default CarSelectionTable;

View File

@@ -4,7 +4,6 @@ import {
Table,
TableBody,
TableCell,
TableContainer,
TableFooter,
TablePagination,
TableRow,
@@ -117,52 +116,50 @@ const MainForm = () => {
<Toolbar className={classes.tableToolbar}>
<SearchField classes={classes} onSearch={handleSearch} />
</Toolbar>
<TableContainer>
<Table>
<TableHeaderSortable
classes={classes}
orderBy={orderBy}
order={order}
columnData={tableColumns}
onSortRequest={sortHandler}
/>
<TableBody>
{vehicles.map((row) => (
<TableRow key={row.vin}>
<TableCell align="center" sortDirection={true}>
<Link to={`/vehicle-status/${row.vin}`}>{row.vin}</Link>
</TableCell>
<TableCell align="center">{row.model}</TableCell>
<TableCell align="center">{row.year}</TableCell>
<TableCell align="center">{row.trim || ""}</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.updated)}
</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={6}
count={totalVehicles}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
<Table>
<TableHeaderSortable
classes={classes}
orderBy={orderBy}
order={order}
columnData={tableColumns}
onSortRequest={sortHandler}
/>
<TableBody>
{vehicles.map((row) => (
<TableRow key={row.vin}>
<TableCell align="center">
<Link to={`/vehicle-status/${row.vin}`}>{row.vin}</Link>
</TableCell>
<TableCell align="center">{row.model}</TableCell>
<TableCell align="center">{row.year}</TableCell>
<TableCell align="center">{row.trim || ""}</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.updated)}
</TableCell>
</TableRow>
</TableFooter>
</Table>
</TableContainer>
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={6}
count={totalVehicles}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
</TableRow>
</TableFooter>
</Table>
</div>
);
};

View File

@@ -88,7 +88,32 @@ const SendCommand = ({ vins }) => {
}}
onChange={changeCommandHandler}
>
{commands.map((item) => (
{commands.map((item, index) => (
<option key={index} value={item.value}>
{item.label}
</option>
))}
</Select>
</FormControl>
<FormControl className={classes.formControlInline} variant="outlined">
<InputLabel
htmlFor="send-parameter"
style={{ backgroundColor: "White" }}
>
Parameter
</InputLabel>
<Select
native
value={parameter}
variant="outlined"
inputProps={{
name: "send-parameter",
id: "send-parameter",
}}
onChange={changeParametersHandler}
disabled={parameters.length === 0}
>
{parameters.map((item) => (
<option key={item.value} value={item.value}>
{item.label}
</option>

View File

@@ -1,124 +1,32 @@
import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import {
Checkbox,
Table,
TableBody,
TableCell,
TableContainer,
TableFooter,
TablePagination,
TableRow,
Toolbar,
} from "@material-ui/core";
import { Grid } from "@material-ui/core";
import {
useVehicleContext,
VehicleProvider,
} from "../../Contexts/VehicleContext";
import { VehicleProvider } from "../../Contexts/VehicleContext";
import { useUserContext } from "../../Contexts/UserContext";
import { useStatusContext } from "../../Contexts/StatusContext";
import useStyles from "../../useStyles";
import { LocalDateTimeString } from "../../../utils/dates";
import TableHeaderSortable from "../../Table/HeaderSortable";
import SendCommand from "../SendCommand";
import SearchField from "../../Controls/SearchField";
const tableColumns = [
{
id: "vin",
label: "VIN",
},
{
id: "model",
label: "Model",
},
{
id: "year",
label: "Year",
},
{
id: "trim",
label: "Trim",
},
{
id: "created_at",
label: "Created",
},
{
id: "updated_at",
label: "Updated",
},
];
import CarSelectionTable from "../CarSelectionTable";
const MainForm = () => {
const classes = useStyles();
const [pageSize, setPageSize] = useState(10);
const [pageIndex, setPageIndex] = useState(0);
const [orderBy, setOrderBy] = useState("vin");
const [order, setOrder] = useState("asc");
const [selected, setSelected] = useState([]);
const [search, setSearch] = useState("");
const { getVehicles, vehicles, totalVehicles } = useVehicleContext();
const { setMessage, setTitle } = useStatusContext();
const { setTitle } = useStatusContext();
const {
token: {
idToken: { jwtToken: token },
},
} = useUserContext();
const sortHandler = (event, property) => {
if (property === orderBy) {
if (order === "asc") {
setOrder("desc");
} else {
setOrder("asc");
}
} else {
setOrderBy(property);
setOrder("asc");
}
const handleSearch = (search) => {
setSelected([]);
setSearch(search);
};
useEffect(() => {
setTitle("Send Command");
// eslint-disable-next-line
}, []);
useEffect(() => {
try {
getVehicles(
{
limit: pageSize,
offset: pageSize * pageIndex,
order: `${orderBy} ${order}`,
search,
},
token
);
} catch (e) {
setMessage(e.message);
}
// eslint-disable-next-line
}, [pageIndex, pageSize, token, orderBy, order, search]);
const handleChangePageIndex = (event, newIndex) => {
setPageIndex(newIndex);
};
const handleChangePageSize = (event) => {
setPageSize(parseInt(event.target.value, 10));
setPageIndex(0);
};
const handleSelectAll = (event) => {
const newSelected = [];
if (event.target.checked) {
vehicles.forEach((car) => {
newSelected.push(car.vin);
});
}
setSelected(newSelected);
const handleSelectAll = (cars) => {
setSelected(cars);
};
const handleSelect = (event, key) => {
@@ -132,76 +40,32 @@ const MainForm = () => {
setSelected(newSelected);
};
const handleSearch = (search) => {
setSelected([]);
setSearch(search);
};
useEffect(() => {
setTitle("Send Command");
// eslint-disable-next-line
}, []);
return (
<div className={classes.paper} style={{ height: 700, width: "100%" }}>
<Toolbar className={classes.tableToolbar}>
<SearchField classes={classes} onSearch={handleSearch} />
</Toolbar>
<TableContainer>
<Table>
<TableHeaderSortable
classes={classes}
orderBy={orderBy}
order={order}
columnData={tableColumns}
onSortRequest={sortHandler}
multiSelect={true}
onSelectAll={handleSelectAll}
selectCount={selected.length}
rowCount={totalVehicles}
/>
<TableBody>
{vehicles.map((row) => {
const isSelected = selected.indexOf(row.vin) !== -1;
return (
<TableRow key={row.vin}>
<TableCell padding="checkbox">
<Checkbox
checked={isSelected}
onChange={(event) => handleSelect(event, row.vin)}
/>
</TableCell>
<TableCell align="center" sortDirection={true}>
<Link to={`/vehicle-status/${row.vin}`}>{row.vin}</Link>
</TableCell>
<TableCell align="center">{row.model}</TableCell>
<TableCell align="center">{row.year}</TableCell>
<TableCell align="center">{row.trim || ""}</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.updated)}
</TableCell>
</TableRow>
);
})}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={7}
count={totalVehicles}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
</TableRow>
</TableFooter>
</Table>
</TableContainer>
<SendCommand vins={selected} />
<Grid container className={classes.root} spacing={2}>
<Grid item md={6}>
<SearchField classes={classes} onSearch={handleSearch} />
<div
className={classes.labelInline}
>{`${selected.length} Selected`}</div>
</Grid>
<Grid item md={6} style={{ textAlign: "right" }}>
<SendCommand vins={selected} style={{ display: "flex" }} />
</Grid>
</Grid>
<CarSelectionTable
classes={classes}
token={token}
search={{ search }}
selected={selected}
onSelect={handleSelect}
onSelectAll={handleSelectAll}
/>
</div>
);
};

View File

@@ -1,11 +1,9 @@
import React, { useEffect, useState } from "react";
import { useParams } from "react-router";
import {
Grid,
Table,
TableBody,
TableCell,
TableContainer,
TableFooter,
TablePagination,
TableRow,
@@ -16,13 +14,11 @@ import {
useUpdatesContext,
} from "../../Contexts/UpdatesContext";
import { VehicleProvider } from "../../Contexts/VehicleContext";
import { useUserContext } from "../../Contexts/UserContext";
import { useStatusContext } from "../../Contexts/StatusContext";
import useStyles from "../../useStyles";
import { LocalDateTimeString } from "../../../utils/dates";
import TableHeaderSortable from "../../Table/HeaderSortable";
import SendCommand from "../SendCommand";
const tableColumns = [
{
@@ -107,54 +103,47 @@ const MainForm = () => {
return (
<div className={classes.paper} style={{ height: 700, width: "100%" }}>
<TableContainer>
<Table>
<TableHeaderSortable
classes={classes}
orderBy={orderBy}
order={order}
columnData={tableColumns}
onSortRequest={handleSort}
/>
<TableBody>
{carUpdates.map((row) => (
<TableRow key={row.id}>
<TableCell align="center">{row.id}</TableCell>
<TableCell align="center">{`${row.updatepackage.package_name} ${row.updatepackage.version}`}</TableCell>
<TableCell align="center">{row.status}</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.updated)}
</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={5}
count={totalCarUpdates}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
<Table>
<TableHeaderSortable
classes={classes}
orderBy={orderBy}
order={order}
columnData={tableColumns}
onSortRequest={handleSort}
/>
<TableBody>
{carUpdates.map((row) => (
<TableRow key={row.id}>
<TableCell align="center">{row.id}</TableCell>
<TableCell align="center">{`${row.updatepackage.package_name} ${row.updatepackage.version}`}</TableCell>
<TableCell align="center">{row.status}</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.updated)}
</TableCell>
</TableRow>
</TableFooter>
</Table>
</TableContainer>
<Grid container className={classes.root} spacing={2}>
<Grid item lg={6} md={12}>
<SendCommand vins={[vin]} />
</Grid>
</Grid>
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={5}
count={totalCarUpdates}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
</TableRow>
</TableFooter>
</Table>
</div>
);
};

View File

@@ -20,9 +20,13 @@ const SearchField = (props) => {
onSearch(searchTerm);
};
const handleEnterPress = (e) => {
if (e.keyCode !== 13) return;
e.preventDefault();
handleSearch(e);
if (e.keyCode === 13) {
e.preventDefault();
handleSearch(e);
} else if (e.keyCode === 27) {
e.preventDefault();
setSearchTerm("");
}
};
return (

View File

@@ -0,0 +1,37 @@
import React, { useEffect } from "react";
import useStyles from "../useStyles";
import { useStatusContext } from "../Contexts/StatusContext";
const Dashboard = () => {
const classes = useStyles();
const { setTitle } = useStatusContext();
useEffect(() => {
setTitle("Dashboard");
// eslint-disable-next-line
}, []);
return (
<div className={classes.paper}>
<iframe
className={classes.iframe}
title="Vehicle Connected"
src="https://grafana.fiskerdps.com/d-solo/1VTVJ_qGk/dashboard?orgId=2&refresh=5s&panelId=6"
width="900"
height="400"
frameBorder="0"
></iframe>
<iframe
className={classes.iframe}
title="Vehicle Signals"
src="https://grafana.fiskerdps.com/d-solo/1VTVJ_qGk/dashboard?orgId=2&refresh=5s&panelId=2"
width="900"
height="400"
frameBorder="0"
></iframe>
</div>
);
};
export default Dashboard;

View File

@@ -1,6 +1,7 @@
import React from "react";
import { List } from "@material-ui/core";
import ListItemLink from "../ListItemLink";
import ListItemExternalLink from "../ListItemExternalLink";
import { useUserContext } from "../Contexts/UserContext";
import { Roles, hasRole } from "../../utils/roles";
@@ -10,6 +11,11 @@ const menuData = [
to: "/home",
roles: [],
},
{
label: "Dashboard",
to: "/dashboard",
roles: [],
},
{
label: "Deploy Packages",
to: "/updates",
@@ -35,6 +41,11 @@ const menuData = [
to: "/vehicles-command",
roles: [Roles.CREATE],
},
{
label: "Create Charts",
url: "https://grafana.fiskerdps.com",
roles: [],
},
];
export default function SideMenu() {
@@ -50,7 +61,12 @@ export default function SideMenu() {
return (
<List>
{menu.map((item, index) => (
<ListItemLink key={index} primary={item.label} to={item.to} />
<li key={index}>
{item.to && <ListItemLink primary={item.label} to={item.to} />}
{item.url && (
<ListItemExternalLink primary={item.label} url={item.url} />
)}
</li>
))}
</List>
);

View File

@@ -30,6 +30,28 @@ exports[`SideMenu Authenticated 1`] = `
/>
</a>
</li>
<li>
<a
aria-disabled="false"
class="MuiButtonBase-root MuiListItem-root MuiListItem-gutters MuiListItem-button"
href="/dashboard"
role="button"
tabindex="0"
>
<div
class="MuiListItemText-root"
>
<span
class="MuiTypography-root MuiListItemText-primary MuiTypography-body1 MuiTypography-displayBlock"
>
Dashboard
</span>
</div>
<span
class="MuiTouchRipple-root"
/>
</a>
</li>
<li>
<a
aria-disabled="false"
@@ -140,6 +162,31 @@ exports[`SideMenu Authenticated 1`] = `
/>
</a>
</li>
<li>
<a
aria-disabled="false"
class="MuiTypography-root MuiLink-root MuiLink-underlineHover MuiButtonBase-root MuiListItem-root MuiListItem-gutters MuiListItem-button MuiTypography-colorPrimary"
href="https://grafana.fiskerdps.com"
rel="noopener"
role="button"
style="text-decoration: inherit;"
tabindex="0"
target="_blank"
>
<div
class="MuiListItemText-root"
>
<span
class="MuiTypography-root MuiListItemText-primary MuiTypography-body1 MuiTypography-displayBlock"
>
Create Charts
</span>
</div>
<span
class="MuiTouchRipple-root"
/>
</a>
</li>
</ul>
</div>
</div>
@@ -175,6 +222,53 @@ exports[`SideMenu Unauthenticated 1`] = `
/>
</a>
</li>
<li>
<a
aria-disabled="false"
class="MuiButtonBase-root MuiListItem-root MuiListItem-gutters MuiListItem-button"
href="/dashboard"
role="button"
tabindex="0"
>
<div
class="MuiListItemText-root"
>
<span
class="MuiTypography-root MuiListItemText-primary MuiTypography-body1 MuiTypography-displayBlock"
>
Dashboard
</span>
</div>
<span
class="MuiTouchRipple-root"
/>
</a>
</li>
<li>
<a
aria-disabled="false"
class="MuiTypography-root MuiLink-root MuiLink-underlineHover MuiButtonBase-root MuiListItem-root MuiListItem-gutters MuiListItem-button MuiTypography-colorPrimary"
href="https://grafana.fiskerdps.com"
rel="noopener"
role="button"
style="text-decoration: inherit;"
tabindex="0"
target="_blank"
>
<div
class="MuiListItemText-root"
>
<span
class="MuiTypography-root MuiListItemText-primary MuiTypography-body1 MuiTypography-displayBlock"
>
Create Charts
</span>
</div>
<span
class="MuiTouchRipple-root"
/>
</a>
</li>
</ul>
</div>
</div>

View File

@@ -0,0 +1,46 @@
import React from "react";
import PropTypes from "prop-types";
import ListItem from "@material-ui/core/ListItem";
import ListItemIcon from "@material-ui/core/ListItemIcon";
import ListItemText from "@material-ui/core/ListItemText";
import { Link } from "@material-ui/core";
function ListItemExternalLink(props) {
const { icon, primary, url } = props;
const style = {
textDecoration: "inherit",
color: "inherit",
"&:link": {
textDecoration: "inherit",
color: "inherit",
cursor: "auto",
},
"&:visited": {
textDecoration: "inherit",
color: "inherit",
cursor: "auto",
},
};
return (
<ListItem
button
component={Link}
style={style}
href={url}
rel="noopener"
target="_blank"
>
{icon ? <ListItemIcon>{icon}</ListItemIcon> : null}
<ListItemText primary={primary} />
</ListItem>
);
}
ListItemExternalLink.propTypes = {
icon: PropTypes.element,
primary: PropTypes.string.isRequired,
url: PropTypes.string.isRequired,
};
export default ListItemExternalLink;

View File

@@ -17,12 +17,10 @@ function ListItemLink(props) {
);
return (
<li>
<ListItem button component={renderLink}>
{icon ? <ListItemIcon>{icon}</ListItemIcon> : null}
<ListItemText primary={primary} />
</ListItem>
</li>
<ListItem button component={renderLink}>
{icon ? <ListItemIcon>{icon}</ListItemIcon> : null}
<ListItemText primary={primary} />
</ListItem>
);
}

View File

@@ -18,6 +18,7 @@ const CarUpdatesStatus = React.lazy(() => import("../CarUpdates/Status"));
const CarUpdates = React.lazy(() => import("../Cars/Status"));
const VehiclesList = React.lazy(() => import("../Cars/List"));
const SendCommandBulk = React.lazy(() => import("../Cars/SendCommandBulk"));
const Dashboard = React.lazy(() => import("../Dashboard"));
const SiteRoutes = () => {
const { token, groups } = useUserContext();
@@ -110,6 +111,14 @@ const SiteRoutes = () => {
groups={groups}
roles={[Roles.CREATE]}
/>
<AuthRoute
path="/dashboard"
render={() => <Dashboard />}
type={TYPES.PROTECTED}
token={token}
groups={groups}
roles={[Roles.READ, Roles.CREATE]}
/>
<PageNotFound />
</Switch>
</Suspense>

View File

@@ -46,10 +46,10 @@ exports[`File Upload Form Should render 1`] = `
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-31 MuiOutlinedInput-notchedOutline"
class="PrivateNotchedOutline-root-33 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-33"
class="PrivateNotchedOutline-legendLabelled-35"
>
<span>
Package name
@@ -92,10 +92,10 @@ exports[`File Upload Form Should render 1`] = `
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-31 MuiOutlinedInput-notchedOutline"
class="PrivateNotchedOutline-root-33 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-33"
class="PrivateNotchedOutline-legendLabelled-35"
>
<span>
Version
@@ -138,10 +138,10 @@ exports[`File Upload Form Should render 1`] = `
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-31 MuiOutlinedInput-notchedOutline"
class="PrivateNotchedOutline-root-33 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-33"
class="PrivateNotchedOutline-legendLabelled-35"
>
<span>
Description
@@ -185,10 +185,10 @@ exports[`File Upload Form Should render 1`] = `
/>
<fieldset
aria-hidden="true"
class="PrivateNotchedOutline-root-31 MuiOutlinedInput-notchedOutline"
class="PrivateNotchedOutline-root-33 MuiOutlinedInput-notchedOutline"
>
<legend
class="PrivateNotchedOutline-legendLabelled-33"
class="PrivateNotchedOutline-legendLabelled-35"
>
<span>
Release Notes URL

View File

@@ -4,7 +4,6 @@ import {
Table,
TableBody,
TableCell,
TableContainer,
TableFooter,
TablePagination,
TableRow,
@@ -151,47 +150,45 @@ const UpdatePackagesList = () => {
<Toolbar className={classes.tableToolbar}>
<SearchField classes={classes} onSearch={handleSearch} />
</Toolbar>
<TableContainer>
<Table>
<TableHeaderSortable
classes={classes}
orderBy={orderBy}
order={order}
columnData={tableColumns}
onSortRequest={handleSort}
/>
<TableBody>
{packages.map((row) => (
<TableRow key={row.id}>
<TableCell align="center">{row.id}</TableCell>
<TableCell align="center">{row.package_name}</TableCell>
<TableCell align="center">{row.version}</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">{Actions(row)}</TableCell>
</TableRow>
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={5}
count={totalPackages}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
<Table>
<TableHeaderSortable
classes={classes}
orderBy={orderBy}
order={order}
columnData={tableColumns}
onSortRequest={handleSort}
/>
<TableBody>
{packages.map((row) => (
<TableRow key={row.id}>
<TableCell align="center">{row.id}</TableCell>
<TableCell align="center">{row.package_name}</TableCell>
<TableCell align="center">{row.version}</TableCell>
<TableCell align="center">
{LocalDateTimeString(row.created)}
</TableCell>
<TableCell align="center">{Actions(row)}</TableCell>
</TableRow>
</TableFooter>
</Table>
</TableContainer>
))}
</TableBody>
<TableFooter>
<TableRow>
<TablePagination
rowsPerPageOptions={[5, 10, 25, 100]}
colSpan={5}
count={totalPackages}
rowsPerPage={pageSize}
page={pageIndex}
SelectProps={{
inputProps: { "aria-label": "rows per page" },
native: true,
}}
onChangePage={handleChangePageIndex}
onChangeRowsPerPage={handleChangePageSize}
/>
</TableRow>
</TableFooter>
</Table>
</div>
);
};

View File

@@ -45,10 +45,10 @@ const useStyles = makeStyles((theme) => ({
},
labelInline: {
fontSize: "1.25em",
margin: theme.spacing(2, 0, 1),
margin: theme.spacing(2, 1, 1),
display: "inline-flex",
boxSizing: "border-box",
position: "relative",
verticalAlign: "bottom",
},
chips: {
display: "flex",
@@ -152,6 +152,7 @@ const useStyles = makeStyles((theme) => ({
width: "25ch",
},
tableToolbar: {
display: "flex",
textAlign: "left",
paddingLeft: theme.spacing(2),
paddingRight: theme.spacing(1),
@@ -162,6 +163,12 @@ const useStyles = makeStyles((theme) => ({
width: 60,
margin: "auto",
},
grow: {
flexGrow: 1,
},
iframe: {
marginTop: 10,
},
}));
export default useStyles;