Skip to content

Commit 36d77a2

Browse files
committed
test variation delete added
1 parent 96b044d commit 36d77a2

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

src/components/TestVariationList.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import {
88
makeStyles,
99
CardActions,
1010
Button,
11+
IconButton,
1112
} from "@material-ui/core";
1213
import { staticService } from "../services";
1314
import { Link } from "react-router-dom";
1415
import { routes } from "../constants";
1516
import { TestVariationDetails } from "./TestVariationDetails";
17+
import { Delete } from "@material-ui/icons";
1618

1719
interface IProps {
1820
items: TestVariation[];
21+
onDeleteClick: (id: string) => void;
1922
}
2023

2124
const useStyles = makeStyles({
@@ -28,7 +31,10 @@ const useStyles = makeStyles({
2831
},
2932
});
3033

31-
const TestVariationList: React.FunctionComponent<IProps> = ({ items }) => {
34+
const TestVariationList: React.FunctionComponent<IProps> = ({
35+
items,
36+
onDeleteClick,
37+
}) => {
3238
const classes = useStyles();
3339

3440
return (
@@ -52,6 +58,13 @@ const TestVariationList: React.FunctionComponent<IProps> = ({ items }) => {
5258
>
5359
History
5460
</Button>
61+
<IconButton
62+
onClick={(event: React.MouseEvent<HTMLElement>) =>
63+
onDeleteClick(t.id)
64+
}
65+
>
66+
<Delete />
67+
</IconButton>
5568
</CardActions>
5669
</Card>
5770
</Grid>

src/pages/TestVariationListPage.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ const TestVariationListPage: React.FunctionComponent = () => {
4545
);
4646
}, [query, branchName, os, device, browser, viewport, testVariations]);
4747

48+
const handleDelete = (id: string) => {
49+
testVariationService.remove(id).then((item) => {
50+
setTestVariations(testVariations.filter((i) => i.id !== item.id));
51+
});
52+
};
53+
4854
return (
4955
<React.Fragment>
5056
<Container>
@@ -74,7 +80,10 @@ const TestVariationListPage: React.FunctionComponent = () => {
7480
/>
7581
</Grid>
7682
<Grid item>
77-
<TestVariationList items={filteredItems} />
83+
<TestVariationList
84+
items={filteredItems}
85+
onDeleteClick={handleDelete}
86+
/>
7887
</Grid>
7988
</Grid>
8089
</Box>

src/services/testVariation.service.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const testVariationService = {
1111
setIgnoreAreas,
1212
setComment,
1313
merge,
14+
remove,
1415
};
1516

1617
function getList(projectId: String): Promise<TestVariation[]> {
@@ -74,4 +75,15 @@ function merge(projectId: String, branchName: String): Promise<Build> {
7475
`${API_URL}${ENDPOINT_URL}/merge?projectId=${projectId}&branchName=${branchName}`,
7576
requestOptions
7677
).then(handleResponse);
77-
}
78+
}
79+
80+
function remove(id: String): Promise<TestVariation> {
81+
const requestOptions = {
82+
method: "DELETE",
83+
headers: authHeader(),
84+
};
85+
86+
return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then(
87+
handleResponse
88+
);
89+
}

0 commit comments

Comments
 (0)