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/Settings-ClbTp_iU.js

import{r as j,j as e,d as t,aY as A,cY as O,cZ as U,c_ as $,c$ as q,d0 as Q,z as T,t as H,u as z,v as G,y as K,Q as Y,d1 as J,cV as M,x as P,d2 as X,d3 as Z,V as W,d4 as F,J as ee,d5 as te,cw as se,d6 as ae,p as ne,cx as re}from"./index-BsQN_SZU.js";import{H as oe}from"./HelpLink-BJF9zWZL.js";import{P as E}from"./PageHeader-BkhUaI4-.js";import{C as B}from"./ConfigFieldDescription-CjXKAIpa.js";import{C as le}from"./ClusterSpecificInput-7EvfCd3b.js";import{C as ce}from"./ClusterSpecificSelect-B2H3HpuO.js";import"./ClusterMemberRichChip-Di9w-E3M.js";import"./ClusterMemberMemoryUsage-DYUQFY0n.js";import"./Meter-cq8smrSm.js";const ie=({initialValue:s,configField:a,onSubmit:n,onCancel:c})=>{const[o,r]=j.useState(s?s==="true":String(a.default)==="true"),d=String(a.default)!==String(o),l=()=>{r(String(a.default)==="true")},i=a.key.split(".")?.pop()?.replaceAll("_"," ")??a.key;return e.jsxs(e.Fragment,{children:[e.jsx(t.Input,{label:i,id:a.key,wrapperClassName:"input-wrapper",type:"checkbox",checked:o,onChange:p=>{r(p.target.checked)},help:e.jsx(B,{description:a.longdesc})}),e.jsx(t.Button,{appearance:"base",onClick:c,children:"Cancel"}),e.jsx(t.Button,{appearance:"positive",onClick:()=>{n(o)},children:"Save"}),d&&e.jsxs(t.Button,{className:"reset-button",appearance:"base",onClick:l,hasIcon:!0,children:[e.jsx(t.Icon,{name:"restart",className:"flip-horizontally"}),e.jsx("span",{children:"Reset to default"})]})]})},ue=({initialValue:s,configField:a,onSubmit:n,onDelete:c,onCancel:o})=>{const[r,d]=j.useState(s),l=()=>a.type==="integer"?"number":"text",i=!a.isUserDefined&&String(a.default)!==String(r),p=()=>{d(a.default)};return e.jsxs(t.Form,{onSubmit:h=>{h.preventDefault(),n(r)},children:[e.jsx(t.Input,{type:"submit",hidden:!0,value:"Hidden input"}),e.jsx(t.Input,{"aria-label":a.key,id:a.key,wrapperClassName:"input-wrapper",type:l(),value:a.type==="bool"?void 0:String(r),onChange:h=>{d(h.target.value)},help:e.jsx(B,{description:a.longdesc})}),e.jsx(t.Button,{appearance:"base",onClick:o,children:"Cancel"}),e.jsx(t.Button,{appearance:"positive",type:"submit",children:"Save"}),a.isUserDefined&&e.jsxs(t.Button,{appearance:"base",hasIcon:!0,className:"delete-button",type:"button",onClick:()=>{c(a.key)},children:[e.jsx(t.Icon,{name:"delete"}),e.jsx("span",{children:"Delete"})]}),i&&e.jsxs(t.Button,{className:"reset-button",appearance:"base",onClick:p,hasIcon:!0,children:[e.jsx(t.Icon,{name:"restart",className:"flip-horizontally"}),e.jsx("span",{children:"Reset to default"})]})]})},de=({isSet:s,configField:a,onSubmit:n,onCancel:c})=>{const[o,r]=j.useState(!s),[d,l]=j.useState(!1),[i,p]=j.useState("");return e.jsxs(t.Form,{onSubmit:h=>{h.preventDefault(),n(i)},children:[e.jsx(t.Input,{type:"submit",hidden:!0,value:"Hidden input"}),o&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"input-row",children:[e.jsx(t.Input,{"aria-label":a.key,id:a.key,wrapperClassName:"input-wrapper",type:d?"text":"password",value:i,onChange:h=>{p(h.target.value)},help:e.jsx(B,{description:a.longdesc})}),e.jsx(t.Button,{appearance:"base",hasIcon:!0,onClick:()=>{l(h=>!h)},"aria-label":"toggle password visibility",children:e.jsx(t.Icon,{name:d?"hide":"show"})})]}),e.jsx(t.Button,{appearance:"base",onClick:c,children:"Cancel"}),e.jsx(t.Button,{appearance:"positive",onClick:()=>{n(i)},children:"Save"})]}),!o&&e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{appearance:"base",onClick:c,children:"Cancel"}),e.jsx(t.Button,{onClick:()=>{r(!0)},children:"Change"}),e.jsx(t.Button,{appearance:"negative",onClick:()=>{n("")},children:"Remove"})]})]})},pe=({configField:s})=>{const[a,n]=j.useState(!1),{data:c=[]}=A(),[o,r]=j.useState(O()||""),d=t.useToastNotification(),l=[{label:"All projects",value:U},...c.map(y=>({label:y.name,value:y.name}))],i=String(s.default)!==String(o),p=()=>{Q(o);const y=e.jsx(T,{bold:!0,type:"setting",value:s.key});d.success(e.jsxs(e.Fragment,{children:["Setting ",y," updated."]})),n(!1)},h=()=>{r(s.default||"")},S=()=>{r(O()||""),n(!1)};return j.useEffect(()=>{if(!a){r(O()||"");return}r($(c))},[a,c]),e.jsxs(e.Fragment,{children:[a&&e.jsxs(t.Form,{onSubmit:y=>{y.preventDefault(),p()},children:[e.jsx(t.Select,{name:`${s.key}-select`,"aria-label":s.key,options:l,value:o,onChange:y=>{r(y.target.value)}}),e.jsx(t.Button,{appearance:"base",onClick:S,children:"Cancel"}),e.jsx(t.Button,{appearance:"positive",type:"submit",children:"Save"}),i&&e.jsxs(t.Button,{className:"reset-button",appearance:"base",onClick:h,hasIcon:!0,children:[e.jsx(t.Icon,{name:"restart",className:"flip-horizontally"}),e.jsx("span",{children:"Reset to default"})]})]}),!a&&e.jsxs(t.Button,{appearance:"base",className:"readmode-button u-no-margin",onClick:()=>{n(!0)},hasIcon:!0,children:[e.jsx("div",{className:"readmode-value u-truncate",children:o===U?"All projects":o||q(c)}),e.jsx(t.Icon,{name:"edit",className:"edit-icon"})]})]})},he=({disableReason:s,initialValue:a,configField:n,onSubmit:c,onCancel:o,readonly:r=!1,toggleReadOnly:d})=>{const[l,i]=j.useState(a),{data:p=[]}=H(),h=p.map(m=>m.server_name),S=n.key==="core.syslog_socket",y=Object.values(l).some(m=>m!==n.default),k=()=>{const m={};h.forEach(C=>{m[C]=n.default}),i(m)},v=e.jsx(B,{description:n.longdesc});return e.jsxs(t.Form,{onSubmit:m=>{m.preventDefault(),c(l)},children:[S?e.jsx(ce,{"aria-label":n.key,classname:r?"read-only":"",disableReason:s,id:n.key,values:l,isReadOnly:r,onChange:m=>{i(m)},toggleReadOnly:d,helpText:v,options:h.map(m=>({memberName:m,values:["true","false"]})),isDefaultSpecific:Object.values(l).some(m=>m!==Object.values(l)[0])}):e.jsx(le,{"aria-label":n.key,classname:r?"read-only":"",disableReason:s,id:n.key,values:l,isReadOnly:r,onChange:m=>{i(m)},memberNames:h,toggleReadOnly:d,helpText:v}),!r&&e.jsxs(e.Fragment,{children:[e.jsx(t.Button,{appearance:"base",onClick:o,children:"Cancel"}),e.jsx(t.Button,{appearance:"positive",type:"submit",children:"Save"}),y&&e.jsxs(t.Button,{className:"reset-button",appearance:"base",type:"button",onClick:k,hasIcon:!0,children:[e.jsx(t.Icon,{name:"restart",className:"flip-horizontally"}),e.jsx("span",{children:"Reset to default"})]})]})]})},me=({configField:s,onDelete:a,value:n,clusteredValue:c})=>{const{isRestricted:o}=z(),[r,d]=j.useState(!1),l=t.useNotify(),i=t.useToastNotification(),p=G(),{canEditServerConfiguration:h}=K(),S=Y(),y=j.useRef(null),k=s.key==="core.trust_password",v=s.key==="loki.auth.password",m=k||v,C=S&&s.scope==="local",V=s.key==="user.ui_theme",L=s.key==="user.ui_login_project",R=e.jsx(T,{bold:!0,type:"setting",value:s.key}),N=u=>{(C||typeof u=="object"?J(u,s.key):M({[s.key]:String(u)})).then(()=>{i.success(e.jsxs(e.Fragment,{children:["Setting ",R," updated."]})),d(!1)}).catch(g=>{l.failure("Setting update failed",g,R)}).finally(()=>{p.invalidateQueries({queryKey:[P.settings]}),p.invalidateQueries({queryKey:[P.settings,P.cluster]})})},f=()=>{d(!1)},w=()=>m?e.jsx("em",{children:n?"set":"not set"}):typeof n=="boolean"?String(n):n||"-";return j.useEffect(()=>{r&&y.current?.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})},[r]),C?e.jsx(he,{initialValue:c??{},disableReason:h()?void 0:"You do not have permission to edit server configuration",configField:s,onSubmit:N,onCancel:f,readonly:!r,toggleReadOnly:()=>{d(!0)}},`${JSON.stringify(c)}-${r}`):V?e.jsx(t.ThemeSwitcher,{}):L?e.jsx("div",{ref:y,children:e.jsx(pe,{configField:s})}):e.jsxs(e.Fragment,{children:[r&&e.jsxs("div",{ref:y,children:[m&&e.jsx(de,{isSet:!!n,configField:s,onSubmit:N,onCancel:f}),!m&&e.jsx(e.Fragment,{children:s.type==="bool"?e.jsx(ie,{initialValue:n,configField:s,onSubmit:N,onCancel:f}):e.jsx(ue,{initialValue:n??"",configField:s,onSubmit:N,onDelete:a,onCancel:f})})]}),!r&&e.jsx(e.Fragment,{children:o?e.jsx("span",{children:n??"-"}):e.jsxs(t.Button,{appearance:"base",className:"readmode-button u-no-margin",onClick:()=>{d(!0)},hasIcon:!0,disabled:!h(),title:h()?"":"You do not have permission to edit server configuration",children:[e.jsx("div",{className:"readmode-value u-truncate",children:w()}),e.jsx(t.Icon,{name:"edit",className:"edit-icon"})]})})]})},_=(s,a,n,c,o)=>{const r=!Object.keys(o?.config??{}).some(l=>l===s.key),d=X(s,o);return{key:s.key,columns:[{content:a&&e.jsx("h2",{className:"p-heading--5",children:s.category}),role:"cell",className:"group","aria-label":"Group"},{content:e.jsxs("div",{className:"key-cell",children:[r?s.key:e.jsx("strong",{children:s.key}),e.jsx("p",{className:"p-text--small u-text--muted u-no-margin--bottom",children:e.jsx(B,{description:s.shortdesc})})]}),role:"rowheader",className:"key","aria-label":"Key"},{content:e.jsx(me,{configField:s,value:d,clusteredValue:n,onDelete:c}),role:"cell","aria-label":"Value",className:"u-vertical-align-middle"}]}},ye=(s,a,n,c)=>{const o=s[a],r=s.some(l=>`user.${o.key}`===l.key),d=r||!o.value||!o.key;return{key:o.id,columns:[{content:!1,role:"cell",className:"group","aria-label":"Group"},{content:e.jsx(e.Fragment,{children:e.jsx(t.Input,{"aria-label":"new user key",id:`new-user-defined-key-${a}`,placeholder:"User key",type:"text",value:o.key,autoFocus:!0,error:r&&e.jsx(e.Fragment,{children:"Setting with this name already exists"}),onChange:l=>{n(i=>{const p=[...i];return p[a]={...p[a],key:l.target.value},p})},help:e.jsxs(e.Fragment,{children:["Key will be saved as ",e.jsx("code",{children:"user.{your-key}"}),". Enter only the part after user."]})})}),role:"rowheader",className:"key","aria-label":"key"},{content:e.jsxs(t.Form,{onSubmit:l=>{l.preventDefault(),c(a)},children:[e.jsx(t.Input,{type:"submit",hidden:!0,value:"Hidden input",disabled:d}),e.jsx(t.Input,{"aria-label":"new user value",id:`new-user-defined-value-${a}`,placeholder:"Value",type:"text",value:o.value,onChange:l=>{n(i=>{const p=[...i];return p[a]={...p[a],value:l.target.value},p})}}),e.jsx(t.Button,{type:"button",appearance:"base",className:"button",onClick:()=>{n(l=>{const i=[...l];return i.splice(a,1),i})},children:"Cancel"}),e.jsx(t.Button,{type:"submit",disabled:d,appearance:"positive",children:"Save"})]}),role:"cell",className:"u-vertical-align-middle","aria-label":"Value"}]}},je=s=>({key:"add-user-config-button",columns:[{content:!1,role:"cell",className:"group","aria-label":"Group"},{content:e.jsx(t.Button,{type:"button",onClick:()=>{s(a=>[...a,{key:"",value:"",default:"",category:"user",type:"string",isSaved:!1,isUserDefined:!0,id:Z()}])},children:"Add user setting"}),role:"rowheader",className:"key"}]}),we=()=>{const[s,a]=j.useState(""),[n,c]=j.useState([]),o=t.useNotify(),r=t.useToastNotification(),{hasMetadataConfiguration:d,settings:l,isSettingsLoading:i,settingsError:p}=W(),{data:h=[]}=A();j.useEffect(()=>{n.length===0&&!i&&c(F(l?.config??{},h))},[l,h,i]);const S=u=>{const x=`user.${n[u].key}`,g=n[u].value,b=e.jsx(T,{bold:!0,type:"setting",value:x});M({[x]:g}).then(()=>{c(I=>{const D=[...I];return D[u].isSaved=!0,D[u].key=x,D[u].default=g??"",D}),r.success(e.jsxs(e.Fragment,{children:["Setting ",b," added."]}))}).catch(I=>{o.failure("Setting add failed",I,b)})},y=u=>{const x=n.findIndex(b=>b.key===u),g=e.jsx(T,{bold:!0,type:"setting",value:u});M({[u]:""}).then(()=>{c(b=>{const I=[...b];return I.splice(x,1),I}),r.success(e.jsxs(e.Fragment,{children:["Setting ",g," deleted."]}))}).catch(b=>{o.failure("Setting delete failed",b,g)})},k=u=>s?u.key.toLowerCase().includes(s.toLowerCase())||u.shortdesc?.toLowerCase().includes(s.toLowerCase()):!0,{canEditServerConfiguration:v}=K(),{data:m,isLoading:C}=ee({queryKey:[P.configOptions],queryFn:async()=>re(d)}),{data:V=[],error:L}=te();if(L&&o.failure("Loading clustered settings failed",L),C||i)return e.jsx(t.Spinner,{className:"u-loader",text:"Loading...",isMainComponent:!0});p&&o.failure("Loading settings failed",p);const R=[{content:"Group",className:"group"},{content:"Key",className:"key"},{content:"Value"}],N=se(m?.configs?.server??{});let f="";const w=N.filter(k).map(u=>{const x=ae(V,u),g=f!==u.category;return f=u.category,_(u,g,x,y,l)});return n.filter(k).forEach((u,x)=>{const g=x===0,b=u.isSaved?_(u,g,{},y,l):ye(n,x,c,S);w.push(b)}),s||w.push(je(c)),e.jsx(e.Fragment,{children:e.jsxs(t.CustomLayout,{header:e.jsx(E,{children:e.jsxs(E.Left,{children:[e.jsx(E.Title,{children:e.jsx(oe,{docPath:"/server/",title:"Learn more about server configuration",children:"Settings"})}),e.jsx(E.Search,{children:e.jsx(t.SearchBox,{name:"search-setting",type:"text",className:"u-no-margin--bottom",onChange:u=>{a(u)},placeholder:"Search",value:s})})]})}),contentClassName:"settings",children:[e.jsx(ne,{}),e.jsxs(t.Row,{children:[!v()&&e.jsx(t.Notification,{severity:"caution",title:"Restricted permissions",titleElement:"h2",children:"You do not have permission to view or edit server settings"}),!d&&v()&&e.jsx(t.Notification,{severity:"information",title:"Get more server settings",titleElement:"h2",children:"Update to LXD v5.19.0 or later to access more server settings"}),v()&&e.jsx(t.ScrollableTable,{dependencies:[o.notification,w],tableId:"settings-table",belowIds:["status-bar"],children:e.jsx(t.MainTable,{id:"settings-table",headers:R,rows:w,emptyStateMsg:"No data to display"})})]})]})})};export{we as default};