import{F as q,K as M,E as J,L as R}from"./repository.9cc76153.js";import{a as U}from"./asyncComputed.b2c7682e.js";import{F as $}from"./forms.8f2b56b4.js";import{H,J as P,S as Q}from"./scripts.714861ba.js";import"./workspaces.afd4edf2.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.8f35e76b.js";import"./envVars.04759b67.js";import{s as ot}from"./metadata.5258e7e7.js";import{L as nt}from"./LoadingOutlined.8ed9851d.js";import{A as L}from"./index.30032ec4.js";import{l as rt}from"./fetch.5a9928e7.js";import{A as st}from"./index.28262921.js";import"./api.a476abaa.js";import"./index.cf4c23b9.js";import"./ant-design.5e6d66d7.js";import"./index.01563854.js";import"./Modal.3cec70ce.js";import"./Text.cb1b4ad4.js";import"./index.1d88a799.js";import"./index.9ae05ba9.js";import"./Paragraph.5b35e944.js";import"./index.8416d0cc.js";import"./Link.453a8ef1.js";import"./Title.984d5105.js";import"./index.85ee2aed.js";import"./CollapsePanel.5542395e.js";import"./index.c56951cc.js";import"./index.fa549dca.js";import"./isNumeric.75337b1e.js";import"./ExpandOutlined.8a63c284.js";import"./Card.05a66930.js";import"./index.1b34424f.js";import"./TabPane.385f8290.js";import"./hasIn.38270313.js";import"./vuedraggable.umd.6098fdf5.js";import"./index.11f203e6.js";import"./Form.357810f8.js";import"./record.56272af3.js";import"./pubsub.aac2ae7d.js";import"./runnerData.6e315e3e.js";import"./url.99f1e379.js";import"./PhCheckCircle.vue.744c2106.js";import"./PhScroll.vue.b0c3dd17.js";import"./PhWebhooksLogo.vue.41e42723.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]="66a8c193-5dc8-4260-8e8c-b74f42ab61d4",a._sentryDebugIdIdentifier="sentry-dbid-66a8c193-5dc8-4260-8e8c-b74f42ab61d4")}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 c,p;const u=await v(),d=await a.getData({filter:{},limit:1e3,offset:0}),g=(c=d.stage_run_cards)==null?void 0:c.map(n=>n.content.map(m=>m.key)).flat(),h=Array.from(new Set(g)),A=[...O.map(n=>n.title),...h],_=(p=d.stage_run_cards)==null?void 0:p.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:[],c=Array.from(new Set(w)),p=(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 c){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 c)m.push({title:r,dataIndex:r.toLowerCase()});return n.push({title:"Data",children:m}),{tableColumns:n,tableRows:p}}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"}},ct=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,c)=>{d.value=w,g.value=c,await i.refetch()}})),_=async()=>{if(b.value=!0,!i.result.value)return;const w=await s();it(w),b.value=!1};return(w,c)=>(C(),j("div",ut,[T(e(L),{justify:"space-between",style:{"margin-bottom":"12px"}},{default:k(()=>[T(e(X),{value:o.value,"onUpdate:value":[c[0]||(c[0]=p=>o.value=p),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:p})=>[tt("p",dt,F(p.title),1)]),bodyCell:k(({column:p,text:n,record:m})=>[p.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 pt{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 pt,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(ct,{key:1,"kanban-repository":e(t)},null,8,["kanban-repository"])):E("",!0)]))}});export{ne as default};
//# sourceMappingURL=WorkflowThreads.cd8dfeb7.js.map
