import{b9 as M,u as U,gy as $,b as p,b3 as g,r as f,b8 as C,aY as w,aZ as O,b1 as Q,aS as z,c as y,fj as H,j as a,a$ as E,E as Z,Q as q,o as j,b4 as K,be as W,aU as X,cu as V,cR as ee,a3 as te,a4 as oe}from"./index-ea7817a2.js";import{u as ae}from"./useDownload-09eaf3eb.js";import{P as re}from"./Panel-041c5d61.js";import{N as se}from"./NoData-8733f606.js";import{u as ie}from"./useUserPermissions-d2903885.js";import{u as ne}from"./useFeatureGroupVersions-ee161b97.js";import"./Deprecated-9bfe2e44.js";import"./CardActionButton-6aa39bc1.js";import"./index-8f672200.js";import"./file-utils-a5f053e8.js";import"./useCurrentProject-0132f110.js";import"./useProject-77619fff.js";import"./project-c611a3ec.js";const Te=()=>{const{DATE_TIME_FULL:m}=M.DATE_TIME,{id:r,fsId:i,fgId:n,commitTime:c}=U(),{canEdit:L,isLoading:P,isDataScientist:I}=ie(),{currentData:o,isFetching:v}=$({pId:+r,fsId:+i,fgId:+n}),{currentData:k=[o],isFetching:S,handleVersionChange:R}=ne(o==null?void 0:o.name,p.featureGroup.code),T=g(t=>t.loading.effects.featureGroupCode.getList),s=g(t=>t.featureGroupCode),N=g(t=>t.loading.effects.featureGroupCodeDetails.get),e=g(t=>t.featureGroupCodeDetails),B=f.useMemo(()=>{let t=c;return s&&(!t||t===s[0].commitTime?t=`${C(+s[0].commitTime,m)} (latest)`:Number.isInteger(+t)&&(t=C(+t,m))),t},[c,s,m]);w(`${O.fgCode} ${o!=null&&o.name?o.name:""}`);const u=Q(),x=z();f.useEffect(()=>(u.featureGroupCode.getList({projectId:+r,featureGroupId:+n,featureStoreId:+i}),u.featureGroupCodeDetails.get({projectId:+r,featureStoreId:+i,featureGroupId:+n,commitTime:c}),()=>{u.featureGroupCode.clear(),u.featureGroupCodeDetails.clear()}),[u,r,i,n,c]);const J=f.useCallback(()=>{u.featureGroupCode.getList({projectId:+r,featureGroupId:+n,featureStoreId:+i}),u.featureGroupCodeDetails.get({projectId:+r,featureGroupId:+n,featureStoreId:+i,commitTime:c})},[u,r,i,n,c]),A=f.useCallback(t=>{var G;const[h]=t;let F=h;h.includes("(latest)")&&(F=h.slice(0,h.indexOf(" (latest)")));const Y=(G=s==null?void 0:s.find(_=>C(+_.commitTime,m)===F))==null?void 0:G.commitTime;x(y(p.featureGroup.codeViewCommit,p.project.value,{id:r,fsId:i,fgId:n,commitTime:Y??""}))},[s,x,r,i,n,m]),b=ae(),D=f.useCallback(()=>{e&&b(+r,e.path,H.FEATURESTORE)},[e,b,r]);let d="",l="";return e&&(e.contentFormat==="IPYNB"?(d="Jupyter notebook",l="Jupyter"):e.contentFormat==="PY"?(d="Python file",l="Python"):e.contentFormat==="JAR"?(d="Jar file",l="Jar"):e.contentFormat==="DBC"&&(d="Databricks notebook",l="Databricks")),v?a.jsx(E,{}):a.jsxs(a.Fragment,{children:[a.jsx(re,{title:o==null?void 0:o.name,data:o,idColor:(o==null?void 0:o.type)==="onDemandFeaturegroupDTO"?"labels.blue":"labels.orange",version:o==null?void 0:o.version,versions:k,isVersionsLoading:S,onVersionChange:R,hasCommits:!0,commits:(s==null?void 0:s.map(t=>t.commitTime))||[],commit:B,handleCommitChange:A,onClickRefresh:J,isEditDisabled:!L||I||P,onClickEdit:()=>{x(y(p.featureGroup.edit,p.project.value,{id:r,fsId:i,fgId:n}))},pathnamePostFix:"/code",editRightText:I?"Your role is not allowed to perform this action":void 0}),!s&&!T?a.jsx(se,{mainText:"No code commit available for this feature group"}):a.jsxs(Z,{children:[a.jsxs(q,{flexDirection:"column",children:[(!!T||!!N)&&a.jsx(E,{}),a.jsxs(j,{children:[a.jsxs(K,{children:["The following ",d," has been used to generate this feature group commit"]}),a.jsx(W,{mt:"5px",width:"90px",value:l,variant:"light"})]}),e&&e.contentFormat==="JAR"&&a.jsx(j,{mt:"5px",alignItems:"right",children:a.jsx(X,{sx:{marginLeft:"auto"},onClick:D,intent:"secondary",children:"Download"})})]}),a.jsx(V,{}),e&&(e.contentFormat==="IPYNB"||e.contentFormat==="DBC")&&a.jsx("div",{dangerouslySetInnerHTML:{__html:e.content||""}}),e&&e.contentFormat==="PY"&&a.jsx(j,{children:a.jsx(ee,{title:"Python code",language:"python",copyButton:!0,downloadButton:!0,downloadCallback:D,showLineNumbers:!0,content:e.content})}),e&&e.contentFormat==="JAR"&&a.jsx(te,{content:"The file used to generate this Feature Group was packaged (jar), you can not visualize the code here.",type:oe.neutral})]})]})};export{Te as default};
