var I=Object.defineProperty;var L=(a,r,t)=>r in a?I(a,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[r]=t;var S=(a,r,t)=>L(a,typeof r!="symbol"?r+"":r,t);import{ds as N,dt as J,ar as W,r as c,d7 as y,bH as B,y as R,u as V,by as _,b9 as G,aC as U,aD as Y,bZ as K,Q as M,q as x,j as e,b as Q,$ as s,b2 as X,aN as Z,aO as z,f as ee,be as re,dS as se,a3 as te,a5 as ae,bF as O,c as k,ao as C,b1 as m,C as v,kq as oe,cC as ie,o as ne,br as ce}from"./index-46ma1THH.js";import{O as f,S as le,a as pe}from"./SketchWorkflow-cQcM8LIa.js";import{Y as de}from"./Project-DqNODNns.js";import"./SingleSelect-DyMHGSBW.js";import"./sum-DF_JiBHo.js";import"./index-BSYtROPn.js";import"./zoom-A7rKCg-F.js";import"./transform-DZgNhtp2.js";import"./string-CFFdVFMV.js";import"./min-C0KmOMTA.js";import"./alertManagerConfig.selectors-ByceE4ck.js";import"./complement-Cl658Mix.js";import"./index-CcWUz40c.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-Bbf2VNbK.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-B8vQLvqE.js";import"./Anchor-VqM1KJ3L.js";class he extends N{constructor(){super(...arguments);S(this,"generateDag",async(t,i)=>{await this.request({url:`${t}/airflow/dag`,type:J.post,data:i})})}}const ue=new he("/project"),xe=W().shape({name:y.label("Name"),schedule:y.label("Schedule")}),me=()=>{const a=B(),[r,t]=c.useState(!1),[i,l]=c.useState([]),[D,T]=c.useState(f.HopsworksLaunchOperator),[P,j]=R(),{id:p}=V(),d=_(),g=G(),{formState:{errors:$},register:q,control:A,handleSubmit:E,reset:w,setError:H}=U({defaultValues:{name:"",schedule:"@once"},shouldUnregister:!1,resolver:Y(xe),reValidateMode:"onChange",mode:"onChange"}),F=c.useCallback(async o=>{const n={name:o.name,scheduleInterval:o.schedule,operators:i};t(!0),await ue.generateDag(+p,n).then(h=>{d.success({title:"Dag Creation",content:"Dag successfully created. You can view it in the Airflow dataset."}),l([]),w(),t(!1)}).catch(h=>{t(!1),d.error({title:"Dag Creation",content:"Failed to create dag."})}).finally(()=>{a(K.invalidateTags([{type:M.ProjectTags.FileExplorer,id:"Airflow"}])),g(x.project.airflow.overview)})},[a,d,i,p,g,w]),b=o=>{T(o),j()};return e.jsxs(e.Fragment,{children:[e.jsx(Q,{title:"Create new workflow",children:e.jsx(s,{sx:{width:"100%"},children:e.jsxs(s,{flexDirection:"column",gap:"20px",children:[e.jsx(X,{disabled:r,...q("name"),label:"Name",placeholder:"Workflow name",...Z("name",$)}),e.jsx(z,{name:"schedule",control:A,render:({field:{value:o,onChange:n},formState:{errors:h}})=>e.jsxs(s,{flexDirection:"column",gap:"10px",children:[e.jsx(s,{alignItems:"center",children:e.jsx(ee,{mr:"4px",children:"Frequency"})}),e.jsx(re,{value:o==="@once"?"Once":"Scheduled",options:["Once","Scheduled"],onChange:u=>n(u==="Once"?"@once":"0 * * * *"),flexDirection:"row"}),o!=="@once"&&e.jsx(de,{value:o,onChange:n,onError:u=>H("schedule",{message:u}),error:h.schedule,withoutLabel:!0})]})})]})})}),e.jsxs(se,{title:"Operators",mt:"-1px",children:[e.jsx(te,{type:ae.neutral,content:e.jsxs(s,{flexDirection:"column",children:[e.jsxs(s,{children:[e.jsx(O,{children:"Launch Operator: "}),e.jsx(k,{children:"Operator to launch a Job in Hopsworks."})]}),e.jsxs(s,{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(s,{gap:"20px",children:[e.jsx(C,{mainText:"",children:e.jsx(m,{disabled:r,intent:"secondary",onClick:()=>{b(f.HopsworksLaunchOperator)},icon:v.plus,sx:{path:{fill:"primary"}},children:"Launch Operator"})}),e.jsx(C,{mainText:"",children:e.jsx(m,{disabled:r,intent:"secondary",onClick:()=>{b(f.HopsworksJobSuccessSensor)},icon:v.plus,sx:{path:{fill:"primary"}},children:"Job Success Sensor"})})]}),e.jsx(oe,{children:e.jsx(le,{operators:i,setOperators:l})}),e.jsx(ie,{}),e.jsx(s,{mt:"20px",justifyContent:"right",children:e.jsxs(s,{flexDirection:"row",children:[e.jsx(m,{intent:"alert",mr:"10px",href:ne(x.project.airflow.overview,x.project.value,{id:p}),children:"Back"}),e.jsx(ce,{disabled:i.length===0||r,onClick:E(F),isLoading:r,children:"Generate Dag"})]})}),e.jsx(pe,{isOpen:!!P,onClose:j,operatorType:D,operators:i,setOperators:l})]}),e.jsx(s,{minHeight:"20px"})]})},Fe=c.memo(me);export{Fe as default,xe as schema};
