Skip to content

Commit 6337a27

Browse files
committed
save added
1 parent 761364d commit 6337a27

File tree

6 files changed

+62
-12
lines changed

6 files changed

+62
-12
lines changed

src/components/CommentsPopper.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,22 @@ const useStyles = makeStyles((theme) => ({
2626
}));
2727

2828
interface IProps {
29-
text: string;
29+
text: string | undefined;
30+
onSave: (comment: string) => Promise<any>;
3031
}
3132

32-
export const CommentsPopper: React.FunctionComponent<IProps> = ({ text }) => {
33+
export const CommentsPopper: React.FunctionComponent<IProps> = ({
34+
text,
35+
onSave,
36+
}) => {
3337
const classes = useStyles();
3438
const popupState = usePopupState({
3539
variant: "popper",
3640
popupId: "commentPopper",
3741
});
38-
const [comment, setComment] = React.useState(text);
42+
const [comment, setComment] = React.useState("");
43+
44+
React.useEffect(() => setComment(text ? text : ""), [text]);
3945

4046
return (
4147
<React.Fragment>
@@ -77,7 +83,7 @@ export const CommentsPopper: React.FunctionComponent<IProps> = ({ text }) => {
7783
/>
7884
<Button
7985
onClick={() => {
80-
popupState.close();
86+
onSave(comment).then(() => popupState.close());
8187
}}
8288
>
8389
Save

src/components/TestDetailsModal.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,20 @@ const TestDetailsModal: React.FunctionComponent<{
204204
</Button>
205205
</Grid>
206206
<Grid item>
207-
<CommentsPopper text={testRun.comment}/>
207+
<CommentsPopper
208+
text={testRun.comment}
209+
onSave={(comment) =>
210+
Promise.all([
211+
// update in test run
212+
testRunService
213+
.setComment(testRun.id, comment)
214+
.then((testRun) => updateTestRun(testRunDispatch, testRun)),
215+
// update in variation
216+
testVariationService
217+
.setComment(testRun.testVariationId, comment),
218+
])
219+
}
220+
/>
208221
</Grid>
209222
<Grid item>
210223
<Paper variant="outlined">

src/services/testRun.service.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const testRunService = {
1212
approve,
1313
reject,
1414
setIgnoreAreas,
15+
setComment,
1516
};
1617

1718
function getList(buildId: string): Promise<TestRun[]> {
@@ -86,3 +87,15 @@ function setIgnoreAreas(
8687
requestOptions
8788
).then(handleResponse);
8889
}
90+
91+
function setComment(id: string, comment: string): Promise<TestRun> {
92+
const requestOptions = {
93+
method: "PUT",
94+
headers: { "Content-Type": "application/json", ...authHeader() },
95+
body: JSON.stringify({ comment }),
96+
};
97+
98+
return fetch(`${API_URL}${ENDPOINT_URL}/comment/${id}`, requestOptions).then(
99+
handleResponse
100+
);
101+
}

src/services/testVariation.service.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import { handleResponse, authHeader } from "../_helpers/service.helpers";
33
import { API_URL } from "../_config/api.config";
44
import { IgnoreArea } from "../types/ignoreArea";
55

6-
const ENDPOINT_URL = "/test-variations"
6+
const ENDPOINT_URL = "/test-variations";
77

88
export const testVariationService = {
99
getList,
1010
getDetails,
11-
setIgnoreAreas
11+
setIgnoreAreas,
12+
setComment,
1213
};
1314

1415
function getList(projectId: String): Promise<TestVariation[]> {
@@ -17,7 +18,10 @@ function getList(projectId: String): Promise<TestVariation[]> {
1718
headers: authHeader(),
1819
};
1920

20-
return fetch(`${API_URL}${ENDPOINT_URL}?projectId=${projectId}`, requestOptions).then(handleResponse);
21+
return fetch(
22+
`${API_URL}${ENDPOINT_URL}?projectId=${projectId}`,
23+
requestOptions
24+
).then(handleResponse);
2125
}
2226

2327
function getDetails(id: String): Promise<TestVariation> {
@@ -26,7 +30,9 @@ function getDetails(id: String): Promise<TestVariation> {
2630
headers: authHeader(),
2731
};
2832

29-
return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then(handleResponse);
33+
return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then(
34+
handleResponse
35+
);
3036
}
3137

3238
function setIgnoreAreas(
@@ -43,4 +49,16 @@ function setIgnoreAreas(
4349
`${API_URL}${ENDPOINT_URL}/ignoreArea/${variationId}`,
4450
requestOptions
4551
).then(handleResponse);
46-
}
52+
}
53+
54+
function setComment(id: string, comment: string): Promise<TestVariation> {
55+
const requestOptions = {
56+
method: "PUT",
57+
headers: { "Content-Type": "application/json", ...authHeader() },
58+
body: JSON.stringify({ comment }),
59+
};
60+
61+
return fetch(`${API_URL}${ENDPOINT_URL}/comment/${id}`, requestOptions).then(
62+
handleResponse
63+
);
64+
}

src/types/testRun.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ export interface TestRun {
1616
viewport: string;
1717
device: string;
1818
ignoreAreas: string;
19-
comment: string;
19+
comment?: string;
2020
}

src/types/testVariation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ export interface TestVariation {
1111
ignoreAreas: string;
1212
projectId: string;
1313
baselines: Baseline[];
14-
comment: string;
14+
comment?: string;
1515
}

0 commit comments

Comments
 (0)