var L=Object.defineProperty;var N=(a,r,t)=>r in a?L(a,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[r]=t;var S=(a,r,t)=>N(a,typeof r!="symbol"?r+"":r,t);import{dt as F,du as J,ar as W,r as c,d8 as y,bI as B,y as R,u as _,bz as G,b9 as V,aC as U,aD as z,b_ as K,Q as M,q as x,j as e,b as Q,$ as s,b2 as X,aN as Y,aO as Z,f as ee,be as re,dT as se,a3 as te,a5 as ae,bG as O,c as k,ao as C,b1 as m,C as v,kt as oe,cD as ie,o as ne,bs as ce}from"./index-Cc-6WbPt.js";import{O as f,S as le,a as pe}from"./SketchWorkflow-CYRKozhF.js";import{Z as de}from"./Project-BB6nGAyP.js";import"./SingleSelect-BdzfpmLO.js";import"./sum-Bb5aTXea.js";import"./index-RxMbRJol.js";import"./zoom-A7rKCg-F.js";import"./transform-DZgNhtp2.js";import"./string-CFFdVFMV.js";import"./min-CZ7D4Cve.js";import"./alertManagerConfig.selectors-ob2Z93Rq.js";import"./complement-BOrTcrWV.js";import"./index-DeWhk8_Z.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-FE3v46aY.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-CGP_51ct.js";import"./Anchor-BpzIF9LH.js";class he extends F{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}=_(),d=G(),g=V(),{formState:{errors:$},register:A,control:E,handleSubmit:I,reset:w,setError:q}=U({defaultValues:{name:"",schedule:"@once"},shouldUnregister:!1,resolver:z(xe),reValidateMode:"onChange",mode:"onChange"}),H=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,...A("name"),label:"Name",placeholder:"Workflow name",...Y("name",$)}),e.jsx(Z,{name:"schedule",control:E,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=>q("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:I(H),isLoading:r,children:"Generate Dag"})]})}),e.jsx(pe,{isOpen:!!P,onClose:j,operatorType:D,operators:i,setOperators:l})]}),e.jsx(s,{minHeight:"20px"})]})},He=c.memo(me);export{He as default,xe as schema};
