import{jz as k,lB as y,p as n,A as u,hB as C,bw as D,D as F,aW as H,b7 as m,s as L,o as d,aX as W,ay as E,ia as z,ib as P,aD as T,at as R,jW as B,B as b,Q as I,dR as N,gX as G,aF as J,r as f,jl as q,jn as M,es as h,gY as Z,j as t,q as c,d as S,L as O,iU as Q,iV as V,h as X,c5 as $,ao as U,v as K,u as A,aL as Y,jB as ee,b6 as se,b4 as te,c as re,bI as ae,F as x,f as oe,aJ as ne,t as ie,x as w,bB as ce,bS as le,gz as pe,gW as ue,dM as g}from"./index-C6OVXshM.js";import{O as v,S as de}from"./SketchWorkflow-CCbDrVfk.js";import{R as me}from"./Renderer-DC9MkZKt.js";import{H as he}from"./HumanizedCronExpression-B7-e7zEg.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";var xe=k(function(s,r,a){return y(function(o,i,l){return s(i,l)},r,a)});const fe=n(e=>[...e.matchAll(/task_id="([^"]+)".*job_name="([^"]+)".*job_arguments="([^"]*)".*wait_for_completion=([^/)]+)/gi)][0]??[],([e,s,r,a,o])=>({name:v.HopsworksLaunchOperator,id:s,jobName:r,jobArgs:a,wait:o==="True",dependsOn:[]})),je=n(e=>[...e.matchAll(/task_id="([^"]+)".*job_name="([^"]+)/gi)][0]??[],([e,s,r])=>({name:v.HopsworksJobSuccessSensor,id:s,jobName:r,jobArgs:"",wait:!1,dependsOn:[]})),we=n(e=>[...e.matchAll(/([a-zA-Z0-9_]+)\.set_upstream\(([^)]*)\)/gi)][0]??[],([e,s,r])=>({jobName:s,dependsOn:r})),ge=n(T(/\s|\\/g,""),e=>e.match(/HopsworksLaunchOperator\([^)]*\)|HopsworksJobSuccessSensor\([^)]*\)|[a-zA-Z0-9_]+\.set_upstream\([^)]*\)/g),E(z([[m("HopsworksLaunchOperator"),fe],[m("HopsworksJobSuccessSensor"),je],[P,we]])),C((e,s)=>s.name?[...e,s]:e.map(D(F("id",s.jobName),xe(H,{dependsOn:m("[",s.dependsOn)?n(L("["),d(",]"),d("]"),W(","))(s.dependsOn):[s.dependsOn]}))),[])),be=e=>{var s,r;return(r=(s=e.matchAll(/schedule_interval = "([^)]+)"/g).next())==null?void 0:s.value)==null?void 0:r[1]},Se=n(e=>({operators:e,schedule:e}),u({operators:ge,schedule:be})),Oe=e=>({attributes:{id:e,name:"any",accessTime:"2023-09-25T12:34:26.946Z"}}),Ae=()=>{const{id:e,project:s}=R(),{currentData:r,isLoading:a,isFetching:o,isUninitialized:i}=B({id:+e,path:"Airflow"},{skip:!(s!=null&&s.projectName),refetchOnFocus:!0,selectFromResult:u({currentData:b(n(u({items:N(G(J(".py"),["attributes","name"]))}),I("items")))})}),[l,j]=f.useState(void 0),_=f.useMemo(()=>[{Header:"Id",accessor:"attributes.id",Cell:q},{Header:"Name",accessor:"attributes.name",Cell:h({transformFn:d(".py")},Z)},{Header:"Access time",accessor:"attributes.accessTime",Cell:M},{Header:"",accessor:"attributes.path",Cell:h({setPreviewDag:j},ve),disableSortBy:!0}],[]);return t.jsxs(c,{width:"100%",flexDirection:"column",mt:"10px",children:[t.jsx(c,{width:"100%",mb:"20px",children:t.jsx(S,{fontSize:"16px",children:"DAGs"})}),o&&t.jsx(O,{}),t.jsx(me,{columns:_.map(p=>({...p,Cell:p.Header?V(a,p.Cell):h({isLoading:a},p.Cell)})),data:a?Q(0,3).map(Oe):r??[],initialState:{sortBy:[{id:"attributes.id",desc:!0}]}}),t.jsx(_e,{dag:l,onClose:()=>j(void 0)}),!a&&!i&&X(r??[])&&t.jsx($,{mainText:"No DAGs",mb:"20px"})]})},ve=({setPreviewDag:e,row:s})=>t.jsx(c,{justifyContent:"end",children:t.jsx(U,{ml:"20px",icon:K.eye,onClick:()=>e(s.original),sx:{cursor:"pointer"}})}),_e=({dag:e,onClose:s})=>{const{id:r}=A(),{currentData:{operators:a,schedule:o}={operators:[],schedule:void 0},isLoading:i,isFetching:l}=Y({id:+r,path:ee(e)},{skip:!e,refetchOnFocus:!0,selectFromResult:u({currentData:b(n(se("",["preview","content"]),Se))})});return t.jsxs(te,{isOpen:!!e,title:d(".py",(e==null?void 0:e.attributes.name)??""),onClose:s,hasCloseButton:!0,size:"7xl",children:[(i||l)&&t.jsx(O,{}),t.jsxs(c,{flexDirection:"column",width:"100%",height:"100%",children:[t.jsxs(c,{gap:"10px",children:[t.jsx(S,{fontSize:"14px",children:"Frequency:"}),t.jsx(re,{fontSize:"14px",children:o==="@once"?"Once":t.jsx(he,{cronExpression:o})})]}),a&&t.jsx(de,{operators:a,setOperators:()=>{},readonly:!0,height:"95%",fitView:!0})]})]})},ke="Airflow",Be=()=>{const{id:e}=A(),s=ae(),[r,a]=f.useState(!1),o=()=>{a(!0);const i=pe.get();ue.get(`${g}/airflow`,{headers:{Authorization:`${i}`}}).then(()=>{window.open(`${g}/airflow/home`,"_blank")}).catch(()=>{s.error({title:"Open Airflow",content:"Failed to open airflow."})}).finally(()=>{a(!1)})};return t.jsx(x,{children:t.jsx(oe,{title:ke,mb:"40px",children:t.jsxs(c,{flexDirection:"column",alignItems:"center",children:[t.jsxs(c,{gap:"20px",my:"20px",children:[t.jsx(ne,{href:ie(w.project.airflow.createWorkflow,w.project.value,{id:e}),children:t.jsx(x,{children:"New Workflow"})}),t.jsx(ce,{intent:"secondary",onClick:o,isLoading:r,children:t.jsx(x,{children:"Open Airflow ↗"})})]}),t.jsx(le,{}),t.jsx(Ae,{})]})})})};export{Be as default};
