Your IP : 216.73.216.52


Current Path : /snap/lxd/38450/share/lxd-ui/assets/
Upload File :
Current File : //snap/lxd/38450/share/lxd-ui/assets/StorageBuckets-DIt3xdzo.js

import{r as y,bu as U,j as e,d as o,H as Z,S as I,v as Q,T as k,ax as G,x as K,f as X,h as q,eb as ee,k as te,p as Y,w as se,ec as V,L as ae,b2 as oe,C as ne,b3 as re}from"./index-BsQN_SZU.js";import{s as ie,p as le}from"./searchAndFilter-DtC_P-vv.js";import{u as ce}from"./useSortTableData-DkMx8bMp.js";import{P as w}from"./PageHeader-BkhUaI4-.js";import{H as ue}from"./HelpLink-BJF9zWZL.js";import{u as de,d as me,c as pe,S as he,a as ge,b as be,e as Se,E as fe}from"./EditStorageBucketPanel-CAwD6Ilg.js";import{u as je}from"./projects-CczQ3aFg.js";import{u as R,p as z}from"./usePanelParams-CNAJZsSX.js";import{S as ke}from"./SelectableMainTable-DBx4rRiq.js";import{S as xe}from"./SelectedTableNotification-BpePAhdG.js";import{B as Ne}from"./BulkDeleteButton-DbqPCHnz.js";import{u as ye}from"./useBulkDetails-ydqvQ5wa.js";import{S as Ce}from"./StoragePoolRichChip-Daex_aZU.js";import"./AutoExpandingTextArea-Bd-45rZK.js";import"./StoragePoolSelector-Bvqvds5t.js";import"./StoragePoolSize-BNbqTfwA.js";import"./Meter-cq8smrSm.js";import"./DiskSizeSelector-C9kWj54D.js";import"./limits-yeXZOxhv.js";const J="query",_="pool",M=[J,_],Be=({buckets:s})=>{const[a,i]=U(),p=[{id:1,heading:"Pool",chips:[...new Set(s.map(c=>c.pool))].map(c=>({lead:_,value:c}))}],g=c=>{const u=le(c,a,M);u.toString()!==a.toString()&&i(u)};return e.jsxs("div",{className:"search-wrapper margin-right",children:[e.jsx("h2",{className:"u-off-screen",children:"Search and filter"}),e.jsx(o.SearchAndFilter,{existingSearchData:ie(a,M),filterPanelData:p,returnSearchData:g,onExpandChange:()=>{window.dispatchEvent(new CustomEvent("resize",{detail:"search-and-filter"}))},onPanelToggle:()=>{window.dispatchEvent(new CustomEvent("sfp-toggle"))}})]})},we=y.memo(Be),P="Name",L="Pool",v="Size",D="Description",E="S3 URL",T="Keys",O="Actions",d={[P]:"8rem",[L]:"8rem",[v]:"5rem",[D]:"10rem",[E]:"15rem",[T]:"3rem",[O]:"8.5rem"},H=({className:s})=>{const a=Z(),{canCreateStorageBuckets:i}=je(),{project:n}=I(),p=R();return e.jsxs(o.Button,{appearance:"positive",hasIcon:!a,onClick:()=>{p.openCreateStorageBucket(n?.name||"")},className:s,disabled:!i(n),title:i(n)?"Create bucket":"You do not have permission to create buckets in this project",children:[!a&&e.jsx(o.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Create bucket"})]})},Pe=({buckets:s,onStart:a,onFinish:i})=>{const n=o.useToastNotification(),p=Q(),[g,c]=y.useState(!1),{canDeleteBucket:u}=de(),l=ye(),{project:r}=I(),b=r?.name||"",S=s.filter(j=>u(j)),f=s.length,m=S.length,x=`Delete ${s.length} ${k("bucket",s.length)}`,$=()=>{c(!0),a();const j=`${S.length} ${k("bucket",S.length)} successfully deleted`;me(S,b).then(h=>{const{fulfilledCount:C,rejectedCount:B}=G(h);C===m?n.success(j,l(h)):B===m?n.failure("Storage bucket bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:m})," ",k("bucket",m)," could not be deleted."]}),l(h)):n.failure("Storage bucket bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:C})," ",k("bucket",C)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:B})," ",k("bucket",B)," could not be deleted."]}),l(h)),p.invalidateQueries({queryKey:[K.storage,b,K.buckets]}),c(!1),i()}).catch(h=>{c(!1),n.failure("Storage bucket bulk deletion failed",h)})},F=()=>{if(m===f)return;const j=f-m;return[`${m} ${k("bucket",m)} will be deleted.`,`${j} ${k("bucket",j)} that you do not have permission to delete will be ignored.`]};return e.jsx(Ne,{entities:s,deletableEntities:S,entityType:"bucket",onDelete:$,disabledReason:m===0?`You do not have permission to delete the selected ${k("bucket",s.length)}`:void 0,confirmationButtonProps:{disabled:g||m===0,loading:g},buttonLabel:x,bulkDeleteBreakdown:F(),className:"u-no-margin--bottom"})},Le=()=>{const s=R(),a=o.useNotify(),i=o.useToastNotification(),n=y.useState(null),p=Q(),g=()=>{s.clear(),a.clear()},c=X().shape({name:q().test(...ee(s.project,n)).required("Bucket name is required"),pool:q().required("Pool must have a Ceph Object driver")}),u=(r,b)=>{i.success(e.jsxs(e.Fragment,{children:["Storage bucket"," ",e.jsx(se,{type:"bucket",value:r,to:V(r,b,s.project)})," ","created."]})),g()},l=te({initialValues:{name:"",pool:""},validationSchema:c,onSubmit:r=>{const b={name:r.name,config:{size:r.size},description:r.description};pe(JSON.stringify(b),s.project,r.pool,r.target).then(()=>{p.invalidateQueries({queryKey:[K.storage,s.project,K.buckets]}),u(r.name,r.pool)}).catch(S=>{l.setSubmitting(!1),a.failure("Storage bucket creation failed",S)})}});return e.jsx(e.Fragment,{children:e.jsxs(o.SidePanel,{children:[e.jsx(o.SidePanel.Header,{children:e.jsx(o.SidePanel.HeaderTitle,{children:"Create storage bucket"})}),e.jsx(Y,{className:"u-no-padding"}),e.jsx(o.SidePanel.Content,{className:"u-no-padding",children:e.jsx(o.ScrollableContainer,{dependencies:[a.notification],belowIds:["panel-footer"],children:e.jsx(he,{formik:l})})}),e.jsxs(o.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(o.Button,{appearance:"base",onClick:g,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(o.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"})]})]})})},ve=({bucket:s,project:a})=>e.jsx(ae,{to:V(s.name,s.pool,a),onClick:i=>{i.stopPropagation()},children:e.jsx(oe,{item:s})}),De=({bucket:s})=>{const{project:a}=I(),{data:i=[]}=ge(s,a?.name??"");return e.jsx(e.Fragment,{children:i?i.length:"-"})},We=()=>{const s=o.useNotify(),{project:a}=ne(),[i]=U(),[n,p]=y.useState([]),[g,c]=y.useState([]),u=R(),l={queries:i.getAll(J),pools:i.getAll(_)};if(!a)return e.jsx(e.Fragment,{children:"Missing project"});const{data:r=[],error:b,isLoading:S}=be(a),f=t=>`${t.name}-${t.pool}-${t.location||""}`;y.useEffect(()=>{const t=new Set(r.map(f)),N=n.filter(W=>t.has(W));N.length!==n.length&&p(N)},[r]),b&&s.failure("Loading storage buckets failed",b);const m=[{content:P,sortKey:"name",className:"name",style:{width:d[P]}},{content:L,sortKey:"pool",className:"pool",style:{width:d[L]}},{content:v,sortKey:"size",className:"size",style:{width:d[v]}},{content:D,className:"description",style:{width:d[D]}},{content:E,sortKey:"s3_url",style:{width:d[E]}},{content:T,style:{width:d[T]},className:"keys"},{className:"actions u-align--right","aria-label":"Actions",style:{width:d[O]}}],x=r.filter(t=>!(!l.queries.every(N=>t.name.toLowerCase().includes(N))||l.pools.length>0&&!l.pools.includes(t.pool))),$=x.map(t=>({key:f(t),name:f(t),className:"u-row",columns:[{content:e.jsx(ve,{bucket:t,project:a}),role:"rowheader","aria-label":P,style:{width:d[P]}},{content:e.jsx(Ce,{poolName:t.pool,projectName:a,location:t.location}),role:"cell","aria-label":L,style:{width:d[L]}},{content:t.config?.size??"-",role:"cell","aria-label":v,style:{width:d[v]}},{content:t.description||"-",role:"cell","aria-label":D,style:{width:d[D]},className:"description u-truncate"},{content:e.jsx("div",{className:"u-truncate",title:t.s3_url,children:t.s3_url}),role:"cell","aria-label":E,style:{width:d[E]}},{content:e.jsx(De,{bucket:t}),role:"cell","aria-label":T,style:{width:d[T]},className:"keys"},{className:"actions u-align--right",content:e.jsx(Se,{bucket:t,className:"storage-bucket-actions u-no-margin--bottom"}),role:"cell","aria-label":O,style:{width:d[O]}}],sortData:{name:t.name,pool:t.pool,size:t.config?.size??"",s3_url:t.s3_url}})),{rows:F,updateSort:j}=ce({rows:$,defaultSortDirection:"descending"});if(S)return e.jsx(o.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});const h=r.length!==0,C=h?e.jsx("div",{className:"storage-buckets",children:e.jsx(o.ScrollableTable,{dependencies:[x],tableId:"bucket-table",belowIds:["status-bar"],children:e.jsx(o.TablePagination,{data:F,id:"pagination",itemName:"bucket",className:"u-no-margin--top","aria-label":"Table pagination control",description:n.length>0&&e.jsx(xe,{totalCount:r.length??0,itemName:"bucket",parentName:"project",selectedNames:n,setSelectedNames:p,filteredNames:x.map(t=>f(t))}),children:e.jsx(ke,{id:"bucket-table",className:"storage-buckets-table",headers:m,rows:F,sortable:!0,emptyStateMsg:"No storage bucket found matching this search",itemName:"bucket",parentName:"project",selectedNames:n,setSelectedNames:p,disabledNames:g,filteredNames:x.map(f),onUpdateSort:j,defaultSortDirection:"descending",responsive:!0})})})}):e.jsxs(o.EmptyState,{className:"empty-state",image:e.jsx(o.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(re,{docPath:"/explanation/storage/#storage-buckets",hasExternalIcon:!0,children:"Learn more about storage buckets"})}),e.jsx(H,{className:"empty-state-button"})]}),B=r.filter(t=>{const N=f(t);return n.includes(N)}),A=r.find(t=>t.name==u.bucket&&t.pool==u.pool&&t.location==u.target);return e.jsxs(e.Fragment,{children:[e.jsxs(o.CustomLayout,{mainClassName:"storage-bucket-list",header:e.jsxs(w,{children:[e.jsxs(w.Left,{children:[e.jsx(w.Title,{children:e.jsx(ue,{docPath:"/explanation/storage/#storage-buckets",title:"Learn more about storage buckets",children:"Buckets"})}),!n.length&&!u.panel&&h&&e.jsx(w.Search,{children:e.jsx(we,{buckets:r},a)}),!!n.length&&e.jsx(Pe,{buckets:B,onStart:()=>{c(n)},onFinish:()=>{c([])}})]}),h&&e.jsx(w.BaseActions,{children:e.jsx(H,{className:"u-float-right u-no-margin--bottom"})})]}),children:[!u.panel&&e.jsx(Y,{}),e.jsx(o.Row,{children:C})]}),u.panel===z.createStorageBucket&&e.jsx(Le,{}),u.panel===z.editStorageBucket&&A&&e.jsx(fe,{bucket:A})]})};export{We as default};