import{j as s,r as x}from"./vendor-react-wBh_31cN.js";import{b as C,e as N,T as F,d as R}from"./table-a0YeQrHM.js";import{S as L}from"./skeleton-C7BaXix8.js";import{V as d}from"./value-7N0Keti9.js";import{A as b}from"./avatar-DDfx1nOU.js";import{a0 as I,R as h,aw as M,d as _,G as V,p as B,cY as W,cF as z,dR as p,a7 as H,aT as U,n as q}from"./index-dNe6i2rS.js";import{T as w}from"./tooltip-DFFgUYh6.js";import{P as G,a as J,b as Q}from"./popover-BzVbz_d3.js";import{B as u}from"./badge-UCnweWGd.js";import{t as f}from"./theme-colors-BFneJNsI.js";import{I as P}from"./icon-button-BZeFL7T7.js";import{n as Y}from"./notifications-5miqOdlG.js";import{c as K}from"./vendor-router-D1GqFWiT.js";import{as as X}from"./vendor-icons-BUUmD6ht.js";const Z="yyyy/MM/dd HH:mm:ss",g=({icon:e,label:a,timestamp:r,status:t,children:o,actions:n,className:i,style:c})=>s.jsxs(C,{className:_("h-14 hover:bg-transparent",i),style:c,children:[s.jsx(N,{className:"w-44",children:s.jsx(w,{content:r?M(r,Z):void 0,side:"left",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(I,{icon:e,color:"gray",size:"sm"}),s.jsx(h,{bold:!0,gray:!0,children:a})]})})}),s.jsx(N,{className:"w-28",children:t}),s.jsx(N,{children:s.jsx("div",{className:"flex items-center gap-1",children:o})}),s.jsx(N,{children:n&&s.jsx("div",{className:"flex items-center justify-end gap-3",children:n})})]}),O=({listData:e,className:a})=>{const[r,t]=x.useState(!1),[o,...n]=e;return s.jsxs("div",{className:a,children:[s.jsxs(d,{children:[o,", ..."]}),s.jsxs(G,{open:r,onOpenChange:t,children:[s.jsx(J,{asChild:!0,children:s.jsxs(V,{variant:"link",size:"sm",className:"h-auto p-0 text-xs",onClick:()=>t(!0),children:["view all ",e.length," new features"]})}),s.jsx(Q,{className:"w-auto p-0",children:s.jsx("div",{className:"max-h-[300px] overflow-auto",children:n.map(i=>s.jsx("div",{className:"border-b border-border p-1 last:border-b-0",children:s.jsx(d,{children:i})},i))})})]})]})},ss=x.memo(O),es=({activity:e})=>{const{titleData:a,listData:r}=x.useMemo(()=>{const{metadata:t}=e;if(t.includes(":")){const[o,n]=t.split(":");return{titleData:`${o}:`,listData:n.split(",")}}return{titleData:t,listData:[]}},[e]);return s.jsxs(g,{icon:"creation",label:"Creation",timestamp:e.timestamp,actions:s.jsx(b,{firstName:e.user.firstname,lastName:e.user.lastname}),children:[s.jsx(d,{children:a}),r.length===1&&s.jsx(d,{children:r[0]}),r.length>1&&s.jsx(ss,{listData:r})]})},A=1,v=.1,S=1,D=30,ts=1e3*60*60*24,ns=new Intl.NumberFormat("en",{notation:"compact",maximumFractionDigits:1}),j=e=>ns.format(e),Cs=(e,a)=>{const t=(e-a)/ts;return t>=D?v:t<=S?A:v+(D-t)*((A-v)/(D-S))},as=({activity:e})=>{var y,E,k,T;const{executions:a}=e.job??{},r=B((E=(y=e.job)==null?void 0:y.executions)==null?void 0:E.finalStatus,{SUCCEEDED:{children:"success",variant:"success"},UNDEFINED:{children:"running",variant:"default"}})??{children:"error",variant:"destructive"},t=a==null?void 0:a.totalIngestedRecords,o=a==null?void 0:a.ingestionStartCursorValue,n=a==null?void 0:a.lastIngestionCursorValue,i=o!=null&&String(o)!=="",c=t!=null,l=n!=null&&String(n)!=="",m=i&&l,$=c||m||l;return s.jsx(g,{icon:"job",label:"Job execution",timestamp:e.timestamp,status:s.jsx(u,{className:"w-fit",variant:r.variant,children:r.children}),actions:s.jsx(b,{firstName:e.user.firstname,lastName:e.user.lastname}),children:s.jsxs("div",{className:"flex flex-col min-w-0",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsxs(d,{children:["#",(k=e.job)==null?void 0:k.executions.id]}),s.jsx(d,{className:"truncate max-w-[500px]",children:(T=e.job)==null?void 0:T.name})]}),$&&s.jsxs("div",{className:"flex items-center flex-wrap mt-1 gap-x-5 text-xs",children:[c&&s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(h,{children:"Ingested"}),s.jsx(d,{className:"text-muted-foreground text-xs font-normal",children:j(t)})]}),m&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(h,{children:"Start:"}),s.jsx(d,{className:"text-muted-foreground text-xs font-normal",children:String(o)})]}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(h,{children:"Latest:"}),s.jsx(d,{className:"text-muted-foreground text-xs font-normal",children:String(n)})]})]}),!m&&l&&s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(h,{children:"Last cursor:"}),s.jsx(d,{className:"text-muted-foreground text-xs font-normal",children:String(n)})]})]})]})})},rs=({rowsDeleted:e,rowsInserted:a,rowsUpdated:r,allRowsCount:t,className:o})=>{const n=x.useMemo(()=>Math.ceil(e/t*100),[t,e]),i=x.useMemo(()=>n+Math.ceil(r/t*100),[t,r,n]);return s.jsx("div",{className:o,children:s.jsxs("svg",{width:"22px",height:"22px",viewBox:"-5 -5 45 45",children:[s.jsx("path",{d:`M18 2.0845
      a 15.9155 15.9155 0 0 1 0 31.831
      a 15.9155 15.9155 0 0 1 0 -31.831`,fill:"none",stroke:f.primary,strokeWidth:"7",strokeDasharray:"100, 100"}),s.jsx("path",{d:`M18 2.0845
      a 15.9155 15.9155 0 0 1 0 31.831
      a 15.9155 15.9155 0 0 1 0 -31.831`,fill:"none",stroke:f.labels.orange,strokeWidth:"7",strokeDasharray:`${i}, 100`}),s.jsx("path",{d:`M18 2.0845
      a 15.9155 15.9155 0 0 1 0 31.831
      a 15.9155 15.9155 0 0 1 0 -31.831`,fill:"none",stroke:f.labels.red,strokeWidth:"7",strokeDasharray:`${n}, 100`})]})})},os="yyyy/MM/dd HH:mm:ss",is=({activity:e})=>{const{commit:a}=e,{rowsUpdated:r=0,rowsInserted:t=0,rowsDeleted:o=0,archived:n=!1,commitID:i}=a,c=x.useMemo(()=>M(+i,os),[i]),l=o+r+t;return s.jsxs(g,{icon:"ingest",label:"Offline ingestion",timestamp:e.timestamp,className:n?"bg-muted":void 0,status:s.jsx(rs,{rowsUpdated:r,rowsDeleted:o,rowsInserted:t,allRowsCount:l}),actions:n?s.jsx(w,{content:"This commit has been archived and cannot be referenced in incremental queries",children:s.jsx("div",{children:s.jsx(I,{icon:"history",size:"sm"})})}):void 0,children:[s.jsx(h,{gray:!0,children:"commit"}),s.jsx(d,{className:"font-mono text-xs",children:c}),s.jsxs(u,{variant:t>0?"success":"outline",className:"ml-4",children:[s.jsx("span",{className:"font-semibold",children:j(t)}),"new rows"]}),s.jsxs(u,{variant:r>0?"notice":"outline",children:[s.jsx("span",{className:"font-semibold",children:j(r)}),"updated rows"]}),s.jsxs(u,{variant:o>0?"fail":"outline",children:[s.jsx("span",{className:"font-semibold",children:j(o)}),"deleted rows"]})]})},ls=({rowsSuccessful:e,rowsIgnored:a,rowsFailed:r,className:t})=>{const o=e+a+r,n=x.useMemo(()=>Math.ceil(e/o*100),[o,e]),i=x.useMemo(()=>n+Math.ceil(a/o*100),[o,a,n]),c=x.useMemo(()=>i+Math.ceil(r/o*100),[o,r,i]);return s.jsx("div",{className:t,children:s.jsxs("svg",{width:"22px",height:"22px",viewBox:"-5 -5 45 45",children:[s.jsx("path",{d:`M18 2.0845
      a 15.9155 15.9155 0 0 1 0 31.831
      a 15.9155 15.9155 0 0 1 0 -31.831`,fill:"none",stroke:f.labels.red,strokeWidth:"7",strokeDasharray:`${c}, 100`}),s.jsx("path",{d:`M18 2.0845
      a 15.9155 15.9155 0 0 1 0 31.831
      a 15.9155 15.9155 0 0 1 0 -31.831`,fill:"none",stroke:f.labels.yellow,strokeWidth:"7",strokeDasharray:`${i}, 100`}),s.jsx("path",{d:`M18 2.0845
      a 15.9155 15.9155 0 0 1 0 31.831
      a 15.9155 15.9155 0 0 1 0 -31.831`,fill:"none",stroke:f.labels.green,strokeWidth:"7",strokeDasharray:`${n}, 100`}),s.jsx("path",{d:`M18 2.0845
      a 15.9155 15.9155 0 0 1 0 31.831
      a 15.9155 15.9155 0 0 1 0 -31.831`,fill:"none",stroke:f.gray,strokeWidth:"7",strokeDasharray:"0, 100"})]})})},cs=({activity:e})=>{const{onlineIngestion:a}=e,{numEntries:r,results:t,id:o}=a,n=t.filter(l=>l.status==="UPSERTED").reduce((l,m)=>l+m.rows,0),i=t.filter(l=>l.status==="IGNORED").reduce((l,m)=>l+m.rows,0),c=t.filter(l=>l.status==="FAILED").reduce((l,m)=>l+m.rows,0);return s.jsxs(g,{icon:"ingest",label:"Online ingestion",timestamp:e.timestamp,status:s.jsx(ls,{rowsSuccessful:n,rowsIgnored:i,rowsFailed:c}),children:[s.jsxs(d,{children:["#",o]}),r&&s.jsx(h,{gray:!0,className:"ml-4",children:"dataset size"}),r&&s.jsx(d,{className:"font-mono text-xs",children:j(r)}),n>0&&s.jsxs(u,{variant:"success",className:"ml-4",children:[s.jsx("span",{className:"font-semibold",children:j(n)}),"upserted"]}),c>0&&s.jsxs(u,{variant:"fail",children:[s.jsx("span",{className:"font-semibold",children:j(c)}),"failed"]}),i>0&&s.jsxs(u,{variant:"notice",children:[s.jsx("span",{className:"font-semibold",children:j(i)}),"ignored"]})]})},ds="yyyy/MM/dd HH:mm:ss",ms=({activity:e,onButtonClick:a})=>{const r=x.useMemo(()=>M(+(e.statistics.computationTime||e.statistics.commitTime),ds),[e]);return s.jsxs(g,{icon:"new_stats",label:"New statistics",timestamp:e.timestamp,actions:s.jsxs(s.Fragment,{children:[a&&s.jsx(w,{content:"open statistics",children:s.jsx(P,{variant:"ghost",onClick:()=>a(+e.statistics.computationTime),children:s.jsx(I,{icon:"stats",size:"lg"})})}),s.jsx(b,{firstName:e.user.firstname,lastName:e.user.lastname})]}),children:[s.jsx(h,{children:"commit"}),s.jsx(d,{children:r})]})},xs=({activity:e})=>s.jsx(g,{icon:"glass",label:"Expectations",timestamp:e.timestamp,actions:s.jsx(b,{firstName:e.user.firstname,lastName:e.user.lastname}),children:s.jsx(d,{children:e.metadata})}),us=async(e,a)=>{var r,t,o,n;try{await W.download(e,a,z.DATASET)}catch(i){const c=((t=(r=i==null?void 0:i.response)==null?void 0:r.data)==null?void 0:t.usrMsg)||((n=(o=i==null?void 0:i.response)==null?void 0:o.data)==null?void 0:n.errorMsg);Y.error({title:"Error",content:c})}},hs=({activity:e})=>{const{id:a}=K();return s.jsxs(g,{icon:"data_validation",label:"Validation Report",timestamp:e.timestamp,actions:s.jsxs(s.Fragment,{children:[s.jsx(w,{content:"Download",children:s.jsx(P,{variant:"ghost",onClick:()=>us(+a,e.validationReport.fullReportPath),children:s.jsx(X,{className:"size-4"})})}),s.jsx(b,{firstName:e.user.firstname,lastName:e.user.lastname})]}),children:[s.jsx(d,{children:"Data Validation Result :"}),s.jsx(js,{success:e.validationReport.success})]})},js=({success:e})=>e?s.jsx(u,{className:"w-fit",variant:"success",children:"success"}):s.jsx(u,{className:"w-fit",variant:"destructive",children:"fail"}),ps=e=>new Map([[p.commit,is],[p.job,as],[p.metadata,es],[p.onlineIngestion,cs],[p.statistics,ms],[p.expectations,xs],[p.validations,hs]]).get(e)??null,Ps=({activities:e,actions:a,loading:r})=>s.jsx(F,{children:s.jsx(R,{children:e.map((t,o)=>{if(r)return s.jsx(C,{className:"hover:bg-transparent",children:s.jsx(N,{colSpan:4,children:s.jsx(L,{className:"h-10 w-full"})})},o);const n=ps(t.type);return n?s.jsx(n,{activity:t,onButtonClick:a==null?void 0:a.get(t.type)},`${t==null?void 0:t.timestamp}-${o}`):null})})}),fs=H.injectEndpoints({endpoints:e=>({getFgActivity:e.query({query:({pId:a,fgId:r,fsId:t,eventType:o,timeOptions:n,params:i={limit:20,offset:0},sortType:c="desc"})=>{const l=U.stringify({expand:["commits","jobs","users","statistics","executions","validationreport","expectationsuite"],filter_by:q(m=>!m,[o!=="ALL"&&`type:${o}`,(n==null?void 0:n.from)&&`timestamp_gt:${n.from-1}`,(n==null?void 0:n.to)&&`timestamp_lt:${n.to}`]),sort_by:`TIMESTAMP:${c}`,...i});return{url:`/project/${a}/featurestores/${t}/featuregroups/${r}/activity?${l}`}}})})}),{useGetFgActivityQuery:$s,endpoints:Fs}=fs;export{Ps as A,us as d,fs as f,Cs as g,$s as u};
