-
Notifications
You must be signed in to change notification settings - Fork 10
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||
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) }}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could use tailwinds |
||
<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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
|
@@ -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"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the action should be more specific, something like |
||
<Play size={20} style={svgOverride} /> | ||
</GetEndpointButton> | ||
|
||
<RunPipelineButton modalPopper={modalPopper} action="Rebuild"> | ||
<Renew size={20} style={svgOverride} /> | ||
|
There was a problem hiding this comment.
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