var H=Object.defineProperty;var I=(o,r,s)=>r in o?H(o,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):o[r]=s;var S=(o,r,s)=>I(o,typeof r!="symbol"?r+"":r,s);import{d4 as W,d5 as F,r as c,aj as $,cN as y,aD as J,c as R,u as V,aE as Q,bL as Z,az as G,W as M,s as u,j as e,m as U,B as t,aM as z,b8 as K,b9 as Y,Q as X,bn as _,ds as ee,af as re,ag as te,bK as O,b as k,ar as v,aG as x,Z as C,ix as se,cA as oe,q as ae,aA as ie}from"./index-dP1W1_bd.js";import{O as f,S as ne,a as ce}from"./SketchWorkflow-BvweAgSN.js";import{h as le}from"./FileUploaderButton-frSujVRY.js";import{B as pe}from"./ButtonWithRole-CF64B_Or.js";import{aD as de}from"./Project-CsYwwOpN.js";import"./utils-UGwNsahk.js";import"./SingleSelect-B8f6hurf.js";import"./sum-ZyenTPNK.js";import"./index-TtxdA7bE.js";import"./zoom-CRTJnDeN.js";import"./transform-C0Urpblx.js";import"./string-CFFdVFMV.js";import"./min-DNV8UA03.js";import"./useDownload-C3yCvYJa.js";import"./useProject-CXVt1xnE.js";import"./length-BzpOfCdE.js";import"./uniq-98MdbBvs.js";import"./uniqBy-6mvKp2Ip.js";import"./dumbPluralize-CcxDsNiu.js";import"./alertManagerConfig.selectors-B_R5cvew.js";import"./__-BIxbRvwe.js";import"./complement-D_Q2yZKt.js";import"./index-MHdXqM53.js";import"./CardActionButton-BtCnEqTK.js";import"./useKeyPress-OcDHupLZ.js";import"./zipObj-DEkcXp9d.js";import"./useScreenWithScroll-zcr7TMGO.js";import"./symmetricDifference-mJT60wVA.js";import"./git-C8OLuEaG.js";import"./NoData-DLZ_8GEo.js";import"./useCopyToClipboard-DTBM3H3Z.js";import"./Anchor-B_lGyhCa.js";class me extends W{constructor(){super(...arguments);S(this,"generateDag",async(s,i)=>{await this.request({url:`${s}/airflow/dag`,type:F.post,data:i})})}}const he=new me("/project"),ue=$().shape({name:y.label("Name"),schedule:y.label("Schedule")}),xe=()=>{const o=J(),[r,s]=c.useState(!1),[i,l]=c.useState([]),[D,T]=c.useState(f.HopsworksLaunchOperator),[A,j]=R(),{id:p}=V(),d=Q(),g=Z(),{formState:{errors:E},register:P,control:N,handleSubmit:B,reset:w,setError:L}=G({defaultValues:{name:"",schedule:"@once"},shouldUnregister:!1,resolver:ie(ue),reValidateMode:"onChange",mode:"onChange"}),q=c.useCallback(async a=>{const n={name:a.name,scheduleInterval:a.schedule,operators:i};s(!0),await he.generateDag(+p,n).then(m=>{d.success({title:"Dag Creation",content:"Dag successfully created. You can view it in the Airflow dataset."}),l([]),w(),s(!1)}).catch(m=>{s(!1),d.error({title:"Dag Creation",content:"Failed to create dag."})}).finally(()=>{o(le.invalidateTags([{type:M.ProjectTags.FileExplorer,id:"Airflow"}])),g(u.airflow.overview)})},[o,d,i,p,g,w]),b=a=>{T(a),j()};return e.jsxs(e.Fragment,{children:[e.jsx(U,{title:"Create new workflow",children:e.jsx(t,{sx:{width:"100%"},children:e.jsxs(t,{flexDirection:"column",gap:"20px",children:[e.jsx(z,{disabled:r,...P("name"),label:"Name",placeholder:"Workflow name",...K("name",E)}),e.jsx(Y,{name:"schedule",control:N,render:({field:{value:a,onChange:n},formState:{errors:m}})=>e.jsxs(t,{flexDirection:"column",gap:"10px",children:[e.jsx(t,{alignItems:"center",children:e.jsx(X,{mr:"4px",children:"Frequency"})}),e.jsx(_,{value:a==="@once"?"Once":"Scheduled",options:["Once","Scheduled"],onChange:h=>n(h==="Once"?"@once":"0 * * * *"),flexDirection:"row"}),a!=="@once"&&e.jsx(de,{value:a,onChange:n,onError:h=>L("schedule",{message:h}),error:m.schedule,withoutLabel:!0})]})})]})})}),e.jsxs(ee,{title:"Operators",mt:"-1px",children:[e.jsx(re,{type:te.neutral,content:e.jsxs(t,{flexDirection:"column",children:[e.jsxs(t,{children:[e.jsx(O,{children:"Launch Operator: "}),e.jsx(k,{children:"Operator to launch a Job in Hopsworks."})]}),e.jsxs(t,{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(t,{gap:"20px",children:[e.jsx(v,{mainText:"",children:e.jsx(x,{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(x,{disabled:r,intent:"secondary",onClick:()=>{b(f.HopsworksJobSuccessSensor)},icon:C.plus,sx:{path:{fill:"primary"}},children:"Job Success Sensor"})})]}),e.jsx(se,{children:e.jsx(ne,{operators:i,setOperators:l})}),e.jsx(oe,{}),e.jsx(t,{mt:"20px",justifyContent:"right",children:e.jsxs(t,{flexDirection:"row",children:[e.jsx(x,{intent:"alert",mr:"10px",href:ae(u.airflow.overview,u.project.value,{id:p}),children:"Back"}),e.jsx(pe,{disabled:i.length===0||r,onClick:B(q),isLoading:r,children:"Generate Dag"})]})}),e.jsx(ce,{isOpen:!!A,onClose:j,operatorType:D,operators:i,setOperators:l})]}),e.jsx(t,{minHeight:"20px"})]})},ze=c.memo(xe);export{ze as default,ue as schema};
