import{jy as v,lA as _,p as n,A as u,hA as C,bw as D,D as F,aW as H,b7 as m,s as L,o as d,aX as E,ay as T,i9 as W,ia as P,aD as z,at as N,jV as R,B as b,Q as I,dS as B,gW as G,aF as J,r as f,jk as q,jm as V,et as h,gX as Z,j as t,q as c,d as S,L as A,iT as M,iU as Q,h as X,c5 as $,ao as U,v as K,u as O,aL as Y,jA 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,gy as pe,gV as ue,dN as g}from"./index-DHiyXWqE.js";import{O as y,S as de}from"./SketchWorkflow-C-UkNDY0.js";import{R as me}from"./Renderer-BPtQWun2.js";import{H as he}from"./HumanizedCronExpression-FxwdMNJF.js";import"./SingleSelect-CAXL6nES.js";import"./sum-BEzIvRoW.js";import"./min-A7xdWBS6.js";import"./index-Y07Nps2b.js";import"./zoom-D5h43YeK.js";import"./transform-C2GfmqNu.js";import"./string-cKWu9XK9.js";import"./index-GdE_-2fu.js";var xe=v(function(s,r,a){return _(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:y.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:y.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(z(/\s|\\/g,""),e=>e.match(/HopsworksLaunchOperator\([^)]*\)|HopsworksJobSuccessSensor\([^)]*\)|[a-zA-Z0-9_]+\.set_upstream\([^)]*\)/g),T(W([[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("]"),E(","))(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})),Ae=e=>({attributes:{id:e,name:"any",accessTime:"2023-09-25T12:34:26.946Z"}}),Oe=()=>{const{id:e,project:s}=N(),{currentData:r,isLoading:a,isFetching:o,isUninitialized:i}=R({id:+e,path:"Airflow"},{skip:!(s!=null&&s.projectName),refetchOnFocus:!0,selectFromResult:u({currentData:b(n(u({items:B(G(J(".py"),["attributes","name"]))}),I("items")))})}),[l,j]=f.useState(void 0),k=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:V},{Header:"",accessor:"attributes.path",Cell:h({setPreviewDag:j},ye),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(A,{}),t.jsx(me,{columns:k.map(p=>({...p,Cell:p.Header?Q(a,p.Cell):h({isLoading:a},p.Cell)})),data:a?M(0,3).map(Ae):r??[],initialState:{sortBy:[{id:"attributes.id",desc:!0}]}}),t.jsx(ke,{dag:l,onClose:()=>j(void 0)}),!a&&!i&&X(r??[])&&t.jsx($,{mainText:"No DAGs",mb:"20px"})]})},ye=({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"}})}),ke=({dag:e,onClose:s})=>{const{id:r}=O(),{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(A,{}),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})]})]})},ve="Airflow",Re=()=>{const{id:e}=O(),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:ve,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(Oe,{})]})})})};export{Re as default};
