MINI Sh3ll
import{b3 as S,al as C,d as c,i as y,r as h,e as b,bi as R,j as i,aa as L,I as D,bj as E,q as x,l as j,x as I,z as F,bk as N,H as q,u as V,A as H,bl as B,C as K,m as T,ae as z,L as O}from"./index-3c1b2661.js";import{P as Q,p as $,b as A,r as M,c as U,i as J,d as W,n as G,a as X}from"./ProjectForm-420f46d7.js";import{S as Y,u as Z}from"./updateMaxHeight-4e644a5f.js";import{c as k,a as P,u as w}from"./index.esm-7989c879.js";import{e as ee,a as p}from"./formFields-e7157cb4.js";import{R as ie}from"./RenameHeader-48dfd372.js";import"./FormMenuItem-c982b037.js";import"./AutoExpandingTextArea-38ef4775.js";import"./DiskSizeSelector-f5c6feab.js";import"./instanceConfigInheritance-8da60590.js";import"./ConfigurationTable-5663621c.js";import"./ConfigFieldDescription-f8ae8325.js";const te=e=>({name:e.name,readOnly:!0,description:e.description,restricted:e.config.restricted==="true",features_images:e.config["features.images"]==="true",features_profiles:S(e),features_networks:e.config["features.networks"]==="true",features_storage_volumes:e.config["features.storage.volumes"]==="true",type:"project",limits_instances:e.config["limits.instances"]?parseInt(e.config["limits.instances"]):void 0,limits_containers:e.config["limits.containers"]?parseInt(e.config["limits.containers"]):void 0,limits_virtual_machines:e.config["limits.virtual-machines"]?parseInt(e.config["limits.virtual-machines"]):void 0,limits_disk:e.config["limits.disk"],limits_networks:e.config["limits.networks"]?parseInt(e.config["limits.networks"]):void 0,limits_cpu:e.config["limits.cpu"]?parseInt(e.config["limits.cpu"]):void 0,limits_memory:e.config["limits.memory"]?parseInt(e.config["limits.memory"]):void 0,limits_processes:e.config["limits.processes"]?parseInt(e.config["limits.processes"]):void 0,restricted_cluster_groups:e.config["restricted.cluster.groups"],restricted_cluster_target:e.config["restricted.cluster.target"],restricted_virtual_machines_low_level:e.config["restricted.virtual-machines.lowlevel"],restricted_containers_low_level:e.config["restricted.containers.lowlevel"],restricted_containers_nesting:e.config["restricted.containers.nesting"],restricted_containers_privilege:e.config["restricted.containers.privilege"],restricted_container_interception:e.config["restricted.containers.interception"],restrict_snapshots:e.config["restricted.snapshots"],restricted_idmap_uid:e.config["restricted.idmap.uid"],restricted_idmap_gid:e.config["restricted.idmap.gid"],restricted_devices_disk:e.config["restricted.devices.disk"],restricted_devices_disk_paths:e.config["restricted.devices.disk.paths"],restricted_devices_gpu:e.config["restricted.devices.gpu"],restricted_devices_infiniband:e.config["restricted.devices.infiniband"],restricted_devices_nic:e.config["restricted.devices.nic"],restricted_devices_pci:e.config["restricted.devices.pci"],restricted_devices_unix_block:e.config["restricted.devices.unix-block"],restricted_devices_unix_char:e.config["restricted.devices.unix-char"],restricted_devices_unix_hotplug:e.config["restricted.devices.unix-hotplug"],restricted_devices_usb:e.config["restricted.devices.usb"],restricted_network_access:e.config["restricted.networks.access"],restricted_network_subnets:e.config["restricted.networks.subnets"],restricted_network_uplinks:e.config["restricted.networks.uplinks"],restricted_network_zones:e.config["restricted.networks.zones"]}),se=({project:e})=>{const s=C(),a=c.useNotify(),m=y(),[d,l]=h.useState(!1),u=b(),r=e.name==="default",n=R(e),t=()=>r?"The default project cannot be deleted":n?"Delete project":"Non-empty projects cannot be deleted",f=()=>{l(!0),E(e).then(()=>{u("/ui/project/default/instances",a.queue(a.success(`Project ${e.name} deleted.`)))}).catch(g=>{l(!1),a.failure("Project deletion failed",g)}).finally(()=>{m.invalidateQueries({queryKey:[x.projects]})})};return i.jsxs(c.ConfirmationButton,{onHoverText:t(),appearance:s?"base":"default",className:L("u-no-margin--bottom",{"has-icon":s}),loading:d,disabled:r||!n,confirmationModalProps:{title:"Confirm delete",confirmButtonLabel:"Delete",onConfirm:f,children:i.jsxs("p",{children:["This will permanently delete project"," ",i.jsx(D,{item:e,bold:!0}),".",i.jsx("br",{}),"This action cannot be undone, and can result in data loss."]})},shiftClickEnabled:!0,showShiftClickHint:!0,children:[s&&i.jsx(c.Icon,{name:"delete"}),!s&&i.jsx("span",{children:"Delete project"})]})},ne=({project:e})=>{const s=j(),a=I(),m=b(),d=c.useNotify(),l=h.useState(null),u=k().shape({name:P().test("deduplicate","A project with this name already exists",n=>e.name===n||F(n,"",l,"projects")).required("Project name is required")}),r=w({initialValues:{name:e.name,isRenaming:!1},validationSchema:u,onSubmit:n=>{if(e.name===n.name){r.setFieldValue("isRenaming",!1),r.setSubmitting(!1);return}N(e.name,n.name).then(t=>a.set(t.metadata.id,()=>{m(`/ui/project/${n.name}/configuration`,d.queue(d.success("Project renamed."))),r.setFieldValue("isRenaming",!1)},f=>d.failure("Renaming failed",new Error(f)),()=>r.setSubmitting(!1)))}});return i.jsx(ie,{name:e.name,parentItems:[i.jsx(q,{href:`${s}/reference/projects/`,title:"Learn more about project configuration",children:"Project configuration"},"project-configuration")],renameDisabledReason:e.name==="default"?"Cannot rename the default project":void 0,controls:i.jsx(se,{project:e}),isLoaded:!!e,formik:r})},ae=({project:e})=>{var g;const{isRestricted:s}=V(),a=c.useNotify(),m=y(),[d,l]=h.useState(Q),u=()=>{Z("form-contents","p-bottom-controls")};h.useEffect(u,[(g=a.notification)==null?void 0:g.message,d]),H("resize",u);const r=k().shape({name:P().required()}),n=te(e),t=w({initialValues:n,validationSchema:r,onSubmit:o=>{const _=f(o);_.etag=e.etag,B(_).then(()=>{a.success("Project updated."),t.setFieldValue("readOnly",!0)}).catch(v=>{a.failure("Project update failed",v)}).finally(()=>{t.setSubmitting(!1),m.invalidateQueries({queryKey:[x.projects]})})}}),f=o=>{const _=ee(),v=new Set(["name","description","config"]);return{...$(o),config:{...A(o),...M(o),...o.restricted?{...U(o),...J(o),...W(o),...G(o)}:{},...p(e.config,_)},...p(e,v)}};return i.jsxs(K,{header:i.jsx(ne,{project:e}),contentClassName:"edit-project",children:[i.jsx(X,{formik:t,project:e,section:d,updateSection:l,isEdit:!0}),!s&&i.jsxs("div",{className:"p-bottom-controls",id:"form-footer",children:[i.jsx("hr",{}),i.jsx(c.Row,{children:i.jsx(c.Col,{size:12,className:"u-align--right",children:t.values.readOnly?i.jsx(i.Fragment,{children:i.jsx(c.Button,{appearance:"positive",onClick:()=>void t.setFieldValue("readOnly",!1),children:"Edit configuration"})}):i.jsxs(i.Fragment,{children:[i.jsx(c.Button,{appearance:"base",onClick:()=>t.setValues(n),children:"Cancel"}),i.jsx(Y,{isSubmitting:t.isSubmitting,isDisabled:!t.isValid||!t.values.name,buttonLabel:"Save changes",onClick:()=>void t.submitForm()})]})})})]})]})},pe=()=>{const{project:e}=T();if(!e)return i.jsx(i.Fragment,{children:"Missing project"});const{project:s,isLoading:a}=z();return a?i.jsx(O,{}):s?i.jsx(ae,{project:s},s.name):i.jsx(i.Fragment,{children:"Loading project failed"})};export{pe as default};
OHA YOOOO