Linux lhjmq-records 5.15.0-118-generic #128-Ubuntu SMP Fri Jul 5 09:28:59 UTC 2024 x86_64
Your IP : 3.143.17.175
import{r as x,j as e,d as s,u as B,i as I,bo as L,q as S,l as R,f as D,n as P,L as q,B as T,H as V,b as E,S as K,bm as M}from"./index-13b2882d.js";import{C as k,t as _}from"./ConfigFieldDescription-00c1a193.js";const O=({initialValue:r,configField:t,onSubmit:l,onCancel:u})=>{const[n,c]=x.useState(r?r==="true":String(t.default)==="true"),o=String(t.default)!==String(n),p=()=>{c(String(t.default)==="true")};return e.jsxs(e.Fragment,{children:[e.jsx(s.Input,{"aria-label":t.key,id:b(t.key),wrapperClassName:"input-wrapper",type:"checkbox",checked:n,onChange:i=>c(i.target.checked),help:e.jsx(k,{description:t.longdesc,className:"p-form-help-text"})}),e.jsx(s.Button,{appearance:"base",onClick:u,children:"Cancel"}),e.jsx(s.Button,{appearance:"positive",onClick:()=>l(n),children:"Save"}),o&&e.jsxs(s.Button,{className:"reset-button",appearance:"base",onClick:p,hasIcon:!0,children:[e.jsx(s.Icon,{name:"restart",className:"flip-horizontally"}),e.jsx("span",{children:"Reset to default"})]})]})},Q=({initialValue:r,configField:t,onSubmit:l,onCancel:u})=>{const[n,c]=x.useState(r),o=()=>{switch(t.type){case"integer":return"number";default:return"text"}},p=String(t.default)!==String(n),i=()=>{c(t.default)};return e.jsxs(s.Form,{onSubmit:d=>{d.preventDefault(),l(n)},children:[e.jsx(s.Input,{type:"submit",hidden:!0}),e.jsx(s.Input,{"aria-label":t.key,id:b(t.key),wrapperClassName:"input-wrapper",type:o(),value:t.type==="bool"?void 0:String(n),onChange:d=>c(d.target.value),help:e.jsx(k,{description:t.longdesc,className:"p-form-help-text"})}),e.jsx(s.Button,{appearance:"base",onClick:u,children:"Cancel"}),e.jsx(s.Button,{appearance:"positive",onClick:()=>l(n),children:"Save"}),p&&e.jsxs(s.Button,{className:"reset-button",appearance:"base",onClick:i,hasIcon:!0,children:[e.jsx(s.Icon,{name:"restart",className:"flip-horizontally"}),e.jsx("span",{children:"Reset to default"})]})]})},z=({isSet:r,configField:t,onSubmit:l,onCancel:u})=>{const[n,c]=x.useState(!r),[o,p]=x.useState(!1),[i,d]=x.useState("");return e.jsxs(s.Form,{onSubmit:h=>{h.preventDefault(),l(i)},children:[e.jsx(s.Input,{type:"submit",hidden:!0}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"input-row",children:[e.jsx(s.Input,{"aria-label":t.key,id:b(t.key),wrapperClassName:"input-wrapper",type:o?"text":"password",value:i,onChange:h=>d(h.target.value),help:e.jsx(k,{description:t.longdesc,className:"p-form-help-text"})}),e.jsx(s.Button,{appearance:"base",hasIcon:!0,onClick:()=>p(h=>!h),"aria-label":"toggle password visibility",children:e.jsx(s.Icon,{name:o?"hide":"show"})})]}),e.jsx(s.Button,{appearance:"base",onClick:u,children:"Cancel"}),e.jsx(s.Button,{appearance:"positive",onClick:()=>l(i),children:"Save"})]}),!n&&e.jsxs(e.Fragment,{children:[e.jsx(s.Button,{appearance:"base",onClick:u,children:"Cancel"}),e.jsx(s.Button,{onClick:()=>c(!0),children:"Change"}),e.jsx(s.Button,{appearance:"negative",onClick:()=>l(""),children:"Remove"})]})]})},b=r=>r.replace(".","___"),A=({configField:r,value:t,isLast:l})=>{const{isRestricted:u}=B(),[n,c]=x.useState(!1),o=s.useNotify(),p=I(),i=x.useRef(null),d=r.key==="core.trust_password",h=r.key==="loki.auth.password",y=d||h,j=m=>{const f={[r.key]:String(m)};L(f).then(()=>{o.success("Setting updated."),c(!1)}).catch(C=>{o.failure("Setting update failed",C)}).finally(()=>{p.invalidateQueries({queryKey:[S.settings]})})},g=()=>{c(!1)},a=()=>y?e.jsx("em",{children:t?"set":"not set"}):typeof t=="boolean"?String(t):t||"-";return x.useEffect(()=>{var m;n&&l&&((m=i.current)==null||m.scrollIntoView({behavior:"smooth"}))},[n]),e.jsxs(e.Fragment,{children:[n&&e.jsxs("div",{ref:i,children:[y&&e.jsx(z,{isSet:!!t,configField:r,onSubmit:j,onCancel:g}),!y&&e.jsx(e.Fragment,{children:r.type==="bool"?e.jsx(O,{initialValue:t,configField:r,onSubmit:j,onCancel:g}):e.jsx(Q,{initialValue:t??"",configField:r,onSubmit:j,onCancel:g})})]}),!n&&e.jsx(e.Fragment,{children:u?e.jsx("span",{children:t??"-"}):e.jsxs(s.Button,{appearance:"base",className:"readmode-button u-no-margin",onClick:()=>{c(!0)},hasIcon:!0,children:[e.jsx("div",{className:"readmode-value u-truncate",children:a()}),e.jsx(s.Icon,{name:"edit",className:"edit-icon"})]})})]})},U=()=>{const r=R(),[t,l]=x.useState(""),u=s.useNotify(),{data:n,isLoading:c}=D({queryKey:[S.configOptions],queryFn:M}),{data:o,error:p,isLoading:i}=P();if(c||i)return e.jsx(q,{});p&&u.failure("Loading settings failed",p);const d=a=>{for(const[m,f]of Object.entries((o==null?void 0:o.config)??{}))if(m===a.key)return f;if(a.type==="bool")return a.default==="true"?"true":"false";if(a.default!=="-")return a.default},h=[{content:"Group",className:"group"},{content:"Key",className:"key"},{content:"Value"}],y=_((n==null?void 0:n.configs.server)??{});y.push({key:"user.ui_title",category:"user",default:"",shortdesc:"Title for the LXD-UI web page. Shows the hostname when unset.",type:"string"});let j="";const g=y.filter(a=>t?a.key.toLowerCase().includes(t.toLowerCase()):!0).map((a,m,{length:f})=>{const C=!Object.keys((o==null?void 0:o.config)??{}).some(v=>v===a.key),w=d(a),N=j!==a.category;return j=a.category,{columns:[{content:N&&e.jsx("h2",{className:"p-heading--5",children:a.category}),role:"cell",className:"group","aria-label":"Group"},{content:e.jsxs("div",{className:"key-cell",children:[C?a.key:e.jsx("strong",{children:a.key}),e.jsx(k,{description:a.shortdesc,className:"p-text--small u-text--muted u-no-margin--bottom"})]}),role:"cell",className:"key","aria-label":"Key"},{content:e.jsx(A,{configField:a,value:w,isLast:m===f-1}),role:"cell","aria-label":"Value",className:"u-vertical-align-middle"}]}});return e.jsx(e.Fragment,{children:e.jsxs(T,{title:e.jsx(V,{href:`${r}/server/`,title:"Learn more about server configuration",children:"Settings"}),contentClassName:"settings",children:[e.jsx(E,{}),e.jsx(s.Row,{children:e.jsx(s.Col,{size:8,children:e.jsx(s.SearchBox,{name:"search-setting",type:"text",onChange:a=>{l(a)},placeholder:"Search",value:t})})}),e.jsx(s.Row,{children:e.jsx(K,{dependencies:[u.notification,g],children:e.jsx(s.MainTable,{headers:h,rows:g,emptyStateMsg:"No data to display"})})})]})})};export{U as default};
|