theme.keycloak.v2.admin.resources.assets.NewClientPolicy-CnABlseI.js Maven / Gradle / Ivy
import{jsx as i,jsxs as c,Fragment as h}from"react/jsx-runtime";import{u as ae,a as j,w as se,a3 as ce,M as Ie,q as Le,i as k,p as re,c as Ve,f as xe,d as Ae,g as Ke,b as Fe,B as H,k as v,dU as S,dT as w,ae as Ee,D as Re,P as Be,F as Ge,y as Me,ac as $e,d2 as He,A as Oe,Z as I,$ as L,ad as V,L as O,ed as je,as as X,ee as qe,ar as Y,dW as ze}from"./main-C7ps2lmX.js";import{useState as p}from"react";import{u as x}from"./ConfirmDialog-hx7XKLbN.js";import{F as Ue}from"./FormAccess-DyLNkc18.js";import{V as We}from"./ViewHeader-B7eeFzFA.js";import{u as Ze}from"./useParams-B67lSY02.js";import{L as Je}from"./PaginatingTableToolbar-Cjsz5Jh4.js";import{K as Qe}from"./KeycloakDataTable-DbY4la1D.js";/* empty css */import{F as _,a as A}from"./FlexItem-BzZfUnQ1.js";import{d as ee,D as ie,a as te,b as le,c as oe}from"./DataListItemRow-BC0LurDd.js";import{T as ne}from"./trash-icon-BkuEbPwb.js";import"react-dom";import"./copy-icon-ACZmDH8e.js";import"./EmptyStateFooter-DqmBOP2I.js";import"./EmptyStateActions-DWNUFByn.js";import"./Td-D2hVFK0Z.js";import"./grip-vertical-icon-BxF7V59o.js";import"./_baseFlatten-eIEJR-AJ.js";const Xe=({name:a,global:t})=>{const{t:n}=j();return c(h,{children:[a," ",t&&i(re,{color:"blue",children:n("global")})]})},Ye=a=>{const{adminClient:t}=ae(),{t:n}=j(),[u,C]=p([]),[f,K]=p();se(()=>t.clientPolicies.listProfiles({includeGlobalProfiles:!0}),y=>{const F=y.globalProfiles?.map(T=>({...T,global:!0})),E=y.profiles?.map(T=>({...T,global:!1}));K([...F??[],...E??[]])},[]);const r=async()=>f?.filter(y=>!a.allProfiles.includes(y.name))??[];return f?i(Ie,{"data-testid":"addClientProfile",title:n("addClientProfile"),isOpen:a.open,onClose:a.toggleDialog,variant:Le.large,actions:[i(k,{"data-testid":"add-client-profile-button",variant:"primary",isDisabled:!u.length,onClick:()=>{a.toggleDialog(),a.onConfirm(u)},children:n("add")},"add"),i(k,{variant:"link",onClick:()=>{a.toggleDialog()},children:n("cancel")},"cancel")],children:i(Qe,{loader:r,ariaLabelKey:"profilesList",searchPlaceholderKey:"searchProfile",canSelectAll:!0,onSelect:y=>{C([...y])},columns:[{name:"name",displayKey:"clientProfileName",cellRenderer:Xe},{name:"description",displayKey:"description"}],emptyState:i(Je,{hasIcon:!0,message:n("noRoles"),instructions:n("noRolesInstructions"),primaryActionText:n("createRole")})})}):i(ce,{})},_e={name:"",description:"",conditions:[],enabled:!0,profiles:[]};function ki(){const{adminClient:a}=ae(),{t}=j(),{realm:n}=Ve(),{addAlert:u,addError:C}=xe(),[f,K]=p(!1),[r,y]=p(),[F,E]=p(),[T,q]=p(),[de,me]=p([]),[g,z]=p(),[D,U]=p(!1),[R,fe]=p(),[W,pe]=p(!1),[B,ue]=p(),{policyName:s}=Ze(),b=Ae(),d=Ke({mode:"onChange",defaultValues:_e}),{handleSubmit:Pe}=d,G=d.getValues();se(async()=>{const[e,l]=await Promise.all([a.clientPolicies.listPolicies({includeGlobalPolicies:!0}),a.clientPolicies.listProfiles({includeGlobalProfiles:!0})]);return{policies:e,profiles:l}},({policies:e,profiles:l})=>{let o=e.policies?.find($=>$.name===s);o===void 0&&(o=e.globalPolicies?.find($=>$.name===s),K(o!==void 0));const P=[...l.globalProfiles??[],...l.profiles??[]],m=[...e.globalPolicies??[],...e.policies??[]];y(e.policies??[]),E(e.globalPolicies??[]),q(m),o&&(Ce(o),me(P),z(o),U(!0))},[]);const Ce=e=>{d.reset(e)},Z=(T||[]).filter(e=>e.name===s),J=Z[0]?.conditions||[],N=Z[0]?.profiles||[],ye=Fe().componentTypes?.["org.keycloak.services.clientpolicy.condition.ClientPolicyConditionProvider"],M=async()=>{const e=d.getValues(),l={...e},o=()=>r?.some(m=>m.name===l.name)?r?.map(m=>m.name===l.name?l:m):e.name!==s?r?.filter(m=>m.name!==s).concat(e):r?.concat(e);try{await a.clientPolicies.updatePolicy({policies:o()}),u(t(s?"updateClientPolicySuccess":"createClientPolicySuccess"),v.success),b(w({realm:n,policyName:e.name})),U(!0)}catch(P){C("createClientPolicyError",P)}},[ge,he]=x({titleKey:t("deleteClientPolicyConfirmTitle"),messageKey:t("deleteClientPolicyConfirm",{policyName:s}),continueButtonLabel:t("delete"),continueButtonVariant:H.danger,onConfirm:async()=>{const e=r?.filter(l=>l.name!==s);try{await a.clientPolicies.updatePolicy({policies:e}),u(t("deleteClientPolicySuccess"),v.success),b(S({realm:n,tab:"policies"}))}catch(l){C(t("deleteClientPolicyError"),l)}}}),[be,ke]=x({titleKey:t("deleteClientPolicyConditionConfirmTitle"),messageKey:t("deleteClientPolicyConditionConfirm",{condition:R?.name}),continueButtonLabel:t("delete"),continueButtonVariant:H.danger,onConfirm:async()=>{if(R?.name){g?.conditions?.splice(R.idx,1);try{await a.clientPolicies.updatePolicy({policies:r}),u(t("deleteConditionSuccess"),v.success),b(w({realm:n,policyName:G.name}))}catch(e){C(t("deleteConditionError"),e)}}else{const e=r?.filter(l=>l.name!==s);try{await a.clientPolicies.updatePolicy({policies:e}),u(t("deleteClientSuccess"),v.success),b(S({realm:n,tab:"policies"}))}catch(l){C(t("deleteClientError"),l)}}}}),[ve,De]=x({titleKey:t("deleteClientPolicyProfileConfirmTitle"),messageKey:t("deleteClientPolicyProfileConfirm",{profileName:B?.name,policyName:s}),continueButtonLabel:t("delete"),continueButtonVariant:H.danger,onConfirm:async()=>{if(B?.name){g?.profiles?.splice(B.idx,1);try{await a.clientPolicies.updatePolicy({policies:r}),u(t("deleteClientPolicyProfileSuccess"),v.success),d.setValue("profiles",g?.profiles||[]),b(w({realm:n,policyName:G.name}))}catch(e){C(t("deleteClientPolicyProfileError"),e)}}else{const e=r?.filter(l=>l.name!==s);try{await a.clientPolicies.updatePolicy({policies:e}),u(t("deleteClientSuccess"),v.success),b(S({realm:n,tab:"policies"}))}catch(l){C(t("deleteClientError"),l)}}}}),Te=()=>{g?.name!==void 0&&d.setValue("name",g.name),g?.description!==void 0&&d.setValue("description",g.description)},Q=()=>{pe(!W)},Ne=async e=>{const l={...g,profiles:N.concat(e),conditions:g?.conditions},o=r?.findIndex(m=>l.name===m.name);if(o===void 0||o===-1)return;const P=[...(r||[]).slice(0,o),l,...(r||[]).slice(o+1)];try{await a.clientPolicies.updatePolicy({policies:P}),y(P);const m=[...F||[],...P];q(m),z(l),d.setValue("profiles",l.profiles),b(w({realm:n,policyName:G.name})),u(t("addClientProfileSuccess"),v.success)}catch(m){C("addClientProfileError",m)}},[Se,we]=x({titleKey:"disablePolicyConfirmTitle",messageKey:"disablePolicyConfirm",continueButtonLabel:"disable",onConfirm:()=>{d.setValue("enabled",!d.getValues().enabled),M()}});return r?c(h,{children:[i(ke,{}),i(De,{}),i(Ye,{onConfirm:e=>{Ne(e.map(l=>l.name))},allProfiles:N,open:W,toggleDialog:Q}),i(Ee,{name:"enabled",defaultValue:!0,control:d.control,render:({field:e})=>c(h,{children:[i(we,{}),i(he,{}),i(We,{titleKey:D||s?s:"createPolicy",badges:[{id:"global-client-policy-badge",text:f?i(re,{color:"blue",children:t("global")}):""}],divider:!0,dropdownItems:(D||s)&&!f?[i(Re,{value:"delete",onClick:()=>{ge()},"data-testid":"deleteClientPolicyDropdown",children:t("deleteClientPolicy")},"delete")]:void 0,isReadOnly:f,isEnabled:e.value,onToggle:l=>{l?(e.onChange(l),M()):Se()}})]})}),i(Be,{variant:"light",children:i(Ue,{onSubmit:Pe(M),isHorizontal:!0,role:"view-realm",className:"pf-v5-u-mt-lg",children:c(Ge,{...d,children:[i(Me,{name:"name",label:t("name"),rules:{required:{value:!0,message:t("required")},validate:e=>r.some(l=>l.name===e)?t("createClientProfileNameHelperText").toString():!0}}),i($e,{label:t("description"),fieldId:"kc-description",children:i(He,{"aria-label":t("description"),id:"kc-client-policy-description","data-testid":"client-policy-description",...d.register("description")})}),c(Oe,{children:[i(k,{variant:"primary",type:"submit","data-testid":"saveCreatePolicy",isDisabled:!d.formState.isValid||f,children:t("save")}),i(k,{id:"cancelCreatePolicy",variant:"link",onClick:()=>(D||s)&&!f?Te():b(S({realm:n,tab:"policies"})),"data-testid":"cancelCreatePolicy",children:t(D&&!f?"reload":"cancel")})]}),(D||d.formState.isSubmitted)&&c(h,{children:[c(_,{children:[i(A,{children:c(I,{className:"kc-conditions",component:L.h1,children:[t("conditions"),i(V,{helpText:t("conditionsHelp"),fieldLabelId:"conditions"})]})}),!f&&i(A,{align:{default:"alignRight"},children:i(k,{id:"addCondition",component:e=>i(O,{...e,to:je({realm:n,policyName:s})}),variant:"link",className:"kc-addCondition","data-testid":"addCondition",icon:i(X,{}),children:t("addCondition")})})]}),J.length>0?i(ee,{"aria-label":t("conditions"),isCompact:!0,children:J.map((e,l)=>i(ie,{"aria-labelledby":"conditions-list-item",id:e.condition,"data-testid":"conditions-list-item",children:i(te,{"data-testid":"conditions-list-row",children:i(le,{dataListCells:[c(oe,{"data-testid":"condition-type",children:[Object.keys(e.configuration).length!==0?i(O,{"data-testid":`${e.condition}-condition-link`,to:qe({realm:n,conditionName:e.condition,policyName:s}),className:"kc-condition-link",children:e.condition},e.condition):e.condition,ye?.map(o=>o.id===e.condition&&c(h,{children:[i(V,{helpText:o.helpText,fieldLabelId:e.condition}),!f&&i(k,{variant:"link","aria-label":"remove-condition",isInline:!0,icon:i(ne,{className:"kc-conditionType-trash-icon","data-testid":`delete-${e.condition}-condition`,onClick:()=>{be(),fe({idx:l,name:o.id})}})})]}))]},`name-${l}`)]})})},`list-item-${l}`))}):c(h,{children:[i(Y,{}),i(I,{className:"kc-emptyConditions",component:L.h2,children:t("emptyConditions")})]})]}),(D||d.formState.isSubmitted)&&c(h,{children:[c(_,{children:[i(A,{children:c(I,{className:"kc-client-profiles",component:L.h1,children:[t("clientProfiles"),i(V,{helpText:t("clientProfilesHelp"),fieldLabelId:"clientProfiles"})]})}),!f&&i(A,{align:{default:"alignRight"},children:i(k,{id:"addClientProfile",variant:"link",className:"kc-addClientProfile","data-testid":"addClientProfile",icon:i(X,{}),onClick:Q,children:t("addClientProfile")})})]}),N.length>0?i(ee,{"aria-label":t("profiles"),isCompact:!0,children:N.map((e,l)=>i(ie,{"aria-labelledby":`${e}-profile-list-item`,id:`${e}-profile-list-item`,"data-testid":"profile-list-item",children:i(te,{"data-testid":"profile-list-row",children:i(le,{dataListCells:[c(oe,{"data-testid":"profile-name",children:[e&&i(O,{"data-testid":"profile-name-link",to:ze({realm:n,profileName:e}),className:"kc-profile-link",children:e},e),N.filter(o=>o===e).map(o=>c(h,{children:[i(V,{helpText:de.find(P=>o===P.name)?.description,fieldLabelId:e}),!f&&i(k,{variant:"link","aria-label":"remove-client-profile",isInline:!0,icon:i(ne,{className:"kc-conditionType-trash-icon","data-testid":"deleteClientProfileDropdown",onClick:()=>{ve(),ue({idx:l,name:o})}})})]}))]},"name")]})})},e))}):c(h,{children:[i(Y,{}),i(I,{className:"kc-emptyClientProfiles",component:L.h2,children:t("emptyProfiles")})]})]})]})})})]}):i(ce,{})}export{ki as default};
//# sourceMappingURL=NewClientPolicy-CnABlseI.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy