Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: endpoint button #68

Closed
wants to merge 2 commits into from
Closed
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
67 changes: 67 additions & 0 deletions frontend/src/components/ui/GetEndpointButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { useImmerAtom } from "jotai-immer";
import axios from "axios";
import { pipelineAtom } from "@/atoms/pipelineAtom";
import { useMutation } from "@tanstack/react-query";
import { Button } from "@carbon/react";
import ClosableModal from "./modal/ClosableModal";
import { useState } from "react";

export default function GetEndpointButton({modalPopper, children, action}) {
const [pipeline, setPipeline] = useImmerAtom(pipelineAtom);
const [validationErrorMsg, setValidationErrorMsg] = useState([]);
const [isOpen, setIsOpen] = useState(false);

const styles = {
margin: '5px',
};

const mutation = useMutation({
mutationFn: async (uuid) => {
return axios.get(`${import.meta.env.VITE_EXECUTOR}/pipeline/${uuid}/list`)
},
})

const endpoint = async (pipeline) => {
const res = await mutation.mutateAsync(pipeline.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function call can throw an error, so you might want to wrap it in a try-catch

if (res.status === 200) {
if (res.data !== null) {
setValidationErrorMsg(prev => {
return [`${import.meta.env.VITE_EXECUTOR}/pipeline/${pipeline.id}/${res.data[0].Hash}/execute`];
})
} else {
setValidationErrorMsg(prev => {
return "This pipeline has not been deployed";
})
}
} else {
setValidationErrorMsg(prev => {
return res.data;
})
}
setIsOpen(true)
}

return (
<>
<Button style={styles} size="sm" onClick={() => { endpoint(pipeline) }}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could use tailwinds m-1 or m-[5px] class instead here.

<span>{ action }</span>
{ children }
</Button>

<ClosableModal
modalHeading="The following error(s) occurred:"
passiveModal={true}
open={isOpen}
onRequestClose={() => setIsOpen(false)}
>
<div className="flex flex-col gap-4 p-3">
{validationErrorMsg.map((error, i) => {
return (
<p key={"error-msg-"+i}>{error}</p>
)
})}
</div>
</ClosableModal>
Comment on lines +51 to +64
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are going to keep this modal? If yes I think you can replace this with the plain Modal component from carbon

</>
);
}
4 changes: 4 additions & 0 deletions frontend/src/components/ui/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PipelineNameLabel from "./PipelineNameLabel";
import SavePipelineButton from "./SavePipelineButton";
import SaveAsPipelineButton from "./SaveAsPipelineButton";
import RunPipelineButton from "./RunPipelineButton";
import GetEndpointButton from "./GetEndpointButton";
import LogsButton from "./LogsButton";
import NewButton from "./NewButton";
import ApiKeysModal from "./modal/ApiKeysModal";
Expand Down Expand Up @@ -153,6 +154,9 @@ export default function Navbar({ children }) {
<RunPipelineButton modalPopper={modalPopper} action="Run">
<Play size={20} style={svgOverride} />
</RunPipelineButton>
<GetEndpointButton modalPopper={modalPopper} action="Something">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the action should be more specific, something like action="Deployment"?

<Play size={20} style={svgOverride} />
</GetEndpointButton>

<RunPipelineButton modalPopper={modalPopper} action="Rebuild">
<Renew size={20} style={svgOverride} />
Expand Down