Skip to content

Commit bab8cd9

Browse files
committed
testVariation notifications are handled
1 parent cbd0969 commit bab8cd9

File tree

6 files changed

+90
-46
lines changed

6 files changed

+90
-46
lines changed

src/components/TestDetailsModal.tsx

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,16 @@ const TestDetailsModal: React.FunctionComponent<{
263263
comment
264264
),
265265
])
266+
.then(() =>
267+
enqueueSnackbar("Comment updated", {
268+
variant: "success",
269+
})
270+
)
271+
.catch((err) =>
272+
enqueueSnackbar(err, {
273+
variant: "error",
274+
})
275+
)
266276
}
267277
/>
268278
</Grid>
@@ -298,11 +308,21 @@ const TestDetailsModal: React.FunctionComponent<{
298308
<Grid item>
299309
<IconButton
300310
disabled={isIgnoreAreasSaved()}
301-
onClick={() => {
302-
// update in test run
303-
testRunService
304-
.setIgnoreAreas(testRun.id, ignoreAreas)
305-
.then(() =>
311+
onClick={() =>
312+
Promise.all([
313+
// update in test run
314+
testRunService.setIgnoreAreas(testRun.id, ignoreAreas),
315+
// update in variation
316+
testVariationService.setIgnoreAreas(
317+
testRun.testVariationId,
318+
ignoreAreas
319+
),
320+
])
321+
.then(() => {
322+
enqueueSnackbar("Ignore areas are updated", {
323+
variant: "success",
324+
});
325+
306326
// recalculate diff
307327
testRunService
308328
.recalculateDiff(testRun.id)
@@ -313,30 +333,14 @@ const TestDetailsModal: React.FunctionComponent<{
313333
enqueueSnackbar("Diff recalculated", {
314334
variant: "success",
315335
})
316-
)
317-
.catch((err) =>
318-
enqueueSnackbar(err, {
319-
variant: "error",
320-
})
321-
)
322-
)
323-
.then(() =>
324-
enqueueSnackbar("Ignore areas are updated", {
325-
variant: "success",
326-
})
327-
)
336+
);
337+
})
328338
.catch((err) =>
329339
enqueueSnackbar(err, {
330340
variant: "error",
331341
})
332-
);
333-
334-
// update in variation
335-
testVariationService.setIgnoreAreas(
336-
testRun.testVariationId,
337-
ignoreAreas
338-
);
339-
}}
342+
)
343+
}
340344
>
341345
<Save />
342346
</IconButton>

src/components/TestRunList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const TestRunList: React.FunctionComponent<{
138138
onClick={() => {
139139
deleteTestRun(testRunDispatch, selectedTestRun.id)
140140
.then((testRun) => {
141-
enqueueSnackbar(`Removed`, {
141+
enqueueSnackbar(`Deleted`, {
142142
variant: "success",
143143
});
144144
})

src/components/TestVariationMergeForm.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Grid, Select, MenuItem, Button } from "@material-ui/core";
33
import { testVariationService } from "../services";
44
import { useHistory } from "react-router-dom";
55
import { buildBuildPageUrl } from "../_helpers/route.helpers";
6+
import { useSnackbar } from "notistack";
67

78
interface IProps {
89
projectId: string;
@@ -14,13 +15,24 @@ export const TestVariationMergeForm: React.FunctionComponent<IProps> = ({
1415
items,
1516
}) => {
1617
const history = useHistory();
18+
const { enqueueSnackbar } = useSnackbar();
1719
const [branch, setBranch] = React.useState("");
1820

1921
const handleSubmit = (event: React.FormEvent) => {
2022
event.preventDefault();
21-
testVariationService.merge(projectId, branch).then((build) => {
22-
history.push(buildBuildPageUrl(projectId, build.id));
23-
});
23+
testVariationService
24+
.merge(projectId, branch)
25+
.then((build) => {
26+
enqueueSnackbar(`Merge started in build: ${build.id}`, {
27+
variant: "success",
28+
});
29+
history.push(buildBuildPageUrl(projectId, build.id));
30+
})
31+
.catch((err) =>
32+
enqueueSnackbar(err, {
33+
variant: "error",
34+
})
35+
);
2436
};
2537

2638
return (

src/pages/TestVariationDetailsPage.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
useTestRunDispatch,
2121
selectTestRun,
2222
} from "../contexts";
23+
import { useSnackbar } from "notistack";
2324

2425
const useStyles = makeStyles({
2526
media: {
@@ -31,18 +32,26 @@ const useStyles = makeStyles({
3132
const TestVariationDetailsPage: React.FunctionComponent = () => {
3233
const classes = useStyles();
3334
const history = useHistory();
35+
const { enqueueSnackbar } = useSnackbar();
3436
const buildDispatch = useBuildDispatch();
3537
const testRunDispatch = useTestRunDispatch();
3638
const { testVariationId } = useParams();
3739
const [testVariation, setTestVariation] = React.useState<TestVariation>();
3840

3941
React.useEffect(() => {
4042
if (testVariationId) {
41-
testVariationService.getDetails(testVariationId).then((item) => {
42-
setTestVariation(item);
43-
});
43+
testVariationService
44+
.getDetails(testVariationId)
45+
.then((item) => {
46+
setTestVariation(item);
47+
})
48+
.catch((err) =>
49+
enqueueSnackbar(err, {
50+
variant: "error",
51+
})
52+
);
4453
}
45-
}, [testVariationId]);
54+
}, [testVariationId, enqueueSnackbar]);
4655

4756
return (
4857
<React.Fragment>

src/pages/TestVariationListPage.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import { Container, Box, Grid, Typography } from "@material-ui/core";
77
import ProjectSelect from "../components/ProjectSelect";
88
import Filters from "../components/Filters";
99
import { TestVariationMergeForm } from "../components/TestVariationMergeForm";
10+
import { useSnackbar } from "notistack";
1011

1112
const TestVariationListPage: React.FunctionComponent = () => {
13+
const { enqueueSnackbar } = useSnackbar();
1214
const { projectId = "" } = useParams();
1315
const [testVariations, setTestVariations] = React.useState<TestVariation[]>(
1416
[]
@@ -25,11 +27,18 @@ const TestVariationListPage: React.FunctionComponent = () => {
2527

2628
React.useEffect(() => {
2729
if (projectId) {
28-
testVariationService.getList(projectId).then((testVariations) => {
29-
setTestVariations(testVariations);
30-
});
30+
testVariationService
31+
.getList(projectId)
32+
.then((testVariations) => {
33+
setTestVariations(testVariations);
34+
})
35+
.catch((err) =>
36+
enqueueSnackbar(err, {
37+
variant: "error",
38+
})
39+
);
3140
}
32-
}, [projectId]);
41+
}, [projectId, enqueueSnackbar]);
3342

3443
React.useEffect(() => {
3544
setFilteredItems(
@@ -46,9 +55,19 @@ const TestVariationListPage: React.FunctionComponent = () => {
4655
}, [query, branchName, os, device, browser, viewport, testVariations]);
4756

4857
const handleDelete = (id: string) => {
49-
testVariationService.remove(id).then((item) => {
50-
setTestVariations(testVariations.filter((i) => i.id !== item.id));
51-
});
58+
testVariationService
59+
.remove(id)
60+
.then((item) => {
61+
setTestVariations(testVariations.filter((i) => i.id !== item.id));
62+
enqueueSnackbar("Deleted", {
63+
variant: "success",
64+
});
65+
})
66+
.catch((err) =>
67+
enqueueSnackbar(err, {
68+
variant: "error",
69+
})
70+
);
5271
};
5372

5473
return (

src/services/testVariation.service.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const testVariationService = {
1414
remove,
1515
};
1616

17-
function getList(projectId: String): Promise<TestVariation[]> {
17+
async function getList(projectId: String): Promise<TestVariation[]> {
1818
const requestOptions = {
1919
method: "GET",
2020
headers: authHeader(),
@@ -26,7 +26,7 @@ function getList(projectId: String): Promise<TestVariation[]> {
2626
).then(handleResponse);
2727
}
2828

29-
function getDetails(id: String): Promise<TestVariation> {
29+
async function getDetails(id: String): Promise<TestVariation> {
3030
const requestOptions = {
3131
method: "GET",
3232
headers: authHeader(),
@@ -37,7 +37,7 @@ function getDetails(id: String): Promise<TestVariation> {
3737
);
3838
}
3939

40-
function setIgnoreAreas(
40+
async function setIgnoreAreas(
4141
variationId: string,
4242
ignoreAreas: IgnoreArea[]
4343
): Promise<TestVariation> {
@@ -53,7 +53,7 @@ function setIgnoreAreas(
5353
).then(handleResponse);
5454
}
5555

56-
function setComment(id: string, comment: string): Promise<TestVariation> {
56+
async function setComment(id: string, comment: string): Promise<TestVariation> {
5757
const requestOptions = {
5858
method: "PUT",
5959
headers: { "Content-Type": "application/json", ...authHeader() },
@@ -65,7 +65,7 @@ function setComment(id: string, comment: string): Promise<TestVariation> {
6565
);
6666
}
6767

68-
function merge(projectId: String, branchName: String): Promise<Build> {
68+
async function merge(projectId: String, branchName: String): Promise<Build> {
6969
const requestOptions = {
7070
method: "GET",
7171
headers: authHeader(),
@@ -77,7 +77,7 @@ function merge(projectId: String, branchName: String): Promise<Build> {
7777
).then(handleResponse);
7878
}
7979

80-
function remove(id: String): Promise<TestVariation> {
80+
async function remove(id: String): Promise<TestVariation> {
8181
const requestOptions = {
8282
method: "DELETE",
8383
headers: authHeader(),

0 commit comments

Comments
 (0)