| Current Path : /proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/ |
| Current File : //proc/thread-self/root/snap/lxd/current/share/lxd-ui/assets/ImageRegistriesList-C0-mmYQS.js |
import{r as w,b8 as I,j as e,d as s,x as T,t as F,f as A,h as $,E,k as B,w as k,p as y,L as K,R as Y}from"./index-BFGypnt-.js";import{u as _}from"./useSortTableData-DMPSUVcX.js";import{u as q}from"./useImageRegistries-BcqfYS33.js";import{H}from"./HelpLink-l4aaXUp-.js";import{P as p}from"./PageHeader-DZVSTM6q.js";import{s as O,p as U}from"./searchAndFilter-DtC_P-vv.js";import{I as M,a as Q,i as S}from"./ImageRegistryRichChip-Fa2NUsp6.js";import{u as P,p as z}from"./usePanelParams-CV5ZHNeu.js";import{c as V}from"./image-registries-YAuyq4CZ.js";import"./useClusterLinks-CpODgtKY.js";import"./images-C6WqBeZG.js";const J="query",v="protocol",R="builtin",L="public",C=[J,v,R,L],X=()=>{const[o,i]=I(),l=[{id:1,heading:"Protocol",chips:["SimpleStreams","LXD"].map(r=>({lead:v,value:r.toLowerCase()}))},{id:2,heading:"Built-in",chips:["Yes","No"].map(r=>({lead:R,value:r}))},{id:3,heading:"Public",chips:["Yes","No"].map(r=>({lead:L,value:r}))}],c=r=>{const u=U(r,o,C);u.toString()!==o.toString()&&i(u)};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"u-off-screen",children:"Search and filter"}),e.jsx(s.SearchAndFilter,{existingSearchData:O(o,C),filterPanelData:l,returnSearchData:c,onExpandChange:()=>{window.dispatchEvent(new CustomEvent("resize",{detail:"search-and-filter"}))},onPanelToggle:()=>{window.dispatchEvent(new CustomEvent("sfp-toggle"))}})]})},Z=w.memo(X),G=()=>{const{canCreateImageRegistries:o}=T(),i=!o(),{openCreateImageRegistry:l}=P();return e.jsxs(s.Button,{name:"Create registry",disabled:i,hasIcon:!0,appearance:"positive",className:"u-float-right u-no-margin--bottom",title:i?"You don't have permissions to create image registries":void 0,onClick:l,children:[e.jsx(s.Icon,{name:"plus",light:!0,className:"u-margin--right"}),e.jsx("span",{children:"Create registry"})]})},W=()=>{const o=P(),i=s.useNotify(),l=s.useToastNotification(),c=F(),r=w.useState(null),u=()=>{o.clear(),i.clear()},b=A().shape({name:$().test("deduplicate","An image registry with this name already exists.",async n=>E(n,"",r,"image-registries")).matches(/^[A-Za-z0-9/\-:_.]+$/,{message:"Name can only contain alphanumeric, forward slash, hyphen, colon, underscore and full stop characters."}).required("Image registry name is required.")}),m=()=>{const n=a.values.protocol==="simplestreams",d={public:n||a.values.cluster===""?"true":"false"};return n||(d.cluster=a.values.cluster,d.source_project=a.values.sourceProject),d.url=a.values.url,{name:a.values.name,description:a.values.description,protocol:a.values.protocol,config:d}},a=B({initialValues:{isCreating:!0,name:"",description:"",sourceProject:"default",cluster:"",protocol:"lxd"},validationSchema:b,onSubmit:()=>{V(JSON.stringify(m())).then(()=>{l.success(e.jsxs(e.Fragment,{children:["Image registry"," ",e.jsx(M,{imageRegistryName:a.values.name??""})," ","created."]})),c.invalidateQueries({queryKey:[k.imageRegistries]}),u()}).catch(n=>{i.failure("Image registry creation failed",n),a.setSubmitting(!1)})}});return e.jsx(e.Fragment,{children:e.jsxs(s.SidePanel,{children:[e.jsx(s.SidePanel.Header,{children:e.jsx(s.SidePanel.HeaderTitle,{children:"Create image registry"})}),e.jsx(y,{className:"u-no-padding"}),e.jsx(s.SidePanel.Content,{className:"u-no-padding",children:e.jsx(s.ScrollableContainer,{dependencies:[i.notification],belowIds:["panel-footer"],children:e.jsx(Q,{formik:a})})}),e.jsxs(s.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(s.Button,{appearance:"base",onClick:u,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(s.ActionButton,{appearance:"positive",onClick:()=>{a.submitForm()},className:"u-no-margin--bottom",disabled:!a.isValid||a.isSubmitting||!a.values.name,loading:a.isSubmitting,children:"Create"})]})]})})},ee=({imageRegistry:o})=>{const i=o.protocol==="simplestreams",l=o.config?.url??"",c=`Project: ${o.config?.source_project??""}`,r=`Cluster: ${o.config?.cluster??""}`,u=i?l:e.jsx(s.List,{inline:!0,middot:!0,className:"image-registry-protocol",items:[r,c]});return e.jsxs(e.Fragment,{children:[o.protocol,u&&e.jsx("div",{className:"u-text--muted u-truncate",title:i?l:`${r} - ${c}`,children:u})]})},de=()=>{const o=s.useNotify(),[i]=I(),l=P(),{data:c=[],error:r,isLoading:u}=q();r&&o.failure("Loading image registries failed",r);const b=[{content:"Name",sortKey:"name",className:"name",title:"Name"},{content:"Description",sortKey:"description",className:"description",title:"Description"},{content:"Protocol",sortKey:"protocol",className:"protocol",title:"Protocol"},{content:"Built-in",sortKey:"builtin",className:"built-in",title:"Built-in"},{content:"Public",sortKey:"public",className:"public",title:"Public"}],m={queries:i.getAll("query").map(t=>t.toLowerCase()),protocol:i.getAll("protocol"),builtin:i.getAll("builtin").map(t=>t.toLowerCase()==="yes"),public:i.getAll("public").map(t=>t.toLowerCase()==="yes")},n=c.filter(t=>{const h=t.description??"",f=t.config?.source_project??"",j=t.config?.cluster??"",x=t?.config?.url??"";return(!m.queries.length||m.queries.some(g=>h.toLowerCase().includes(g)||t.name.toLowerCase().includes(g)||f.includes(g)||j.includes(g)||x.includes(g)))&&(!m.protocol.length||m.protocol.includes(t.protocol))&&(!m.builtin.length||m.builtin.includes(t.builtin))&&(!m.public.length||m.public.includes(S(t)))}).map(t=>{const h=S(t),f=t.protocol==="simplestreams",j=t.config?.url??"",x=t.config?.source_project??"",g=t.config?.cluster??"";return{key:t.name,name:t.name,columns:[{content:e.jsx(K,{to:`${Y}/ui/image-registry/${encodeURIComponent(t.name)}`,className:"u-truncate",children:t.name}),role:"rowheader","aria-label":"Name",title:`Image registry ${t.name}`,className:"name"},{content:e.jsx("div",{className:"u-truncate",title:t.description,children:t.description}),role:"cell","aria-label":"Description",className:"description"},{content:e.jsx(ee,{imageRegistry:t}),role:"cell","aria-label":"Protocol",className:"protocol"},{content:t.builtin?"Yes":"No",role:"cell","aria-label":"Built-in",className:"built-in"},{content:h?"Yes":"No",role:"cell","aria-label":"Public",className:"public"}],sortData:{name:t.name.toLowerCase(),description:t.description.toLowerCase(),protocol:t.protocol.toLowerCase(),builtin:t.builtin,public:h,source:f?j.toLowerCase():`${g}/${x}`.toLowerCase()}}}),{rows:N,updateSort:d}=_({rows:n});if(u)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});const D=()=>n.length===0?"Showing 0 image registries":n.length>1?`Showing all ${n.length} image registries`:"Showing 1 out of 1 image registry";return e.jsxs(e.Fragment,{children:[e.jsxs(s.CustomLayout,{contentClassName:"u-no-padding--bottom",mainClassName:"image-registry-list",header:e.jsxs(p,{children:[e.jsxs(p.Left,{children:[e.jsx(p.Title,{children:e.jsx(H,{docPath:"/image-handling/",title:"Learn more about image registries",children:"Image registries"})}),c.length>0&&e.jsx(p.Search,{children:e.jsx(Z,{})})]}),e.jsx(p.BaseActions,{children:e.jsx(G,{})})]}),children:[!l.panel&&e.jsx(y,{}),e.jsx(s.Row,{children:e.jsx(s.ScrollableTable,{dependencies:[c],tableId:"image-registries-table",belowIds:["status-bar"],children:e.jsx(s.TablePagination,{data:N,id:"pagination",className:"u-no-margin--top",itemName:"registry","aria-label":"Table pagination control",description:D(),children:e.jsx(s.MainTable,{id:"image-registries-table",className:"image-registry-table",defaultSort:"Name",headers:b,rows:n,sortable:!0,emptyStateMsg:"No matching image registries found.",onUpdateSort:d})})})})]}),l.panel===z.createImageRegistry&&e.jsx(W,{})]})};export{de as default};