var L=Object.defineProperty;var F=(a,r,t)=>r in a?L(a,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[r]=t;var y=(a,r,t)=>F(a,typeof r!="symbol"?r+"":r,t);import{dv as N,dw as V,ar as $,r as c,d8 as S,bI as q,y as B,u as R,bz as _,b9 as G,aC as U,aD as Y,b_ as Z,P as z,t as x,j as e,W as M,a as s,aH as X,aY as K,aZ as Q,f as ee,be as re,dV as se,a3 as te,a5 as ae,bG as k,c as O,ao as v,aJ as m,d as C,kV as oe,cD as ie,s as ne,bs as ce}from"./index-_eM6l4Nf.js";import{O as f,S as le,a as pe}from"./SketchWorkflow-D-hKhMyT.js";import{a0 as de}from"./Project-BTH4PZdL.js";import"./SingleSelect-DCo75wUx.js";import"./sum-D-ETrf05.js";import"./index-E_WbQbNt.js";import"./zoom-B-6v1BMB.js";import"./transform-Cm7rL0Nj.js";import"./string-cKWu9XK9.js";import"./min-CIERvabW.js";import"./alertManagerConfig.selectors-B-zYrdGC.js";import"./complement-CE-nEpWn.js";import"./index-B-5JhFyZ.js";import"./form-CMT9TYED.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-BIbwssIf.js";import"./git-BLdzamrJ.js";import"./useCopyToClipboard-BUvZjse8.js";import"./Anchor-JEsUSbQH.js";class he extends N{constructor(){super(...arguments);y(this,"generateDag",async(t,i)=>{await this.request({url:`${t}/airflow/dag`,type:V.post,data:i})})}}const ue=new he("/project"),xe=$().shape({name:S.label("Name"),schedule:S.label("Schedule")}),me=()=>{const a=q(),[r,t]=c.useState(!1),[i,l]=c.useState([]),[D,T]=c.useState(f.HopsworksLaunchOperator),[P,j]=B(),{id:p}=R(),d=_(),g=G(),{formState:{errors:I},register:A,control:E,handleSubmit:H,reset:w,setError:W}=U({defaultValues:{name:"",schedule:"@once"},shouldUnregister:!1,resolver:Y(xe),reValidateMode:"onChange",mode:"onChange"}),J=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(Z.invalidateTags([{type:z.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(M,{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",...K("name",I)}),e.jsx(Q,{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=>W("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(k,{children:"Launch Operator: "}),e.jsx(O,{children:"Operator to launch a Job in Hopsworks."})]}),e.jsxs(s,{children:[e.jsx(k,{children:"Job Success Sensor: "}),e.jsx(O,{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(v,{mainText:"",children:e.jsx(m,{disabled:r,intent:"secondary",onClick:()=>{b(f.HopsworksLaunchOperator)},icon:C.plus,sx:{path:{fill:"primary"}},children:"Launch Operator"})}),e.jsx(v,{mainText:"",children:e.jsx(m,{disabled:r,intent:"secondary",onClick:()=>{b(f.HopsworksJobSuccessSensor)},icon:C.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:H(J),isLoading:r,children:"Generate Dag"})]})}),e.jsx(pe,{isOpen:!!P,onClose:j,operatorType:D,operators:i,setOperators:l})]}),e.jsx(s,{minHeight:"20px"})]})},Le=c.memo(me);export{Le as default,xe as schema};
