var F=Object.defineProperty;var L=(a,r,t)=>r in a?F(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{dN as N,dO as W,r as c,bW as J,w as R,u as $,bI as Z,ba as V,aA as M,aB as U,cb as Y,O as z,x as m,j as e,f as G,q as s,aH as _,aY as K,aZ as Q,d as X,bf as ee,bk as re,a4 as se,a5 as te,bl as O,c as k,an as y,aJ as x,v,lC as ae,bS as oe,t as ie,bB as ne,Z as ce,dk as C}from"./index-C6OVXshM.js";import{O as f,S as le,a as pe}from"./SketchWorkflow-CCbDrVfk.js";import{Z as de}from"./Project-CZXtYPe0.js";import"./SingleSelect-7lunYcLR.js";import"./sum-BYCx-hLx.js";import"./min-BF2EoXpM.js";import"./index-H5LhWHal.js";import"./zoom-D5h43YeK.js";import"./transform-C2GfmqNu.js";import"./string-cKWu9XK9.js";import"./index-B71lCevS.js";import"./alertManagerConfig.selectors-DfRN6QT6.js";import"./defineProperty-C28biA2x.js";import"./HumanizedCronExpression-B7-e7zEg.js";import"./index-D-ycbDlq.js";import"./form-DrxIax0x.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-BYGiWULO.js";import"./index-Cgrh9eC0.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-CRR-Czhi.js";class he extends N{constructor(){super(...arguments);S(this,"generateDag",async(t,i)=>{await this.request({url:`${t}/airflow/dag`,type:W.post,data:i})})}}const ue=new he("/project"),me=ce().shape({name:C.label("Name"),schedule:C.label("Schedule")}),xe=()=>{const a=J(),[r,t]=c.useState(!1),[i,l]=c.useState([]),[D,T]=c.useState(f.HopsworksLaunchOperator),[P,j]=R(),{id:p}=$(),d=Z(),g=V(),{formState:{errors:A},register:E,control:H,handleSubmit:I,reset:w,setError:q}=M({defaultValues:{name:"",schedule:"@once"},shouldUnregister:!1,resolver:U(me),reValidateMode:"onChange",mode:"onChange"}),B=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(Y.invalidateTags([{type:z.ProjectTags.FileExplorer,id:"Airflow"}])),g(m.project.airflow.overview)})},[a,d,i,p,g,w]),b=o=>{T(o),j()};return e.jsxs(e.Fragment,{children:[e.jsx(G,{title:"Create new workflow",children:e.jsx(s,{sx:{width:"100%"},children:e.jsxs(s,{flexDirection:"column",gap:"20px",children:[e.jsx(_,{disabled:r,...E("name"),label:"Name",placeholder:"Workflow name",...K("name",A)}),e.jsx(Q,{name:"schedule",control:H,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(X,{mr:"4px",children:"Frequency"})}),e.jsx(ee,{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=>q("schedule",{message:u}),error:h.schedule,withoutLabel:!0})]})})]})})}),e.jsxs(re,{title:"Operators",mt:"-1px",children:[e.jsx(se,{type:te.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(y,{mainText:"",children:e.jsx(x,{disabled:r,intent:"secondary",onClick:()=>{b(f.HopsworksLaunchOperator)},icon:v.plus,sx:{path:{fill:"primary"}},children:"Launch Operator"})}),e.jsx(y,{mainText:"",children:e.jsx(x,{disabled:r,intent:"secondary",onClick:()=>{b(f.HopsworksJobSuccessSensor)},icon:v.plus,sx:{path:{fill:"primary"}},children:"Job Success Sensor"})})]}),e.jsx(ae,{children:e.jsx(le,{operators:i,setOperators:l})}),e.jsx(oe,{}),e.jsx(s,{mt:"20px",justifyContent:"right",children:e.jsxs(s,{flexDirection:"row",children:[e.jsx(x,{intent:"alert",mr:"10px",href:ie(m.project.airflow.overview,m.project.value,{id:p}),children:"Back"}),e.jsx(ne,{disabled:i.length===0||r,onClick:I(B),isLoading:r,children:"Generate Dag"})]})}),e.jsx(pe,{isOpen:!!P,onClose:j,operatorType:D,operators:i,setOperators:l})]}),e.jsx(s,{minHeight:"20px"})]})},Ne=c.memo(xe);export{Ne as default,me as schema};
