Skip to content

Commit

Permalink
move releaseEnvironment logic into ReleaseEnvironmentModal (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelquigley committed Jan 24, 2025
1 parent 3a71848 commit a6bd682
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
21 changes: 1 addition & 20 deletions ui100/src/EnvironmentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,6 @@ const EnvironmentPanel = ({environment}: EnvironmentPanelProps) => {
})
}, [environment]);

const releaseEnvironment = () => {
if(environment.data && environment.data.envZId) {
console.log("releasing");
let cfg = new Configuration({
headers: {
"X-TOKEN": user.token
}
});
let environmentApi = new EnvironmentApi(cfg);
environmentApi.disable({body: {identity: environment.data.envZId as string}})
.then(d => {
setReleaseEnvironmentOpen(false);
})
.catch(e => {
console.log("releaseEnvironment", e);
});
}
}

return (
<>
<Typography component="div">
Expand All @@ -97,7 +78,7 @@ const EnvironmentPanel = ({environment}: EnvironmentPanelProps) => {
</Grid2>
</Grid2>
</Typography>
<ReleaseEnvironmentModal close={closeReleaseEnvironment} isOpen={releaseEnvironmentOpen} detail={detail} action={releaseEnvironment} />
<ReleaseEnvironmentModal close={closeReleaseEnvironment} isOpen={releaseEnvironmentOpen} user={user} environment={environment} detail={detail} />
</>
);
}
Expand Down
34 changes: 29 additions & 5 deletions ui100/src/ReleaseEnvironmentModal.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import {Environment} from "./api";
import {Configuration, Environment, EnvironmentApi} from "./api";
import {useEffect, useRef, useState} from "react";
import {Box, Button, Checkbox, FormControlLabel, Grid2, Modal, Typography} from "@mui/material";
import {modalStyle} from "./styling/theme.ts";
import {User} from "./model/user.ts";
import {Node} from "@xyflow/react";

interface ReleaseEnvironmentProps {
close: () => void;
isOpen: boolean;
user: User;
environment: Node;
detail: Environment;
action: () => void;
}

const ReleaseEnvironmentModal = ({ close, isOpen, detail, action }: ReleaseEnvironmentProps) => {
const ReleaseEnvironmentModal = ({ close, isOpen, user, environment, detail }: ReleaseEnvironmentProps) => {
const [description, setDescription] = useState<String>("");
const [checked, setChecked] = useState<boolean>(false);
const checkedRef = useRef<boolean>();
checkedRef.current = checked;

const toggleChecked = (event: React.ChangeEvent<HTMLInputElement>) => {
const toggleChecked = () => {
setChecked(!checkedRef.current);
}

Expand All @@ -30,6 +33,27 @@ const ReleaseEnvironmentModal = ({ close, isOpen, detail, action }: ReleaseEnvir
}
}, [detail]);

const releaseEnvironment = () => {
if(environment.data && environment.data.envZId) {
console.log("releasing");
let cfg = new Configuration({
headers: {
"X-TOKEN": user.token
}
});
let environmentApi = new EnvironmentApi(cfg);
environmentApi.disable({body: {identity: environment.data.envZId as string}})
.then(d => {
close();
})
.catch(e => {
e.response.json().then(ex => {
console.log("releaseEnvironment", ex.message);
})
});
}
}

return (
<Modal open={isOpen} onClose={close}>
<Box sx={{ ...modalStyle }}>
Expand All @@ -46,7 +70,7 @@ const ReleaseEnvironmentModal = ({ close, isOpen, detail, action }: ReleaseEnvir
<FormControlLabel control={<Checkbox checked={checked} onChange={toggleChecked} />} label={<p>I confirm the release of <code>{description}</code></p>} sx={{ mt: 2 }} />
</Grid2>
<Grid2 container sx={{ flexGrow: 1 }} alignItems="center">
<Button color="error" variant="contained" disabled={!checked} onClick={action}>Release</Button>
<Button color="error" variant="contained" disabled={!checked} onClick={releaseEnvironment}>Release</Button>
</Grid2>
</Box>
</Modal>
Expand Down

0 comments on commit a6bd682

Please sign in to comment.