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/ImageRegistryDetail-DiKObTQC.js

import{O as A,c as E,a1 as K,d as n,r as j,t as L,j as e,s as D,y as P,R as b,w as F,f as H,h as Q,E as Y,k,L as V,T as O,an as G,a0 as J,b8 as z,Q as W,b as X,v as Z,p as B,I as ee,b3 as te}from"./index-BFGypnt-.js";import{T as se}from"./TabLinks-BlmDr2on.js";import{b as ae,a as q}from"./useImageRegistries-BcqfYS33.js";import{d as ne,r as re,u as ie}from"./image-registries-YAuyq4CZ.js";import{R as oe}from"./RenameHeader-yxEpJNaX.js";import{I as $,i as le,a as ce}from"./ImageRegistryRichChip-Fa2NUsp6.js";import{a as R}from"./images-CNjYzWxH.js";import{u as T,p as ue}from"./usePanelParams-CV5ZHNeu.js";import{E as de}from"./ExpandableList-DK5_MQFC.js";import{C as me}from"./CreateInstanceFromImageBtn-D60qjybc.js";import{a as S,g as he,b as ge}from"./architectures-BcTUUUGa.js";import{d as pe,g as fe,e as U,l as xe}from"./images-C6WqBeZG.js";import{u as je}from"./useSortTableData-DMPSUVcX.js";import"./useClusterLinks-CpODgtKY.js";import"./projects-DAlFlfjH.js";const ye=({imageRegistry:s})=>{const l=A(),g=E(),o=K(),i=n.useNotify(),m=n.useToastNotification(),[h,p]=j.useState(!1),f=L(),{canDeleteImageRegistry:r}=R(),d=y=>{m.success(e.jsxs(e.Fragment,{children:["Image registry"," ",e.jsx(P,{bold:!0,type:"image-registry",value:y})," ","deleted."]}))},t=()=>{f.invalidateQueries({queryKey:[F.imageRegistries]})},a=()=>{t();const y=`${b}/ui/image-registry/${encodeURIComponent(s.name)}`;o.pathname.startsWith(y)&&g(`${b}/ui/image-registries`),d(s.name)},c=y=>{t(),p(!1),i.failure(`Deleting image registry ${s.name} failed`,y)},u=()=>{p(!0),ne(s.name).then(a).catch(c)},x=()=>{if(s.builtin)return"Built-in image registries cannot be deleted";if(!r(s))return"You do not have permission to delete this image registry"};return e.jsxs(n.ConfirmationButton,{confirmationModalProps:{title:"Confirm delete",children:e.jsxs("p",{children:["This will permanently delete image registry"," ",e.jsx(P,{type:"image-registry",value:s.name,bold:!0}),"."]}),confirmButtonLabel:"Delete registry",onConfirm:u,message:"Delete image registry"},appearance:"default",className:D("u-no-margin--bottom",{"has-icon":!l}),loading:h,shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!!x()||h,onHoverText:x(),children:[!l&&e.jsx(n.Icon,{name:"delete"}),e.jsx("span",{children:"Delete registry"})]})},be=({imageRegistry:s})=>{const{openEditImageRegistry:l}=T(),{canEditImageRegistry:g}=R(),o=A(),i=()=>{if(s.builtin)return"Built-in image registries cannot be edited";if(!g(s))return"You do not have permission to edit this image registry"},m=i()!==void 0;return e.jsxs(n.Button,{appearance:"default",className:D("u-no-margin--bottom",{"has-icon":!o}),disabled:m,type:"button",hasIcon:!0,title:i()||"Edit registry",onClick:()=>{l(s.name)},children:[!o&&e.jsx(n.Icon,{name:"edit"}),e.jsx("span",{children:"Edit Registry"})]})},Ne=({imageRegistry:s})=>{const l=E(),g=n.useNotify(),o=n.useToastNotification(),{canEditImageRegistry:i}=R(),m=j.useState(null),h=H().shape({name:Q().test("deduplicate","An image registry with this name already exists",async t=>Y(t,"",m,"image-registries")).required("Image registry name is required")}),p=()=>{if(!i(s))return"You do not have permission to rename this image registry";if(!s)return"Invalid Image Registry: Cannot be renamed";if(s.builtin)return"Built-in image registries cannot be renamed"},f=t=>{const a=`${b}/ui/image-registry/${encodeURIComponent(t)}`;l(a),o.success(e.jsxs(e.Fragment,{children:["Image registry ",e.jsx("strong",{children:s.name})," renamed to"," ",e.jsx($,{imageRegistryName:t})]}))},r=(t,a)=>{g.failure(`Renaming of image registry ${t} failed`,a)},d=k({initialValues:{name:s.name,isRenaming:!1},validationSchema:h,onSubmit:t=>{if(s.name===t.name){d.setFieldValue("isRenaming",!1),d.setSubmitting(!1);return}re(s.name,t.name).then(()=>{f(t.name),d.setFieldValue("isRenaming",!1)}).catch(a=>{r(t.name,a)}).finally(()=>{d.setSubmitting(!1)})}});return e.jsx(oe,{name:s.name,parentItems:[e.jsx(V,{to:`${b}/ui/image-registries`,children:"Image registries"},1)],controls:[e.jsx(be,{imageRegistry:s},"edit"),e.jsx(ye,{imageRegistry:s},"delete")],isLoaded:!!s.name,formik:d,renameDisabledReason:p()})},Se=({images:s,supportedArchitectures:l=[],imageRegistryName:g})=>{const{projectName:o,project:i}=O(),m=()=>i?.config.restricted!=="true"?!0:(i?.config["restricted.registries"]?.split(",")??[]).includes(g),h=t=>{if(!l.includes(t.architecture))return"Image is incompatible with your hardware architecture";if(!m())return"Images from this registry are not allowed in this project"},p=[{content:"Name",sortKey:"name"},{content:"Alias",sortKey:"alias",className:"aliases"},{content:"Architecture",sortKey:"architecture",className:"architecture"},{content:"Type",sortKey:"type",className:"type"},{content:"Upload date",sortKey:"uploaded_at",className:"uploaded_at"},{content:"Size",sortKey:"size",className:"u-align--right size"},{"aria-label":"Actions",className:"actions"}],f=s.map(t=>{const a=pe(t),c=fe(t),u=t.aliases&&Array.isArray(t.aliases)?t.aliases.filter(x=>x&&x.name).map(x=>e.jsx("div",{className:"u-truncate",title:x.name,children:x.name},x.name)):[];return{key:t.fingerprint,name:t.fingerprint,columns:[{content:c,role:"rowheader","aria-label":"Name"},{content:u.length>0?e.jsx(de,{items:u,displayCount:2}):null,role:"cell","aria-label":"Aliases",className:"aliases"},{content:S(t.architecture),role:"cell","aria-label":"Architecture",className:"architecture"},{content:U(t),role:"cell","aria-label":"Type",className:"type"},{content:G(t.uploaded_at),role:"cell","aria-label":"Upload date",className:"uploaded_at"},{content:J(t.size),role:"cell","aria-label":"Size",className:"u-align--right size"},{content:e.jsx(me,{projectName:o,image:xe(t),disabledReason:h(t)},"launch"),role:"cell","aria-label":"Actions",className:"u-align--right actions"}],sortData:{name:c.toLowerCase(),alias:a?.toLowerCase(),architecture:t.architecture,cached:t.cached,type:t.type,size:+t.size,uploaded_at:t.uploaded_at}}}),{rows:r,updateSort:d}=je({rows:f});return s.length===0?"No images found":e.jsx(n.ScrollableTable,{dependencies:[s],tableId:"image-table",belowIds:["status-bar"],children:e.jsx(n.TablePagination,{data:r,id:"pagination",itemName:"image",className:"u-no-margin--top","aria-label":"Table pagination control",children:e.jsx(n.MainTable,{id:"image-table",headers:p,sortable:!0,className:"image-registry-image-table",emptyStateMsg:"No images found",onUpdateSort:d,rows:r})})})},I="query",N="arch",v="type",w=[I,N,v],Ie=({images:s,supportedArchitectures:l,isImagesLoading:g})=>{const[o,i]=z(),m=j.useRef(!1),h=j.useMemo(()=>[...new Set((s??[]).map(t=>t.architecture))],[s]),p=j.useMemo(()=>[...new Set((s??[]).map(a=>a.type).filter(a=>!!a))].map(a=>W.find(u=>u.value===a)?.label??a),[s]);j.useEffect(()=>{if(m.current||g||h.length===0)return;const t=new URLSearchParams(window.location.search);if(t.getAll(N).length===0&&t.getAll(I).length===0&&t.getAll(v).length===0){const a=l.filter(c=>h.includes(c));a.length>0&&(m.current=!0,i(c=>(a.forEach(u=>{c.append(N,S(u))}),c),{replace:!0}))}else m.current=!0},[h,l,g,i]);const f=j.useMemo(()=>{const t=[];for(const[a,c]of o.entries())if(w.includes(a)){const u=a==="query"?{quoteValue:!0,value:c}:{lead:a,value:c};t.push(u)}return t},[o]),r=[{id:1,heading:"Architecture",chips:h.map(t=>({lead:N,value:S(t),label:S(t)}))},{id:2,heading:"Type",chips:p.map(t=>({lead:v,value:t}))}],d=t=>{const a=new URLSearchParams(o.toString());w.forEach(c=>{a.delete(c)}),t.forEach(c=>{c.lead&&w.includes(c.lead)?a.append(c.lead,c.value):c.quoteValue&&a.append(I,c.value)}),a.toString()!==o.toString()&&i(a)};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"u-off-screen",children:"Search and filter"}),e.jsx(n.SearchAndFilter,{existingSearchData:f,filterPanelData:r,returnSearchData:d,onExpandChange:()=>{window.dispatchEvent(new CustomEvent("resize",{detail:"search-and-filter"}))},onPanelToggle:()=>{window.dispatchEvent(new CustomEvent("sfp-toggle"))}},o.toString())]})},ve=j.memo(Ie),Ce=({imageRegistry:s})=>{const[l]=z(),g=n.useNotify(),{data:o,isLoading:i,error:m}=ae(s.name),{data:h,error:p}=X(),f=m||p;f&&g.failure("Loading images failed",f);const r=h?.environment?.architectures??[],d=j.useMemo(()=>he(r),[r]),t={queries:l.getAll(I).map(u=>u.toLowerCase()),arch:l.getAll(N),type:l.getAll(v)},a=t.arch.map(ge),c=(o??[]).filter(u=>{if(s.builtin&&(!u.aliases||u.aliases.length===0)||!(t.arch.length===0||a.includes(u.architecture))||!(t.type.length===0||u.type&&t.type.includes(U(u))))return!1;if(t.queries.length>0){const M=(u.properties?.description??"").toLowerCase();if(!t.queries.some(C=>M.includes(C)||u.name?.toLowerCase().includes(C)||(u.aliases?.some(_=>_.name.toLowerCase().includes(C))??!1)))return!1}return!0});return i?e.jsx(n.Row,{children:e.jsx(n.Spinner,{text:"Loading images..."})}):e.jsxs(e.Fragment,{children:[o&&o.length>0&&e.jsx("div",{className:"u-sv3",children:e.jsx(ve,{images:o,supportedArchitectures:d,isImagesLoading:i})}),e.jsx(Se,{images:c,imageRegistryName:s.name,supportedArchitectures:d})]})},we=({imageRegistry:s})=>e.jsxs(e.Fragment,{children:[e.jsxs(n.Row,{className:"section",children:[e.jsx(n.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"General"})}),e.jsx(n.Col,{size:7,children:e.jsx("table",{children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Name"}),e.jsx("td",{children:s.name})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Description"}),e.jsx("td",{children:s.description||"-"})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Protocol"}),e.jsx("td",{children:s.protocol})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Built-in"}),e.jsx("td",{children:s.builtin?"Yes":"No"})]})]})})})]}),e.jsxs(n.Row,{className:"section",children:[e.jsx(n.Col,{size:3,children:e.jsx("h2",{className:"p-heading--5",children:"Configuration"})}),e.jsx(n.Col,{size:7,children:e.jsx("table",{children:e.jsxs("tbody",{children:[e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Server"}),e.jsx("td",{children:s.config?.url||"-"})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Public"}),e.jsx("td",{children:le(s)?"Yes":"No"})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Cluster"}),e.jsx("td",{children:s.config?.cluster?e.jsx(Z,{type:"cluster-link",value:s.config?.cluster||"",to:`${b}/ui/cluster/links`}):"-"})]}),e.jsxs("tr",{children:[e.jsx("th",{className:"u-text--muted",children:"Source project"}),e.jsx("td",{children:s.config?.source_project||"-"})]})]})})})]})]}),Re=()=>{const s=T(),l=n.useNotify(),g=n.useToastNotification(),o=L(),{data:i,error:m,isLoading:h}=q(s.imageRegistry??""),p=()=>{s.clear(),l.clear()},f=()=>{const d=r.values.protocol==="simplestreams",a={public:d||r.values.cluster===""?"true":"false"};return d||(a.cluster=r.values.cluster,a.source_project=r.values.sourceProject),a.url=r.values.url,{description:r.values.description,protocol:r.values.protocol,config:a}},r=k({initialValues:{isCreating:!1,name:i?.name??"",description:i?.description??"",sourceProject:i?.config?.source_project??"",cluster:i?.config?.cluster??"",protocol:i?.protocol??"lxd",url:i?.config?.url??""},enableReinitialize:!0,onSubmit:()=>{ie(i?.name??"",JSON.stringify(f())).then(()=>{g.success(e.jsxs(e.Fragment,{children:["Image registry"," ",e.jsx($,{imageRegistryName:r.values.name??""})," ","updated."]})),o.invalidateQueries({queryKey:[F.imageRegistries]}),p()}).catch(d=>{l.failure("Image registry update failed",d),r.setSubmitting(!1)})}});return h?e.jsx(n.Spinner,{text:"Loading image registry..."}):m||!i?(l.failure("Loading image registry failed",m),null):e.jsx(e.Fragment,{children:e.jsxs(n.SidePanel,{children:[e.jsx(n.SidePanel.Header,{children:e.jsx(n.SidePanel.HeaderTitle,{children:"Edit image registry"})}),e.jsx(B,{className:"u-no-padding"}),e.jsx(n.SidePanel.Content,{className:"u-no-padding",children:e.jsx(n.ScrollableContainer,{dependencies:[l.notification],belowIds:["panel-footer"],children:e.jsx(ce,{formik:r})})}),e.jsxs(n.SidePanel.Footer,{className:"u-align--right",children:[e.jsx(n.Button,{appearance:"base",onClick:p,className:"u-no-margin--bottom",children:"Cancel"}),e.jsx(n.ActionButton,{appearance:"positive",onClick:()=>{r.submitForm()},className:"u-no-margin--bottom",disabled:!r.isValid||r.isSubmitting||!r.values.name,loading:r.isSubmitting,children:"Save"})]})]})})},He=()=>{const{name:s,activeTab:l}=ee(),g=T();if(!s)return e.jsx(e.Fragment,{children:"Missing name"});const{data:o,error:i,isLoading:m}=q(s);if(m)return e.jsx(n.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});if(!o)return e.jsx(te,{entityType:"image-registry",entityName:s,errorMessage:i?.message});const h=["Images","Configuration"];return e.jsxs(e.Fragment,{children:[e.jsxs(n.CustomLayout,{header:e.jsx(Ne,{imageRegistry:o}),contentClassName:"detail-page",children:[e.jsx(B,{}),e.jsxs(n.Row,{children:[e.jsx(se,{tabs:h,activeTab:l,tabUrl:`${b}/ui/image-registry/${encodeURIComponent(s)}`}),!l&&e.jsx("div",{role:"tabpanel","aria-labelledby":"images",children:e.jsx(Ce,{imageRegistry:o})}),l==="configuration"&&e.jsx("div",{role:"tabpanel","aria-labelledby":"configuration",children:e.jsx(we,{imageRegistry:o})})]})]}),g.panel===ue.editImageRegistry&&e.jsx(Re,{})]})};export{He as default};