* CEC-2056 safari map (#186) * CEC-2056 Fix Safari map popup * Snapshot serializer for Private styles * Combine serializers * CEC-2207 Add is-online filter for vehicles list (#187) * Add OptionsDropdown component * Add is-online filter * CEC-2237 Track sign in and keys (#188) * Update stage (#189) * CEC-2056 safari map (#186) * CEC-2056 Fix Safari map popup * Snapshot serializer for Private styles * Combine serializers * CEC-2207 Add is-online filter for vehicles list (#187) * Add OptionsDropdown component * Add is-online filter * CEC-2237 Track sign in and keys (#188) Co-authored-by: arpanetus <arpanetus@protonmail.com> * CEC-2281 Update certificate form (#190) * CEC-2281 Fix cert name * CEC-2360 Fix filename display and add manifest type (#191) * CEC-2360 Fix filename display and add manifest type * const * Push to Stage (#200) * CEC-2144, CEC-2338 Add deploy by fleets and fix fleets table (#192) * Add fix for fleets search * Decompose fleets table * Add deploy by fleets * Add snapshots * CEC-2385 Only show software updates (#193) * CEC-2385 Only show software updates * Update browser list * update threshold * Clean up * CEC-2291 Remote Commands (#194) * CEC-2378 Add fix for fleet vehicles' search * CEC-1235 Fix fleet name update (#196) Co-authored-by: arpanetus <arpanetus@protonmail.com> Co-authored-by: arpanetus <arpanetus@protonmail.com>
265 lines
7.1 KiB
JavaScript
265 lines
7.1 KiB
JavaScript
import React, { useEffect, useState } from "react";
|
|
import { Link } from "react-router-dom";
|
|
import {
|
|
Grid,
|
|
Table,
|
|
TableBody,
|
|
TableCell,
|
|
TableFooter,
|
|
TablePagination,
|
|
TableRow,
|
|
Tooltip,
|
|
} from "@material-ui/core";
|
|
import SendIcon from "@material-ui/icons/Send";
|
|
import VisibilityIcon from "@material-ui/icons/Visibility";
|
|
import DeleteIcon from "@material-ui/icons/Delete";
|
|
import clsx from "clsx";
|
|
|
|
import {
|
|
useManifestsContext,
|
|
ManifestsProvider,
|
|
} from "../../Contexts/ManifestsContext";
|
|
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 SearchField from "../../Controls/SearchField";
|
|
import { logger } from "../../../services/monitoring";
|
|
import ECUList from "../../Controls/ECUList";
|
|
import { Roles, hasRole } from "../../../utils/roles";
|
|
import { useLocalStorage } from "../../useLocalStorage";
|
|
import { TYPE_MANIFEST_SOFTWARE } from "../../../utils/manifest_types";
|
|
|
|
const tableColumns = [
|
|
{
|
|
id: "id",
|
|
label: "ID",
|
|
},
|
|
{
|
|
id: "name",
|
|
label: "Name",
|
|
},
|
|
{
|
|
id: "version",
|
|
label: "Version",
|
|
},
|
|
{
|
|
id: "created_at",
|
|
label: "Created",
|
|
},
|
|
{
|
|
id: "updated_at",
|
|
label: "Updated",
|
|
},
|
|
{
|
|
id: "",
|
|
label: "Actions",
|
|
},
|
|
];
|
|
|
|
const PAGE_SIZE = "MANIFEST_LIST_PAGE_SIZE";
|
|
|
|
const MainForm = () => {
|
|
const classes = useStyles();
|
|
const [pageSize, setPageSize] = useLocalStorage(PAGE_SIZE, 10);
|
|
const [pageIndex, setPageIndex] = useState(0);
|
|
const [orderBy, setOrderBy] = useState("id");
|
|
const [order, setOrder] = useState("asc");
|
|
const [search, setSearch] = useState("");
|
|
const { getManifests, deleteManifest, manifests, totalManifests } =
|
|
useManifestsContext();
|
|
const { setMessage, setTitle, setSitePath } = useStatusContext();
|
|
const {
|
|
token: {
|
|
idToken: { jwtToken: token },
|
|
},
|
|
groups,
|
|
} = useUserContext();
|
|
|
|
const sortHandler = (event, property) => {
|
|
if (property === orderBy) {
|
|
if (order === "asc") {
|
|
setOrder("desc");
|
|
} else {
|
|
setOrder("asc");
|
|
}
|
|
} else {
|
|
setOrderBy(property);
|
|
setOrder("asc");
|
|
}
|
|
};
|
|
|
|
useEffect(() => {
|
|
setTitle("Deployments");
|
|
setSitePath([]);
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
(async () => {
|
|
try {
|
|
await getManifests(
|
|
{
|
|
limit: pageSize,
|
|
offset: pageSize * pageIndex,
|
|
order: `${orderBy} ${order}`,
|
|
manifest_type: TYPE_MANIFEST_SOFTWARE,
|
|
search,
|
|
},
|
|
token
|
|
);
|
|
} catch (e) {
|
|
setMessage(e.message);
|
|
logger.warn(e.stack);
|
|
}
|
|
})();
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [pageIndex, pageSize, token, orderBy, order, search]);
|
|
|
|
const handleChangePageIndex = (_event, newIndex) => {
|
|
setPageIndex(newIndex);
|
|
};
|
|
|
|
const handleChangePageSize = (event) => {
|
|
setPageSize(parseInt(event.target.value, 10));
|
|
setPageIndex(0);
|
|
};
|
|
|
|
const handleSearch = (query) => {
|
|
setPageIndex(0);
|
|
setSearch(query);
|
|
};
|
|
|
|
const onDelete = async (manifest_id) => {
|
|
try {
|
|
await deleteManifest(parseInt(manifest_id), token);
|
|
} catch (e) {
|
|
setMessage(e.message);
|
|
logger.warn(e.stack);
|
|
}
|
|
};
|
|
|
|
const Actions = (row) => {
|
|
let actions = [];
|
|
if (hasRole([Roles.CREATE, Roles.READ], groups)) {
|
|
actions.push({
|
|
tip: `Status "${row.name} ${row.version}"`,
|
|
link: `/package-status/${row.id}`,
|
|
icon: (
|
|
<VisibilityIcon aria-label={`Status ${row.name} ${row.version}`} />
|
|
),
|
|
});
|
|
}
|
|
if (hasRole([Roles.CREATE], groups)) {
|
|
actions.push({
|
|
tip: `Deploy "${row.name} ${row.version}"`,
|
|
link: `/package-deploy/${row.id}`,
|
|
icon: <SendIcon aria-label={`Deploy ${row.name} ${row.version}`} />,
|
|
});
|
|
}
|
|
if (hasRole([Roles.DELETE], groups)) {
|
|
actions.push({
|
|
tip: `Delete "${row.name} ${row.version}"`,
|
|
id: row.id,
|
|
icon: <DeleteIcon aria-label={`Delete ${row.name} ${row.version}`} />,
|
|
});
|
|
}
|
|
if (actions.length === 0) return ["No actions"];
|
|
|
|
return actions.map((action) => {
|
|
if (action.link != null) {
|
|
return (
|
|
<Tooltip key={action.link} title={action.tip}>
|
|
<Link to={action.link} style={{ margin: 5 }}>
|
|
{action.icon}
|
|
</Link>
|
|
</Tooltip>
|
|
);
|
|
} else {
|
|
return (
|
|
<Tooltip key={`delete-${action.id}`} title={action.tip}>
|
|
<Link to="#" onClick={() => onDelete(action.id)}>
|
|
{action.icon}
|
|
</Link>
|
|
</Tooltip>
|
|
);
|
|
}
|
|
});
|
|
};
|
|
|
|
return (
|
|
<div className={clsx(classes.paper, classes.tableSize)}>
|
|
<Grid container className={classes.root} spacing={2}>
|
|
<Grid item md={4} className={classes.textJustifyAlign}></Grid>
|
|
<Grid item md={4} className={classes.textCenterAlign}>
|
|
<SearchField classes={classes} onSearch={handleSearch} />
|
|
</Grid>
|
|
<Grid item md={4} className={classes.textRightAlign}></Grid>
|
|
</Grid>
|
|
<Table>
|
|
<TableHeaderSortable
|
|
classes={classes}
|
|
orderBy={orderBy}
|
|
order={order}
|
|
columnData={tableColumns}
|
|
onSortRequest={sortHandler}
|
|
/>
|
|
<TableBody>
|
|
{manifests.map((row) => (
|
|
<TableRow key={row.id}>
|
|
<TableCell align="center">{row.id}</TableCell>
|
|
<TableCell align="center">
|
|
{row.name}
|
|
{row.ecu_list && (
|
|
<>
|
|
<br />
|
|
<ECUList
|
|
list={row.ecu_list}
|
|
search={search}
|
|
searchedOnly={true}
|
|
/>
|
|
</>
|
|
)}
|
|
</TableCell>
|
|
<TableCell align="center">{row.version}</TableCell>
|
|
<TableCell align="center">
|
|
{LocalDateTimeString(row.created)}
|
|
</TableCell>
|
|
<TableCell align="center">
|
|
{LocalDateTimeString(row.updated)}
|
|
</TableCell>
|
|
<TableCell align="center">{Actions(row)}</TableCell>
|
|
</TableRow>
|
|
))}
|
|
</TableBody>
|
|
<TableFooter>
|
|
<TableRow>
|
|
<TablePagination
|
|
rowsPerPageOptions={[5, 10, 25, 100]}
|
|
colSpan={6}
|
|
count={totalManifests}
|
|
rowsPerPage={pageSize}
|
|
page={pageIndex}
|
|
SelectProps={{
|
|
inputProps: { "aria-label": "rows per page" },
|
|
native: true,
|
|
}}
|
|
onPageChange={handleChangePageIndex}
|
|
onRowsPerPageChange={handleChangePageSize}
|
|
/>
|
|
</TableRow>
|
|
</TableFooter>
|
|
</Table>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const ManifestsList = () => (
|
|
<ManifestsProvider>
|
|
<MainForm />
|
|
</ManifestsProvider>
|
|
);
|
|
|
|
export default ManifestsList;
|