0x1949 Team - FAZEMRX - MANAGER
Edit File: ClusterGroupForm-f258bb5e.js
import{e as v,d as r,m as j,i as N,r as h,f as y,z as S,q as n,A as g,j as t,B as q,b as B,p as E,R as F,T as k}from"./index-13b2882d.js";import{c as w,a as G,u as R}from"./index.esm-82c30f37.js";import{S as $,u as A}from"./updateMaxHeight-325b3cd4.js";import{b as z,g as H}from"./clusterGroups-3fc1789d.js";import{S as L}from"./SelectableMainTable-5a3f3fef.js";import{A as D}from"./AutoExpandingTextArea-3a779a81.js";const _=({group:s})=>{var d;const o=v(),i=r.useNotify(),{group:b}=j(),p=N(),f=h.useState(null),{data:m=[],error:c}=y({queryKey:[n.cluster,n.members],queryFn:E});c&&i.failure("Loading cluster members failed",c);const x=w().shape({name:G().test("deduplicate","A cluster group with this name already exists",a=>(s==null?void 0:s.name)===a||S(a,"",f,"cluster/groups")).required()}),e=R({initialValues:{description:(s==null?void 0:s.description)??"",members:(s==null?void 0:s.members)??[],name:(s==null?void 0:s.name)??""},validationSchema:x,onSubmit:a=>{(s?F:k)({name:a.name,description:a.description,members:a.members}).then(()=>{const l=s?"saved":"created";o(`/ui/cluster/groups/detail/${a.name}`,i.queue(i.success(`Cluster group ${a.name} ${l}.`)))}).catch(l=>{e.setSubmitting(!1);const C=s?"save":"creation";i.failure(`Cluster group ${C} failed`,l)}).finally(()=>{p.invalidateQueries({queryKey:[n.cluster,n.groups]})})}}),u=()=>{A("form-contents","p-bottom-controls")};return h.useEffect(u,[(d=i.notification)==null?void 0:d.message]),g("resize",u),t.jsxs(q,{title:s?"Edit cluster group":"Create cluster group",contentClassName:"cluster-group-form",children:[t.jsx(r.Form,{onSubmit:e.handleSubmit,stacked:!0,className:"form",children:t.jsx(r.Row,{className:"form-contents",children:t.jsxs(r.Col,{size:12,children:[t.jsx(B,{}),t.jsxs("div",{className:"cluster-group-metadata",children:[t.jsx(r.Input,{id:"name",type:"text",label:"Group name",placeholder:"Enter name",required:!0,disabled:!!s,onBlur:e.handleBlur,onChange:e.handleChange,value:e.values.name,error:e.touched.name?e.errors.name:null}),t.jsx(D,{id:"description",name:"description",label:"Description",placeholder:"Enter description",onBlur:e.handleBlur,onChange:e.handleChange,value:e.values.description,error:e.touched.description?e.errors.description:null,dynamicHeight:!0})]}),t.jsxs("div",{className:"choose-label",children:["Choose members from the list"," ",t.jsxs("span",{className:"u-text--muted",children:["(",e.values.members.length," selected)"]})," "]}),t.jsx(L,{headers:z(),rows:H(m,b),sortable:!0,className:"cluster-group-select-members",filteredNames:m.map(a=>a.server_name),itemName:"member",parentName:"cluster",selectedNames:e.values.members,setSelectedNames:a=>void e.setFieldValue("members",a),processingNames:[]})]})})}),t.jsxs("div",{className:"p-bottom-controls",id:"form-footer",children:[t.jsx("hr",{}),t.jsx(r.Row,{className:"u-align--right",children:t.jsxs(r.Col,{size:12,children:[t.jsx(r.Button,{appearance:"base",onClick:()=>o("/ui/cluster"),children:"Cancel"}),t.jsx($,{isSubmitting:e.isSubmitting,isDisabled:!e.isValid||!e.values.name,buttonLabel:s?"Save changes":"Create",onClick:()=>void e.submitForm()})]})})]})]})};export{_ as C};