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
57 changes: 56 additions & 1 deletion src/components/BuildList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
useBuildDispatch,
deleteBuild,
selectBuild,
modifyBuild,
stopBuild,
getBuildList,
useProjectState,
Expand All @@ -31,9 +32,10 @@ import { BuildStatusChip } from "../BuildStatusChip";
import { SkeletonList } from "../SkeletonList";
import { formatDateTime } from "../../_helpers/format.helper";
import { useSnackbar } from "notistack";
import { TextValidator } from "react-material-ui-form-validator";
import { Pagination } from "@material-ui/lab";
import { Build } from "../../types";
import { BaseModal } from "../BaseModal";
import { Pagination } from "@material-ui/lab";

const useStyles = makeStyles((theme: Theme) =>
createStyles({
Expand All @@ -60,8 +62,10 @@ const BuildList: FunctionComponent = () => {
const { enqueueSnackbar } = useSnackbar();
const { selectedProjectId } = useProjectState();
const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false);
const [editDialogOpen, setEditDialogOpen] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const [menuBuild, setMenuBuild] = React.useState<Build | null>();
const [newCiBuildId, setNewCiBuildId] = React.useState("");

const handleMenuClick = (
event: React.MouseEvent<HTMLElement>,
Expand All @@ -80,6 +84,10 @@ const BuildList: FunctionComponent = () => {
setDeleteDialogOpen(!deleteDialogOpen);
};

const toggleEditDialogOpen = () => {
setEditDialogOpen(!editDialogOpen);
};

React.useEffect(() => {
if (!selectedBuild && buildList.length > 0) {
selectBuild(buildDispatch, buildList[0].id);
Expand Down Expand Up @@ -204,9 +212,56 @@ const BuildList: FunctionComponent = () => {
Stop
</MenuItem>
)}
<MenuItem onClick={toggleEditDialogOpen}>Edit CI Build</MenuItem>
<MenuItem onClick={toggleDeleteDialogOpen}>Delete</MenuItem>
</Menu>
)}
{menuBuild && (
<BaseModal
open={editDialogOpen}
title={"Edit CI Build ID"}
submitButtonText={"Edit"}
onCancel={toggleEditDialogOpen}
content={
<React.Fragment>
<Typography>{`Edit the ci build id for build: #${
menuBuild.number || menuBuild.id
}`}</Typography>
<TextValidator
name="newCiBuildId"
validators={["minStringLength:2"]}
errorMessages={["Enter at least two characters."]}
margin="dense"
id="name"
label="New CI Build Id"
type="text"
fullWidth
required
value={newCiBuildId}
inputProps={{
onChange: (event: any) =>
setNewCiBuildId((event.target as HTMLInputElement).value),
"data-testid": "newCiBuildId",
}}
/>
</React.Fragment>
}
onSubmit={() => {
modifyBuild(buildDispatch, menuBuild.id, {
ciBuildId: newCiBuildId,
})
.then((b) => {
toggleEditDialogOpen();
})
.catch((err) =>
enqueueSnackbar(err, {
variant: "error",
})
);
handleMenuClose();
}}
/>
)}
{menuBuild && (
<BaseModal
open={deleteDialogOpen}
Expand Down
7 changes: 6 additions & 1 deletion src/contexts/build.context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,16 @@ async function deleteBuild(dispatch: Dispatch, id: string) {
}

async function stopBuild(dispatch: Dispatch, id: string) {
return buildsService.stop(id).then((build) => {
return buildsService.update(id, { "isRunning": false }).then((build) => {
dispatch({ type: "update", payload: build });
return build;
});
}

async function modifyBuild(dispatch: Dispatch, id: string, body: object) {
return buildsService.update(id, body);
}

async function selectBuild(dispatch: Dispatch, id: string | null) {
if (id === null) {
dispatch({ type: "select", payload: null });
Expand Down Expand Up @@ -207,5 +211,6 @@ export {
selectBuild,
addBuild,
updateBuild,
modifyBuild,
stopBuild,
};
8 changes: 5 additions & 3 deletions src/services/builds.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Build, PaginatedData } from "../types";
import { handleResponse, authHeader } from "../_helpers/service.helpers";
import { API_URL } from "../_config/env.config";
import {BuildDto} from "../types/dto/build.dto";

const ENDPOINT_URL = "/builds";

Expand Down Expand Up @@ -42,10 +43,11 @@ async function remove(id: string): Promise<Build> {
);
}

async function stop(id: string): Promise<Build> {
async function update(id: string, body: BuildDto): Promise<Build> {
const requestOptions = {
method: "PATCH",
headers: authHeader(),
headers: { "Content-Type": "application/json", ...authHeader() },
body: JSON.stringify(body)
};

return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then(
Expand All @@ -70,5 +72,5 @@ export const buildsService = {
getList,
approve,
remove,
stop,
update,
};
4 changes: 4 additions & 0 deletions src/types/dto/build.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface BuildDto {
ciBuildId?: string;
isRunning?: boolean;
}