"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4869,2003],{81260:function(e,s,r){r.d(s,{Z:function(){return l}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let l=(0,r(60998).Z)("Plus",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]])},47603:function(e,s,r){r.d(s,{Z:function(){return l}});/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let l=(0,r(60998).Z)("Trash2",[["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6",key:"4alrt4"}],["path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2",key:"v07s0e"}],["line",{x1:"10",x2:"10",y1:"11",y2:"17",key:"1uufr5"}],["line",{x1:"14",x2:"14",y1:"11",y2:"17",key:"xtxkd"}]])},1812:function(e,s,r){r.d(s,{X:function(){return n}});var l=r(85893),t=r(67294);let a=e=>{if(!(null==e?void 0:e.message))return"An unexpected error occurred.";let s=e.message;return s.includes("failed:")&&(s=s.split("failed:")[1].trim()),s},n=e=>{let{error:s,title:r="Error",onDismiss:n}=e,[i,o]=(0,t.useState)(!1);if((0,t.useEffect)(()=>{s&&o(!1)},[s]),!s||i)return null;let c="string"==typeof s?s:a(s);return(0,l.jsx)("div",{className:"bg-red-50 border border-red-200 rounded-md p-3 mb-4",children:(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsxs)("div",{className:"flex",children:[(0,l.jsx)("div",{className:"flex-shrink-0",children:(0,l.jsx)("svg",{className:"h-5 w-5 text-red-400",viewBox:"0 0 20 20",fill:"currentColor",children:(0,l.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})})}),(0,l.jsx)("div",{className:"ml-3",children:(0,l.jsxs)("div",{className:"text-sm text-red-800",children:[(0,l.jsxs)("strong",{children:[r,":"]})," ",c]})})]}),(0,l.jsx)("button",{onClick:()=>{o(!0),n&&n()},className:"flex-shrink-0 ml-4 text-red-400 hover:text-red-600 focus:outline-none focus:ring-2 focus:ring-red-500 focus:ring-offset-2 focus:ring-offset-red-50 rounded","aria-label":"Dismiss error",children:(0,l.jsx)("svg",{className:"h-4 w-4",viewBox:"0 0 20 20",fill:"currentColor",children:(0,l.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})})]})})}},82077:function(e,s,r){r.r(s),r.d(s,{Workspaces:function(){return M}});var l=r(85893),t=r(67294),a=r(11163),n=r(23266),i=r(68969),o=r(17324),c=r(37673),d=r(68764),u=r(30803),m=r(55739),x=r(1272),h=r(50326);r(53850);var p=r(1812),g=r(13626),j=r(81260);/**
 * @license lucide-react v0.407.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */let f=(0,r(60998).Z)("SquarePen",[["path",{d:"M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7",key:"1m0v6g"}],["path",{d:"M18.375 2.625a1 1 0 0 1 3 3l-9.013 9.014a2 2 0 0 1-.853.505l-2.873.84a.5.5 0 0 1-.62-.62l.84-2.873a2 2 0 0 1 .506-.852z",key:"ohrbg2"}]]);var v=r(47603),w=r(23001),b=r(80938),N=r(6378),k=r(51214),y=r(36856),C=r(47145),L=r(94545),S=r(93225),z=r(41664),Z=r.n(z);let D=e=>{let{isPrivate:s}=e;return s?(0,l.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-gray-100 text-gray-700 border border-gray-300",children:"Private"}):(0,l.jsx)("span",{className:"inline-flex items-center px-2 py-1 rounded-full text-xs font-medium bg-green-100 text-green-700 border border-green-300",children:"Public"})},E=k.nb.REFRESH_INTERVAL;function M(){let[e,s]=(0,t.useState)([]),[r,k]=(0,t.useState)({runningClusters:0,totalClusters:0,managedJobs:0}),[z,M]=(0,t.useState)(!0),[R,O]=(0,t.useState)(null),[J,A]=(0,t.useState)({key:"name",direction:"asc"}),[P,T]=(0,t.useState)(""),[W,F]=(0,t.useState)(!1),[B,V]=(0,t.useState)({confirmOpen:!1,workspaceToDelete:null,deleting:!1,error:null}),[X,q]=(0,t.useState)({open:!1,message:"",userName:""}),[I,_]=(0,t.useState)(null),[H,K]=(0,t.useState)(!1),[U,$]=(0,t.useState)(null),[G,Q]=(0,t.useState)(null),Y=(0,a.useRouter)(),ee=(0,w.X)(),es=async()=>{if(I&&Date.now()-I.timestamp<3e5)return I;K(!0);try{let e=await C.x.get("/users/role");if(!e.ok){let s=await e.json();throw Error(s.detail||"Failed to get user role")}let s=await e.json(),r={role:s.role,name:s.name,timestamp:Date.now()};return _(r),K(!1),r}catch(e){throw K(!1),e}},er=async(e,s)=>{try{let r=await es();if("admin"!==r.role)return q({open:!0,message:e,userName:r.name.toLowerCase()}),!1;return s(),!0}catch(e){return console.error("Failed to check user role:",e),q({open:!0,message:"Error: ".concat(e.message),userName:""}),!1}},el=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];e&&M(!0);try{let[e,r,l]=await Promise.all([N.default.get(o.fX),N.default.get(n.getClusters),N.default.get(i.getManagedJobs,[{allUsers:!0}])]);O(e);let t=Object.keys(e),a=await Promise.all(t.map(e=>N.default.get(o.yz,[e]))),c=Object.fromEntries(t.map((e,s)=>[e,a[s]]));Object.fromEntries(r.map(e=>[e.cluster,e.workspace||"default"]));let d={};t.forEach(e=>{d[e]={name:e,totalClusterCount:0,runningClusterCount:0,managedJobsCount:0,clouds:new Set}});let u=0;r.forEach(e=>{let s=e.workspace||"default";d[s]||(d[s]={name:s,totalClusterCount:0,runningClusterCount:0,managedJobsCount:0,clouds:new Set}),d[s].totalClusterCount++,("RUNNING"===e.status||"LAUNCHING"===e.status)&&(d[s].runningClusterCount++,u++),e.cloud&&d[s].clouds.add(e.cloud)});let m=l.jobs||[],x=new Set(b.statusGroups.active),h=0;m.forEach(e=>{let s=e.workspace||"default";d[s]&&x.has(e.status)&&d[s].managedJobsCount++,x.has(e.status)&&h++});let p=Object.values(d).filter(e=>t.includes(e.name)).map(e=>({...e,clouds:Array.isArray(c[e.name])?c[e.name]:[]})).sort((e,s)=>e.name.localeCompare(s.name));s(p),k({runningClusters:u,totalClusters:r.length,managedJobs:h})}catch(e){console.error("Error fetching workspace data:",e),s([]),k({runningClusters:0,totalClusters:0,managedJobs:0})}e&&M(!1)};(0,t.useEffect)(()=>{(async()=>{await y.ZP.preloadForPage("workspaces"),el(!0)})();let e=setInterval(()=>{el(!1)},E);return()=>clearInterval(e)},[]);let et=e=>{let s="asc";J.key===e&&"asc"===J.direction&&(s="desc"),A({key:e,direction:s})},ea=e=>J.key===e?"asc"===J.direction?" ↑":" ↓":"",en=t.useMemo(()=>{if(!e)return[];let s=e;if(P&&""!==P.trim()){let r=P.toLowerCase().trim();s=e.filter(e=>!!(e.name.toLowerCase().includes(r)||e.clouds.some(e=>{let s=S.Z2[e.toLowerCase()]||e;return e.toLowerCase().includes(r)||s.toLowerCase().includes(r)}))||!!(!0===((null==R?void 0:R[e.name])||{}).private?"private":"public").includes(r))}return(0,L.R0)(s,J.key,J.direction)},[e,J,P,R]),ei=e=>{er("cannot delete workspace",()=>{V({confirmOpen:!0,workspaceToDelete:e,deleting:!1,error:null})})},eo=async()=>{if(B.workspaceToDelete){V(e=>({...e,deleting:!0,error:null}));try{await (0,o.zl)(B.workspaceToDelete),Q('Workspace "'.concat(B.workspaceToDelete,'" deleted successfully!')),V({confirmOpen:!1,workspaceToDelete:null,deleting:!1,error:null}),N.default.invalidate(o.fX),await el(!0)}catch(e){console.error("Error deleting workspace:",e),V(e=>({...e,deleting:!1,error:null})),$(e)}}},ec=()=>{V({confirmOpen:!1,workspaceToDelete:null,deleting:!1,error:null})},ed=e=>{er("cannot edit workspace",()=>{Y.push("/workspaces/".concat(e))})};return z&&0===e.length?(0,l.jsxs)("div",{className:"flex justify-center items-center h-64",children:[(0,l.jsx)(m.Z,{}),(0,l.jsx)("span",{className:"ml-2 text-gray-500",children:"Loading workspaces..."})]}):(0,l.jsxs)("div",{children:[(0,l.jsxs)("div",{className:"fixed top-20 right-4 z-[9999] max-w-md",children:[G&&(0,l.jsx)("div",{className:"bg-green-50 border border-green-200 rounded p-4 mb-4",children:(0,l.jsxs)("div",{className:"flex items-center justify-between",children:[(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)("div",{className:"flex-shrink-0",children:(0,l.jsx)("svg",{className:"h-5 w-5 text-green-400",viewBox:"0 0 20 20",fill:"currentColor",children:(0,l.jsx)("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})})}),(0,l.jsx)("div",{className:"ml-3",children:(0,l.jsx)("p",{className:"text-sm font-medium text-green-800",children:G})})]}),(0,l.jsx)("div",{className:"ml-auto pl-3",children:(0,l.jsxs)("button",{type:"button",onClick:()=>Q(null),className:"inline-flex rounded-md bg-green-50 p-1.5 text-green-500 hover:bg-green-100",children:[(0,l.jsx)("span",{className:"sr-only",children:"Dismiss"}),(0,l.jsx)("svg",{className:"h-5 w-5",viewBox:"0 0 20 20",fill:"currentColor",children:(0,l.jsx)("path",{fillRule:"evenodd",d:"M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",clipRule:"evenodd"})})]})})]})}),(0,l.jsx)(p.X,{error:U,title:"Error",onDismiss:()=>$(null)})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between mb-2 h-5",children:[(0,l.jsx)("div",{className:"text-base flex items-center",children:(0,l.jsx)("span",{className:"text-sky-blue leading-none",children:"Workspaces"})}),(0,l.jsxs)("div",{className:"flex items-center",children:[z&&(0,l.jsxs)("div",{className:"flex items-center mr-2",children:[(0,l.jsx)(m.Z,{size:15,className:"mt-0"}),(0,l.jsx)("span",{className:"ml-2 text-gray-500 text-xs",children:"Refreshing..."})]}),(0,l.jsxs)("button",{onClick:()=>{N.default.invalidate(o.fX),N.default.invalidate(n.getClusters),N.default.invalidate(i.getManagedJobs,[{allUsers:!0}]),N.default.invalidateFunction(o.yz),el(!0)},disabled:z,className:"text-sky-blue hover:text-sky-blue-bright flex items-center",children:[(0,l.jsx)(g.Z,{className:"h-4 w-4 mr-1.5"}),!ee&&(0,l.jsx)("span",{children:"Refresh"})]})]})]}),(0,l.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,l.jsxs)("div",{className:"relative flex-1 max-w-md",children:[(0,l.jsx)("input",{type:"text",placeholder:"Filter workspaces",value:P,onChange:e=>T(e.target.value),className:"h-8 w-full px-3 pr-8 text-sm border border-gray-300 rounded-md focus:ring-1 focus:ring-sky-500 focus:border-sky-500 outline-none"}),P&&(0,l.jsx)("button",{onClick:()=>T(""),className:"absolute right-2 top-1/2 transform -translate-y-1/2 text-gray-400 hover:text-gray-600",title:"Clear search",children:(0,l.jsx)("svg",{className:"h-4 w-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:(0,l.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})})})]}),(0,l.jsx)("button",{onClick:()=>{er("cannot create workspace",()=>{Y.push("/workspace/new")})},disabled:H,className:"ml-4 bg-sky-600 hover:bg-sky-700 text-white flex items-center rounded-md px-3 py-1 text-sm font-medium transition-colors duration-200",title:"Create Workspace",children:H?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(m.Z,{size:12,className:"mr-2"}),(0,l.jsx)("span",{children:"Create Workspace"})]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(j.Z,{className:"h-4 w-4 mr-2"}),"Create Workspace"]})})]}),0!==e.length||z?(0,l.jsx)(c.Zb,{children:(0,l.jsx)("div",{className:"overflow-x-auto rounded-lg",children:(0,l.jsxs)(d.iA,{className:"min-w-full",children:[(0,l.jsx)(d.xD,{children:(0,l.jsxs)(d.SC,{children:[(0,l.jsxs)(d.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>et("name"),children:["Workspace",ea("name")]}),(0,l.jsxs)(d.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>et("totalClusterCount"),children:["Clusters ",ea("totalClusterCount")]}),(0,l.jsxs)(d.ss,{className:"sortable whitespace-nowrap cursor-pointer hover:bg-gray-50",onClick:()=>et("managedJobsCount"),children:["Jobs",ea("managedJobsCount")]}),(0,l.jsx)(d.ss,{className:"whitespace-nowrap",children:"Enabled infra"}),(0,l.jsx)(d.ss,{className:"whitespace-nowrap",children:"Actions"})]})}),(0,l.jsx)(d.RM,{children:z&&0===en.length?(0,l.jsx)(d.SC,{children:(0,l.jsx)(d.pj,{colSpan:5,className:"text-center py-6 text-gray-500",children:(0,l.jsxs)("div",{className:"flex justify-center items-center",children:[(0,l.jsx)(m.Z,{size:20,className:"mr-2"}),(0,l.jsx)("span",{children:"Loading..."})]})})}):en.length>0?en.map(e=>{let s=!0===((null==R?void 0:R[e.name])||{}).private;return(0,l.jsxs)(d.SC,{className:"hover:bg-gray-50",children:[(0,l.jsxs)(d.pj,{className:"",children:[(0,l.jsx)("button",{onClick:()=>ed(e.name),disabled:H,className:"text-blue-600 hover:text-blue-600 hover:underline text-left",children:e.name}),(0,l.jsx)("span",{className:"ml-2",children:(0,l.jsx)(D,{isPrivate:s})})]}),(0,l.jsx)(d.pj,{children:(0,l.jsxs)("button",{onClick:()=>{Y.push({pathname:"/clusters",query:{workspace:e.name}})},className:"text-gray-700 hover:text-blue-600 hover:underline",children:[e.runningClusterCount," running,"," ",e.totalClusterCount," total"]})}),(0,l.jsx)(d.pj,{children:(0,l.jsx)("button",{onClick:()=>{Y.push({pathname:"/jobs",query:{workspace:e.name}})},className:"text-gray-700 hover:text-blue-600 hover:underline",children:e.managedJobsCount})}),(0,l.jsx)(d.pj,{children:e.clouds.length>0?[...e.clouds].sort().map((s,r)=>{let t=S.Z2[s.toLowerCase()]||s;return(0,l.jsxs)("span",{children:[(0,l.jsx)(Z(),{href:"/infra",className:"inline-flex items-center px-2 py-1 rounded text-sm bg-sky-100 text-sky-800 hover:bg-sky-200 hover:text-sky-900 transition-colors duration-200",children:t}),r<e.clouds.length-1&&" "]},s)}):(0,l.jsx)("span",{className:"text-gray-500 text-sm",children:"-"})}),(0,l.jsxs)(d.pj,{children:[(0,l.jsx)(u.z,{variant:"ghost",size:"sm",onClick:()=>ed(e.name),disabled:H,className:"text-gray-600 hover:text-gray-800 mr-1",children:(0,l.jsx)(f,{className:"w-4 h-4"})}),(0,l.jsx)(u.z,{variant:"ghost",size:"sm",onClick:()=>ei(e.name),disabled:"default"===e.name||H,title:"default"===e.name?"Cannot delete default workspace":"Delete workspace",className:"text-red-600 hover:text-red-700 hover:bg-red-50",children:(0,l.jsx)(v.Z,{className:"w-4 h-4"})})]})]},e.name)}):(0,l.jsx)(d.SC,{children:(0,l.jsx)(d.pj,{colSpan:5,className:"text-center py-6 text-gray-500",children:"No workspaces found"})})})]})})}):(0,l.jsxs)("div",{className:"text-center py-10",children:[(0,l.jsx)("p",{className:"text-lg text-gray-600",children:"No workspaces found."}),(0,l.jsx)("p",{className:"text-sm text-gray-500 mt-2",children:"Create a cluster to see its workspace here."})]}),R&&(0,l.jsx)(h.Vq,{open:W,onOpenChange:F,children:(0,l.jsxs)(h.cZ,{className:"sm:max-w-md md:max-w-lg lg:max-w-xl xl:max-w-2xl w-full max-h-[90vh] flex flex-col",children:[(0,l.jsx)(h.fK,{children:(0,l.jsx)(h.$N,{className:"pr-10",children:"All Workspaces Configuration"})}),(0,l.jsx)("div",{className:"flex-grow overflow-y-auto py-4",children:(0,l.jsx)("pre",{style:{backgroundColor:"#f5f5f5",padding:"16px",borderRadius:"8px",overflowX:"auto",whiteSpace:"pre",wordBreak:"normal"},children:x.ZP.dump(R,{indent:2})})})]})}),(0,l.jsx)(h.Vq,{open:X.open,onOpenChange:e=>{q(s=>({...s,open:e})),e||$(null)},children:(0,l.jsxs)(h.cZ,{className:"sm:max-w-md transition-all duration-200 ease-in-out",children:[(0,l.jsxs)(h.fK,{children:[(0,l.jsx)(h.$N,{children:"Permission Denied"}),(0,l.jsx)(h.Be,{children:H?(0,l.jsxs)("div",{className:"flex items-center py-2",children:[(0,l.jsx)(m.Z,{size:16,className:"mr-2"}),(0,l.jsx)("span",{children:"Checking permissions..."})]}):(0,l.jsx)(l.Fragment,{children:X.userName?(0,l.jsxs)(l.Fragment,{children:[X.userName," is logged in as non-admin and ",X.message,"."]}):X.message})})]}),(0,l.jsx)(h.cN,{children:(0,l.jsx)(u.z,{variant:"outline",onClick:()=>q(e=>({...e,open:!1})),disabled:H,children:"OK"})})]})}),(0,l.jsx)(h.Vq,{open:B.confirmOpen,onOpenChange:e=>{e||(ec(),$(null))},children:(0,l.jsxs)(h.cZ,{className:"sm:max-w-md",children:[(0,l.jsxs)(h.fK,{children:[(0,l.jsx)(h.$N,{children:"Delete Workspace"}),(0,l.jsxs)(h.Be,{children:['Are you sure you want to delete workspace "',B.workspaceToDelete,'"? This action cannot be undone.']})]}),(0,l.jsxs)(h.cN,{children:[(0,l.jsx)(u.z,{variant:"outline",onClick:ec,disabled:B.deleting,children:"Cancel"}),(0,l.jsx)(u.z,{variant:"destructive",onClick:eo,disabled:B.deleting,children:B.deleting?"Deleting...":"Delete"})]})]})})]})}},12003:function(e,s,r){r.d(s,{j:function(){return n}});var l=r(90512);let t=e=>"boolean"==typeof e?`${e}`:0===e?"0":e,a=l.W,n=(e,s)=>r=>{var l;if((null==s?void 0:s.variants)==null)return a(e,null==r?void 0:r.class,null==r?void 0:r.className);let{variants:n,defaultVariants:i}=s,o=Object.keys(n).map(e=>{let s=null==r?void 0:r[e],l=null==i?void 0:i[e];if(null===s)return null;let a=t(s)||t(l);return n[e][a]}),c=r&&Object.entries(r).reduce((e,s)=>{let[r,l]=s;return void 0===l||(e[r]=l),e},{});return a(e,o,null==s?void 0:null===(l=s.compoundVariants)||void 0===l?void 0:l.reduce((e,s)=>{let{class:r,className:l,...t}=s;return Object.entries(t).every(e=>{let[s,r]=e;return Array.isArray(r)?r.includes({...i,...c}[s]):({...i,...c})[s]===r})?[...e,r,l]:e},[]),null==r?void 0:r.class,null==r?void 0:r.className)}}}]);