theme.keycloak.v2.admin.resources.assets.KeyValueInput-B0tpVTv9.js Maven / Gradle / Ivy
import{jsx as e,jsxs as i,Fragment as q}from"react/jsx-runtime";import{useState as N,useMemo as x,Fragment as F}from"react";import{a as E,a$ as T,b5 as P,U as j,am as h,aj as w,b4 as G,ab as O,bu as B,bv as d,b_ as $,b$ as b,i as v,ap as H,as as g}from"./main-C7ps2lmX.js";import{K as L,A as M,a as R}from"./KeySelect-jKxsKqdI.js";import{E as U,a as z,b as K}from"./EmptyStateFooter-DqmBOP2I.js";const V=({selectItems:t,keyValue:n,...l})=>{const{t:s}=E(),{field:r}=T(l),[u,c]=N(!1),p=x(()=>t.find(a=>a.key===n),[t,n]);return p?.values?e(P,{onToggle:a=>c(a),isOpen:u,onSelect:a=>{r.onChange(a),c(!1)},selections:r.value?[r.value]:s("choose"),placeholderText:s("valuePlaceholder"),children:p.values.map(a=>e(j,{value:a,children:a},a))}):e(h,{"aria-label":s("customValue"),"data-testid":l.name,...r})},Z=({name:t,label:n="attributes",defaultKeyValue:l,isDisabled:s=!1})=>{const{t:r}=E(),{control:u,register:c,formState:{errors:p}}=w(),{fields:a,append:I,remove:S}=G({shouldUnregister:!0,control:u,name:t}),f=()=>I({key:"",value:""}),_=O({name:t,control:u,defaultValue:[]});return a.length>0?i(q,{children:[i(B,{hasGutter:!0,children:[e(d,{className:"pf-v5-c-form__label",span:5,children:e("span",{className:"pf-v5-c-form__label-text",children:r("key")})}),e(d,{className:"pf-v5-c-form__label",span:7,children:e("span",{className:"pf-v5-c-form__label-text",children:r("value")})}),a.map((A,o)=>{const m=p[t]?.[o],k=!!m?.key,y=!!m?.value||!!m?.message,C=m?.message||r("valueError");return i(F,{children:[i(d,{span:5,children:[l?e(L,{name:`${t}.${o}.key`,selectItems:l,rules:{required:!0}}):e(h,{placeholder:r("keyPlaceholder"),"aria-label":r("key"),"data-testid":`${t}-key`,...c(`${t}.${o}.key`,{required:!0}),validated:k?"error":"default",isRequired:!0,isDisabled:s}),k&&e($,{children:e(b,{variant:"error",children:r("keyError")})})]}),i(d,{span:5,children:[l?e(V,{name:`${t}.${o}.value`,keyValue:_[o]?.key,selectItems:l,rules:{required:!0}}):e(h,{placeholder:r("valuePlaceholder"),"aria-label":r("value"),"data-testid":`${t}-value`,...c(`${t}.${o}.value`,{required:!0}),validated:y?"error":"default",isRequired:!0,isDisabled:s}),y&&e($,{children:e(b,{variant:"error",children:C})})]}),e(d,{span:2,children:e(v,{variant:"link",title:r("removeAttribute"),onClick:()=>S(o),"data-testid":`${t}-remove`,isDisabled:s,children:e(H,{})})})]},A.id)})]}),e(M,{children:e(R,{children:e(v,{"data-testid":`${t}-add-row`,className:"pf-v5-u-px-0 pf-v5-u-mt-sm",variant:"link",icon:e(g,{}),onClick:f,isDisabled:s,children:r("addAttribute",{label:n})})})})]}):i(U,{"data-testid":`${t}-empty-state`,className:"pf-v5-u-p-0",variant:"xs",children:[e(z,{children:r("missingAttributes",{label:n})}),e(K,{children:e(v,{"data-testid":`${t}-add-row`,variant:"link",icon:e(g,{}),size:"sm",onClick:f,isDisabled:s,children:r("addAttribute",{label:n})})})]})};export{Z as K};
//# sourceMappingURL=KeyValueInput-B0tpVTv9.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy