theme.keycloak.v2.admin.resources.assets.NewAttributeSettings-B6FILl0O.js Maven / Gradle / Ivy
import{jsx as e,jsxs as u,Fragment as O}from"react/jsx-runtime";import{a as I,ac as N,bu as ae,bv as B,u as ve,c as ye,aj as F,ab as $,w as U,a3 as we,F as te,ad as x,am as ce,aq as Ie,ay as De,i as H,v as Re,ar as X,R as W,ae as j,b5 as Y,b6 as ue,U as ee,a4 as xe,bS as me,b as ge,g as fe,M as Pe,q as Ee,r as Te,B as Oe,as as He,Z as Le,$ as Ge,d as Me,f as ze,P as We,b1 as $e,L as je,e6 as ke,e0 as Be,k as Ke,Q as Ue,ef as Fe}from"./main-C7ps2lmX.js";import{useState as T,useEffect as Ne,useMemo as _e}from"react";import{F as ne,a as Qe}from"./FormAccess-DyLNkc18.js";import{V as Ze}from"./ViewHeader-B7eeFzFA.js";import{u as Je}from"./useLocale-BsnKjfE6.js";import{u as le}from"./useParams-B67lSY02.js";/* empty css */import{U as Xe}from"./UserProfileContext-BkGsi2EQ.js";import{K as Ye}from"./KeyValueInput-B0tpVTv9.js";import{u as ie}from"./useToggle-K3Kx99tM.js";import{u as ea}from"./ConfirmDialog-hx7XKLbN.js";import{D as aa}from"./DynamicComponents-DvaX3FJx.js";import{U as ta,V as na,W as pe,X as Z,Y as la,Z as J}from"./Td-D2hVFK0Z.js";import{A as ia,G as ra}from"./AddTranslationsDialog-rQeJZUHO.js";import{D as sa}from"./SwitchControl-C_9Y74oV.js";import{i as oa}from"./isEqual-BWOcMitS.js";import"react-dom";import"./copy-icon-ACZmDH8e.js";import"./KeySelect-jKxsKqdI.js";import"./EmptyStateFooter-DqmBOP2I.js";import"./ClientSelect-B9UqjyP6.js";import"./FileUpload-CumNwlWc.js";import"./CodeEditor-C-nZkUJx.js";import"./EmptyStateActions-DWNUFByn.js";import"./GroupPickerDialog-C09EjRTA.js";import"./PaginatingTableToolbar-Cjsz5Jh4.js";import"./DataListItemRow-BC0LurDd.js";import"./FlexItem-BzZfUnQ1.js";import"./MultiLineInput-DiPNQ1LE.js";import"./AddRoleMappingModal-DW8o4W0z.js";import"./KeycloakDataTable-DbY4la1D.js";import"./_baseFlatten-eIEJR-AJ.js";import"./filter-icon-DO0QNij3.js";import"./grip-vertical-icon-BxF7V59o.js";const da=()=>{const{t}=I();return e(ne,{role:"manage-realm",isHorizontal:!0,children:e(N,{hasNoPaddingTop:!0,label:t("annotations"),fieldId:"kc-annotations",className:"kc-annotations-label",children:e(ae,{className:"kc-annotations",children:e(B,{children:e(Ye,{name:"annotations",label:t("annotations"),defaultKeyValue:[{key:"inputType",label:t("inputType"),values:["text","textarea","select","select-radiobuttons","multiselect","multiselect-checkboxes","html5-email","html5-tel","html5-url","html5-number","html5-range","html5-datetime-local","html5-date","html5-month","html5-week","html5-time"]},{key:"inputHelperTextBefore",label:t("inputHelperTextBefore")},{key:"inputHelperTextAfter",label:t("inputHelperTextAfter")},{key:"inputOptionLabelsI18nPrefix",label:t("inputOptionLabelsI18nPrefix")},{key:"inputTypePlaceholder",label:t("inputTypePlaceholder")},{key:"inputTypeSize",label:t("inputTypeSize")},{key:"inputTypeCols",label:t("inputTypeCols")},{key:"inputTypeRows",label:t("inputTypeRows")},{key:"inputTypeStep",label:t("inputTypeStep")},{key:"kcNumberFormat",label:t("kcNumberFormat")},{key:"kcNumberUnFormat",label:t("kcNumberUnFormat")}]})})})})})},he=[{label:"requiredForLabel.both",value:["admin","user"]},{label:"requiredForLabel.users",value:["user"]},{label:"requiredForLabel.admins",value:["admin"]}],ca=({onHandlingTranslationData:t,onHandlingGeneratedDisplayName:p})=>{const{adminClient:c}=ve(),{t:a}=I(),{realmRepresentation:i}=ye(),l=F(),[h,f]=T(),[C,o]=T(),[v,L]=T(!1),[y,S]=T(!1),[P,G]=ie(),{attributeName:M}=le(),D=!!M,[z,g]=T(""),[b,r]=T(""),[w,A]=T(),[k,E]=T({key:"",translations:[]}),m=/\$\{([^}]+)\}/,d=(n,s)=>{g(s);const V=s!==""&&i?.internationalizationEnabled?`\${profile.attributes.${s}}`:"";r(V)},q=$({control:l.control,name:"hasSelector"}),_=$({control:l.control,name:"hasRequiredScopes"}),Ce=$({control:l.control,name:"isRequired",defaultValue:!1}),K=$({control:l.control,name:"displayName"}),qe=m.test(K);U(()=>c.clientScopes.find(),f,[]),U(()=>c.users.getProfile(),o,[]);const re=n=>{t(n)},se=n=>{p(n)};if(Ne(()=>{re(k),se(b)},[k,b]),!h)return e(we,{});function oe(n){l.setValue("hasSelector",n)}function de(n){l.setValue("hasRequiredScopes",n)}const Ve=n=>{E(n)},Se=()=>{G(),re(k),se(b)},Ae=K?.substring(2,K.length-1);return u(O,{children:[P&&e(ia,{translationKey:D?Ae:`profile.attributes.${z}`,translations:k,type:w??"displayName",onTranslationsAdded:Ve,toggleDialog:Se,onCancel:()=>{G()}}),e(ne,{role:"manage-realm",isHorizontal:!0,children:u(te,{...l,children:[u(N,{label:a("attributeName"),labelIcon:e(x,{helpText:a("upAttributeNameHelp"),fieldLabelId:"attributeName"}),fieldId:"kc-attribute-name",isRequired:!0,children:[e(ce,{isRequired:!0,id:"kc-attribute-name",defaultValue:"","data-testid":"attribute-name",isDisabled:D,validated:l.formState.errors.name?"error":"default",...l.register("name",{required:!0}),onChange:d}),l.formState.errors.name&&e(Ie,{message:a("validateAttributeName")})]}),e(N,{label:a("attributeDisplayName"),labelIcon:e(x,{helpText:a("attributeDisplayNameHelp"),fieldLabelId:"attributeDisplayName"}),fieldId:"kc-attribute-display-name",children:u(ae,{hasGutter:!0,children:[u(B,{span:i?.internationalizationEnabled?11:12,children:[e(ce,{id:"kc-attribute-display-name","data-testid":"attribute-display-name",isDisabled:i?.internationalizationEnabled&&z!==""||D&&qe,value:D?K:i?.internationalizationEnabled?b:void 0,...l.register("displayName")}),b&&e(De,{className:"pf-v5-u-mt-sm",variant:"info",isInline:!0,isPlain:!0,title:a("addAttributeTranslationInfo")})]}),i?.internationalizationEnabled&&e(B,{span:1,children:e(H,{variant:"link",className:"pf-m-plain kc-attribute-display-name-iconBtn","data-testid":"addAttributeTranslationBtn","aria-label":a("addAttributeTranslationBtn"),isDisabled:!z&&!D,onClick:()=>{A("displayName"),G()},icon:e(ra,{})})})]})}),e(sa,{name:"multivalued",label:a("multivalued"),labelIcon:a("multivaluedHelp")}),e(Re,{name:"group",label:a("attributeGroup"),labelIcon:a("attributeGroupHelp"),controller:{defaultValue:""},options:[{key:"",value:a("none")},...C?.groups?.map(n=>({key:n.name,value:n.name}))||[]]}),!ba.includes(M)&&u(O,{children:[e(X,{}),u(N,{label:a("enabledWhen"),labelIcon:e(x,{helpText:a("enabledWhenTooltip"),fieldLabelId:"enabled-when"}),fieldId:"enabledWhen",hasNoPaddingTop:!0,children:[e(W,{id:"always","data-testid":"always",isChecked:!q,name:"enabledWhen",label:a("always"),onChange:()=>oe(!1),className:"pf-v5-u-mb-md"}),e(W,{id:"scopesAsRequested","data-testid":"scopesAsRequested",isChecked:q,name:"enabledWhen",label:a("scopesAsRequested"),onChange:()=>oe(!0),className:"pf-v5-u-mb-md"})]}),q&&e(N,{fieldId:"kc-scope-enabled-when",children:e(j,{name:"selector.scopes",control:l.control,defaultValue:[],render:({field:n})=>e(Y,{"data-testid":"enabled-when-scope-field",variant:ue.typeaheadMulti,typeAheadAriaLabel:"Select",chipGroupProps:{numChips:3,expandedText:a("hide"),collapsedText:a("showRemaining")},onToggle:s=>L(s),selections:n.value,onSelect:s=>{const V=s.toString();let R=[""];n.value?R=n.value.includes(V)?n.value.filter(Q=>Q!==V):[...n.value,V]:R=[V],n.onChange(R)},onClear:()=>{n.onChange([])},isOpen:v,"aria-labelledby":"scope",children:h.map(s=>e(ee,{value:s.name,children:s.name},s.name))})})})]}),M!=="username"&&u(O,{children:[e(X,{}),e(N,{label:a("required"),labelIcon:e(x,{helpText:a("requiredHelp"),fieldLabelId:"required"}),fieldId:"kc-required",hasNoPaddingTop:!0,children:e(j,{name:"isRequired","data-testid":"required",defaultValue:!1,control:l.control,render:({field:n})=>e(xe,{id:"kc-required",onChange:n.onChange,isChecked:n.value,label:a("on"),labelOff:a("off"),"aria-label":a("required")})})}),Ce&&u(O,{children:[e(N,{label:a("requiredFor"),fieldId:"requiredFor",hasNoPaddingTop:!0,children:e(j,{name:"required.roles","data-testid":"requiredFor",defaultValue:he[0].value,control:l.control,render:({field:n})=>e("div",{className:"kc-requiredFor",children:he.map(s=>e(W,{id:s.label,"data-testid":s.label,isChecked:oa(n.value,s.value),name:"roles",onChange:()=>{n.onChange(s.value)},label:a(s.label),className:"kc-requiredFor-option"},s.label))})})}),u(N,{label:a("requiredWhen"),labelIcon:e(x,{helpText:a("requiredWhenTooltip"),fieldLabelId:"required-when"}),fieldId:"requiredWhen",hasNoPaddingTop:!0,children:[e(W,{id:"requiredAlways","data-testid":"requiredAlways",isChecked:!_,name:"requiredWhen",label:a("always"),onChange:()=>de(!1),className:"pf-v5-u-mb-md"}),e(W,{id:"requiredScopesAsRequested","data-testid":"requiredScopesAsRequested",isChecked:_,name:"requiredWhen",label:a("scopesAsRequested"),onChange:()=>de(!0),className:"pf-v5-u-mb-md"})]}),_&&e(N,{fieldId:"kc-scope-required-when",children:e(j,{name:"required.scopes",control:l.control,defaultValue:[],render:({field:n})=>e(Y,{"data-testid":"required-when-scope-field",variant:ue.typeaheadMulti,typeAheadAriaLabel:"Select",chipGroupProps:{numChips:3,expandedText:a("hide"),collapsedText:a("showRemaining")},onToggle:s=>S(s),selections:n.value,onSelect:s=>{const V=s.toString();let R=[""];n.value?R=n.value.includes(V)?n.value.filter(Q=>Q!==V):[...n.value,V]:R=[V],n.onChange(R)},onClear:()=>{n.onChange([])},isOpen:y,"aria-labelledby":"scope",children:h.map(s=>e(ee,{value:s.name,children:s.name},s.name))})})})]})]})]})})]})},be=({name:t})=>{const{t:p}=I(),{control:c}=F();return e(ae,{children:e(j,{name:`permissions.${t}`,control:c,defaultValue:[],render:({field:a})=>u(O,{children:[e(B,{lg:4,sm:6,children:e(me,{id:`user-${t}`,label:p("user"),value:"user","data-testid":`user-${t}`,isChecked:a.value.includes("user"),onChange:()=>{const i="user",l=a.value.includes(i)?a.value.filter(h=>h!==i):[...a.value,i];a.onChange(l)}})}),e(B,{lg:8,sm:6,children:e(me,{id:`admin-${t}`,label:p("admin"),value:"admin","data-testid":`admin-${t}`,isChecked:a.value.includes("admin"),onChange:()=>{const i="admin",l=a.value.includes(i)?a.value.filter(h=>h!==i):[...a.value,i];a.onChange(l)}})})]})})})},ua=()=>{const{t}=I();return u(ne,{role:"manage-realm",isHorizontal:!0,children:[e(N,{hasNoPaddingTop:!0,label:t("whoCanEdit"),labelIcon:e(x,{helpText:t("whoCanEditHelp"),fieldLabelId:"whoCanEdit"}),fieldId:"kc-who-can-edit",children:e(be,{name:"edit"})}),e(N,{hasNoPaddingTop:!0,label:t("whoCanView"),labelIcon:e(x,{helpText:t("whoCanViewHelp"),fieldLabelId:"whoCanView"}),fieldId:"kc-who-can-view",children:e(be,{name:"view"})})]})},ma=({selectedValidators:t,onChange:p})=>{const{t:c}=I(),a=ge().componentTypes?.["org.keycloak.validate.Validator"]||[],i=_e(()=>a.filter(({id:o})=>!t.includes(o)),[t]),[l,h]=ie(),[f,C]=T();return e(N,{label:c("validatorType"),fieldId:"validator",children:e(Y,{toggleId:"validator",onToggle:h,onSelect:o=>{const v=o;p(v),C(v),h()},selections:f?.id,variant:"single","aria-label":c("selectOne"),isOpen:l,placeholderText:c("choose"),menuAppendTo:"parent",maxHeight:300,children:i.map(o=>e(ee,{selected:f?.id===o.id,value:o,description:o.helpText,children:o.id},o.id))})})},pa=({selectedValidators:t,toggleDialog:p,onConfirm:c})=>{const{t:a}=I(),[i,l]=T(),h=ge().componentTypes?.["org.keycloak.validate.Validator"].length===t.length,f=fe(),{handleSubmit:C}=f,o=v=>{c({...v,id:i?.id}),p()};return e(Pe,{variant:Ee.small,title:a("addValidator"),isOpen:!0,onClose:p,actions:[e(H,{"data-testid":"save-validator-role-button",variant:"primary",type:"submit",form:"add-validator",children:a("save")},"save"),e(H,{"data-testid":"cancel-validator-role-button",variant:"link",onClick:p,children:a("cancel")},"cancel")],children:h?a("emptyValidators"):u(Te,{id:"add-validator",onSubmit:C(o),children:[e(ma,{selectedValidators:t.map(v=>v.key),onChange:l}),i&&e(te,{...f,children:e(aa,{properties:i.properties})})]})})},ha=()=>{const{t}=I(),[p,c]=ie(),[a,i]=T(),{setValue:l,control:h,register:f,getValues:C}=F(),o=$({name:"validations",control:h,defaultValue:[]});Ne(()=>{f("validations")},[f]);const[v,L]=ea({titleKey:t("deleteValidatorConfirmTitle"),messageKey:t("deleteValidatorConfirmMsg",{validatorName:a}),continueButtonLabel:"delete",continueButtonVariant:Oe.danger,onConfirm:async()=>{const y=o.filter(S=>S.key!==a);l("validations",[...y])}});return u(O,{children:[p&&e(pa,{selectedValidators:o,onConfirm:y=>{const S=C("annotations");y.id==="options"&&!S.find(P=>P.key==="inputType")&&l("annotations",[...S,{key:"inputType",value:"select"}]),l("validations",[...o,{key:y.id,value:y.config}])},toggleDialog:c}),e(L,{}),u("div",{className:"kc-attributes-validations",children:[e(H,{id:"addValidator",onClick:()=>c(),variant:"link","data-testid":"addValidator",className:"kc--attributes-validations--add-validation-button",icon:e(He,{}),children:t("addValidator")}),e(X,{}),o.length!==0?u(ta,{children:[e(na,{children:u(pe,{children:[e(Z,{children:t("validatorColNames.colName")}),e(Z,{children:t("validatorColNames.colConfig")}),e(Z,{"aria-hidden":"true"})]})}),e(la,{children:o.map(y=>u(pe,{children:[e(J,{dataLabel:t("validatorColNames.colName"),children:y.key}),e(J,{dataLabel:t("validatorColNames.colConfig"),children:JSON.stringify(y.value)}),e(J,{className:"kc--attributes-validations--action-cell",children:e(H,{variant:"link","data-testid":"deleteValidator",onClick:()=>{v(),i(y.key)},children:t("delete")},"validator")})]},y.key))})]}):e(Le,{className:"kc-emptyValidators",component:Ge.p,children:t("emptyValidators")})]})]})},ba=["username","email"],va=({onHandlingTranslationsData:t,onHandlingGeneratedDisplayName:p,save:c})=>{const{t:a}=I(),i=F(),{realm:l,attributeName:h}=le(),f=!!h,C=v=>{t(v)},o=v=>{p(v)};return u(Xe,{children:[e($e,{label:a("jumpToSection"),sections:[{title:a("generalSettings"),panel:e(ca,{onHandlingTranslationData:C,onHandlingGeneratedDisplayName:o})},{title:a("permission"),panel:e(ua,{})},{title:a("validations"),panel:e(ha,{})},{title:a("annotations"),panel:e(da,{})}]}),e(Te,{onSubmit:i.handleSubmit(c),children:u(Qe,{name:"attribute-settings",children:[e(H,{variant:"primary",type:"submit","data-testid":"attribute-create",children:a(f?"save":"create")}),e(je,{to:ke({realm:l,tab:"attributes"}),"data-testid":"attribute-cancel",className:"kc-attributeCancel",children:a("cancel")})]})})]})};function Xa(){const{adminClient:t}=ve(),{realm:p,attributeName:c}=le(),{realmRepresentation:a}=ye(),i=fe(),{t:l}=I(),h=Je(),f=Me(),{addAlert:C,addError:o}=ze(),[v,L]=T(null),y=!!c,[S,P]=T({key:"",translations:[]}),[G,M]=T("");U(async()=>{const g=[];return await Promise.all(h.map(async b=>{try{const r=await t.realms.getRealmLocalizationTexts({realm:p,selectedLocale:b}),w=i.getValues(),A=w.displayName?.substring(2,w.displayName.length-1),k=[];Object.entries(r).map(([d,q])=>({key:d,value:q})).forEach(d=>{d.key===A&&k.push({locale:b,value:d.value})});const m={key:A,translations:k};g.push(m)}catch(r){console.error(`Error fetching translations for ${b}:`,r)}})),g},g=>{P(()=>({key:g[0].key,translations:g.flatMap(b=>b.translations)}))},[h]),U(()=>t.users.getProfile(),g=>{L(g);const{annotations:b,validations:r,permissions:w,selector:A,required:k,multivalued:E,...m}=g.attributes.find(d=>d.name===c)||{permissions:{edit:["admin"]}};Ue({...m,hasSelector:typeof A<"u",hasRequiredScopes:typeof k?.scopes<"u"},i.setValue),Object.entries(Fe({permissions:w,selector:A,required:k},{safe:!0})).map(([d,q])=>i.setValue(d,q)),i.setValue("annotations",Object.entries(b||{}).map(([d,q])=>({key:d,value:q}))),i.setValue("validations",Object.entries(r||{}).map(([d,q])=>({key:d,value:q}))),i.setValue("isRequired",k!==void 0),i.setValue("multivalued",E===!0)},[]);const D=async()=>{try{const g=S.translations.map(async b=>{try{await t.realms.addLocalization({realm:p,selectedLocale:b.locale,key:S.key},b.value)}catch{console.error(`Error saving translation for ${b.locale}`)}});await Promise.all(g)}catch(g){console.error(`Error saving translations: ${g}`)}},z=async({hasSelector:g,hasRequiredScopes:b,...r})=>{g||delete r.selector,b||delete r.required?.scopes;const w=r.validations.reduce((m,d)=>(m[d.key]=d.value||{},m),{}),A=r.annotations.reduce((m,d)=>Object.assign(m,{[d.key]:d.value}),{}),k=()=>(v?.attributes||[]).map(m=>m.name!==c?m:(delete m.required,Object.assign({...m,name:c,displayName:r.displayName,selector:r.selector,permissions:r.permissions,multivalued:r.multivalued,annotations:A,validations:w},r.isRequired?{required:r.required}:void 0,r.group?{group:r.group}:{group:null}))),E=()=>(v?.attributes||[]).concat([Object.assign({name:r.name,displayName:r.displayName||G,required:r.isRequired?r.required:void 0,selector:r.selector,permissions:r.permissions,multivalued:r.multivalued,annotations:A,validations:w},r.isRequired?{required:r.required}:void 0,r.group?{group:r.group}:void 0)]);if(a?.internationalizationEnabled&&!S.translations.some(d=>d.value.trim()!=="")){o("createAttributeError",l("translationError"));return}try{const m=y?k():E();await t.users.updateProfile({...v,attributes:m,realm:p}),await D(),Be.reloadResources(),f(ke({realm:p,tab:"attributes"})),C(l("createAttributeSuccess"),Ke.success)}catch(m){o("createAttributeError",m)}};return u(te,{...i,children:[e(Ze,{titleKey:y?c:l("createAttribute"),subKey:y?"":l("createAttributeSubTitle")}),e(We,{variant:"light",children:e(va,{save:()=>i.handleSubmit(z)(),onHandlingTranslationsData:P,onHandlingGeneratedDisplayName:M})})]})}export{ba as USERNAME_EMAIL,Xa as default};
//# sourceMappingURL=NewAttributeSettings-B6FILl0O.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy