Skip to content

Commit 69b7661

Browse files
committed
TestVariationMergeForm added
1 parent 6242872 commit 69b7661

File tree

5 files changed

+104
-21
lines changed

5 files changed

+104
-21
lines changed

src/_helpers/route.helpers.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
import { TestRun, TestVariation } from "../types"
2-
import { routes } from "../constants"
1+
import { TestRun, TestVariation } from "../types";
2+
import { routes } from "../constants";
33

4-
export const buildTestRunUrl = (testVariation: TestVariation, testRun: TestRun) =>
5-
`${routes.HOME}${testVariation.projectId}?buildId=${testRun.buildId}&testId=${testRun.id}`
4+
export const buildTestRunUrl = (
5+
testVariation: TestVariation,
6+
testRun: TestRun
7+
) =>
8+
`${routes.HOME}${testVariation.projectId}?buildId=${testRun.buildId}&testId=${testRun.id}`;
69

710
export const buildTestRunLocation = (testRun: TestRun) => ({
8-
search: `buildId=${testRun.buildId}&testId=${testRun.id}`,
9-
})
11+
search: `buildId=${testRun.buildId}&testId=${testRun.id}`,
12+
});
13+
14+
export const buildBuildPageUrl = (projectId: string, buildId: string) =>
15+
`${routes.HOME}${projectId}?buildId=${buildId}`;

src/components/TestDetailsModal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,11 @@ const TestDetailsModal: React.FunctionComponent<{
160160
{testRun.merge && (
161161
<Grid item>
162162
<Tooltip title="Will replace target branch baseline if accepted">
163-
<Chip label="merge" color="secondary" size="small" />
163+
<Chip
164+
label={`merge into: ${testRun.baselineBranchName}`}
165+
color="secondary"
166+
size="small"
167+
/>
164168
</Tooltip>
165169
</Grid>
166170
)}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React from "react";
2+
import { Grid, Select, MenuItem, Button } from "@material-ui/core";
3+
import { testVariationService } from "../services";
4+
import { useHistory } from "react-router-dom";
5+
import { buildBuildPageUrl } from "../_helpers/route.helpers";
6+
7+
interface IProps {
8+
projectId: string;
9+
items: string[];
10+
}
11+
12+
export const TestVariationMergeForm: React.FunctionComponent<IProps> = ({
13+
projectId,
14+
items,
15+
}) => {
16+
const history = useHistory();
17+
const [branch, setBranch] = React.useState("");
18+
19+
const handleSubmit = (event: React.FormEvent) => {
20+
event.preventDefault();
21+
testVariationService.merge(projectId, branch).then((build) => {
22+
history.push(buildBuildPageUrl(projectId, build.id));
23+
});
24+
};
25+
26+
return (
27+
<form onSubmit={handleSubmit}>
28+
<Grid container spacing={2}>
29+
<Grid item>
30+
<Select
31+
displayEmpty
32+
value={branch}
33+
onChange={(event) => setBranch(event.target.value as string)}
34+
>
35+
<MenuItem value="">
36+
<em>Select branch</em>
37+
</MenuItem>
38+
{items.map((i) => (
39+
<MenuItem key={i} value={i}>
40+
{i}
41+
</MenuItem>
42+
))}
43+
</Select>
44+
</Grid>
45+
<Grid item>
46+
<Button type="submit" color="primary" variant="contained">
47+
Merge
48+
</Button>
49+
</Grid>
50+
</Grid>
51+
</form>
52+
);
53+
};

src/pages/TestVariationListPage.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { testVariationService } from "../services";
66
import { Container, Box, Grid, Typography } from "@material-ui/core";
77
import ProjectSelect from "../components/ProjectSelect";
88
import Filters from "../components/Filters";
9+
import { TestVariationMergeForm } from "../components/TestVariationMergeForm";
910

1011
const TestVariationListPage: React.FunctionComponent = () => {
11-
const { projectId } = useParams();
12+
const { projectId = "" } = useParams();
1213
const [testVariations, setTestVariations] = React.useState<TestVariation[]>(
1314
[]
1415
);
@@ -54,17 +55,23 @@ const TestVariationListPage: React.FunctionComponent = () => {
5455
<ProjectSelect selectedId={projectId} />
5556
</Grid>
5657
<Grid item>
57-
<Box m={2}>
58-
<Filters
59-
items={testVariations}
60-
queryState={[query, setQuery]}
61-
osState={[os, setOs]}
62-
deviceState={[device, setDevice]}
63-
browserState={[browser, setBrowser]}
64-
viewportState={[viewport, setViewport]}
65-
branchNameState={[branchName, setBranchName]}
66-
/>
67-
</Box>
58+
<TestVariationMergeForm
59+
projectId={projectId}
60+
items={Array.from(
61+
new Set(testVariations.map((t) => t.branchName))
62+
)}
63+
/>
64+
</Grid>
65+
<Grid item>
66+
<Filters
67+
items={testVariations}
68+
queryState={[query, setQuery]}
69+
osState={[os, setOs]}
70+
deviceState={[device, setDevice]}
71+
browserState={[browser, setBrowser]}
72+
viewportState={[viewport, setViewport]}
73+
branchNameState={[branchName, setBranchName]}
74+
/>
6875
</Grid>
6976
<Grid item>
7077
<TestVariationList items={filteredItems} />

src/services/testVariation.service.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestVariation } from "../types";
1+
import { TestVariation, Build } from "../types";
22
import { handleResponse, authHeader } from "../_helpers/service.helpers";
33
import { API_URL } from "../_config/api.config";
44
import { IgnoreArea } from "../types/ignoreArea";
@@ -10,6 +10,7 @@ export const testVariationService = {
1010
getDetails,
1111
setIgnoreAreas,
1212
setComment,
13+
merge,
1314
};
1415

1516
function getList(projectId: String): Promise<TestVariation[]> {
@@ -30,7 +31,7 @@ function getDetails(id: String): Promise<TestVariation> {
3031
headers: authHeader(),
3132
};
3233

33-
return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then(
34+
return fetch(`${API_URL}${ENDPOINT_URL}/details/${id}`, requestOptions).then(
3435
handleResponse
3536
);
3637
}
@@ -62,3 +63,15 @@ function setComment(id: string, comment: string): Promise<TestVariation> {
6263
handleResponse
6364
);
6465
}
66+
67+
function merge(projectId: String, branchName: String): Promise<Build> {
68+
const requestOptions = {
69+
method: "GET",
70+
headers: authHeader(),
71+
};
72+
73+
return fetch(
74+
`${API_URL}${ENDPOINT_URL}/merge?projectId=${projectId}&branchName=${branchName}`,
75+
requestOptions
76+
).then(handleResponse);
77+
}

0 commit comments

Comments
 (0)