import{F as q,K as M,E as J,L as R}from"./repository.67aa9953.js";import{a as U}from"./asyncComputed.4686243d.js";import{F as $}from"./forms.1626a906.js";import{H,J as P,S as Q}from"./scripts.8065963b.js";import"./workspaces.7927d7fb.js";import{r as S,d as V,eM as W,H as G,b as C,eu as j,f as T,w as k,u as e,c as I,ew as E,bx as X,eQ as Y,bE as Z,aq as N,e as tt,eD as F,eC as et,cC as at}from"./outputWidgets.63450c6a.js";import"./envVars.ca604fe5.js";import{s as ot}from"./metadata.c602b311.js";import{L as nt}from"./LoadingOutlined.8a2a4850.js";import{A as L}from"./index.aeb802d2.js";import{l as rt}from"./fetch.8f066b2e.js";import{A as st}from"./index.ae091a28.js";import"./api.f3269e65.js";import"./index.cf4c23b9.js";import"./ant-design.a74b142d.js";import"./index.080f3c3e.js";import"./Modal.138f2689.js";import"./Text.3d888762.js";import"./index.078560f6.js";import"./index.31725fef.js";import"./Paragraph.b0baea90.js";import"./index.b1e32faf.js";import"./Link.7de1e23e.js";import"./Title.05596582.js";import"./index.3aa90d91.js";import"./CollapsePanel.920bac17.js";import"./index.2d327eaf.js";import"./index.5e0a6543.js";import"./isNumeric.75337b1e.js";import"./ExpandOutlined.06b9fe67.js";import"./Card.da73e562.js";import"./index.ea8e22a2.js";import"./TabPane.a821d847.js";import"./hasIn.1b20766f.js";import"./vuedraggable.umd.ac9f6e5c.js";import"./index.e3e8bdaa.js";import"./Form.bd89de9c.js";import"./record.884a3745.js";import"./pubsub.9ff806ef.js";import"./runnerData.389ea402.js";import"./url.181b4bfa.js";import"./PhCheckCircle.vue.44c83f97.js";import"./PhScroll.vue.5668f698.js";import"./PhWebhooksLogo.vue.894c1942.js";(function(){try{var a=typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},t=new Error().stack;t&&(a._sentryDebugIds=a._sentryDebugIds||{},a._sentryDebugIds[t]="8658b258-3eb0-46b6-89b3-ea6f585379f5",a._sentryDebugIdIdentifier="sentry-dbid-8658b258-3eb0-46b6-89b3-ea6f585379f5")}catch{}})();const O=[{title:"Thread",dataIndex:"thread"},{title:"Stage",dataIndex:"stage"},{title:"Status",dataIndex:"status"},{title:"Updated at",dataIndex:"updated_at"}],lt=({kanbanRepository:a})=>{const t=q(),o=S(0),l=S(1),b=S(10),v=async()=>await Promise.all([$.list(),H.list(),P.list(),Q.list()]).then(([u,d,g,h])=>[...u,...d,...g,...h].map(s=>({title:s.title,id:s.id,type:s.type,can_be_started:!!(s.type==="job"||s.type==="form"&&s.isInitial),path:s.type==="form"?s.path:void 0}))),K=async()=>{var p,c;const u=await v(),d=await a.getData({filter:{},limit:1e3,offset:0}),g=(p=d.stage_run_cards)==null?void 0:p.map(n=>n.content.map(m=>m.key)).flat(),h=Array.from(new Set(g)),A=[...O.map(n=>n.title),...h],_=(c=d.stage_run_cards)==null?void 0:c.map(n=>{var r,f;const m=u.find(y=>y.id===n.stage);return[n.id,(r=m==null?void 0:m.title)!=null?r:"",n.status,(f=n.updated_at)!=null?f:"",...h.map(y=>{const x=n.content.find(D=>D.key===y);return x?JSON.stringify(x.value):""})]}),w=new Date;return{columns:A,rows:_!=null?_:[],fileName:`therads-${w.toISOString()}`}};return{tableAsyncComputed:U(async()=>{var u,d,g,h;try{const s=await v();t.limit.value=b.value*l.value,t.offset.value=(l.value-1)*b.value;const A=t.requestDataFactory(),_=await a.getData(A);o.value=_.total_count;const w=(d=(u=_.stage_run_cards)==null?void 0:u.map(r=>r.content.map(f=>f.key)).flat())!=null?d:[],p=Array.from(new Set(w)),c=(h=(g=_.stage_run_cards)==null?void 0:g.reduce((r,f)=>{const y=s.find(D=>D.id===f.stage);let x={};for(const D of p){const z=f.content.find(B=>B.key===D);x={...x,[D]:z?z.value:null,status:f.status,thread:f.id,updated_at:f.updated_at,stage:y==null?void 0:y.title}}return r==null||r.push({type:y==null?void 0:y.type,...x}),r},[]))!=null?h:[],n=[];for(const r of O)n.push({title:r.title,dataIndex:r.dataIndex});const m=[];for(const r of p)m.push({title:r,dataIndex:r.toLowerCase()});return n.push({title:"Data",children:m}),{tableColumns:n,tableRows:c}}catch{return{tableColumns:[],tableRows:[]}}}),totalCount:o,current:l,pageSize:b,filterController:t,getDataAsCsv:K}},it=a=>{let t=a.columns.join(",")+`
`;a.rows.forEach(l=>{t+=l.join(","),t+=`
`});const o=document.createElement("a");o.href="data:text/csv;charset=utf-8,"+encodeURIComponent(t),o.target="_blank",o.download=`${a.fileName}.csv`,o.click()},ut={style:{padding:"20px"}},dt={style:{"text-align":"center",margin:"0"}},pt=V({__name:"TableView",props:{kanbanRepository:{}},setup(a){const t=a,o=S(""),l=S(!1),b=S(!1),v=()=>{l.value=!0,h.filterSearch.value=o.value,K()},K=W.exports.debounce(()=>{i.refetch(),l.value=!1},500),{tableAsyncComputed:i,totalCount:u,current:d,pageSize:g,filterController:h,getDataAsCsv:s}=lt({kanbanRepository:t.kanbanRepository}),A=G(()=>({total:u.value,current:d.value,pageSize:g.value,totalBoundaryShowSizeChanger:10,showSizeChanger:!0,pageSizeOptions:["10","25","50","100"],onChange:async(w,p)=>{d.value=w,g.value=p,await i.refetch()}})),_=async()=>{if(b.value=!0,!i.result.value)return;const w=await s();it(w),b.value=!1};return(w,p)=>(C(),j("div",ut,[T(e(L),{justify:"space-between",style:{"margin-bottom":"12px"}},{default:k(()=>[T(e(X),{value:o.value,"onUpdate:value":[p[0]||(p[0]=c=>o.value=c),v],placeholder:"Search data or status",style:{width:"400px"},"allow-clear":""},{prefix:k(()=>[T(e(Y))]),suffix:k(()=>[l.value?(C(),I(e(nt),{key:0})):E("",!0)]),_:1},8,["value"]),T(e(Z),{loading:b.value,onClick:_},{default:k(()=>[N("Export to CSV")]),_:1},8,["loading"])]),_:1}),e(i).result.value?(C(),I(e(at),{key:0,columns:e(i).result.value.tableColumns,"data-source":e(i).result.value.tableRows,loading:l.value,pagination:A.value,scroll:{x:2400,y:700},bordered:"",size:"middle"},{headerCell:k(({column:c})=>[tt("p",dt,F(c.title),1)]),bodyCell:k(({column:c,text:n,record:m})=>[c.dataIndex==="stage"?(C(),I(e(L),{key:0,gap:"small"},{default:k(()=>[(C(),I(et(e(ot)(m.type)),{size:"20"})),N(" "+F(n),1)]),_:2},1024)):E("",!0)]),_:1},8,["columns","data-source","loading","pagination"])):E("",!0)]))}});class ct{constructor(t=rt){this.fetch=t}async fork(t){return(await this.fetch("/_editor/api/stage_runs/fork",{method:"POST",body:JSON.stringify({stage_run_id:t}),headers:{"Content-Type":"application/json"}})).json()}}const mt={style:{padding:"20px"}},ne=V({__name:"WorkflowThreads",setup(a){const t=new J,o=new ct,l=new R("kanban"),b=["Kanban","Table view"],v=S("Kanban");return(K,i)=>(C(),j("div",mt,[T(e(st),{value:v.value,"onUpdate:value":i[0]||(i[0]=u=>v.value=u),options:b,style:{"margin-bottom":"16px"}},null,8,["value"]),v.value==="Kanban"?(C(),I(M,{key:0,"kanban-repository":e(t),storage:e(l),"stage-run-repository":e(o)},null,8,["kanban-repository","storage","stage-run-repository"])):E("",!0),v.value==="Table view"?(C(),I(pt,{key:1,"kanban-repository":e(t)},null,8,["kanban-repository"])):E("",!0)]))}});export{ne as default};
//# sourceMappingURL=WorkflowThreads.42355af9.js.map
