/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/StorageBucketDetail-e9YB7NqL.js
import{j as e,L as $,x as M,ak as H,F as C,d as s,r as N,l as L,m as F,q as y,ah as b,R as B,aj as Q,n as U,C as V,e as w,f as Y,g as z,i as I,o as _}from"./index-dL2n30-Z.js";import{e as J,u as E,f as O,g as G,a as W,h as X,i as Z,j as ee,k as te,E as ae}from"./EditStorageBucketPanel-CgvzJxUU.js";import{R as se}from"./RenameHeader-BZc6vaTG.js";import{I as ne}from"./ItemName-BzCTqTL3.js";import{S as oe}from"./SelectableMainTable-DeGTWeiA.js";import{S as ie}from"./ScrollableTable-CQDmfMtz.js";import{S as re}from"./SelectedTableNotification-BHmDbErh.js";import{u as le}from"./useSortTableData-8PACcjA7.js";import{u as v,p as K}from"./usePanelParams-BJBr0ywH.js";import{B as ce}from"./BulkDeleteButton-DzyTAjHk.js";import{g as D,a as de}from"./storageBucket-Bz2jIa5m.js";import{S as T}from"./ScrollableContainer-ceiHesUW.js";import{A as ue}from"./AutoExpandingTextArea-CQuEMXHF.js";import"./StoragePoolSelector-BbIrdWMX.js";import"./StoragePoolSize-BwIynhzl.js";import"./Meter-BBGrNnHA.js";import"./DiskSizeSelector-DZsA03GF.js";import"./limits-CLEFMbq-.js";const me=({bucket:t,project:n})=>e.jsx(se,{name:t.name,parentItems:[e.jsx($,{to:`/ui/project/${encodeURIComponent(n)}/storage/buckets`,children:"Storage buckets"},1)],controls:t?e.jsx(J,{bucket:t,isDetailPage:!0}):null,isLoaded:!0,renameDisabledReason:"Storage buckets cannot be renamed"}),R=({className:t})=>{const n=M(),{canCreateStorageBuckets:i}=H(),{project:l}=C(),m=v();return e.jsxs(s.Button,{appearance:"positive",hasIcon:!n,onClick:()=>{m.openCreateStorageBucketKey((l==null?void 0:l.name)||"")},className:t,disabled:!i(l),title:i(l)?"Create bucket key":"You do not have permission to create keys for this bucket",children:[!n&&e.jsx(s.Icon,{name:"plus",light:!0}),e.jsx("span",{children:"Create key"})]})},pe=({bucket:t,bucketKey:n})=>{const i=s.useNotify(),[l,m]=N.useState(!1),o=L(),{canEditBucket:c}=E(),{project:p}=C(),a=(p==null?void 0:p.name)||"",x=s.useToastNotification(),d=()=>{x.success(e.jsxs(e.Fragment,{children:["Bucket key"," ",e.jsx(F,{bold:!0,type:"bucket-key",value:n.name})," deleted for bucket ",e.jsx(F,{bold:!0,type:"bucket",value:t.name}),"."]}))},h=()=>{m(!0),O(t.name,n.name,t.pool,a).then(d).catch(u=>{i.failure("Bucket key deletion failed",u)}).finally(()=>{m(!1),o.invalidateQueries({queryKey:[y.storage,t.pool,(p==null?void 0:p.name)??"",y.buckets,t.name,y.keys]})})};return e.jsx(s.ConfirmationButton,{loading:l,confirmationModalProps:{title:"Confirm delete",children:e.jsxs("p",{children:["This will permanently delete key"," ",e.jsx(F,{type:"bucket-key",value:n.name,bold:!0}),".",e.jsx("br",{}),"This action cannot be undone, and can result in data loss."]}),confirmButtonLabel:"Delete",onConfirm:h},appearance:"base",className:"has-icon",shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!c(t),onHoverText:c(t)?"Delete key":"You do not have permission to delete this key.",children:e.jsx(s.Icon,{name:"delete"})})},ge=({bucket:t,bucketKey:n})=>{const i=v(),{canEditBucket:l}=E();return e.jsx(s.Button,{className:"has-icon",appearance:"base",hasIcon:!0,onClick:()=>{i.openEditStorageBucketKey(n.name)},title:l(t)?"Edit bucket":"You do not have permission to edit this bucket",children:e.jsx(s.Icon,{name:"edit"})})},he=({bucketKey:t,bucket:n})=>{const i=[e.jsx(ge,{bucketKey:t,bucket:n},"edit"),e.jsx(pe,{bucketKey:t,bucket:n},"delete")];return e.jsx(s.List,{inline:!0,className:"u-no-margin--bottom actions-list",items:i})},ye=({keys:t,bucket:n,onStart:i,onFinish:l})=>{const m=s.useToastNotification(),o=L(),[c,p]=N.useState(!1),{project:a}=C(),x=(a==null?void 0:a.name)||"",d=t.length,h=`Delete ${t.length} ${b("key",t.length)}`,u=()=>{p(!0),i();const f=e.jsxs(e.Fragment,{children:[t.length," ",b("key",t.length)," deleted for bucket"," ",e.jsx(B,{type:"bucket",value:n.name,to:D(n.name,n.pool,(a==null?void 0:a.name)??"")}),"."]});G(n,t,x).then(g=>{const{fulfilledCount:j,rejectedCount:S}=Q(g);j===d?m.success(f):S===d?m.failure("Key bulk deletion failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:d})," ",b("key",d)," could not be deleted."]})):m.failure("Key bulk deletion partially failed",void 0,e.jsxs(e.Fragment,{children:[e.jsx("b",{children:j})," ",b("key",j)," ","deleted.",e.jsx("br",{}),e.jsx("b",{children:S})," ",b("key",S)," could not be deleted."]})),o.invalidateQueries({queryKey:[y.storage,n.pool,(a==null?void 0:a.name)??"",y.buckets,n.name,y.keys]}),p(!1),l()}).catch(g=>{p(!1),m.failure(`Key bulk deletion failed for bucket ${n.name}`,g)})};return e.jsx(ce,{entities:t,deletableEntities:t,entityType:"key",onDelete:u,disabledReason:d===0?`You do not have permission to delete the selected ${b("key",t.length)}`:void 0,confirmationButtonProps:{disabled:c||d===0,loading:c},buttonLabel:h})},xe=({bucket:t})=>{const n=U(),[i,l]=N.useState(""),m=s.useNotify(),[o,c]=N.useState([]),[p,a]=N.useState([]),{project:x}=C(),{data:d=[]}=W(t,(x==null?void 0:x.name)??"");N.useEffect(()=>{const r=new Set(d==null?void 0:d.map(P=>P.name)),k=o.filter(P=>r.has(P));k.length!==o.length&&c(k)},[d]);const h=(d==null?void 0:d.filter(r=>{if(i){const k=i.toLowerCase();return r.name.toLowerCase().includes(k)||r.role.toLowerCase().includes(k)||r.description.toLowerCase().includes(k)||r["access-key"].toLowerCase().includes(k)||r["secret-key"].toLowerCase().includes(k)}return!0}))??[],u=d&&d.length>0,f=[{content:"Name",sortKey:"name",className:"name"},{content:"Role",sortKey:"role",className:"role"},{content:"Description",sortKey:"description",className:"description"},{content:"Access key",className:"key-field",sortKey:"access-key"},{content:"Secret key",className:"key-field",sortKey:"secret-key"},{"aria-label":"Actions",className:"actions"}],g=h.map(r=>({key:r.name,className:"u-row",name:r.name,columns:[{content:e.jsx("div",{className:"u-truncate",title:`Key ${r.name}`,children:e.jsx(ne,{item:r})}),role:"rowheader","aria-label":"Name",className:"name"},{content:V(r.role),role:"cell","aria-label":"Role",className:"role"},{content:r.description||"-",title:r.description,role:"cell","aria-label":"Description",className:"description u-truncate"},{content:r["access-key"],role:"cell","aria-label":"Access key",className:"key-field"},{content:r["secret-key"],role:"cell","aria-label":"Secret key",className:"key-field"},{content:e.jsx(he,{bucketKey:r,bucket:t}),role:"cell","aria-label":"Actions",className:"u-align--right actions"}],sortData:{name:r.name.toLowerCase(),role:r.role,description:r.description.toLowerCase(),"access-key":r["access-key"],"secret-key":r["secret-key"]}})),j=d.filter(r=>o.includes(r.name)),{rows:S,updateSort:A}=le({rows:g,defaultSort:"name",defaultSortDirection:"ascending"});return e.jsxs("div",{className:"storage-bucket-key-list",children:[u&&e.jsx("div",{className:"upper-controls-bar",children:o.length===0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"search-box-wrapper",children:e.jsx(s.SearchBox,{name:"search-snapshot",className:"search-box margin-right",type:"text",onChange:r=>{l(r)},placeholder:"Search for keys",value:i,"aria-label":"Search for keys"})}),e.jsx(R,{})]}):e.jsx("div",{className:"p-panel__controls",children:e.jsx(ye,{keys:j,bucket:t,onStart:()=>{a(o)},onFinish:()=>{a([])}})})}),e.jsx(w,{}),u?e.jsx(e.Fragment,{children:e.jsx(ie,{dependencies:[h,m.notification],tableId:"buckets-key-table",belowIds:["status-bar"],children:e.jsx(s.TablePagination,{data:S,id:"pagination",itemName:"key",className:"u-no-margin--top","aria-label":"Table pagination control",description:o.length>0&&e.jsx(re,{totalCount:(d==null?void 0:d.length)??0,itemName:"key",parentName:"bucket",selectedNames:o,setSelectedNames:c,filteredNames:h.map(r=>r.name)}),children:e.jsx(oe,{id:"buckets-key-table",headers:f,rows:S,sortable:!0,emptyStateMsg:"No key found matching this search",itemName:"key",parentName:"bucket",selectedNames:o,setSelectedNames:c,disabledNames:p,filteredNames:h.map(r=>r.name),onUpdateSort:A,defaultSort:"name",defaultSortDirection:"ascending",responsive:!0})})})}):e.jsxs(s.EmptyState,{className:"empty-state",image:e.jsx(s.Icon,{name:"private-key",className:"empty-state-icon"}),title:"No keys",children:[e.jsx("p",{children:"This bucket does not contain any keys."}),e.jsx("p",{children:e.jsxs("a",{href:`${n}/explanation/storage/`,target:"_blank",rel:"noopener noreferrer",children:["Learn more about storage",e.jsx(s.Icon,{className:"external-link-icon",name:"external-link"})]})}),e.jsx(R,{})]})]})},q=({formik:t,bucket:n})=>{const{canEditBucket:i}=E(),l=c=>({id:c,name:c,onBlur:t.handleBlur,onChange:t.handleChange,value:t.values[c]??"",error:t.touched[c]?t.errors[c]:null,placeholder:`Enter ${c.replaceAll("-"," ")}`}),m=!!n,o=!m||i(n)?"":"You do not have permission to edit this bucket";return e.jsxs(s.Form,{onSubmit:t.handleSubmit,className:"bucket-create-form",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsx(s.Input,{...l("name"),type:"text",label:"Name",required:!0,autoFocus:!0,disabled:!!o||m,title:o}),e.jsx(s.Select,{id:"bucketKey",label:"Role",onChange:c=>{t.setFieldValue("role",c.target.value)},value:t.values.role,options:[{label:"Admin",value:"admin"},{label:"Read-only",value:"read-only"}]}),e.jsx(ue,{...l("description"),label:"Description",disabled:!!o,title:o}),e.jsx(s.Input,{...l("access-key"),type:"text",label:"Access Key",disabled:!!o,title:o}),e.jsx(s.Input,{...l("secret-key"),type:"text",label:"Secret Key",disabled:!!o,title:o})]})},fe=({bucket:t})=>{const n=v(),{project:i}=C(),l=s.useNotify(),m=s.useToastNotification(),o=L(),c=N.useState(null),p=()=>{n.clear(),l.clear()},a=D(t.name,t.pool,(i==null?void 0:i.name)??""),x=Y().shape({name:z().test(...de(n.project,t,c)).required("Key name is required")}),d=u=>{m.success(e.jsxs(e.Fragment,{children:["Key ",e.jsx(B,{type:"bucket-key",value:u,to:a})," ","created for bucket"," ",e.jsx(B,{type:"bucket",value:t.name,to:a}),"."]})),p()},h=I({initialValues:{name:"",role:"read-only"},validationSchema:x,onSubmit:u=>{const f={name:u.name,role:u.role,description:u.description,"access-key":u["access-key"],"secret-key":u["secret-key"]};X(JSON.stringify(f),n.project,t.pool,t.name).then(()=>{o.invalidateQueries({queryKey:[y.storage,t.pool,n.project,y.buckets,t.name,y.keys]}),d(u.name)}).catch(g=>{h.setSubmitting(!1),l.failure("Key creation failed",g)})}});return e.jsx(e.Fragment,{children:e.jsxs(s.SidePanel,{children:[e.jsx(s.SidePanel.Header,{children:e.jsx(s.SidePanel.HeaderTitle,{children:"Create key"})}),e.jsx(w,{className:"u-no-padding"}),e.jsx(s.SidePanel.Content,{className:"u-no-padding",children:e.jsx(T,{dependencies:[l.notification],belowIds:["panel-footer"],children:e.jsx(q,{formik:h})})}),e.jsxs(s.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(s.Button,{appearance:"base",onClick:p,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",loading:h.isSubmitting,onClick:()=>void h.submitForm(),className:"u-no-margin--bottom",disabled:!h.isValid||h.isSubmitting||!h.values.name,children:"Create key"})]})]})})},je=({bucket:t})=>{const n=v(),{project:i,key:l}=n,m=s.useNotify(),o=s.useToastNotification(),c=L(),p=()=>{n.clear(),m.clear()},{data:a,error:x,isLoading:d}=Z(t,l??"",i),h=g=>{const j=D(g.name,g.pool,i);o.success(e.jsxs(e.Fragment,{children:["Key"," ",e.jsx(B,{type:"bucket-key",value:(a==null?void 0:a.name)??"",to:j})," ","updated for bucket"," ",e.jsx(B,{type:"bucket",value:(g==null?void 0:g.name)??"",to:j}),"."]})),p()},u=I({initialValues:{name:(a==null?void 0:a.name)??"",role:a==null?void 0:a.role,description:a==null?void 0:a.description,"access-key":(a==null?void 0:a["access-key"])??"","secret-key":(a==null?void 0:a["secret-key"])??""},enableReinitialize:!0,onSubmit:g=>{const j={name:g.name,role:g.role,description:g.description,"access-key":g["access-key"],"secret-key":g["secret-key"]};ee(t.name,j,t.pool,i||"").then(()=>{c.invalidateQueries({queryKey:[y.storage,t.pool,i,y.buckets,t.name,y.keys]}),c.invalidateQueries({queryKey:[y.storage,t.pool,i,y.buckets,t.name,y.keys,a==null?void 0:a.name]}),h(t)}).catch(S=>{u.setSubmitting(!1),m.failure("Key update failed",S)})}});if(!i)return e.jsx(e.Fragment,{children:"Missing project"});if(!l)return e.jsx(e.Fragment,{children:"Missing key"});if(x&&m.failure("Loading key failed",x),d)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});if(!a)return e.jsx(e.Fragment,{children:"Loading key failed"});const f=(u.values.description!==a.description?1:0)+(u.values.role!==a.role?1:0)+(u.values["access-key"]!==a["access-key"]?1:0)+(u.values["secret-key"]!==a["secret-key"]?1:0);return e.jsx(e.Fragment,{children:e.jsxs(s.SidePanel,{children:[e.jsx(s.SidePanel.Header,{children:e.jsxs(s.SidePanel.HeaderTitle,{children:["Edit key ",a.name]})}),e.jsx(w,{className:"u-no-padding"}),e.jsx(s.SidePanel.Content,{className:"u-no-padding",children:e.jsx(T,{dependencies:[m.notification],belowIds:["panel-footer"],children:e.jsx(q,{formik:u,bucket:t})})}),e.jsxs(s.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(s.Button,{appearance:"base",onClick:p,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",loading:u.isSubmitting,onClick:()=>void u.submitForm(),className:"u-no-margin--bottom",disabled:!u.isValid||u.isSubmitting||f===0,children:f===0?"Save changes":`Save ${f} ${b("change",f)}`})]})]})})},Ae=()=>{const t=s.useNotify(),{pool:n,project:i,member:l,bucket:m}=_();if(!n)return e.jsx(e.Fragment,{children:"Missing storage pool"});if(!i)return e.jsx(e.Fragment,{children:"Missing project"});if(!m)return e.jsx(e.Fragment,{children:"Missing bucket"});const{data:o,error:c,isLoading:p}=te(m,n,i,l),a=v();return c&&t.failure("Loading storage bucket failed",c),p?e.jsx(s.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0}):o?e.jsxs(e.Fragment,{children:[e.jsx(s.CustomLayout,{header:e.jsx(me,{bucket:o,project:i}),contentClassName:"detail-page u-no-padding--bottom",children:e.jsx(s.Row,{children:e.jsx(xe,{bucket:o})})}),a.panel===K.editStorageBucket&&e.jsx(ae,{bucket:o}),a.panel===K.createStorageBucketKey&&e.jsx(fe,{bucket:o}),a.panel===K.editStorageBucketKey&&e.jsx(je,{bucket:o})]}):e.jsx(e.Fragment,{children:"Loading storage bucket failed"})};export{Ae as default};
Copyright ©2k19 -
Hexid
|
Tex7ure