/
snap
/
lxd
/
current
/
share
/
lxd-ui
/
assets
/
File Upload :
llllll
Current File: //snap/lxd/current/share/lxd-ui/assets/ProxyDeviceForm-DVEGshLd.js
import{j as e,v as $,d as s,bo as oe,bt as Ce,S as Ie,bp as we,am as Re,bu as $e,e as De,l as Fe,r as D,t as Se,G as ie,b as Pe,aG as ce,f as Be,g as fe,bv as Le,i as Ee,q as T,T as Ae,E as Ve,bw as q,bq as X,bx as Oe,O,by as Me,aX as Ue,bz as W,b2 as le,bs as re,R as G,bA as de,bB as Z,bC as _e,bD as Te,m as Ge,A as ue,bE as qe,bF as He,aJ as k,bG as A,bH as ze,br as ee,bI as Ke,bJ as Qe,bK as Ye}from"./index-B3cgCbnJ.js";import{p as R,n as f,k as g,q as L,t as H,u as E,v as Je,w as M,x as he,y as J,z as We,A as Xe}from"./FormMenuItem-BwEOqt61.js";import{S as Ze}from"./StoragePoolSelector-_Ij9bIB_.js";import{D as ke}from"./DiskSizeSelector-CIkNkBL4.js";import{f as V,S as z}from"./FormFooterLayout-ChlQYZN0.js";import{D as et,v as tt,h as te,S as st}from"./StorageVolumeForm-0OnQ0JYw.js";import{u as nt}from"./projects-9DerJg4m.js";import{a as at}from"./useVolumes-BGHjBnNk.js";import{c as ot}from"./storage-volumes-BlpH9Ab1.js";import{B as pe,F as se}from"./FormLink-B3Ky5UhN.js";import{b as ve}from"./useNetworks-DC9cTd9P.js";import{N as it}from"./YamlNotification-C209eie-.js";import{E as ct}from"./ExpandableList-DwC4iUKg.js";import{N as lt}from"./NetworkSelector-DygdY6TH.js";import{C as me}from"./ConfigFieldDescription-C9KDhW5s.js";import{p as rt,a as dt}from"./instanceOptions-D4bz_1Ev.js";const B=({id:t,label:n,inheritValue:r,inheritSource:o,readOnly:a,overrideValue:i,overrideForm:d,addOverride:u,clearOverride:x,isDeactivated:v,className:l,disabledReason:c})=>R({className:$("no-border-top",l),configuration:t?!a&&i?e.jsx(s.Label,{forId:t,className:$({"u-text--muted":v}),children:n}):e.jsx("p",{className:$("p-form__label u-no-margin--bottom u-no-padding--top",{"u-text--muted":v}),children:n}):e.jsx("div",{className:$({"u-text--muted":v}),children:n}),inherited:r&&e.jsxs("div",{className:$({"u-text--muted":i||v,"u-text--line-through":i||v}),children:[e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:r})}),o&&e.jsxs("div",{className:"p-text--small u-text--muted u-no-margin--bottom",children:["From: ",o]})]}),override:a?i?e.jsx("div",{className:"mono-font",children:e.jsx("b",{children:i})}):"":i?e.jsxs("div",{className:"override-form",children:[e.jsx("div",{children:d}),x&&e.jsx("div",{children:e.jsx(s.Button,{onClick:x,type:"button",appearance:"base",title:c??"Clear override",hasIcon:!0,className:"u-no-margin--bottom",disabled:!!c,children:e.jsx(s.Icon,{name:"close",className:"clear-configuration-icon"})})})]}):u&&e.jsx(s.Button,{onClick:u,type:"button",appearance:"base",title:c??"Create override",className:"u-no-margin--bottom",hasIcon:!0,disabled:!!c,children:e.jsx(s.Icon,{name:"edit"})})}),ut=({formik:t,pools:n,profiles:r})=>{var p;const o=t.values.readOnly,a=t.values.devices.findIndex(oe),i=a!==-1,d=t.values.devices[a],u=t.values.entityType==="instance"&&!t.values.isCreating,x=t.values.entityType==="instance"&&t.values.instanceType==="virtual-machine",v=x?"10GiB":"unlimited",l=(p=n.find(h=>h.name===(d==null?void 0:d.pool)))==null?void 0:p.driver,[c,m]=Ce(t.values,r),b=()=>{var N;const h=[...t.values.devices];h.push({type:"disk",name:c!=null&&c.name?c.name:"root",path:"/",pool:c?c.pool:((N=n[0])==null?void 0:N.name)??void 0}),t.setFieldValue("devices",h)};return e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"p-heading--4",children:"Root storage"}),e.jsx(f,{rows:[R({className:"override-with-form",configuration:e.jsx("b",{className:"device-name",children:"Root storage"}),inherited:"",override:i?e.jsx("div",{children:e.jsx(s.Button,{onClick:()=>{g(t),L(a,t)},type:"button",appearance:"base",title:t.values.editRestriction??"Clear override",hasIcon:!0,className:"u-no-margin--bottom",disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"close",className:"clear-configuration-icon"})})}):e.jsx(s.Button,{onClick:()=>{g(t),b()},type:"button",appearance:"base",title:t.values.editRestriction??"Create override",className:"u-no-margin--bottom",hasIcon:!0,disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"edit"})})}),B({label:"Pool",id:"storage-pool-selector-disk",className:"override-with-form",inheritValue:(c==null?void 0:c.pool)??"",inheritSource:m,readOnly:o,disabledReason:t.values.editRestriction,overrideValue:i&&e.jsxs(e.Fragment,{children:[d==null?void 0:d.pool,t.values.entityType==="profile"&&e.jsx(s.Button,{onClick:()=>{g(t),V("storage-pool-selector")},type:"button",appearance:"base",title:t.values.editRestriction??"Edit",className:"u-no-margin--bottom",hasIcon:!0,disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"edit"})})]}),overrideForm:e.jsx(e.Fragment,{children:e.jsx(Ze,{value:(d==null?void 0:d.pool)??"",setValue:h=>void t.setFieldValue(`devices.${a}.pool`,h),selectProps:{id:"storage-pool-selector-disk",className:u?"":"u-no-margin--bottom",disabled:u,help:u?"Use the migrate button in the header to change root storage.":""}})})}),B({label:"Size",id:"limits_disk",className:"override-with-form",inheritValue:(c==null?void 0:c.size)??(c?v:""),inheritSource:m,readOnly:o,disabledReason:t.values.editRestriction,overrideValue:i&&e.jsxs(e.Fragment,{children:[(d==null?void 0:d.size)??"unlimited",e.jsx(s.Button,{onClick:()=>{g(t),V("limits_disk")},type:"button",appearance:"base",title:t.values.editRestriction??"Edit",className:"u-no-margin--bottom",hasIcon:!0,disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"edit"})})]}),overrideForm:i&&e.jsxs(e.Fragment,{children:[e.jsx(ke,{value:(d==null?void 0:d.size)??"GiB",setMemoryLimit:h=>void t.setFieldValue(`devices.${a}.size`,h)}),e.jsxs("p",{className:"p-form-help-text",children:[e.jsx(et,{driver:l}),"Size of root storage. If empty, root storage will"," ",x?"be 10GiB.":"not have a size limit."]})]})})]}),Ie(t.values,r)&&e.jsx("div",{className:"is-error ",children:e.jsxs("p",{className:"p-form-validation__message",children:[e.jsx("strong",{children:"Error:"})," Missing root storage. Create an override, or add a profile with root storage."]})})]})},xe=({onDetach:t,disabledReason:n})=>e.jsxs(s.ConfirmationButton,{appearance:"base",type:"button",title:n??"Detach disk",className:"has-icon u-no-margin--bottom is-dense",confirmationModalProps:{title:"Confirm disk detachment",children:e.jsxs("p",{children:["Are you sure you want to clear this disk attachment?",e.jsx("br",{}),"This action may result in data loss if the disk is still mounted."]}),confirmButtonLabel:"Detach",onConfirm:t},shiftClickEnabled:!0,showShiftClickHint:!0,disabled:!!n,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]}),ht=({formik:t,inheritedDiskDevices:n})=>{const r=t.values.readOnly,o=[];return n.forEach(a=>{const i=H(a.key,t),d=i!==-1;o.push(R({className:"no-border-top override-with-form",configuration:e.jsx("div",{className:$("device-name",{"u-text--muted":d}),children:e.jsx("b",{children:a.key})}),inherited:e.jsxs("div",{className:"p-text--small u-text--muted u-no-margin--bottom",children:["From: ",a.source]}),override:d?e.jsxs(s.Button,{appearance:"base",type:"button",title:t.values.editRestriction??"Reattach device",onClick:()=>{g(t),L(i,t)},className:"has-icon u-no-margin--bottom",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}):e.jsx(xe,{onDetach:()=>{g(t),E(a.key,t)},disabledReason:t.values.editRestriction})})),we(a.disk)?o.push(B({label:"Host path",inheritValue:a.disk.source,readOnly:r,isDeactivated:d,disabledReason:t.values.editRestriction})):o.push(B({label:"Pool / volume",inheritValue:e.jsxs(e.Fragment,{children:[a.disk.pool," / ",a.disk.source]}),readOnly:r,isDeactivated:d,disabledReason:t.values.editRestriction})),o.push(B({label:"Mount point",inheritValue:a.disk.path,readOnly:r,isDeactivated:d,disabledReason:t.values.editRestriction}))}),n.length>0?e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited disk devices"}),e.jsx(f,{rows:o})]}):null},pt=({project:t,primaryVolume:n,instanceLocation:r,onFinish:o,onCancel:a,onCreate:i,hasPrevStep:d})=>{const u=s.useNotify(),{canCreateStorageVolumes:x}=nt(),{data:v}=Re(t),{data:l=[],error:c,isLoading:m,isFetching:b}=at(t,{refetchOnMount:j=>j.state.isInvalidated});c&&u.failure("Loading storage volumes failed",c);const p=j=>{u.clear(),o(j)},h=[{content:"Name"},{content:"Pool"},...r?[{content:"Location"}]:[],{content:"Content type"},{content:"Used by"},{"aria-label":"Actions",className:"actions"}],N=b?[]:l.sort((j,y)=>j.created_at>y.created_at?-1:1).map(j=>{var F;const y=!!j.location,C=r!==void 0&&y&&r!==j.location,I=C?`Instance location (${r}) does not match local volume location (${j.location}). `:void 0,w=()=>{I||p(j)};return{key:j.name,className:$("u-row",{"u-text--muted":C,"u-row--disabled":C}),columns:[{content:e.jsx("div",{className:"u-truncate iso-name",title:`Volume ${j.name}`,children:j.name}),role:"rowheader","aria-label":"Name",onClick:w},{content:j.pool,role:"cell","aria-label":"Storage pool",onClick:w},...r?[{content:j.location,role:"cell","aria-label":"Location",onClick:w}]:[],{content:$e(j),role:"cell","aria-label":"Content type",onClick:w},{content:(F=j.used_by)==null?void 0:F.length,role:"cell","aria-label":"Used by",onClick:w},{content:e.jsx(s.Button,{onClick:()=>{p(j)},dense:!0,appearance:(n==null?void 0:n.name)===j.name&&(n==null?void 0:n.type)===j.type&&(n==null?void 0:n.pool)==j.pool?"positive":"",title:C?I:`Select ${j.name}`,disabled:C,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right",onClick:w}]}});return e.jsxs(e.Fragment,{children:[e.jsx(De,{}),e.jsx(s.ScrollableTable,{dependencies:[l,N,u.notification],belowIds:["modal-footer"],tableId:"volume-select-table",children:e.jsx(s.MainTable,{id:"volume-select-table",headers:h,rows:N,sortable:!0,className:"u-selectable-table-rows u-table-layout--auto",emptyStateMsg:m||b?e.jsx(s.Spinner,{className:"u-loader",text:"Loading volumes..."}):"No custom volumes found"})}),!m&&e.jsxs("footer",{className:"p-modal__footer",id:"modal-footer",children:[e.jsx(s.Button,{className:"u-no-margin--bottom",onClick:a,appearance:"base",children:d?"Back":"Cancel"}),e.jsx(s.Button,{className:"u-no-margin--bottom",appearance:l.length===0?"positive":"",onClick:i,disabled:!x(v),title:x(v)?"":"You do not have permission to create storage volumes in this project",children:"Create volume"})]})]})},vt=({project:t,instanceLocation:n,onCancel:r,onFinish:o})=>{var C;const a=s.useNotify(),i=Fe(),d=D.useState(null),u=Se(),{hasStorageAndProfileOperations:x}=ie(),{data:v}=Pe(),{data:l=[]}=ce(),c=Be().shape({name:fe().test(...Le(t,"custom",d)).required("This field is required")}),m=I=>{i.invalidateQueries({queryKey:[T.storage]}),i.invalidateQueries({queryKey:[T.customVolumes,t]}),a.success(`Storage volume ${I.name} created.`),o(I)},b=I=>{a.failure("Storage volume creation failed",I)},p=()=>{h.setSubmitting(!1)},h=Ee({initialValues:{content_type:"filesystem",name:"",project:t,pool:"",size:"GiB",volumeType:"custom",readOnly:!1,isCreating:!0,entityType:"storageVolume"},validationSchema:c,onSubmit:I=>{const w=tt(I,t),F=te(I.pool,l,v)?n:void 0;ot(I.pool,t,w,F).then(S=>{x?u.set(S.metadata.id,()=>{m(w)},Q=>{b(new Error(Q))},p):(m(w),p())}).catch(b)}}),N=!te(h.values.pool,l,v)||n!=="any",j=N?void 0:"Please select a remote storage pool, or set a cluster member for the instance",y=()=>{Ae("volume-create-form","p-modal__footer",32,void 0,[])};return D.useEffect(y,[(C=a.notification)==null?void 0:C.message]),s.useListener(window,y,"resize",!0),e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"volume-create-form",children:e.jsx(st,{formik:h,poolError:j})}),e.jsxs("footer",{className:"p-modal__footer",children:[e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",onClick:r,children:"Back"}),e.jsx(s.ActionButton,{appearance:"positive",className:"u-no-margin--bottom",onClick:()=>void h.submitForm(),disabled:!h.isValid||h.isSubmitting||!N,loading:h.isSubmitting,children:"Create volume"})]})]})},mt=t=>!Ve()||t.values.entityType!=="instance"?void 0:t.values.isCreating?t.values.target??"any":t.values.location,_="selectVolume",Y="createVolume",be=({formik:t,project:n,onFinish:r,onCancel:o,onClose:a,title:i})=>{const[d,u]=D.useState(_),[x,v]=D.useState(void 0),l=mt(t),c=p=>{u(_),v(p)},m=()=>{u(_)};let b=i??"Choose custom volume";return d===Y&&(b=i?e.jsx(pe,{title:"Create volume",onClick:m,linkText:"Attach custom volume"}):"Create volume"),e.jsxs(s.Modal,{className:"custom-volume-modal",close:a,title:b,children:[d===_&&e.jsx(pt,{project:n,primaryVolume:x,instanceLocation:l,onFinish:r,onCancel:o,onCreate:()=>{u(Y)},hasPrevStep:!!i}),d===Y&&e.jsx(vt,{project:n,instanceLocation:l,onCancel:m,onFinish:c})]})},xt=({formik:t,children:n,buttonProps:r,project:o,setValue:a})=>{const{openPortal:i,closePortal:d,isOpen:u,Portal:x}=s.usePortal(),v=l=>{a(l),d()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{onClick:i,type:"button",hasIcon:!0,...r,children:n}),u&&e.jsx(x,{children:e.jsx(be,{formik:t,project:o,onFinish:v,onCancel:d,onClose:d})})]})},K=({name:t,index:n,setName:r,disableReason:o})=>{const[a,i]=D.useState(!1);return e.jsx("div",{className:"rename-device device-name",children:a?e.jsx(s.Input,{autoFocus:!0,className:"u-no-margin--bottom",type:"text",value:t,onChange:d=>{r(d.target.value)},onBlur:()=>{i(!1)}}):e.jsxs(e.Fragment,{children:[e.jsx(s.Label,{forId:`device-${n}-name`,children:e.jsx("b",{children:t})}),e.jsx(s.Button,{id:`device-${n}-name`,hasIcon:!0,dense:!0,onClick:()=>{i(!0)},appearance:"base",className:"u-no-margin--bottom","aria-label":"Rename device",disabled:!!o,title:o,children:e.jsx(s.Icon,{name:"edit"})})]})})},bt=({formik:t,onFinish:n,onCancel:r,onClose:o,title:a})=>{const[i,d]=D.useState(""),[u,x]=D.useState(""),v=D.useRef({source:!1,path:!1});D.useEffect(()=>{V("host-path")},[]);const l=()=>{n({type:"disk",source:i,path:u})};return e.jsxs(s.Modal,{className:"host-path-device-modal",close:o,title:a,buttonRow:e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",type:"button",onClick:r,children:"Back"}),e.jsx(s.Button,{appearance:"",className:"u-no-margin--bottom",type:"button",loading:t.isSubmitting,disabled:!i||!u||t.isSubmitting,onClick:l,children:"Attach"})]}),children:[e.jsx(s.Input,{id:"host-path",value:i,onChange:c=>{v.current.source=!0,d(c.target.value)},type:"text",label:"Host path",required:!0,error:!i&&v.current.source?"Host path is required":void 0,placeholder:"Enter full path (e.g. /home)"}),e.jsx(s.Input,{value:u,onChange:c=>{v.current.path=!0,x(c.target.value)},type:"text",label:"Mount point",required:!0,error:!u&&v.current.path?"Mount point is required":void 0,placeholder:"Enter full path (e.g. /data)"})]})},gt=({close:t,formik:n,project:r,onFinish:o})=>{const[a,i]=D.useState("choose type"),d=l=>{l.key==="Escape"&&t()},u=()=>{i("choose type")},x=l=>{const c={type:"disk",pool:l.pool,source:l.name,path:l.content_type==="filesystem"?"":void 0};o(c)},v=a==="choose type"?"Choose disk type":e.jsx(pe,{title:a==="host path"?"Mount host path":"Attach custom volume",onClick:u,linkText:"Choose disk type"});return e.jsxs(e.Fragment,{children:[a==="choose type"&&e.jsx(s.Modal,{close:t,className:"migrate-instance-modal",title:v,onKeyDown:d,children:e.jsxs("div",{className:"choose-migration-type",children:[e.jsx(se,{icon:"add-logical-volume",title:"Attach custom volume",onClick:()=>{i("custom volume")}}),e.jsx(se,{icon:"mount",title:"Mount host path",onClick:()=>{i("host path")}})]})}),a==="custom volume"&&e.jsx(be,{formik:n,project:r,onFinish:x,onCancel:u,onClose:t,title:v}),a==="host path"&&e.jsx(bt,{formik:n,onFinish:o,onCancel:u,onClose:t,title:v})]})},jt=({formik:t,children:n,buttonProps:r,project:o,setValue:a})=>{const{openPortal:i,closePortal:d,isOpen:u,Portal:x}=s.usePortal(),v=l=>{a(l),d()};return e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{onClick:i,type:"button",hasIcon:!0,...r,disabled:!!t.values.editRestriction,title:t.values.editRestriction,children:n}),u&&e.jsx(x,{children:e.jsx(gt,{formik:t,project:o,onFinish:v,close:d})})]})},Nt=({formik:t,project:n,profiles:r})=>{const o=t.values.readOnly,a=q(t.values,r),i=l=>{const c=[...t.values.devices],m={...l,name:M("disk-device",1,a)};c.push(m),t.setFieldValue("devices",c);const b=`devices.${c.length-1}.path`;V(b)},d=(l,c,m)=>{t.setFieldValue(`devices.${m}.pool`,l.pool),t.setFieldValue(`devices.${m}.source`,l.name),l.content_type==="filesystem"&&c.path===void 0&&t.setFieldValue(`devices.${m}.path`,""),l.content_type==="block"&&t.setFieldValue(`devices.${m}.path`,void 0)},u=l=>e.jsx(s.Button,{appearance:"base",className:"u-no-margin--bottom",hasIcon:!0,dense:!0,title:t.values.editRestriction??"Edit",onClick:()=>{g(t),V(l)},disabled:!!t.values.editRestriction,children:e.jsx(s.Icon,{name:"edit"})}),x=[];let v=0;for(let l=0;l<t.values.devices.length;l++){const c=t.values.devices[l];if(!Je(c)||oe(c))continue;x.push(R({className:"no-border-top custom-device-name",configuration:e.jsx(K,{name:c.name,index:l,setName:p=>{g(t),t.setFieldValue(`devices.${l}.name`,p)},disableReason:t.values.editRestriction}),inherited:"",override:e.jsx(xe,{onDetach:()=>{g(t),L(l,t)},disabledReason:t.values.editRestriction})}));const m=()=>R({className:"no-border-top inherited-with-form",configuration:e.jsx(s.Label,{forId:`devices.${l}.pool`,children:"Pool / volume"}),inherited:e.jsxs("div",{className:"custom-disk-volume-source",children:[e.jsx("div",{className:$("mono-font","u-truncate"),title:`${c.pool} / ${c.source??""}`,children:e.jsxs("b",{children:[c.pool," / ",c.source]})}),e.jsx(xt,{formik:t,project:n,setValue:p=>{g(t),d(p,c,l)},buttonProps:{id:`devices.${l}.pool`,appearance:"base",className:"u-no-margin--bottom",title:t.values.editRestriction??"Select storage volume",dense:!0,disabled:!!t.values.editRestriction},children:e.jsx(s.Icon,{name:"edit"})})]}),override:""}),b=()=>R({className:"no-border-top inherited-with-form",configuration:e.jsx(s.Label,{forId:`devices.${l}.source`,children:"Host path"}),inherited:o?e.jsxs("div",{className:"custom-disk-read-mode",children:[e.jsx("div",{className:"mono-font custom-disk-value u-truncate",children:e.jsx("b",{children:c.source})}),u(`devices.${l}.source`)]}):e.jsx(s.Input,{id:`devices.${l}.source`,name:`devices.${l}.source`,onBlur:t.handleBlur,onChange:p=>{t.setFieldValue(`devices.${l}.source`,p.target.value)},value:c.source,type:"text",placeholder:"Enter full host path (e.g. /data)",className:c.source?"u-no-margin--bottom":void 0,error:c.source?void 0:"Host path is required"}),override:""});if(x.push(X(c)?m():b()),!X(c)||c.path!==void 0){const p=Oe(t,l);x.push(R({className:"no-border-top inherited-with-form",configuration:e.jsx(s.Label,{forId:`devices.${l}.path`,required:!0,children:"Mount point"}),inherited:o?e.jsxs("div",{className:"custom-disk-read-mode",children:[e.jsx("div",{className:"mono-font custom-disk-value",children:e.jsx("b",{children:c.path})}),u(`devices.${l}.path`)]}):e.jsx(s.Input,{id:`devices.${l}.path`,name:`devices.${l}.path`,onBlur:t.handleBlur,onChange:h=>{t.setFieldValue(`devices.${l}.path`,h.target.value)},value:c.path,type:"text",placeholder:"Enter full path (e.g. /data)",className:p?void 0:"u-no-margin--bottom",error:p?"Path is required":void 0}),override:""}))}v++}return e.jsxs("div",{className:"custom-devices",children:[v>0&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom disk devices"}),e.jsx(f,{rows:x})]}),e.jsxs(jt,{formik:t,project:n,setValue:l=>{g(t),i(l)},children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Attach disk device"})]})]})},Ht=({formik:t,project:n})=>{const r=s.useNotify(),{data:o=[],isLoading:a,error:i}=O(n);i&&r.failure("Loading profiles failed",i);const{data:d=[],isLoading:u,error:x}=ce();if(x&&r.failure("Loading storage pools failed",x),a||u)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."});const v=Me(t.values,o);return e.jsx("div",{className:$("disk-device-form","device-form",{"disk-device-form--edit":!t.values.readOnly}),children:e.jsxs(z,{children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsx(ut,{formik:t,pools:d,profiles:o}),e.jsx(ht,{formik:t,inheritedDiskDevices:v}),e.jsx(Nt,{formik:t,project:n,profiles:o})]})})},yt=({readOnly:t,formik:n,index:r,device:o,inheritedDevice:a})=>{const i=a&&!o,d=a&&o&&Ue(o),u=a&&o&&W(o),x=!a&&o,v=!!n.values.editRestriction,c=n.values.editRestriction?n.values.editRestriction:i||u?"Create override":d?"Edit override":"Edit network",m=()=>{var N;if(g(n),i||u){const j=n.values.devices.length;he({formik:n,deviceName:a.key,deviceNetworkName:((N=a.network)==null?void 0:N.network)??""}),J(j)}else J(r)},b=()=>{g(n),We({formik:n,deviceName:(o==null?void 0:o.name)||""})},p=()=>{g(n),E((a==null?void 0:a.key)||"",n)},h=()=>{g(n),E((o==null?void 0:o.name)||"",n)};return e.jsxs("div",{className:"network-device-actions",children:[(t||i)&&e.jsxs(s.Button,{onClick:m,type:"button",appearance:"base",title:c,className:"u-no-margin--top",hasIcon:!0,dense:!0,disabled:v,children:[e.jsx(s.Icon,{name:"edit"}),e.jsx("span",{children:"Edit"})]}),i&&e.jsxs(s.Button,{className:"u-no-margin--top",onClick:p,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:n.values.editRestriction||"Detach network",disabled:v,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]}),d&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Button,{className:"u-no-margin--top",onClick:b,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:n.values.editRestriction||"Clear override",disabled:v,children:[e.jsx(s.Icon,{name:"close"}),e.jsx("span",{children:"Clear"})]}),e.jsxs(s.Button,{className:"u-no-margin--top",onClick:p,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:n.values.editRestriction||"Detach network",disabled:v,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})]}),u&&e.jsxs(s.Button,{className:"u-no-margin--top",onClick:b,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:n.values.editRestriction||"Reattach inherited network",disabled:v,children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}),x&&e.jsxs(s.Button,{className:"u-no-margin--top",onClick:h,type:"button",appearance:"base",hasIcon:!0,dense:!0,title:n.values.editRestriction||"Detach network",disabled:v,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})]})},ge=({project:t,network:n,device:r,isOverridden:o})=>{const a=le(n),i=re(r),d=Array.from(new Set(a.concat(i)));return d.length?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:$("acl-label",{"u-text--muted":o,"u-text--line-through":o}),children:"ACLs"}),e.jsx(ct,{items:d.map(u=>e.jsx(G,{type:"network-acl",value:u,to:`/ui/project/${encodeURIComponent(t||"default")}/network-acl/${encodeURIComponent(u)}`,className:$("acl-chip",{"u-text--line-through":o})},u))})]}):null},ne=({project:t,network:n,device:r,readOnly:o,formik:a,canSelectManualAcls:i})=>{if(o)return e.jsx(ge,{project:t,network:n,device:r});const d=D.useId(),u=le(n),x=re(r),v=Array.from(new Set(u.concat(x))),l=()=>{if(!i)return"Network must be of type OVN to customize ACLs.";if(u.length!==0)return"Some ACLs are inherited from the network. They cannot be deselected here."};return e.jsxs(e.Fragment,{children:[e.jsx("label",{className:i?"":"u-text--muted",htmlFor:d,children:"ACLs"}),a&&e.jsx(it,{project:t,selectedAcls:v,setSelectedAcls:c=>{a.setFieldValue(`devices.${de(r.name||"",a)}["security.acls"]`,c.join(","))},id:d,inheritedAcls:u,canSelectManualAcls:i,help:l()})]})},Ct=({readOnly:t,project:n,formik:r,device:o,index:a,managedNetworks:i,network:d})=>W(o)?e.jsx("span",{className:"u-text--muted",children:e.jsx("i",{children:"detached"})}):t?e.jsxs(e.Fragment,{children:[e.jsx("div",{children:"Network"}),e.jsx(G,{type:"network",value:o.network,to:`/ui/project/${encodeURIComponent(n??"")}/network/${encodeURIComponent(o.network)}`}),e.jsx(ne,{project:n,network:d,device:o,readOnly:!0})]}):e.jsxs(e.Fragment,{children:[e.jsx(lt,{value:o.network,setValue:u=>{r.setFieldValue(`devices.${a}.network`,u);const x=i.find(v=>v.name===u);x&&!Z(x)&&r.setFieldValue(`devices.${a}["security.acls"]`,void 0)},id:`devices.${a}.network`,name:`devices.${a}.network`,managedNetworks:i}),e.jsx(ne,{project:n,network:d,device:o,readOnly:t,formik:r,canSelectManualAcls:Z(d)})]}),je=({project:t,formik:n,device:r,network:o,inheritedDevice:a})=>{const i=n.values.readOnly,{data:d=[]}=ve(t),u=d.filter(v=>v.managed),x=de((r==null?void 0:r.name)||"",n);return e.jsxs("div",{className:"network-device",children:[e.jsx("div",{className:"network-device-content",children:r&&e.jsx(Ct,{readOnly:i,project:t,device:r,formik:n,index:x,managedNetworks:u,network:o})}),e.jsx(yt,{readOnly:i,formik:n,index:x,device:r,inheritedDevice:a})]},x)},It=({device:t,project:n,managedNetworks:r,formik:o})=>{var x,v;const a=o.values.devices.find(l=>l.name===t.key),i=a!==void 0,d=a&&W(a),u=r.find(l=>l.name===(a==null?void 0:a.network));return R({configuration:e.jsx("b",{className:$({"u-text--muted":d,"u-text--line-through":d}),children:t.key}),inherited:e.jsxs("div",{children:[e.jsxs("div",{className:$("p-text--small","u-text--muted",{"u-text--line-through":i}),children:["From profile"," ",e.jsx(G,{type:"profile",value:t.sourceProfile,to:`/ui/project/${encodeURIComponent(n)}/profile/${encodeURIComponent(t.sourceProfile)}`,className:$({"u-text--line-through":i})})]}),e.jsx("div",{className:$({"u-text--muted":i,"u-text--line-through":i}),children:"Network"}),e.jsx(G,{type:"network",value:((x=t.network)==null?void 0:x.network)||"",to:`/ui/project/${encodeURIComponent(n??"")}/network/${encodeURIComponent(((v=t.network)==null?void 0:v.network)||"")}`,className:$({"u-text--line-through":i})}),e.jsx(ge,{project:n,network:r.find(l=>{var c;return l.name===((c=t.network)==null?void 0:c.network)}),device:t.network,isOverridden:i})]}),override:e.jsx(je,{formik:o,project:n,device:a,network:u,inheritedDevice:t})})},zt=({formik:t,project:n})=>{const r=s.useNotify(),{data:o=[],isLoading:a,error:i}=O(n);i&&r.failure("Loading profiles failed",i);const{data:d=[],isLoading:u,error:x}=ve(n);if(D.useEffect(()=>{x&&r.failure("Loading networks failed",x)},[x]),a||u)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."});const v=d.filter(p=>p.managed),l=q(t.values,o),c=()=>{var h;g(t);const p=he({formik:t,deviceName:M("eth",1,l),deviceNetworkName:((h=v[0])==null?void 0:h.name)??""});J(p-1)},m=_e(t.values,o),b=t.values.readOnly;return e.jsx(Xe,{className:"device-form",rows:[...m.map(p=>It({device:p,project:n,managedNetworks:v,formik:t})),...t.values.devices.map((p,h)=>{var j;if(!((j=p.type)!=null&&j.includes("nic"))||m.map(y=>y.key).includes(p.name))return{};const N=t.values.devices[h];return R({name:`devices.${h}.name`,edit:b?"read":"edit",configuration:e.jsx(e.Fragment,{children:b||N.type==="custom-nic"?N.name:e.jsx(s.Input,{label:"Device name",required:!0,name:`devices.${h}.name`,id:`devices.${h}.name`,onBlur:t.handleBlur,onChange:t.handleChange,value:t.values.devices[h].name,type:"text",placeholder:"Enter name",error:Te(t,h)?"Device name is required":void 0})}),inherited:"",override:N.type==="custom-nic"?e.jsxs(e.Fragment,{children:["custom network"," ",e.jsx(s.Tooltip,{message:"A custom network can be viewed and edited only from the YAML configuration",children:e.jsx(s.Icon,{name:"information"})})," "]}):e.jsx(je,{formik:t,project:n,device:N,network:v.find(y=>y.name===t.values.devices[h].network)})})}),R({configuration:"",inherited:"",override:e.jsxs(s.Button,{onClick:c,type:"button",hasIcon:!0,disabled:!!t.values.editRestriction,title:t.values.editRestriction,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Attach network"})]})})].filter(p=>Object.values(p).length>0),emptyStateMsg:"No networks defined"})},wt=({onSelect:t,onClose:n})=>{var x,v;const{canViewResources:r}=Ge(),{data:o,isLoading:a}=ue({queryKey:[T.resources],queryFn:async()=>qe(),enabled:r()}),i=[{content:"Vendor"},{content:"Driver"},{content:"PCI address"},{content:"ID"},{"aria-label":"Actions",className:"actions"}],d=a?[]:(v=(x=o==null?void 0:o.gpu)==null?void 0:x.cards)==null?void 0:v.map(l=>{var m;const c=()=>{t(l)};return{key:l.pci_address,className:"u-row",columns:[{content:l.vendor,role:"rowheader","aria-label":"Vendor",onClick:c},{content:e.jsxs(e.Fragment,{children:[l.driver," ",e.jsx("span",{className:"u-text--muted",children:l.driver_version})]}),role:"cell","aria-label":"Driver",onClick:c},{content:l.pci_address,role:"cell","aria-label":"PCI Address",onClick:c},{content:((m=l.drm)==null?void 0:m.id)??"-",role:"cell","aria-label":"ID",onClick:c},{content:e.jsx(s.Button,{onClick:c,dense:!0,"aria-label":`Select ${l.pci_address}`,children:"Select"}),role:"cell","aria-label":"Actions",className:"u-align--right",onClick:c}]}}),u=()=>r()?e.jsx(s.ScrollableTable,{dependencies:[o,d],belowIds:["modal-footer"],tableId:"gpu-select-table",children:e.jsx(s.MainTable,{id:"gpu-select-table",headers:i,rows:d,sortable:!0,className:"u-selectable-table-rows u-table-layout--auto",emptyStateMsg:a?e.jsx(s.Spinner,{className:"u-loader",text:"Loading GPUs..."}):"No GPUs found"})}):e.jsx(s.Notification,{severity:"caution",title:"Restricted permissions",children:"You do not have permission to view available GPUs on the server."});return e.jsxs(s.Modal,{close:n,title:"Select GPU",children:[u(),e.jsx("footer",{className:"p-modal__footer",id:"modal-footer",children:e.jsx(s.Button,{className:"u-no-margin--bottom",onClick:()=>{t({pci_address:""})},children:"Enter details manually"})})]})},Rt=({onSelect:t,disabledReason:n})=>{const{openPortal:r,closePortal:o,isOpen:a,Portal:i}=s.usePortal(),d=u=>{o(),t(u)};return e.jsxs(e.Fragment,{children:[e.jsxs(s.Button,{onClick:r,type:"button",hasIcon:!0,disabled:!!n,title:n,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Attach GPU"})]}),a&&e.jsx(i,{children:e.jsx(wt,{onClose:o,onSelect:d})})]})},$t=({device:t,onChange:n,disableReason:r})=>{const[o,a]=D.useState(t.pci?"pci":"id"),i=o==="pci",d=`device.${t.name}.${i?"pci":"id"}`;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"u-sv1",children:[e.jsx(s.RadioInput,{inline:!0,labelClassName:"margin-right",label:"ID",checked:!i,onClick:()=>{a("id")},disabled:!!r}),e.jsx(s.RadioInput,{inline:!0,label:"PCI",checked:i,onClick:()=>{a("pci")},disabled:!!r})]}),e.jsx(s.Input,{type:"text",label:i?"PCI Address":"ID",value:i?t.pci:t.id,onChange:u=>n==null?void 0:n(i?u.target.value:void 0,i?void 0:u.target.value),disabled:!!r},d)]})},Kt=({formik:t,project:n})=>{const r=s.useNotify(),{data:o=[],isLoading:a,error:i}=O(n);i&&r.failure("Loading profiles failed",i);const d=He(t.values,o),u=q(t.values,o),x=m=>{var h;const b=(h=m.drm)!=null&&h.id?m.drm.id.toString():void 0,p=[...t.values.devices];p.push({type:"gpu",gputype:"physical",pci:m.pci_address,id:m.pci_address===void 0?b:void 0,name:M("gpu",1,u)}),t.setFieldValue("devices",p)},v=t.values.devices.some(m=>m.type==="gpu"),l=[];d.forEach(m=>{const b=H(m.key,t),p=b!==-1;l.push(R({className:"no-border-top override-with-form",configuration:e.jsx("div",{className:$("device-name",{"u-text--muted":p}),children:e.jsx("b",{children:m.key})}),inherited:e.jsxs("div",{className:"p-text--small u-text--muted u-no-margin--bottom",children:["From: ",m.source]}),override:p?e.jsxs(s.Button,{appearance:"base",type:"button",title:"Reattach GPU",onClick:()=>{g(t),L(b,t)},className:"has-icon u-no-margin--bottom",children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}):e.jsxs(s.Button,{appearance:"base",type:"button",onClick:()=>{g(t),E(m.key,t)},className:"has-icon u-no-margin--bottom",dense:!0,title:t.values.editRestriction??"Detach GPU",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),Object.keys(m.gpu).forEach(h=>{h==="name"||h==="type"||l.push(B({label:A(h),inheritValue:m.gpu[h],readOnly:!1,isDeactivated:p}))})});const c=[];return t.values.devices.forEach((m,b)=>{if(m.type!=="gpu")return;const p=t.values.devices[b];c.push(R({className:"no-border-top custom-device-name",configuration:e.jsx(K,{name:p.name,index:b,setName:h=>{g(t),t.setFieldValue(`devices.${b}.name`,h)},disableReason:t.values.editRestriction}),inherited:"",override:e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{g(t),L(b,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction??"Detach GPU",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),Object.keys(p).forEach(h=>{h==="name"||h==="type"||h==="pci"||h==="id"||c.push(B({label:A(h),inheritValue:p[h],readOnly:!1}))}),c.push(B({label:"Identify by",inheritValue:e.jsx($t,{device:p,onChange:(h,N)=>{g(t),t.setFieldValue(`devices.${b}.pci`,h),t.setFieldValue(`devices.${b}.id`,N)},disableReason:t.values.editRestriction}),readOnly:!1}))}),a?e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."}):e.jsxs(z,{className:"device-form",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsxs(s.Notification,{severity:"information",title:"GPU passthrough",children:["Learn more about"," ",e.jsx(k,{docPath:"/reference/devices_gpu/#devices-gpu",children:"GPU devices"})," ","and"," ",e.jsx(k,{docPath:"/howto/container_gpu_passthrough_with_docker/#container-gpu-passthrough-with-docker",children:"container GPU passthrough with Docker"})]}),l.length>0&&e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited GPU devices"}),e.jsx(f,{rows:l})]}),v&&e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom GPU devices"}),e.jsx(f,{rows:c})]}),e.jsx(Rt,{onSelect:m=>{g(t),x(m)},disabledReason:t.values.editRestriction})]})},Qt=({formik:t,project:n})=>{const r=s.useNotify(),o=t.values.entityType==="instance",a=o&&t.values.instanceType==="container",i=o&&t.values.instanceType==="virtual-machine",{hasMetadataConfiguration:d}=ie(),{data:u,isLoading:x}=ue({queryKey:[T.configOptions],queryFn:async()=>Qe(d)}),{data:v=[],isLoading:l,error:c}=O(n);c&&r.failure("Loading profiles failed",c);const m=ze(t.values,v),b=q(t.values,v),p=()=>{const y=[...t.values.devices];y.push({type:"usb",name:M("custom-device",1,b)}),t.setFieldValue("devices",y)};if(l||x)return e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."});const h=t.values.devices.some(ee),N=[];m.forEach(y=>{const C=H(y.key,t),I=C!==-1;N.push(R({className:"no-border-top override-with-form",configuration:e.jsx("div",{className:$("device-name",{"u-text--muted":I}),children:e.jsx("b",{children:y.key})}),inherited:e.jsxs("div",{className:"p-text--small u-text--muted u-no-margin--bottom",children:["From: ",y.source]}),override:I?e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{g(t),L(C,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,title:"Attach device",children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}):e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{g(t),E(y.key,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction??"Detach device",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),Object.keys(y.device).forEach(w=>{w!=="name"&&N.push(B({label:A(w),inheritValue:y.device[w],readOnly:!1,isDeactivated:I}))})});const j=[];return t.values.devices.forEach((y,C)=>{if(!ee(y))return;const I=t.values.devices[C],w=I.type==="usb"?"unix-usb":I.type,F=`device-${w}`,S=u==null?void 0:u.configs[F],Q=S?Ke(S):[];j.push(R({className:"no-border-top custom-device-name",configuration:e.jsx(K,{name:I.name,index:C,setName:P=>{g(t),t.setFieldValue(`devices.${C}.name`,P)},disableReason:t.values.editRestriction}),inherited:"",override:e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{g(t),L(C,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,title:t.values.editRestriction??"Detach device",disabled:!!t.values.editRestriction,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),j.push(R({className:"no-border-top inherited-with-form",configuration:e.jsx(s.Label,{forId:`devices.${C}.type`,children:"Type"}),inherited:e.jsx(s.Select,{name:`devices.${C}.type`,id:`devices.${C}.type`,className:"u-no-margin--bottom",onBlur:t.handleBlur,onChange:P=>{g(t),t.setFieldValue(`devices.${C}`,{type:P.target.value,name:I.name})},value:I.type,options:[{label:"Infiniband (Containers only)",value:"infiniband",disabled:i},{label:"PCI (VMs only)",value:"pci",disabled:a},{label:"TPM",value:"tpm"},{label:"Unix Block (Containers only)",value:"unix-block",disabled:i},{label:"Unix Char (Containers only)",value:"unix-char",disabled:i},{label:"Unix Hotplug (Containers only)",value:"unix-hotplug",disabled:i},{label:"USB",value:"usb"}],disabled:!!t.values.editRestriction,title:t.values.editRestriction}),override:""})),Q.forEach(P=>{const U=`devices.${C}.${P.key}`,Ne=I[P.key];P.key!=="name"&&j.push(R({className:"no-border-top inherited-with-form",configuration:e.jsx(s.Label,{forId:U,children:A(P.key)}),inherited:e.jsx(s.Input,{name:U,id:U,onBlur:t.handleBlur,onChange:ye=>{g(t),t.handleChange(ye)},value:Ne,type:"text",placeholder:P.default,help:e.jsx(me,{description:P.shortdesc}),helpClassName:"configuration-help",className:"u-no-margin--bottom",disabled:!!t.values.editRestriction,title:t.values.editRestriction},`${U}-${w}`),override:""}))})}),e.jsxs(z,{className:"device-form",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),N.length>0&&e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited devices"}),e.jsx(f,{rows:N})]}),h&&e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom devices"}),e.jsx(f,{rows:j})]}),e.jsxs(s.Button,{onClick:()=>{g(t),p()},type:"button",hasIcon:!0,disabled:!!t.values.editRestriction,title:t.values.editRestriction,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"Attach custom device"})]})]})},Dt=({onSelect:t,disabledReason:n})=>e.jsxs(s.Button,{onClick:t,type:"button",hasIcon:!0,disabled:!!n,title:n,children:[e.jsx(s.Icon,{name:"plus"}),e.jsx("span",{children:"New Proxy Device"})]}),ae=(t,n,r,o,a,i)=>{var l;const d=((l=n[o])==null?void 0:l.split(":"))||[],u=d.length>0?d[0]:"tcp",x=d.length>1?d[1]:"",v=d.length>2?d[2]:"";t.push(R({className:"no-border-top inherited-with-form p-heading--6",configuration:i,inherited:"",override:""})),t.push(R({className:"no-border-top inherited-with-form",configuration:e.jsx(s.Label,{forId:`devices.${r}.${o}`,children:"Type"}),inherited:e.jsx(s.Select,{id:`devices.${r}.${o}`,onChange:c=>{var b;g(a);const m=c.target.value;if(a.setFieldValue(`devices.${r}.${o}`,`${m}:${x}:${v}`),n.nat==="true"){const p=((b=n.connect)==null?void 0:b.split(":"))||[],h=p.length>1?p[1]:"",N=p.length>2?p[2]:"";a.setFieldValue(`devices.${r}.connect`,`${m}:${h}:${N}`)}},value:u,options:rt,className:"u-no-margin--bottom",disabled:!!a.values.editRestriction||o==="connect"&&n.nat==="true",title:a.values.editRestriction??(n.nat?"This is determined by the listen type when nat mode is enabled":void 0)}),override:""})),t.push(R({className:"no-border-top inherited-with-form",configuration:u==="unix"?e.jsx(s.Label,{forId:`devices.${r}.${o}.unixsocket`,required:!0,children:"Socket path"}):e.jsx(s.Label,{forId:`devices.${r}.${o}.address`,required:!0,children:"Address"}),inherited:u==="unix"?e.jsx(s.Input,{id:`devices.${r}.${o}.unixsocket`,onChange:c=>{g(a);const m=c.target.value;a.setFieldValue(`devices.${r}.${o}`,`unix:${m}`)},value:x,placeholder:"/<socket_path>",type:"text",className:"u-no-margin--bottom",disabled:!!a.values.editRestriction,title:a.values.editRestriction}):e.jsx(s.Input,{id:`devices.${r}.${o}.address`,onChange:c=>{g(a);const m=c.target.value;a.setFieldValue(`devices.${r}.${o}`,`${u}:${m}:${v}`)},value:x,placeholder:"127.0.0.1",type:"text",className:"u-no-margin--bottom",disabled:!!a.values.editRestriction,title:a.values.editRestriction}),override:""})),u!=="unix"&&t.push(R({className:"no-border-top inherited-with-form",configuration:e.jsx(s.Label,{forId:`devices.${r}.${o}.port`,required:!0,children:"Port"}),inherited:e.jsx(s.Input,{id:`devices.${r}.${o}.port`,onChange:c=>{g(a);const m=c.target.value;a.setFieldValue(`devices.${r}.${o}`,`${u}:${x}:${m}`)},value:v,placeholder:"00[-00]",type:"text",className:"u-no-margin--bottom",disabled:!!a.values.editRestriction,title:a.values.editRestriction}),override:""}))},Yt=({formik:t,project:n})=>{const r=s.useNotify(),{data:o=[],isLoading:a,error:i}=O(n);i&&r.failure("Loading profiles failed",i);const d=Ye(t.values,o),u=[];u.push(...d.map(b=>b.key)),u.push(...t.values.devices.map(b=>b.name));const x=()=>{const b=[...t.values.devices],p=t.values.entityType!=="profile"&&t.values.instanceType!=="container";b.push({type:"proxy",name:M("proxy",1,u),nat:String(p)}),t.setFieldValue("devices",b)},v=t.values.devices.some(b=>b.type==="proxy"),l=(b,p,h,N,j,y,C,I)=>{const w=`devices.${h}.${p}`;return R({className:"no-border-top inherited-with-form",configuration:e.jsx(s.Label,{forId:w,children:b}),inherited:e.jsx(s.Select,{name:w,id:w,onBlur:t.handleBlur,onChange:F=>{g(t),t.setFieldValue(w,F.target.value),C==null||C(F.target.value)},value:j??"",options:N,help:e.jsx(me,{description:y}),helpClassName:"configuration-help",className:"u-no-margin--bottom",disabled:!!I||!!t.values.editRestriction,title:t.values.editRestriction??I},w),override:""})},c=[];d.forEach(b=>{const p=H(b.key,t),h=p!==-1;c.push(R({className:"no-border-top override-with-form",configuration:e.jsx("div",{className:$("device-name",{"u-text--muted":h}),children:e.jsx("b",{children:b.key})}),inherited:e.jsxs("div",{className:"p-text--small u-text--muted u-no-margin--bottom",children:["From: ",b.source]}),override:h?e.jsxs(s.Button,{appearance:"base",type:"button",title:"Reattach volume",onClick:()=>{g(t),L(p,t)},className:"has-icon u-no-margin--bottom",children:[e.jsx(s.Icon,{name:"connected"}),e.jsx("span",{children:"Reattach"})]}):e.jsxs(s.Button,{disabled:!!t.values.editRestriction,title:t.values.editRestriction,appearance:"base",type:"button",onClick:()=>{g(t),E(b.key,t)},className:"has-icon u-no-margin--bottom",dense:!0,children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),Object.keys(b.proxy).forEach(N=>{N==="name"||N==="type"||c.push(B({label:A(N),inheritValue:b.proxy[N],readOnly:!1,isDeactivated:h}))})});const m=[];return t.values.devices.forEach((b,p)=>{var w,F;if(b.type!=="proxy")return;const h=t.values.devices[p],N=((w=h.listen)==null?void 0:w.split(":"))||[],j=N.length>0?N[0]:"tcp",y=((F=h.connect)==null?void 0:F.split(":"))||[],C=y.length>1?y[1]:"",I=y.length>2?y[2]:"";m.push(R({className:"no-border-top custom-device-name",configuration:e.jsx(K,{name:h.name,index:p,setName:S=>{g(t),t.setFieldValue(`devices.${p}.name`,S)},disableReason:t.values.editRestriction}),inherited:"",override:e.jsxs(s.Button,{className:"u-no-margin--top u-no-margin--bottom",onClick:()=>{g(t),L(p,t)},type:"button",appearance:"base",hasIcon:!0,dense:!0,disabled:!!t.values.editRestriction,title:t.values.editRestriction??"Detach Proxy",children:[e.jsx(s.Icon,{name:"disconnect"}),e.jsx("span",{children:"Detach"})]})})),m.push(l("Bind","bind",p,[{label:"Select option",value:"",disabled:!0},{label:"Host",value:"host"},{label:"Instance",value:"instance"}],h.bind,"Whether to bind the listen address to the instance or host",S=>{S==="instance"&&t.setFieldValue(`devices.${p}.nat`,void 0)})),m.push(l("NAT mode","nat",p,dt,h.nat,void 0,S=>{S==="true"&&t.setFieldValue(`devices.${p}.connect`,`${j}:${C}:${I}`)},h.bind==="instance"?"Only host-bound proxies can use NAT":void 0)),ae(m,h,p,"listen",t,"Listen"),ae(m,h,p,"connect",t,"Connect")}),a?e.jsx(s.Spinner,{className:"u-loader",text:"Loading..."}):e.jsxs(z,{className:"device-form",children:[e.jsx(s.Input,{type:"submit",hidden:!0,value:"Hidden input"}),c.length>0&&e.jsxs("div",{className:"inherited-devices",children:[e.jsx("h2",{className:"p-heading--4",children:"Inherited Proxy devices"}),e.jsx(f,{rows:c})]}),v&&e.jsxs("div",{className:"custom-devices",children:[e.jsx("h2",{className:"p-heading--4 custom-devices-heading",children:"Custom Proxy devices"}),e.jsx(f,{rows:m})]}),e.jsx(Dt,{onSelect:()=>{g(t),x()},disabledReason:t.values.editRestriction})]})};export{Ht as D,Kt as G,zt as N,Qt as O,Yt as P};
Copyright ©2k19 -
Hexid
|
Tex7ure