var J=Object.defineProperty;var N=(t,r,s)=>r in t?J(t,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[r]=s;var b=(t,r,s)=>(N(t,typeof r!="symbol"?r+"":r,s),s);import{dl as q,dm as V,r as c,a7 as W,cI as y,b1 as z,P as B,u as R,a_ as U,b2 as $,an as G,s as Q,b as x,j as e,E as M,Q as a,aH as Y,ay as _,az as K,g as X,aI as Z,fO as ee,a3 as re,a4 as se,b4 as O,x as k,af as C,aU as l,z as v,jm as ae,cu as te,c as oe,ao as ie}from"./index-ea7817a2.js";import{O as f,S as ne,a as ce}from"./SketchWorkflow-dbb8df08.js";import{d as le}from"./index-8f672200.js";import{e as pe}from"./Project-80a71be4.js";import"./zoom-0ed3d19c.js";import"./FileUploaderButton-495e1c87.js";import"./useDownload-09eaf3eb.js";import"./useCurrentProject-0132f110.js";import"./useProject-77619fff.js";import"./sum-a0d3316b.js";import"./file-utils-a5f053e8.js";import"./index-43e7382e.js";import"./PrimaryIconButton-fe990c52.js";import"./zipObj-08c84ab1.js";import"./dumbPluralize-86a9b9d6.js";import"./git-d9965c1a.js";import"./NoData-8733f606.js";import"./alertManagerConfig.selectors-c57f191b.js";class de extends q{constructor(){super(...arguments);b(this,"generateDag",async(s,i)=>{await this.request({url:`${s}/airflow/dag`,type:V.post,data:i})})}}const he=new de("/project"),me=W().shape({name:y.label("Name"),schedule:y.label("Schedule")}),ue=()=>{const t=z(),[r,s]=c.useState(!1),[i,p]=c.useState([]),[D,P]=c.useState(f.HopsworksLaunchOperator),[T,j]=B(),{id:d}=R(),h=U(),g=$(),{formState:{errors:E},register:A,control:H,handleSubmit:I,reset:w,setError:L}=G({defaultValues:{name:"",schedule:"@once"},shouldUnregister:!1,resolver:ie(me),reValidateMode:"onChange",mode:"onChange"}),F=c.useCallback(async o=>{const n={name:o.name,scheduleInterval:o.schedule,operators:i};s(!0),await he.generateDag(+d,n).then(m=>{h.success({title:"Dag Creation",content:"Dag successfully created. You can view it in the Airflow dataset."}),p([]),w(),s(!1)}).catch(m=>{s(!1),h.error({title:"Dag Creation",content:"Failed to create dag."})}).finally(()=>{t(le.invalidateTags([{type:Q.ProjectTags.FileExplorer,id:"Airflow"}])),g(x.airflow.overview)})},[t,h,i,d,g,w]),S=o=>{P(o),j()};return e.jsxs(e.Fragment,{children:[e.jsx(M,{title:"Create new workflow",children:e.jsx(a,{sx:{width:"100%"},children:e.jsxs(a,{flexDirection:"column",gap:"20px",children:[e.jsx(Y,{disabled:r,...A("name"),label:"Name",placeholder:"Workflow name",..._("name",E)}),e.jsx(K,{name:"schedule",control:H,render:({field:{value:o,onChange:n},formState:{errors:m}})=>e.jsxs(a,{flexDirection:"column",gap:"10px",children:[e.jsx(a,{alignItems:"center",children:e.jsx(X,{mr:"4px",children:"Frequency"})}),e.jsx(Z,{value:o==="@once"?"Once":"Scheduled",options:["Once","Scheduled"],onChange:u=>n(u==="Once"?"@once":"0 * * * *"),flexDirection:"row"}),o!=="@once"&&e.jsx(pe,{value:o,onChange:n,onError:u=>L("schedule",{message:u}),error:m.schedule,withoutLabel:!0})]})})]})})}),e.jsxs(ee,{title:"Operators",mt:"-1px",children:[e.jsx(re,{type:se.neutral,content:e.jsxs(a,{flexDirection:"column",children:[e.jsxs(a,{children:[e.jsx(O,{children:"Launch Operator: "}),e.jsx(k,{children:"Operator to launch a Job in Hopsworks."})]}),e.jsxs(a,{children:[e.jsx(O,{children:"Job Success Sensor: "}),e.jsx(k,{children:"Operator which waits for the completion of a specific job. The task will fail too if the job which is waiting for fails."})]})]}),mb:"20px"}),e.jsxs(a,{gap:"20px",children:[e.jsx(C,{mainText:"",children:e.jsx(l,{disabled:r,intent:"secondary",onClick:()=>{S(f.HopsworksLaunchOperator)},icon:v.plus,sx:{path:{fill:"primary"}},children:"Launch Operator"})}),e.jsx(C,{mainText:"",children:e.jsx(l,{disabled:r,intent:"secondary",onClick:()=>{S(f.HopsworksJobSuccessSensor)},icon:v.plus,sx:{path:{fill:"primary"}},children:"Job Success Sensor"})})]}),e.jsx(ae,{children:e.jsx(ne,{operators:i,setOperators:p})}),e.jsx(te,{}),e.jsx(a,{mt:"20px",justifyContent:"right",children:e.jsxs(a,{flexDirection:"row",children:[e.jsx(l,{intent:"alert",mr:"10px",href:oe(x.airflow.overview,x.project.value,{id:d}),children:"Back"}),e.jsx(l,{disabled:i.length===0||r,onClick:I(F),isLoading:r,children:"Generate Dag"})]})}),e.jsx(ce,{isOpen:!!T,onClose:j,operatorType:D,operators:i,setOperators:p})]}),e.jsx(a,{minHeight:"20px"})]})},Le=c.memo(ue);export{Le as default,me as schema};
