Your IP : 216.73.216.189


Current Path : /proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/
Upload File :
Current File : //proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/StorageBuckets-BkZzaXgW.js

import{r as B,b8 as Q,j as e,d as n,O as G,T as I,t as H,K as Y,U as j,ak as X,w as K,J as ee,f as te,h as z,dg as ae,k as se,y as oe,p as J,v as ne,dh as V,L as re,aM as ie,I as le,M as ce}from"./index-BFGypnt-.js";import{s as ue,p as de}from"./searchAndFilter-DtC_P-vv.js";import{u as me}from"./useSortTableData-DMPSUVcX.js";import{P as L}from"./PageHeader-DZVSTM6q.js";import{H as pe}from"./HelpLink-l4aaXUp-.js";import{u as he,d as ge,c as be,S as Se,a as fe,b as je,e as ke,E as xe}from"./EditStorageBucketPanel-CMxW242a.js";import{u as Ne}from"./projects-DAlFlfjH.js";import{u as R,p as q}from"./usePanelParams-CV5ZHNeu.js";import{S as ye}from"./SelectableMainTable-BZaSR8Vv.js";import{S as Ce}from"./SelectedTableNotification-D7txT2Gz.js";import{B as we}from"./BulkDeleteButton-Cy-zhz39.js";import{u as Be}from"./useBulkDetails-_NNE1L7C.js";import{S as Pe}from"./StoragePoolRichChip-CxRTjvv2.js";import"./AutoExpandingTextArea-WEdimI5c.js";import"./StoragePoolSelector-CIzPJc24.js";import"./useStoragePools-qBtKr1j9.js";import"./useClusterMembers-B29_ixY7.js";import"./cluster-members-CG6XHzn4.js";import"./StoragePoolSize-ChYxPd_8.js";import"./Meter-VGEmUMfL.js";import"./DiskSizeSelector-C_YZZUSe.js";const W="query",_="pool",M=[W,_],Le=({buckets:a})=>{const[s,c]=Q(),h=[{id:1,heading:"Pool",chips:[...new Set(a.map(u=>u.pool))].map(u=>({lead:_,value:u}))}],b=u=>{const d=de(u,s,M);d.toString()!==s.toString()&&c(d)};return e.jsxs("div",{className:"search-wrapper margin-right--large",children:[e.jsx("h2",{className:"u-off-screen",children:"Search and filter"}),e.jsx(n.SearchAndFilter,{existingSearchData:ue(s,M),filterPanelData:h,returnSearchData:b,onExpandChange:()=>{window.dispatchEvent(new CustomEvent("resize",{detail:"search-and-filter"}))},onPanelToggle:()=>{window.dispatchEvent(new CustomEvent("sfp-toggle"))}})]})},De=B.memo(Le),D="Name",v="Pool",E="Size",F="Description",O="S3 URL",T="Keys",$="Actions",m={[D]:"8rem",[v]:"8rem",[E]:"5rem",[F]:"10rem",[O]:"15rem",[T]:"3rem",[$]:"8.5rem"},U=({className:a})=>{const s=G(),{canCreateStorageBuckets:c}=Ne(),{project:r}=I(),h=R();return e.jsxs(n.Button,{appearance:"positive",hasIcon:!s,onClick:()=>{h.openCreateStorageBucket(r?.name||"")},className:a,disabled:!c(r),title:c(r)?"Create bucket":"You do not have permission to create buckets in this project",children:[!s&&e.jsx(n.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Create bucket"})]})},ve=({buckets:a,onStart:s,onFinish:c})=>{const r=n.useToastNotification(),h=H(),[b,u]=B.useState(!1),{canDeleteBucket:d}=he(),S=Be(),{project:p}=I(),{hasStorageAndNetworkOperations:k}=Y(),x=p?.name||"",l=a.filter(g=>d(g)),o=a.length,i=l.length,N=`Delete ${a.length} ${j("bucket",a.length)}`,y=()=>{u(!0),s();const g=`${l.length} ${j("bucket",l.length)} successfully deleted`;ge(l,x,k).then(f=>{const{fulfilledCount:P,rejectedCount:C}=X(f);P===i?r.success(g,S(f)):C===i?r.failure("Storage bucket bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:i})," ",j("bucket",i)," could not be deleted."]}),S(f)):r.failure("Storage bucket bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:P})," ",j("bucket",P)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:C})," ",j("bucket",C)," could not be deleted."]}),S(f)),h.invalidateQueries({queryKey:[K.storage,x,K.buckets]}),u(!1),c()}).catch(f=>{u(!1),r.failure("Storage bucket bulk deletion failed",f)})},A=()=>{if(i===o)return;const g=o-i;return[`${i} ${j("bucket",i)} will be deleted.`,`${g} ${j("bucket",g)} that you do not have permission to delete will be ignored.`]};return e.jsx(we,{entities:a,deletableEntities:l,entityType:"bucket",onDelete:y,disabledReason:i===0?`You do not have permission to delete the selected ${j("bucket",a.length)}`:void 0,confirmationButtonProps:{disabled:b||i===0,loading:b},buttonLabel:N,bulkDeleteBreakdown:A(),className:"u-no-margin--bottom"})},Ee=()=>{const a=R(),s=n.useNotify(),c=n.useToastNotification(),r=B.useState(null),h=H(),b=()=>{a.clear(),s.clear()},{hasStorageAndNetworkOperations:u}=Y(),d=ee(),S=te().shape({name:z().min(3,"Name must be at least 3 characters").max(63,"Name must be at most 63 characters").matches(/^[a-z0-9][a-z0-9.-]*$/,"Name must contain only lowercase letters, numbers, periods, or hyphens and must start with a letter or number").test(...ae(a.project,r)).required("Storage bucket name is required"),pool:z().required("Pool must have a Ceph Object driver")}),p=()=>{h.invalidateQueries({queryKey:[K.storage,a.project,K.buckets]})},k=(o,i)=>{p(),c.success(e.jsxs(e.Fragment,{children:["Storage bucket"," ",e.jsx(ne,{type:"bucket",value:o,to:V(o,i,a.project)})," ","created."]})),b()},x=(o,i)=>{p(),l.setSubmitting(!1),s.failure(`Creation of storage bucket ${o} failed`,i)},l=se({initialValues:{name:"",pool:""},validationSchema:S,onSubmit:o=>{const i={name:o.name,config:{size:o.size},description:o.description};be(JSON.stringify(i),a.project,o.pool,o.target).then(N=>{u?(c.info(e.jsxs(e.Fragment,{children:["Creation of storage bucket"," ",e.jsx(oe,{bold:!0,type:"bucket",value:o.name})," has started."]})),d.set(N.metadata.id,()=>{k(o.name,o.pool)},y=>{x(o.name,new Error(y))})):k(o.name,o.pool)}).catch(N=>{x(o.name,N)})}});return e.jsx(e.Fragment,{children:e.jsxs(n.SidePanel,{children:[e.jsx(n.SidePanel.Header,{children:e.jsx(n.SidePanel.HeaderTitle,{children:"Create storage bucket"})}),e.jsx(J,{className:"u-no-padding"}),e.jsx(n.SidePanel.Content,{className:"u-no-padding",children:e.jsx(n.ScrollableContainer,{dependencies:[s.notification],belowIds:["panel-footer"],children:e.jsx(Se,{formik:l})})}),e.jsxs(n.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(n.Button,{appearance:"base",onClick:b,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(n.ActionButton,{appearance:"positive",loading:l.isSubmitting,onClick:()=>{l.submitForm()},className:"u-no-margin--bottom",disabled:!l.isValid||l.isSubmitting||!l.values.name,children:"Create bucket"})]})]})})},Fe=({bucket:a,project:s})=>e.jsx(re,{to:V(a.name,a.pool,s),onClick:c=>{c.stopPropagation()},children:e.jsx(ie,{item:a})}),Oe=({bucket:a})=>{const{project:s}=I(),{data:c=[]}=fe(a,s?.name??"");return e.jsx(e.Fragment,{children:c?c.length:"-"})},tt=()=>{const a=n.useNotify(),{project:s}=le(),[c]=Q(),[r,h]=B.useState([]),[b,u]=B.useState([]),d=R(),S={queries:c.getAll(W),pools:c.getAll(_)};if(!s)return e.jsx(e.Fragment,{children:"Missing project"});const{data:p=[],error:k,isLoading:x}=je(s),l=t=>`${t.name}-${t.pool}-${t.location||""}`;B.useEffect(()=>{const t=new Set(p.map(l)),w=r.filter(Z=>t.has(Z));w.length!==r.length&&h(w)},[p]),k&&a.failure("Loading storage buckets failed",k);const o=[{content:D,sortKey:"name",className:"name",style:{width:m[D]}},{content:v,sortKey:"pool",className:"pool",style:{width:m[v]}},{content:E,sortKey:"size",className:"size",style:{width:m[E]}},{content:F,className:"description",style:{width:m[F]}},{content:O,sortKey:"s3_url",style:{width:m[O]}},{content:T,style:{width:m[T]},className:"keys"},{className:"actions u-align--right","aria-label":"Actions",style:{width:m[$]}}],i=p.filter(t=>!(!S.queries.every(w=>t.name.toLowerCase().includes(w))||S.pools.length>0&&!S.pools.includes(t.pool))),N=i.map(t=>({key:l(t),name:l(t),className:"u-row",columns:[{content:e.jsx(Fe,{bucket:t,project:s}),role:"rowheader","aria-label":D,style:{width:m[D]}},{content:e.jsx(Pe,{poolName:t.pool,projectName:s,location:t.location}),role:"cell","aria-label":v,style:{width:m[v]}},{content:t.config?.size??"-",role:"cell","aria-label":E,style:{width:m[E]}},{content:t.description||"-",role:"cell","aria-label":F,style:{width:m[F]},className:"description u-truncate"},{content:e.jsx("div",{className:"u-truncate",title:t.s3_url,children:t.s3_url}),role:"cell","aria-label":O,style:{width:m[O]}},{content:e.jsx(Oe,{bucket:t}),role:"cell","aria-label":T,style:{width:m[T]},className:"keys"},{className:"actions u-align--right",content:e.jsx(ke,{bucket:t,className:"storage-bucket-actions u-no-margin--bottom"}),role:"cell","aria-label":$,style:{width:m[$]}}],sortData:{name:t.name,pool:t.pool,size:t.config?.size??"",s3_url:t.s3_url}})),{rows:y,updateSort:A}=me({rows:N,defaultSortDirection:"descending"});if(x)return e.jsx(n.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});const g=p.length!==0,f=g?e.jsx("div",{className:"storage-buckets",children:e.jsx(n.ScrollableTable,{dependencies:[i],tableId:"bucket-table",belowIds:["status-bar"],children:e.jsx(n.TablePagination,{data:y,id:"pagination",itemName:"bucket",className:"u-no-margin--top","aria-label":"Table pagination control",description:r.length>0&&e.jsx(Ce,{totalCount:p.length??0,itemName:"bucket",parentName:"project",selectedNames:r,setSelectedNames:h,filteredNames:i.map(t=>l(t))}),children:e.jsx(ye,{id:"bucket-table",className:"storage-buckets-table",headers:o,rows:y,sortable:!0,emptyStateMsg:"No storage bucket found matching this search",itemName:"bucket",parentName:"project",selectedNames:r,setSelectedNames:h,disabledNames:b,filteredNames:i.map(l),onUpdateSort:A,defaultSortDirection:"descending",responsive:!0})})})}):e.jsxs(n.EmptyState,{className:"empty-state",image:e.jsx(n.Icon,{name:"storage-bucket",className:"empty-state-icon"}),title:"No buckets found in this project",children:[e.jsx("p",{children:"Storage buckets will appear here"}),e.jsx("p",{children:e.jsx(ce,{docPath:"/explanation/storage/#storage-buckets",hasExternalIcon:!0,children:"Learn more about storage buckets"})}),e.jsx(U,{className:"empty-state-button"})]}),P=p.filter(t=>{const w=l(t);return r.includes(w)}),C=p.find(t=>t.name==d.bucket&&t.pool==d.pool&&t.location==d.target);return e.jsxs(e.Fragment,{children:[e.jsxs(n.CustomLayout,{mainClassName:"storage-bucket-list",header:e.jsxs(L,{children:[e.jsxs(L.Left,{children:[e.jsx(L.Title,{children:e.jsx(pe,{docPath:"/explanation/storage/#storage-buckets",title:"Learn more about storage buckets",children:"Buckets"})}),!r.length&&!d.panel&&g&&e.jsx(L.Search,{children:e.jsx(De,{buckets:p},s)}),!!r.length&&e.jsx(ve,{buckets:P,onStart:()=>{u(r)},onFinish:()=>{u([])}})]}),g&&e.jsx(L.BaseActions,{children:e.jsx(U,{className:"u-float-right u-no-margin--bottom"})})]}),children:[!d.panel&&e.jsx(J,{}),e.jsx(n.Row,{children:f})]}),d.panel===q.createStorageBucket&&e.jsx(Ee,{}),d.panel===q.editStorageBucket&&C&&e.jsx(xe,{bucket:C})]})};export{tt as default};