Skip to content

Commit cf0e5fe

Browse files
committed
Delete Target
1 parent 88e6320 commit cf0e5fe

File tree

5 files changed

+54
-16
lines changed

5 files changed

+54
-16
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
types: [python]
1919
- id: black
2020
name: black
21-
entry: black backend
21+
entry: black backend/app
2222
language: python
2323
types: [python]
2424
- id: pylint

backend/app/router/targets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def create_target(
2121
@router.get(
2222
"/targets",
2323
response_model=tp.List[schemas.Target],
24-
response_model_include=["id", "first_name", "last_name"],
24+
response_model_include={"id", "first_name", "last_name"},
2525
)
2626
def read_targets(db: Session = Depends(get_db)) -> tp.List[schemas.Target]:
2727
"""Get all targets."""

frontend/app/src/App.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
11
import React, { FC } from "react";
2-
import { Navbar } from "react-bootstrap";
3-
import { BrowserRouter, Route, Switch } from "react-router-dom";
4-
import { Home, TargetInfo, TargetSearch } from "./components/public";
2+
import { BrowserRouter, Redirect, Route, Switch } from "react-router-dom";
3+
4+
import {
5+
Home,
6+
TargetInfo,
7+
TargetSearch,
8+
NavigationBar,
9+
TargetCreate,
10+
} from "./components/public";
511

612
export const App: FC = () => {
713
return (
814
<>
915
<BrowserRouter basename="/">
16+
<NavigationBar />
1017
<Switch>
11-
<Navbar></Navbar>
1218
<Route exact path="/" component={Home} />
1319
<Route exact path="/targets" component={TargetSearch} />
20+
<Route exact path="/targets/create" component={TargetCreate} />
1421
<Route path="/targets/:id" component={TargetInfo} />
22+
<Route>
23+
<Redirect to="/" />
24+
</Route>
1525
</Switch>
1626
</BrowserRouter>
1727
</>

frontend/app/src/components/public/TargetInfo.tsx

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,39 @@
11
import React, { FC, useEffect, useState } from "react";
2-
import { useParams } from "react-router";
3-
import { Row, Col, Container, ListGroup } from "react-bootstrap";
2+
import { useHistory, useParams } from "react-router";
3+
import {
4+
Row,
5+
Col,
6+
Container,
7+
ListGroup,
8+
DropdownButton,
9+
Dropdown,
10+
Jumbotron,
11+
} from "react-bootstrap";
412

513
import { Target } from ".";
614

7-
const loadTarget = async (id: string) => {
8-
return fetch("/api/targets/" + id, {
9-
method: "GET",
10-
});
11-
};
12-
1315
export const TargetInfo: FC = () => {
1416
const { id }: { id: string } = useParams();
1517
const [target, setTarget] = useState<Target | null>(null);
18+
const history = useHistory();
1619

1720
useEffect(() => {
18-
loadTarget(id)
21+
fetch("/api/targets/" + id, {
22+
method: "GET",
23+
})
1924
.then((res) => res.json())
2025
.then((data) => setTarget(data))
2126
.catch(console.error);
2227
}, [id]);
2328

29+
const deleteTarget = (e: React.MouseEvent) => {
30+
if (window.confirm("Are you sure you want to delete this target ?")) {
31+
fetch("/api/targets/" + id, { method: "DELETE" })
32+
.then(() => history.push("/"))
33+
.catch(console.error);
34+
}
35+
};
36+
2437
const listPaths = target && (
2538
<ListGroup>
2639
{target.pictures.map((picture) => (
@@ -42,9 +55,22 @@ export const TargetInfo: FC = () => {
4255

4356
return (
4457
<Container>
58+
<Row>
59+
<Col style={{ textAlign: "center" }}>
60+
<Jumbotron>
61+
<h1>Target File</h1>
62+
<br />
63+
<DropdownButton title="Options">
64+
<Dropdown.Item onClick={deleteTarget}>
65+
Delete Target
66+
</Dropdown.Item>
67+
</DropdownButton>
68+
</Jumbotron>
69+
</Col>
70+
</Row>
4571
<Row>
4672
<Col xs={6}>
47-
<h1>Target Atrtibutes</h1>
73+
<h1>Target Attributes</h1>
4874
{listAttributes}
4975
</Col>
5076
<Col xs={6}>

frontend/app/src/components/public/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export * from "./Home";
22
export * from "./TargetInfo";
33
export * from "./TargetSearch";
4+
export * from "./TargetCreate";
5+
export * from "./NavigationBar";
46

57
export interface Picture {
68
id: number;

0 commit comments

Comments
 (0)