Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/components/TestVariationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import {
makeStyles,
CardActions,
Button,
IconButton,
} from "@material-ui/core";
import { staticService } from "../services";
import { Link } from "react-router-dom";
import { routes } from "../constants";
import { TestVariationDetails } from "./TestVariationDetails";
import { Delete } from "@material-ui/icons";

interface IProps {
items: TestVariation[];
onDeleteClick: (id: string) => void;
}

const useStyles = makeStyles({
Expand All @@ -28,7 +31,10 @@ const useStyles = makeStyles({
},
});

const TestVariationList: React.FunctionComponent<IProps> = ({ items }) => {
const TestVariationList: React.FunctionComponent<IProps> = ({
items,
onDeleteClick,
}) => {
const classes = useStyles();

return (
Expand All @@ -52,6 +58,13 @@ const TestVariationList: React.FunctionComponent<IProps> = ({ items }) => {
>
History
</Button>
<IconButton
onClick={(event: React.MouseEvent<HTMLElement>) =>
onDeleteClick(t.id)
}
>
<Delete />
</IconButton>
</CardActions>
</Card>
</Grid>
Expand Down
11 changes: 10 additions & 1 deletion src/pages/TestVariationListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ const TestVariationListPage: React.FunctionComponent = () => {
);
}, [query, branchName, os, device, browser, viewport, testVariations]);

const handleDelete = (id: string) => {
testVariationService.remove(id).then((item) => {
setTestVariations(testVariations.filter((i) => i.id !== item.id));
});
};

return (
<React.Fragment>
<Container>
Expand Down Expand Up @@ -74,7 +80,10 @@ const TestVariationListPage: React.FunctionComponent = () => {
/>
</Grid>
<Grid item>
<TestVariationList items={filteredItems} />
<TestVariationList
items={filteredItems}
onDeleteClick={handleDelete}
/>
</Grid>
</Grid>
</Box>
Expand Down
14 changes: 13 additions & 1 deletion src/services/testVariation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const testVariationService = {
setIgnoreAreas,
setComment,
merge,
remove,
};

function getList(projectId: String): Promise<TestVariation[]> {
Expand Down Expand Up @@ -74,4 +75,15 @@ function merge(projectId: String, branchName: String): Promise<Build> {
`${API_URL}${ENDPOINT_URL}/merge?projectId=${projectId}&branchName=${branchName}`,
requestOptions
).then(handleResponse);
}
}

function remove(id: String): Promise<TestVariation> {
const requestOptions = {
method: "DELETE",
headers: authHeader(),
};

return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then(
handleResponse
);
}