added delete button to deploy packages

This commit is contained in:
jcw-fisker
2021-06-09 10:36:00 -07:00
parent e6d48ae75e
commit 067e465b59
7 changed files with 207 additions and 46 deletions

View File

@@ -127,7 +127,7 @@ describe("App", () => {
it("Route /carupdate-status authenticated", async () => { it("Route /carupdate-status authenticated", async () => {
setToken(TEST_AUTH_OBJECT); setToken(TEST_AUTH_OBJECT);
await check("/carupdate-status/1", "h6", ""); await check("/carupdate-status/1", "h6", "Package Package 1.0");
}); });
it("Route /vehicles authenticated", async () => { it("Route /vehicles authenticated", async () => {
@@ -156,7 +156,7 @@ describe("App", () => {
it("Route /carupdate-deploy authenticated", async () => { it("Route /carupdate-deploy authenticated", async () => {
setToken(TEST_AUTH_OBJECT); setToken(TEST_AUTH_OBJECT);
await check("/carupdate-deploy/1", "h6", "Deploy "); await check("/carupdate-deploy/1", "h6", "Deploy Package 1.0");
}); });
it("Route /dashboard authenticated", async () => { it("Route /dashboard authenticated", async () => {

View File

@@ -308,7 +308,7 @@ exports[`App Route /carupdate-deploy authenticated 1`] = `
<h6 <h6
class="MuiTypography-root MuiTypography-h6 MuiTypography-noWrap" class="MuiTypography-root MuiTypography-h6 MuiTypography-noWrap"
> >
Deploy Deploy Package 1.0
</h6> </h6>
<button <button
class="MuiButtonBase-root MuiButton-root MuiButton-text makeStyles-rightToolbar-812 MuiButton-colorInherit" class="MuiButtonBase-root MuiButton-root MuiButton-text makeStyles-rightToolbar-812 MuiButton-colorInherit"
@@ -531,9 +531,9 @@ exports[`App Route /carupdate-deploy authenticated 1`] = `
class="MuiTypography-root MuiTypography-body2" class="MuiTypography-root MuiTypography-body2"
> >
Created Created
Invalid Date Invalid Date
. .
No description Description
</p> </p>
<div <div
class="MuiGrid-root makeStyles-root-802 MuiGrid-container MuiGrid-spacing-xs-2" class="MuiGrid-root makeStyles-root-802 MuiGrid-container MuiGrid-spacing-xs-2"
@@ -1020,7 +1020,9 @@ exports[`App Route /carupdate-status authenticated 1`] = `
> >
<h6 <h6
class="MuiTypography-root MuiTypography-h6 MuiTypography-noWrap" class="MuiTypography-root MuiTypography-h6 MuiTypography-noWrap"
/> >
Package Package 1.0
</h6>
<button <button
class="MuiButtonBase-root MuiButton-root MuiButton-text makeStyles-rightToolbar-612 MuiButton-colorInherit" class="MuiButtonBase-root MuiButton-root MuiButton-text makeStyles-rightToolbar-612 MuiButton-colorInherit"
tabindex="0" tabindex="0"
@@ -3139,8 +3141,8 @@ exports[`App Route /update authenticated 1`] = `
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth" class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
> >
<label <label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-filled" class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-filled MuiFormLabel-filled"
data-shrink="false" data-shrink="true"
> >
Create Date Create Date
</label> </label>
@@ -3153,7 +3155,7 @@ exports[`App Route /update authenticated 1`] = `
maxlength="1024" maxlength="1024"
readonly="" readonly=""
type="text" type="text"
value="" value="Invalid Date Invalid Date"
/> />
</div> </div>
</div> </div>
@@ -3161,8 +3163,8 @@ exports[`App Route /update authenticated 1`] = `
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth" class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
> >
<label <label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined Mui-required Mui-required" class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined MuiFormLabel-filled Mui-required Mui-required"
data-shrink="false" data-shrink="true"
for="packagename" for="packagename"
id="packagename-label" id="packagename-label"
> >
@@ -3186,14 +3188,14 @@ exports[`App Route /update authenticated 1`] = `
name="packagename" name="packagename"
required="" required=""
type="text" type="text"
value="" value="Package"
/> />
<fieldset <fieldset
aria-hidden="true" aria-hidden="true"
class="PrivateNotchedOutline-root-585 MuiOutlinedInput-notchedOutline" class="PrivateNotchedOutline-root-585 MuiOutlinedInput-notchedOutline"
> >
<legend <legend
class="PrivateNotchedOutline-legendLabelled-587" class="PrivateNotchedOutline-legendLabelled-587 PrivateNotchedOutline-legendNotched-588"
> >
<span> <span>
Package name Package name
@@ -3207,8 +3209,8 @@ exports[`App Route /update authenticated 1`] = `
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth" class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
> >
<label <label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined Mui-required Mui-required" class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined MuiFormLabel-filled Mui-required Mui-required"
data-shrink="false" data-shrink="true"
for="version" for="version"
id="version-label" id="version-label"
> >
@@ -3232,14 +3234,14 @@ exports[`App Route /update authenticated 1`] = `
name="version" name="version"
required="" required=""
type="text" type="text"
value="" value="1.0"
/> />
<fieldset <fieldset
aria-hidden="true" aria-hidden="true"
class="PrivateNotchedOutline-root-585 MuiOutlinedInput-notchedOutline" class="PrivateNotchedOutline-root-585 MuiOutlinedInput-notchedOutline"
> >
<legend <legend
class="PrivateNotchedOutline-legendLabelled-587" class="PrivateNotchedOutline-legendLabelled-587 PrivateNotchedOutline-legendNotched-588"
> >
<span> <span>
Version Version
@@ -3299,8 +3301,8 @@ exports[`App Route /update authenticated 1`] = `
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth" class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
> >
<label <label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined" class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined MuiFormLabel-filled"
data-shrink="false" data-shrink="true"
for="description" for="description"
id="description-label" id="description-label"
> >
@@ -3317,13 +3319,15 @@ exports[`App Route /update authenticated 1`] = `
name="description" name="description"
placeholder="Package description" placeholder="Package description"
rows="4" rows="4"
/> >
Description
</textarea>
<fieldset <fieldset
aria-hidden="true" aria-hidden="true"
class="PrivateNotchedOutline-root-585 MuiOutlinedInput-notchedOutline" class="PrivateNotchedOutline-root-585 MuiOutlinedInput-notchedOutline"
> >
<legend <legend
class="PrivateNotchedOutline-legendLabelled-587" class="PrivateNotchedOutline-legendLabelled-587 PrivateNotchedOutline-legendNotched-588"
> >
<span> <span>
Description Description
@@ -3336,8 +3340,8 @@ exports[`App Route /update authenticated 1`] = `
class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth" class="MuiFormControl-root MuiTextField-root MuiFormControl-marginNormal MuiFormControl-fullWidth"
> >
<label <label
class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-outlined" class="MuiFormLabel-root MuiInputLabel-root MuiInputLabel-formControl MuiInputLabel-animated MuiInputLabel-shrink MuiInputLabel-outlined MuiFormLabel-filled"
data-shrink="false" data-shrink="true"
for="releasenotes" for="releasenotes"
id="releasenotes-label" id="releasenotes-label"
> >
@@ -3354,14 +3358,14 @@ exports[`App Route /update authenticated 1`] = `
name="releasenotes" name="releasenotes"
placeholder="Release Notes URL" placeholder="Release Notes URL"
type="text" type="text"
value="" value="https://www.google.com/"
/> />
<fieldset <fieldset
aria-hidden="true" aria-hidden="true"
class="PrivateNotchedOutline-root-585 MuiOutlinedInput-notchedOutline" class="PrivateNotchedOutline-root-585 MuiOutlinedInput-notchedOutline"
> >
<legend <legend
class="PrivateNotchedOutline-legendLabelled-587" class="PrivateNotchedOutline-legendLabelled-587 PrivateNotchedOutline-legendNotched-588"
> >
<span> <span>
Release Notes URL Release Notes URL
@@ -3849,7 +3853,88 @@ exports[`App Route /updates authenticated 1`] = `
</thead> </thead>
<tbody <tbody
class="MuiTableBody-root" class="MuiTableBody-root"
>
<tr
class="MuiTableRow-root"
>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
0
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
Package
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
1.0
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
Invalid Date Invalid Date
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-alignCenter"
>
<a
class=""
href="/carupdate-status/0"
style="margin: 5px;"
title="Status \\"Package 1.0\\""
>
<svg
aria-hidden="true"
aria-label="Status Package 1.0"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M12 4.5C7 4.5 2.73 7.61 1 12c1.73 4.39 6 7.5 11 7.5s9.27-3.11 11-7.5c-1.73-4.39-6-7.5-11-7.5zM12 17c-2.76 0-5-2.24-5-5s2.24-5 5-5 5 2.24 5 5-2.24 5-5 5zm0-8c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"
/> />
</svg>
</a>
<a
class=""
href="/carupdate-deploy/0"
style="margin: 5px;"
title="Deploy \\"Package 1.0\\""
>
<svg
aria-hidden="true"
aria-label="Deploy Package 1.0"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M2.01 21L23 12 2.01 3 2 10l15 2-15 2z"
/>
</svg>
</a>
<span
class="MuiTypography-root MuiTypography-colorPrimary"
title="Delete \\"Package 1.0\\""
>
<svg
aria-hidden="true"
aria-label="Delete Package 1.0"
class="MuiSvgIcon-root"
focusable="false"
viewBox="0 0 24 24"
>
<path
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z"
/>
</svg>
</span>
</td>
</tr>
</tbody>
<tfoot <tfoot
class="MuiTableFooter-root" class="MuiTableFooter-root"
> >

View File

@@ -5,7 +5,7 @@ import { StatusProvider } from "../Contexts/StatusContext";
import { CssBaseline } from "@material-ui/core"; import { CssBaseline } from "@material-ui/core";
import MenuDrawer from "../Layouts/MenuDrawer"; import MenuDrawer from "../Layouts/MenuDrawer";
import SiteRoutes from "../Routes/SiteRoutes"; import SiteRoutes from "../Routes/SiteRoutes";
import {} from "../../services/monitoring"; //import {} from "../../services/monitoring";
function App() { function App() {
return ( return (

View File

@@ -48,6 +48,26 @@ export const UpdatesProvider = ({ children }) => {
return result; return result;
}; };
const deletePackage = async (package_id, token) => {
let result;
let index = packages.findIndex((element) => {
return element.id === package_id;
});
packages.splice(index, 1);
try {
setBusy(true);
result = await api.deletePackage(package_id, token);
if (result.error)
throw new Error(`Delete package error. ${result.message}`);
} finally {
setBusy(false);
}
return result;
};
const createCarUpdates = async (data, token) => { const createCarUpdates = async (data, token) => {
let result; let result;
@@ -188,6 +208,7 @@ export const UpdatesProvider = ({ children }) => {
totalCarUpdates, totalCarUpdates,
getPackages, getPackages,
updatePackage, updatePackage,
deletePackage,
createCarUpdates, createCarUpdates,
getCarUpdates, getCarUpdates,
getVINUpdates, getVINUpdates,

View File

@@ -4,6 +4,15 @@ const UpdatesContext = React.createContext();
let busy = false; let busy = false;
let packages = []; let packages = [];
const examplePackage = {
id: 0,
package_name: "Package",
version: "1.0",
desc: "Description",
release_notes: "https://www.google.com/",
created: Date.now().toString(),
};
packages.push(examplePackage)
let totalPackages = 0; let totalPackages = 0;
let carUpdates = []; let carUpdates = [];
let totalCarUpdates = 0; let totalCarUpdates = 0;

View File

@@ -1,6 +1,7 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import { import {
Button,
Table, Table,
TableBody, TableBody,
TableCell, TableCell,
@@ -9,9 +10,11 @@ import {
TableRow, TableRow,
Toolbar, Toolbar,
Tooltip, Tooltip,
Typography,
} from "@material-ui/core"; } from "@material-ui/core";
import SendIcon from "@material-ui/icons/Send"; import SendIcon from "@material-ui/icons/Send";
import VisibilityIcon from "@material-ui/icons/Visibility"; import VisibilityIcon from "@material-ui/icons/Visibility";
import DeleteIcon from "@material-ui/icons/Delete";
import useStyles from "../../useStyles"; import useStyles from "../../useStyles";
import { import {
UpdatesProvider, UpdatesProvider,
@@ -23,6 +26,7 @@ import { LocalDateTimeString } from "../../../utils/dates";
import { Roles, hasRole } from "../../../utils/roles"; import { Roles, hasRole } from "../../../utils/roles";
import TableHeaderSortable from "../../Table/HeaderSortable"; import TableHeaderSortable from "../../Table/HeaderSortable";
import SearchField from "../../Controls/SearchField"; import SearchField from "../../Controls/SearchField";
import { MicNone, PrintOutlined } from "@material-ui/icons";
const tableColumns = [ const tableColumns = [
{ {
@@ -54,7 +58,7 @@ const UpdatePackagesList = () => {
const [orderBy, setOrderBy] = useState("id"); const [orderBy, setOrderBy] = useState("id");
const [order, setOrder] = useState("desc"); const [order, setOrder] = useState("desc");
const [search, setSearch] = useState(""); const [search, setSearch] = useState("");
const { getPackages, packages, totalPackages } = useUpdatesContext(); const { getPackages, deletePackage, packages, totalPackages } = useUpdatesContext();
const { const {
token: { token: {
idToken: { jwtToken: token }, idToken: { jwtToken: token },
@@ -107,6 +111,10 @@ const UpdatePackagesList = () => {
setSearch(search); setSearch(search);
}; };
const onDelete = async (package_id) => {
await deletePackage(parseInt(package_id), token);
};
const Actions = (row) => { const Actions = (row) => {
let actions = []; let actions = [];
if (hasRole([Roles.CREATE, Roles.READ], groups)) { if (hasRole([Roles.CREATE, Roles.READ], groups)) {
@@ -131,18 +139,50 @@ const UpdatePackagesList = () => {
/> />
), ),
}, },
{
tip: `Delete "${row.package_name} ${row.version}"`,
id: row.id,
icon: (
<DeleteIcon
aria-label={`Delete ${row.package_name} ${row.version}`}
/>
),
},
]); ]);
} }
if (actions.length === 0) return "No actions"; if (actions.length === 0) return "No actions";
return actions.map((action) => ( return actions.map((action) => {
if (action.link != null) {
return (
< Tooltip key={action.link} title={action.tip} > < Tooltip key={action.link} title={action.tip} >
<Link to={action.link} style={{ margin: 5 }}> <Link to={action.link} style={{ margin: 5 }}>
{action.icon} {action.icon}
</Link> </Link>
</Tooltip > </Tooltip >
)); );
} else {
return (
< Tooltip key={action.link} title={action.tip} >
<Typography
color="primary"
variant="inherit"
onClick={() => onDelete(action.id)}
>
{action.icon}
</Typography>
</Tooltip >
/**
< Tooltip key={action.link} title={action.tip} >
<Link onClick={() => onDelete(action.id)} style={{ margin: 5 }}>
{action.icon}
</Link>
</Tooltip >
*/
)
}
});
}; };
return ( return (

View File

@@ -10,6 +10,12 @@ const updatesAPI = {
}) })
.then(fetchRespHandler), .then(fetchRespHandler),
deletePackage: async (package_id, token) => fetch(`${API_ENDPOINT}/update?id=${package_id}`, {
method: "DELETE",
headers: Object.assign({ "Content-Type": "application/json" }, getAuthHeaderOptions(token)),
})
.then(fetchRespHandler),
getPackages: async (search, token) => { getPackages: async (search, token) => {
var u = addQueryParams(`${API_ENDPOINT}/updates`, search); var u = addQueryParams(`${API_ENDPOINT}/updates`, search);
return fetch(u, { return fetch(u, {