All Downloads are FREE. Search and download functionalities are using the official Maven repository.

theme.keycloak.v2.admin.resources.assets.NewAttributeSettings-BMpAgcYM.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 ye,c as ge,aj as F,ab as j,v as U,a3 as we,F as te,ad as x,am as ce,aq as Ie,ay as De,h as L,y as Re,ar as X,R as W,ae as $,b5 as Y,b6 as ue,U as ee,a4 as xe,bR as me,b as ve,g as fe,M as Pe,q as Ee,r as Te,B as Oe,as as Le,Z as He,$ as Ge,d as Me,f as ze,P as We,b1 as je,L as $e,e4 as ke,j as Be,Q as Ke,ed as Ue}from"./index-C1LIsRX7.js";import{useState as T,useEffect as Ne,useMemo as Fe}from"react";import{F as ne,a as _e}from"./FormAccess-BcY70QlP.js";import{V as Qe}from"./ViewHeader-qjLr6U82.js";import{u as Ze}from"./useLocale-CzIrpa16.js";import{u as le}from"./useParams-n_2fXkN1.js";/* empty css                               */import{U as Je}from"./UserProfileContext-BX1nihnb.js";import{K as Xe}from"./KeyValueInput-CoupoYmE.js";import{u as ie}from"./useToggle-K3Kx99tM.js";import{u as Ye}from"./ConfirmDialog-B5qjiAuo.js";import{D as ea}from"./DynamicComponents-CIZcko9u.js";import{U as aa,V as ta,W as pe,X as Z,Y as na,Z as J}from"./Td-BwjBKSkH.js";import{A as la,G as ia}from"./AddTranslationsDialog-Cim-Za0P.js";import{i as ra}from"./isEqual-DmIBnf3S.js";import"react-dom";import"./copy-icon-DOS8MmN7.js";import"./KeySelect-B2uWUd6C.js";import"./EmptyStateFooter-Cm2IMTi1.js";import"./ClientSelect-BTkwOwGP.js";import"./FileUpload-T43Q4AfB.js";import"./CodeEditor-CIeIZGz7.js";import"./EmptyStateActions-DBSnfkAA.js";import"./GroupPickerDialog-DmX3SBxL.js";import"./PaginatingTableToolbar-CpMLQtqt.js";import"./DataListItemRow-COCiEHyF.js";import"./FlexItem-DCAd8FXq.js";import"./MultiLineInput-AcwuO_FT.js";import"./AddRoleMappingModal-Ds4yp8lg.js";import"./KeycloakDataTable-jyvvxdb8.js";import"./_baseFlatten-BHAcGTxk.js";import"./filter-icon-BVyMUArZ.js";import"./grip-vertical-icon-Bnn0MebT.js";const sa=()=>{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(Xe,{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"]}],oa=({onHandlingTranslationData:t,onHandlingGeneratedDisplayName:p})=>{const{adminClient:c}=ye(),{t:a}=I(),{realmRepresentation:i}=ge(),l=F(),[h,f]=T(),[C,o]=T(),[y,H]=T(!1),[g,S]=T(!1),[P,G]=ie(),{attributeName:M}=le(),D=!!M,[z,v]=T(""),[b,r]=T(""),[w,A]=T(),[k,E]=T({key:"",translations:[]}),m=/\$\{([^}]+)\}/,d=(n,s)=>{v(s);const V=s!==""&&i?.internationalizationEnabled?`\${profile.attributes.${s}}`:"";r(V)},q=j({control:l.control,name:"hasSelector"}),_=j({control:l.control,name:"hasRequiredScopes"}),Ce=j({control:l.control,name:"isRequired",defaultValue:!1}),K=j({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(la,{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(L,{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(ia,{})})})]})}),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}))||[]]}),!pa.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($,{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=>H(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))})})})]}),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($,{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($,{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:ra(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($,{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:g,"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($,{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)}})})]})})})},da=()=>{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"})})]})},ca=({selectedValidators:t,onChange:p})=>{const{t:c}=I(),a=ve().componentTypes?.["org.keycloak.validate.Validator"]||[],i=Fe(()=>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 y=o;p(y),C(y),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))})})},ua=({selectedValidators:t,toggleDialog:p,onConfirm:c})=>{const{t:a}=I(),[i,l]=T(),h=ve().componentTypes?.["org.keycloak.validate.Validator"].length===t.length,f=fe(),{handleSubmit:C}=f,o=y=>{c({...y,id:i?.id}),p()};return e(Pe,{variant:Ee.small,title:a("addValidator"),isOpen:!0,onClose:p,actions:[e(L,{"data-testid":"save-validator-role-button",variant:"primary",type:"submit",form:"add-validator",children:a("save")},"save"),e(L,{"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(ca,{selectedValidators:t.map(y=>y.key),onChange:l}),i&&e(te,{...f,children:e(ea,{properties:i.properties})})]})})},ma=()=>{const{t}=I(),[p,c]=ie(),[a,i]=T(),{setValue:l,control:h,register:f,getValues:C}=F(),o=j({name:"validations",control:h,defaultValue:[]});Ne(()=>{f("validations")},[f]);const[y,H]=Ye({titleKey:t("deleteValidatorConfirmTitle"),messageKey:t("deleteValidatorConfirmMsg",{validatorName:a}),continueButtonLabel:"delete",continueButtonVariant:Oe.danger,onConfirm:async()=>{const g=o.filter(S=>S.key!==a);l("validations",[...g])}});return u(O,{children:[p&&e(ua,{selectedValidators:o,onConfirm:g=>{const S=C("annotations");g.id==="options"&&!S.find(P=>P.key==="inputType")&&l("annotations",[...S,{key:"inputType",value:"select"}]),l("validations",[...o,{key:g.id,value:g.config}])},toggleDialog:c}),e(H,{}),u("div",{className:"kc-attributes-validations",children:[e(L,{id:"addValidator",onClick:()=>c(),variant:"link","data-testid":"addValidator",className:"kc--attributes-validations--add-validation-button",icon:e(Le,{}),children:t("addValidator")}),e(X,{}),o.length!==0?u(aa,{children:[e(ta,{children:u(pe,{children:[e(Z,{children:t("validatorColNames.colName")}),e(Z,{children:t("validatorColNames.colConfig")}),e(Z,{"aria-hidden":"true"})]})}),e(na,{children:o.map(g=>u(pe,{children:[e(J,{dataLabel:t("validatorColNames.colName"),children:g.key}),e(J,{dataLabel:t("validatorColNames.colConfig"),children:JSON.stringify(g.value)}),e(J,{className:"kc--attributes-validations--action-cell",children:e(L,{variant:"link","data-testid":"deleteValidator",onClick:()=>{y(),i(g.key)},children:t("delete")},"validator")})]},g.key))})]}):e(He,{className:"kc-emptyValidators",component:Ge.p,children:t("emptyValidators")})]})]})},pa=["username","email"],ha=({onHandlingTranslationsData:t,onHandlingGeneratedDisplayName:p,save:c})=>{const{t:a}=I(),i=F(),{realm:l,attributeName:h}=le(),f=!!h,C=y=>{t(y)},o=y=>{p(y)};return u(Je,{children:[e(je,{label:a("jumpToSection"),sections:[{title:a("generalSettings"),panel:e(oa,{onHandlingTranslationData:C,onHandlingGeneratedDisplayName:o})},{title:a("permission"),panel:e(da,{})},{title:a("validations"),panel:e(ma,{})},{title:a("annotations"),panel:e(sa,{})}]}),e(Te,{onSubmit:i.handleSubmit(c),children:u(_e,{name:"attribute-settings",children:[e(L,{variant:"primary",type:"submit","data-testid":"attribute-create",children:a(f?"save":"create")}),e($e,{to:ke({realm:l,tab:"attributes"}),"data-testid":"attribute-cancel",className:"kc-attributeCancel",children:a("cancel")})]})})]})};function Qa(){const{adminClient:t}=ye(),{realm:p,attributeName:c}=le(),{realmRepresentation:a}=ge(),i=fe(),{t:l}=I(),h=Ze(),f=Me(),{addAlert:C,addError:o}=ze(),[y,H]=T(null),g=!!c,[S,P]=T({key:"",translations:[]}),[G,M]=T("");U(async()=>{const v=[];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};v.push(m)}catch(r){console.error(`Error fetching translations for ${b}:`,r)}})),v},v=>{P(()=>({key:v[0].key,translations:v.flatMap(b=>b.translations)}))},[h]),U(()=>t.users.getProfile(),v=>{H(v);const{annotations:b,validations:r,permissions:w,selector:A,required:k,multivalued:E,...m}=v.attributes.find(d=>d.name===c)||{permissions:{edit:["admin"]}};Ke({...m,hasSelector:typeof A<"u",hasRequiredScopes:typeof k?.scopes<"u"},i.setValue),Object.entries(Ue({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 v=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(v)}catch(v){console.error(`Error saving translations: ${v}`)}},z=async({hasSelector:v,hasRequiredScopes:b,...r})=>{v||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=()=>(y?.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=()=>(y?.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=g?k():E();await t.users.updateProfile({...y,attributes:m,realm:p}),await D(),f(ke({realm:p,tab:"attributes"})),C(l("createAttributeSuccess"),Be.success)}catch(m){o("createAttributeError",m)}};return u(te,{...i,children:[e(Qe,{titleKey:g?c:l("createAttribute"),subKey:g?"":l("createAttributeSubTitle")}),e(We,{variant:"light",children:e(ha,{save:()=>i.handleSubmit(z)(),onHandlingTranslationsData:P,onHandlingGeneratedDisplayName:M})})]})}export{pa as USERNAME_EMAIL,Qa as default};
//# sourceMappingURL=NewAttributeSettings-BMpAgcYM.js.map




© 2015 - 2025 Weber Informatics LLC | Privacy Policy