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

theme.keycloak.v2.admin.resources.assets.NewClientPolicy-B5wSExYx.js Maven / Gradle / Ivy

There is a newer version: 26.0.7
Show newest version
import{jsx as i,jsxs as c,Fragment as g}from"react/jsx-runtime";import{u as ae,a as j,v as se,a3 as ce,M as Ie,q as Le,h as v,o as re,c as Ve,f as xe,d as Ae,g as Ke,b as Fe,B as H,j as k,dT as N,dS as w,ae as Ee,D as Re,P as Be,F as Ge,x as Me,ac as $e,d2 as He,A as Oe,Z as I,$ as L,ad as V,L as O,eb as je,as as X,ec as qe,ar as Y,dV as ze}from"./index-C1LIsRX7.js";import{useState as p}from"react";import{u as x}from"./ConfirmDialog-B5qjiAuo.js";import{F as Ze}from"./FormAccess-BcY70QlP.js";import{V as Je}from"./ViewHeader-qjLr6U82.js";import{u as Qe}from"./useParams-n_2fXkN1.js";import{L as Ue}from"./PaginatingTableToolbar-CpMLQtqt.js";import{K as We}from"./KeycloakDataTable-jyvvxdb8.js";/* empty css                               */import{F as _,a as A}from"./FlexItem-DCAd8FXq.js";import{d as ee,D as ie,a as te,b as le,c as oe}from"./DataListItemRow-COCiEHyF.js";import{T as ne}from"./trash-icon-DDaN0w_B.js";import"react-dom";import"./copy-icon-DOS8MmN7.js";import"./EmptyStateFooter-Cm2IMTi1.js";import"./EmptyStateActions-DBSnfkAA.js";import"./Td-BwjBKSkH.js";import"./grip-vertical-icon-Bnn0MebT.js";import"./_baseFlatten-BHAcGTxk.js";const Xe=({name:a,global:t})=>{const{t:n}=j();return c(g,{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(v,{"data-testid":"add-client-profile-button",variant:"primary",isDisabled:!u.length,onClick:()=>{a.toggleDialog(),a.onConfirm(u)},children:n("add")},"add"),i(v,{variant:"link",onClick:()=>{a.toggleDialog()},children:n("cancel")},"cancel")],children:i(We,{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(Ue,{hasIcon:!0,message:n("noRoles"),instructions:n("noRolesInstructions"),primaryActionText:n("createRole")})})}):i(ce,{})},_e={name:"",description:"",conditions:[],enabled:!0,profiles:[]};function vi(){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([]),[h,z]=p(),[D,Z]=p(!1),[R,fe]=p(),[J,pe]=p(!1),[B,ue]=p(),{policyName:s}=Qe(),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),Z(!0))},[]);const Ce=e=>{d.reset(e)},Q=(T||[]).filter(e=>e.name===s),U=Q[0]?.conditions||[],S=Q[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"),k.success),b(w({realm:n,policyName:e.name})),Z(!0)}catch(P){C("createClientPolicyError",P)}},[he,ge]=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"),k.success),b(N({realm:n,tab:"policies"}))}catch(l){C(t("deleteClientPolicyError"),l)}}}),[be,ve]=x({titleKey:t("deleteClientPolicyConditionConfirmTitle"),messageKey:t("deleteClientPolicyConditionConfirm",{condition:R?.name}),continueButtonLabel:t("delete"),continueButtonVariant:H.danger,onConfirm:async()=>{if(R?.name){h?.conditions?.splice(R.idx,1);try{await a.clientPolicies.updatePolicy({policies:r}),u(t("deleteConditionSuccess"),k.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"),k.success),b(N({realm:n,tab:"policies"}))}catch(l){C(t("deleteClientError"),l)}}}}),[ke,De]=x({titleKey:t("deleteClientPolicyProfileConfirmTitle"),messageKey:t("deleteClientPolicyProfileConfirm",{profileName:B?.name,policyName:s}),continueButtonLabel:t("delete"),continueButtonVariant:H.danger,onConfirm:async()=>{if(B?.name){h?.profiles?.splice(B.idx,1);try{await a.clientPolicies.updatePolicy({policies:r}),u(t("deleteClientPolicyProfileSuccess"),k.success),d.setValue("profiles",h?.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"),k.success),b(N({realm:n,tab:"policies"}))}catch(l){C(t("deleteClientError"),l)}}}}),Te=()=>{h?.name!==void 0&&d.setValue("name",h.name),h?.description!==void 0&&d.setValue("description",h.description)},W=()=>{pe(!J)},Se=async e=>{const l={...h,profiles:S.concat(e),conditions:h?.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"),k.success)}catch(m){C("addClientProfileError",m)}},[Ne,we]=x({titleKey:"disablePolicyConfirmTitle",messageKey:"disablePolicyConfirm",continueButtonLabel:"disable",onConfirm:()=>{d.setValue("enabled",!d.getValues().enabled),M()}});return r?c(g,{children:[i(ve,{}),i(De,{}),i(Ye,{onConfirm:e=>{Se(e.map(l=>l.name))},allProfiles:S,open:J,toggleDialog:W}),i(Ee,{name:"enabled",defaultValue:!0,control:d.control,render:({field:e})=>c(g,{children:[i(we,{}),i(ge,{}),i(Je,{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:()=>{he()},"data-testid":"deleteClientPolicyDropdown",children:t("deleteClientPolicy")},"delete")]:void 0,isReadOnly:f,isEnabled:e.value,onToggle:l=>{l?(e.onChange(l),M()):Ne()}})]})}),i(Be,{variant:"light",children:i(Ze,{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(v,{variant:"primary",type:"submit","data-testid":"saveCreatePolicy",isDisabled:!d.formState.isValid||f,children:t("save")}),i(v,{id:"cancelCreatePolicy",variant:"link",onClick:()=>(D||s)&&!f?Te():b(N({realm:n,tab:"policies"})),"data-testid":"cancelCreatePolicy",children:t(D&&!f?"reload":"cancel")})]}),(D||d.formState.isSubmitted)&&c(g,{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(v,{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")})})]}),U.length>0?i(ee,{"aria-label":t("conditions"),isCompact:!0,children:U.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(g,{children:[i(V,{helpText:o.helpText,fieldLabelId:e.condition}),!f&&i(v,{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(g,{children:[i(Y,{}),i(I,{className:"kc-emptyConditions",component:L.h2,children:t("emptyConditions")})]})]}),(D||d.formState.isSubmitted)&&c(g,{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(v,{id:"addClientProfile",variant:"link",className:"kc-addClientProfile","data-testid":"addClientProfile",icon:i(X,{}),onClick:W,children:t("addClientProfile")})})]}),S.length>0?i(ee,{"aria-label":t("profiles"),isCompact:!0,children:S.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),S.filter(o=>o===e).map(o=>c(g,{children:[i(V,{helpText:de.find(P=>o===P.name)?.description,fieldLabelId:e}),!f&&i(v,{variant:"link","aria-label":"remove-client-profile",isInline:!0,icon:i(ne,{className:"kc-conditionType-trash-icon","data-testid":"deleteClientProfileDropdown",onClick:()=>{ke(),ue({idx:l,name:o})}})})]}))]},"name")]})})},e))}):c(g,{children:[i(Y,{}),i(I,{className:"kc-emptyClientProfiles",component:L.h2,children:t("emptyProfiles")})]})]})]})})})]}):i(ce,{})}export{vi as default};
//# sourceMappingURL=NewClientPolicy-B5wSExYx.js.map




© 2015 - 2025 Weber Informatics LLC | Privacy Policy