theme.keycloak.v2.admin.resources.assets.AttributesGroupDetails-CZKYpGGU.js Maven / Gradle / Ivy
import{jsxs as m,Fragment as la,jsx as t}from"react/jsx-runtime";import{u as da,a as pa,c as ca,d as ua,e as ya,g as ma,f as ba,w as Da,ab as $,P as fa,F as ga,y as ha,ac as I,ad as C,bu as K,bv as N,am as L,ay as M,i as x,aa as Ha,Z as Ta,A as va,L as Aa,e6 as V,e0 as Ga}from"./main-C7ps2lmX.js";import{useState as T,useMemo as ka,useEffect as R}from"react";import{F as Ea}from"./FormAccess-DyLNkc18.js";import{K as Na}from"./KeyValueInput-B0tpVTv9.js";import{V as xa}from"./ViewHeader-B7eeFzFA.js";import{u as za}from"./useLocale-BsnKjfE6.js";import{u as Ia}from"./useToggle-K3Kx99tM.js";/* empty css */import{u as wa,U as Fa}from"./UserProfileContext-BkGsi2EQ.js";import{A as Pa,G as j}from"./AddTranslationsDialog-rQeJZUHO.js";import"react-dom";import"./copy-icon-ACZmDH8e.js";import"./KeySelect-jKxsKqdI.js";import"./EmptyStateFooter-DqmBOP2I.js";import"./PaginatingTableToolbar-Cjsz5Jh4.js";import"./EmptyStateActions-DWNUFByn.js";import"./FlexItem-BzZfUnQ1.js";import"./Td-D2hVFK0Z.js";import"./grip-vertical-icon-BxF7V59o.js";function Sa(b){return Object.entries(b).reduce((i,[D,n])=>typeof n=="string"?[...i,{key:D,value:n}]:[...i],[])}function $a(b){return Object.fromEntries(b.filter(i=>i.key.length>0).map(i=>[i.key,i.value]))}const B={annotations:[],displayDescription:"",displayHeader:"",name:""};function Ca(){const{adminClient:b}=da(),{t:i}=pa(),{realm:D,realmRepresentation:n}=ca(),{config:h,save:O}=wa(),U=ua(),w=za(),F=ya(),l=ma({defaultValues:B}),{addError:q}=ba(),c=!!F.name,[f,W]=T(""),[v,Z]=T(""),[A,J]=T(""),[Q,G]=Ia(),X=/\$\{([^}]+)\}/,[g,P]=T(),[o,z]=T({displayHeader:{key:"",translations:[]},displayDescription:{key:"",translations:[]}}),r=ka(()=>h?.groups?.find(({name:e})=>e===F.name),[h?.groups]);R(()=>{if(!r)return;const e=r.annotations?Sa(r.annotations):[];l.reset({...B,...r,annotations:e})},[r]),R(()=>{l.setValue("displayHeader",r?r.displayHeader:v),l.setValue("displayDescription",r?r.displayDescription:A)},[v,A]),Da(async()=>{const e=[],a=[],s=l.getValues();return(await Promise.all(w.map(async d=>{try{const p=await b.realms.getRealmLocalizationTexts({realm:D,selectedLocale:d}),H=s.displayHeader?.substring(2,s.displayHeader.length-1),y=s.displayDescription?.substring(2,s.displayDescription.length-1);return{locale:d,headerTranslation:p[H]??"",descriptionTranslation:p[y]??""}}catch(p){return console.error(`Error fetching translations for ${d}:`,p),null}}))).forEach(d=>{if(d){const{locale:p,headerTranslation:H,descriptionTranslation:y}=d;e.push({key:s.displayHeader?.substring(2,s.displayHeader.length-1),translations:[{locale:p,value:H}]}),a.push({key:s.displayDescription?.substring(2,s.displayDescription.length-1),translations:[{locale:p,value:y}]})}}),{translationsToSaveDisplayHeader:e,translationsToSaveDisplayDescription:a}},e=>{z({displayHeader:{key:e.translationsToSaveDisplayHeader[0].key,translations:e.translationsToSaveDisplayHeader.flatMap(a=>a.translations)},displayDescription:{key:e.translationsToSaveDisplayDescription[0].key,translations:e.translationsToSaveDisplayDescription.flatMap(a=>a.translations)}})},[w]);const Y=async()=>{const e=async(a,s,u)=>{try{await b.realms.addLocalization({realm:D,selectedLocale:s,key:a},u)}catch(d){console.error(`Error saving translation for locale ${s}: ${d}`)}};try{if(o.displayHeader&&o.displayHeader.translations.length>0)for(const a of o.displayHeader.translations)await e(o.displayHeader.key,a.locale,a.value);if(o.displayDescription&&o.displayDescription.translations.length>0)for(const a of o.displayDescription.translations)await e(o.displayDescription.key,a.locale,a.value)}catch(a){console.error(`Error while processing translations: ${a}`)}},_=async e=>{if(!h)return;const a=[...h.groups??[]],s=r?a.indexOf(r):-1,u={...e,annotations:$a(e.annotations)};if(s===-1?a.push(u):a[s]=u,n?.internationalizationEnabled){const p=o.displayHeader.translations.some(y=>y.value.trim()!==""),H=o.displayDescription.translations.some(y=>y.value.trim()!=="");if(!p||!H){q("createAttributeError",i("translationError"));return}}await O({...h,groups:a})&&(await Y(),Ga.reloadResources(),U(V({realm:D,tab:"attributes-group"})))},k=$({control:l.control,name:"displayHeader"}),E=$({control:l.control,name:"displayDescription"}),aa=(e,a)=>{const s=a!==""&&n?.internationalizationEnabled?`\${profile.attribute-group.${a}}`:"",u=a!==""&&n?.internationalizationEnabled?`\${profile.attribute-group-description.${a}}`:"";W(a),Z(s),J(u)},S=X.test(k||E),ta=k?.substring(2,k.length-1),ea=E?.substring(2,E.length-1),ia=e=>{z(a=>({...a,displayHeader:e}))},sa=e=>{z(a=>({...a,displayDescription:e}))},na=()=>{G()},ra=g==="displayHeader"?ta:`profile.attribute-group.${f}`,oa=g==="displayDescription"?ea:`profile.attribute-group-description.${f}`;return m(la,{children:[Q&&t(Pa,{translationKey:g==="displayHeader"?ra:oa,type:g==="displayHeader"?"displayHeader":"displayDescription",translations:g==="displayHeader"?o.displayHeader:o.displayDescription,onTranslationsAdded:g==="displayHeader"?ia:sa,toggleDialog:na,onCancel:()=>{G()}}),t(xa,{titleKey:r?"editGroupText":"createGroupText",divider:!0}),t(fa,{variant:"light",onSubmit:l.handleSubmit(_),children:t(Ea,{isHorizontal:!0,role:"manage-realm",children:m(ga,{...l,children:[t(ha,{name:"name",label:i("nameField"),labelIcon:i("nameHintHelp"),isDisabled:!!r||c,rules:{required:{value:!0,message:i("required")},onChange:e=>{aa(e,e.target.value)}}}),!!r&&t("input",{type:"hidden",...l.register("name")}),t(I,{label:i("displayHeaderField"),labelIcon:t(C,{helpText:i("displayHeaderHintHelp"),fieldLabelId:"displayHeaderField"}),fieldId:"kc-attributes-group-display-header",children:m(K,{hasGutter:!0,children:[m(N,{span:n?.internationalizationEnabled?11:12,children:[t(L,{id:"kc-attributes-group-display-header","data-testid":"attributes-group-display-header",isDisabled:n?.internationalizationEnabled&&f!==""||c&&S,value:c?k:n?.internationalizationEnabled?v:void 0,...l.register("displayHeader")}),v&&t(M,{className:"pf-v5-u-mt-sm",variant:"info",isInline:!0,isPlain:!0,title:i("addAttributesGroupTranslationInfo")})]}),n?.internationalizationEnabled&&t(N,{span:1,children:t(x,{variant:"link",className:"pf-m-plain","data-testid":"addAttributeDisplayNameTranslationBtn","aria-label":i("addAttributeDisplayNameTranslation"),isDisabled:!f&&!c,onClick:()=>{P("displayHeader"),G()},icon:t(j,{})})})]})}),t(I,{label:i("displayDescriptionField"),labelIcon:t(C,{helpText:i("displayDescriptionHintHelp"),fieldLabelId:"displayDescriptionField"}),fieldId:"kc-attributes-group-display-description",children:m(K,{hasGutter:!0,children:[m(N,{span:n?.internationalizationEnabled?11:12,children:[t(L,{id:"kc-attributes-group-display-description","data-testid":"attributes-group-display-description",isDisabled:n?.internationalizationEnabled&&f!==""||c&&S,value:c?E:n?.internationalizationEnabled?A:void 0,...l.register("displayDescription")}),A&&t(M,{className:"pf-v5-u-mt-sm",variant:"info",isInline:!0,isPlain:!0,title:i("addAttributesGroupTranslationInfo")})]}),n?.internationalizationEnabled&&t(N,{span:1,children:t(x,{variant:"link",className:"pf-m-plain","data-testid":"addAttributeDisplayDescriptionTranslationBtn","aria-label":i("addAttributeDisplayDescriptionTranslation"),isDisabled:!f&&!c,onClick:()=>{P("displayDescription"),G()},icon:t(j,{})})})]})}),t(Ha,{children:t(Ta,{component:"h2",children:i("annotationsText")})}),t(I,{label:i("annotationsText"),fieldId:"kc-annotations",children:t(Na,{label:i("annotationsText"),name:"annotations"})}),m(va,{children:[t(x,{variant:"primary",type:"submit","data-testid":"saveGroupBtn",children:i("save")}),t(x,{variant:"link",component:e=>t(Aa,{...e,to:V({realm:D,tab:"attributes-group"})}),children:i("cancel")})]})]})})})]})}const it=()=>t(Fa,{children:t(Ca,{})});export{it as default};
//# sourceMappingURL=AttributesGroupDetails-CZKYpGGU.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy