theme.keycloak.v2.admin.resources.assets.KeyValueInput-CoupoYmE.js Maven / Gradle / Ivy
import{jsx as e,jsxs as c,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 v,aj as w,b4 as G,ab as O,bu as B,bv as d,bZ as $,b_ as b,h as m,ap as H,as as g}from"./index-C1LIsRX7.js";import{K as L,A as M,a as R}from"./KeySelect-B2uWUd6C.js";import{E as U,a as z,b as K}from"./EmptyStateFooter-Cm2IMTi1.js";const V=({selectItems:t,keyValue:n,...l})=>{const{t:s}=E(),{field:r}=T(l),[u,i]=N(!1),p=x(()=>t.find(a=>a.key===n),[t,n]);return p?.values?e(P,{onToggle:a=>i(a),isOpen:u,onSelect:a=>{r.onChange(a),i(!1)},selections:r.value?[r.value]:s("choose"),placeholderText:s("valuePlaceholder"),children:p.values.map(a=>e(j,{value:a,children:a},a))}):e(v,{"aria-label":s("customValue"),"data-testid":l.name,...r})},Y=({name:t,label:n="attributes",defaultKeyValue:l,isDisabled:s=!1})=>{const{t:r}=E(),{control:u,register:i,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?c(q,{children:[c(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 h=p[t]?.[o],k=!!h?.key,y=!!h?.value||!!h?.message,C=h?.message||r("valueError");return c(F,{children:[c(d,{span:5,children:[l?e(L,{name:`${t}.${o}.key`,selectItems:l,rules:{required:!0}}):e(v,{placeholder:r("keyPlaceholder"),"aria-label":r("key"),"data-testid":`${t}-key`,...i(`${t}.${o}.key`,{required:!0}),validated:k?"error":"default",isRequired:!0,isDisabled:s}),k&&e($,{children:e(b,{variant:"error",children:r("keyError")})})]}),c(d,{span:5,children:[l?e(V,{name:`${t}.${o}.value`,keyValue:_[o]?.key,selectItems:l,rules:{required:!0}}):e(v,{placeholder:r("valuePlaceholder"),"aria-label":r("value"),"data-testid":`${t}-value`,...i(`${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(m,{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(m,{"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})})})})]}):c(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(m,{"data-testid":`${t}-add-row`,variant:"link",icon:e(g,{}),size:"sm",onClick:f,isDisabled:s,children:r("addAttribute",{label:n})})})]})};export{Y as K};
//# sourceMappingURL=KeyValueInput-CoupoYmE.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy