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
18 changes: 12 additions & 6 deletions src/_helpers/route.helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { TestRun, TestVariation } from "../types"
import { routes } from "../constants"
import { TestRun, TestVariation } from "../types";
import { routes } from "../constants";

export const buildTestRunUrl = (testVariation: TestVariation, testRun: TestRun) =>
`${routes.HOME}${testVariation.projectId}?buildId=${testRun.buildId}&testId=${testRun.id}`
export const buildTestRunUrl = (
testVariation: TestVariation,
testRun: TestRun
) =>
`${routes.HOME}${testVariation.projectId}?buildId=${testRun.buildId}&testId=${testRun.id}`;

export const buildTestRunLocation = (testRun: TestRun) => ({
search: `buildId=${testRun.buildId}&testId=${testRun.id}`,
})
search: `buildId=${testRun.buildId}&testId=${testRun.id}`,
});

export const buildBuildPageUrl = (projectId: string, buildId: string) =>
`${routes.HOME}${projectId}?buildId=${buildId}`;
67 changes: 45 additions & 22 deletions src/components/TestDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
Paper,
Box,
makeStyles,
Chip,
Tooltip,
} from "@material-ui/core";
import { ToggleButton } from "@material-ui/lab";
import { TestRun } from "../types";
Expand Down Expand Up @@ -154,26 +156,45 @@ const TestDetailsModal: React.FunctionComponent<{
{(testRun.status === TestStatus.unresolved ||
testRun.status === TestStatus.new) && (
<Grid item>
<Button
color="inherit"
onClick={() =>
testRunService.approve(testRun.id).then((testRun) => {
updateTestRun(testRunDispatch, testRun);
})
}
>
Approve
</Button>
<Button
color="secondary"
onClick={() =>
testRunService.reject(testRun.id).then((testRun) => {
updateTestRun(testRunDispatch, testRun);
})
}
>
Reject
</Button>
<Grid container spacing={2} alignItems="center">
{testRun.merge && (
<Grid item>
<Tooltip title="Will replace target branch baseline if accepted">
<Chip
label={`merge into: ${testRun.baselineBranchName}`}
color="secondary"
size="small"
/>
</Tooltip>
</Grid>
)}
<Grid item>
<Button
color="inherit"
onClick={() =>
testRunService
.approve(testRun.id, testRun.merge)
.then((testRun) => {
updateTestRun(testRunDispatch, testRun);
})
}
>
Approve
</Button>
</Grid>
<Grid item>
<Button
color="secondary"
onClick={() =>
testRunService.reject(testRun.id).then((testRun) => {
updateTestRun(testRunDispatch, testRun);
})
}
>
Reject
</Button>
</Grid>
</Grid>
</Grid>
)}
<Grid item>
Expand Down Expand Up @@ -213,8 +234,10 @@ const TestDetailsModal: React.FunctionComponent<{
.setComment(testRun.id, comment)
.then((testRun) => updateTestRun(testRunDispatch, testRun)),
// update in variation
testVariationService
.setComment(testRun.testVariationId, comment),
testVariationService.setComment(
testRun.testVariationId,
comment
),
])
}
/>
Expand Down
53 changes: 53 additions & 0 deletions src/components/TestVariationMergeForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from "react";
import { Grid, Select, MenuItem, Button } from "@material-ui/core";
import { testVariationService } from "../services";
import { useHistory } from "react-router-dom";
import { buildBuildPageUrl } from "../_helpers/route.helpers";

interface IProps {
projectId: string;
items: string[];
}

export const TestVariationMergeForm: React.FunctionComponent<IProps> = ({
projectId,
items,
}) => {
const history = useHistory();
const [branch, setBranch] = React.useState("");

const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
testVariationService.merge(projectId, branch).then((build) => {
history.push(buildBuildPageUrl(projectId, build.id));
});
};

return (
<form onSubmit={handleSubmit}>
<Grid container spacing={2}>
<Grid item>
<Select
displayEmpty
value={branch}
onChange={(event) => setBranch(event.target.value as string)}
>
<MenuItem value="">
<em>Select branch</em>
</MenuItem>
{items.map((i) => (
<MenuItem key={i} value={i}>
{i}
</MenuItem>
))}
</Select>
</Grid>
<Grid item>
<Button type="submit" color="primary" variant="contained">
Merge
</Button>
</Grid>
</Grid>
</form>
);
};
31 changes: 19 additions & 12 deletions src/pages/TestVariationListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import { testVariationService } from "../services";
import { Container, Box, Grid, Typography } from "@material-ui/core";
import ProjectSelect from "../components/ProjectSelect";
import Filters from "../components/Filters";
import { TestVariationMergeForm } from "../components/TestVariationMergeForm";

const TestVariationListPage: React.FunctionComponent = () => {
const { projectId } = useParams();
const { projectId = "" } = useParams();
const [testVariations, setTestVariations] = React.useState<TestVariation[]>(
[]
);
Expand Down Expand Up @@ -54,17 +55,23 @@ const TestVariationListPage: React.FunctionComponent = () => {
<ProjectSelect selectedId={projectId} />
</Grid>
<Grid item>
<Box m={2}>
<Filters
items={testVariations}
queryState={[query, setQuery]}
osState={[os, setOs]}
deviceState={[device, setDevice]}
browserState={[browser, setBrowser]}
viewportState={[viewport, setViewport]}
branchNameState={[branchName, setBranchName]}
/>
</Box>
<TestVariationMergeForm
projectId={projectId}
items={Array.from(
new Set(testVariations.map((t) => t.branchName))
)}
/>
</Grid>
<Grid item>
<Filters
items={testVariations}
queryState={[query, setQuery]}
osState={[os, setOs]}
deviceState={[device, setDevice]}
browserState={[browser, setBrowser]}
viewportState={[viewport, setViewport]}
branchNameState={[branchName, setBranchName]}
/>
</Grid>
<Grid item>
<TestVariationList items={filteredItems} />
Expand Down
9 changes: 5 additions & 4 deletions src/services/testRun.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,16 @@ function recalculateDiff(id: string): Promise<TestRun> {
).then(handleResponse);
}

function approve(id: string): Promise<TestRun> {
function approve(id: string, merge: boolean): Promise<TestRun> {
const requestOptions = {
method: "GET",
headers: authHeader(),
};

return fetch(`${API_URL}${ENDPOINT_URL}/approve/${id}`, requestOptions).then(
handleResponse
);
return fetch(
`${API_URL}${ENDPOINT_URL}/approve?id=${id}&merge=${merge}`,
requestOptions
).then(handleResponse);
}

function reject(id: string): Promise<TestRun> {
Expand Down
17 changes: 15 additions & 2 deletions src/services/testVariation.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { TestVariation } from "../types";
import { TestVariation, Build } from "../types";
import { handleResponse, authHeader } from "../_helpers/service.helpers";
import { API_URL } from "../_config/api.config";
import { IgnoreArea } from "../types/ignoreArea";
Expand All @@ -10,6 +10,7 @@ export const testVariationService = {
getDetails,
setIgnoreAreas,
setComment,
merge,
};

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

return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then(
return fetch(`${API_URL}${ENDPOINT_URL}/details/${id}`, requestOptions).then(
handleResponse
);
}
Expand Down Expand Up @@ -62,3 +63,15 @@ function setComment(id: string, comment: string): Promise<TestVariation> {
handleResponse
);
}

function merge(projectId: String, branchName: String): Promise<Build> {
const requestOptions = {
method: "GET",
headers: authHeader(),
};

return fetch(
`${API_URL}${ENDPOINT_URL}/merge?projectId=${projectId}&branchName=${branchName}`,
requestOptions
).then(handleResponse);
}
1 change: 1 addition & 0 deletions src/types/testRun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface TestRun {
comment?: string;
branchName: string;
baselineBranchName: string;
merge: boolean;
}