theme.keycloak.v2.admin.resources.assets.GroupsSection-BcH1Eqbu.js Maven / Gradle / Ivy
import{jsxs as D,jsx as n,Fragment as H}from"react/jsx-runtime";import*as R from"react";import E,{useState as I,useEffect as Re,useRef as Ge}from"react";import{_ as ae,l as _,ce as ge,ar as Oe,bG as Ee,cf as Ze,m as De,aM as Ie,cg as ke,ch as xe,n as et,ci as tt,cj as nt,a as U,ck as X,c as se,bK as re,cl as at,cm as Se,L as de,u as P,f as W,g as Le,v as ue,P as Be,cn as Ke,bP as st,Q as rt,S as ot,j as me,M as it,q as ct,p as lt,h as oe,B as Fe,F as dt,r as ut,x as mt,b3 as ie,a2 as J,J as fe,K as be,aB as ve,N as we,D as Q,co as pt,a3 as Ue,bR as $e,aC as he,bx as ht,cp as gt,d as ye,bb as ft,bc as Te,cq as Ve,c7 as te,I as je,cr as bt,aH as vt,aI as wt,cs as yt,ct as Ct,cu as Nt,cv as Gt,cb as Et,au as It}from"./index-C1LIsRX7.js";import{P as kt}from"./PermissionTab-DXe9jq3w.js";import{V as xt}from"./ViewHeader-qjLr6U82.js";import{u as q}from"./useToggle-K3Kx99tM.js";import{A as St}from"./AttributeForm-DDUkni1v.js";import{R as Tt}from"./AddRoleMappingModal-Ds4yp8lg.js";import{L as qe,P as Vt}from"./PaginatingTableToolbar-CpMLQtqt.js";import{l as At,i as Ae,K as He}from"./KeycloakDataTable-jyvvxdb8.js";import{C as Mt}from"./ConfirmDialog-B5qjiAuo.js";import{G as _t,a as Rt}from"./GroupPickerDialog-DmX3SBxL.js";import{M as Ot}from"./MembersModal-BMzek0-s.js";import{b as Dt,a as Lt}from"./_baseFlatten-BHAcGTxk.js";import{T as Bt,a as Z,b as ee}from"./Tabs-CNBvRApH.js";import"react-dom";import"./Trans-DZTM8FLp.js";import"./Td-BwjBKSkH.js";import"./grip-vertical-icon-Bnn0MebT.js";import"./FormAccess-BcY70QlP.js";import"./copy-icon-DOS8MmN7.js";import"./KeyValueInput-CoupoYmE.js";import"./KeySelect-B2uWUd6C.js";import"./EmptyStateFooter-Cm2IMTi1.js";import"./filter-icon-BVyMUArZ.js";import"./EmptyStateActions-DBSnfkAA.js";import"./DataListItemRow-COCiEHyF.js";const ze=t=>{var{className:e="",children:a,hasNoPadding:o=!1}=t,r=ae(t,["className","children","hasNoPadding"]);return R.createElement("div",Object.assign({className:_(ge.drawerBody,o&&ge.modifiers.noPadding,e)},r),a)};ze.displayName="DrawerPanelBody";const Pe=t=>{var{className:e="",children:a,hasNoPadding:o=!1}=t,r=ae(t,["className","children","hasNoPadding"]);return R.createElement(ze,{hasNoPadding:o},R.createElement("div",Object.assign({className:_(ge.drawerHead,e)},r),a))};Pe.displayName="DrawerHead";const y={badge:"pf-v5-c-badge",dirRtl:"pf-v5-m-dir-rtl",modifiers:{compact:"pf-m-compact",guides:"pf-m-guides",expanded:"pf-m-expanded",noBackground:"pf-m-no-background",current:"pf-m-current",read:"pf-m-read",selectable:"pf-m-selectable",truncate:"pf-m-truncate"},themeDark:"pf-v5-theme-dark",treeView:"pf-v5-c-tree-view",treeViewAction:"pf-v5-c-tree-view__action",treeViewContent:"pf-v5-c-tree-view__content",treeViewListItem:"pf-v5-c-tree-view__list-item",treeViewNode:"pf-v5-c-tree-view__node",treeViewNodeCheck:"pf-v5-c-tree-view__node-check",treeViewNodeContainer:"pf-v5-c-tree-view__node-container",treeViewNodeContent:"pf-v5-c-tree-view__node-content",treeViewNodeCount:"pf-v5-c-tree-view__node-count",treeViewNodeIcon:"pf-v5-c-tree-view__node-icon",treeViewNodeText:"pf-v5-c-tree-view__node-text",treeViewNodeTitle:"pf-v5-c-tree-view__node-title",treeViewNodeToggle:"pf-v5-c-tree-view__node-toggle",treeViewNodeToggleIcon:"pf-v5-c-tree-view__node-toggle-icon",treeViewSearch:"pf-v5-c-tree-view__search"},Qe=t=>{var{isNested:e=!1,toolbar:a,children:o}=t,r=ae(t,["isNested","toolbar","children"]);return R.createElement(R.Fragment,null,a&&R.createElement(R.Fragment,null,a,R.createElement(Oe,null)),R.createElement("ul",Object.assign({className:_(`${y.treeView}__list`),role:e?"group":"tree"},r),o))};Qe.displayName="TreeViewList";const Kt=({name:t,title:e,id:a,isExpanded:o,defaultExpanded:r=!1,children:i=null,onSelect:l,onExpand:s,onCollapse:d,onCheck:c,hasCheckbox:p=!1,checkProps:N={checked:!1},hasBadge:g=!1,customBadgeContent:G,badgeProps:h={isRead:!0},isSelectable:w=!1,isCompact:S,activeItems:M=[],itemData:k,parentItem:T,icon:x,expandedIcon:$,action:L,compareItems:B,useMemo:u})=>{const[m,C]=I(r);Re(()=>{o!=null?C(o):r!=null&&C(m||r)},[o,r]);let v="button";p?v="label":w&&(v="div");const F=p||w?"button":"span",O=b=>E.createElement(F,Object.assign({className:_(y.treeViewNodeToggle),onClick:f=>{(w||p)&&(m?d&&d(f,k,T):s&&s(f,k,T),C(!m)),w&&f.stopPropagation()}},(p||w)&&{"aria-labelledby":`label-${b}`},F==="button"&&{type:"button"},{tabIndex:-1}),E.createElement("span",{className:_(y.treeViewNodeToggleIcon)},E.createElement(De,{"aria-hidden":"true"}))),V=b=>E.createElement("span",{className:_(y.treeViewNodeCheck)},E.createElement("input",Object.assign({type:"checkbox",onChange:f=>c&&c(f,k,T),onClick:f=>f.stopPropagation(),ref:f=>f&&(f.indeterminate=N.checked===null)},N,{checked:N.checked===null?!1:N.checked,id:b,tabIndex:-1}))),K=E.createElement("span",{className:_(y.treeViewNodeIcon)},!m&&x,m&&($||x)),Y=()=>{const b=E.createElement(E.Fragment,null,S&&e&&E.createElement("span",{className:_(y.treeViewNodeTitle)},e),w?E.createElement("button",{tabIndex:-1,className:_(y.treeViewNodeText),type:"button"},t):E.createElement("span",{className:_(y.treeViewNodeText)},t));return S?E.createElement("span",{className:_(y.treeViewNodeContent)},b):b},ce=E.createElement(E.Fragment,null,g&&i&&E.createElement("span",{className:_(y.treeViewNodeCount)},E.createElement(Ee,Object.assign({},h),G||i.props.data.length)),g&&!i&&G!==void 0&&E.createElement("span",{className:_(y.treeViewNodeCount)},E.createElement(Ee,Object.assign({},h),G)));return E.createElement("li",{id:a,className:_(y.treeViewListItem,m&&y.modifiers.expanded),"aria-expanded":m,role:"treeitem",tabIndex:-1},E.createElement("div",{className:_(y.treeViewContent)},E.createElement(Ze,{prefix:w?"selectable-id":"checkbox-id"},b=>E.createElement(v,Object.assign({className:_(y.treeViewNode,i&&(w||p)&&y.modifiers.selectable,(!i||w)&&M&&M.length>0&&M.some(f=>B&&f&&B(f,k))?y.modifiers.current:""),onClick:f=>{p||(l&&l(f,k,T),!w&&i&&f.isDefaultPrevented()!==!0&&(m?d&&d(f,k,T):s&&s(f,k,T),C(!m)))}},p&&{htmlFor:b},(p||w&&i)&&{id:`label-${b}`},v==="button"&&{type:"button"}),E.createElement("span",{className:_(y.treeViewNodeContainer)},i&&O(b),p&&V(b),x&&K,Y(),ce))),L&&E.createElement("div",{className:_(y.treeViewAction)},L)),m&&i)},We=E.memo(Kt,(t,e)=>{if(!e.useMemo)return!1;const a=t.activeItems&&t.activeItems.length>0&&t.activeItems.some(r=>t.compareItems&&r&&t.compareItems(r,t.itemData)),o=e.activeItems&&e.activeItems.length>0&&e.activeItems.some(r=>e.compareItems&&r&&e.compareItems(r,e.itemData));return!(a||o||t.name!==e.name||t.title!==e.title||t.id!==e.id||t.isExpanded!==e.isExpanded||t.defaultExpanded!==e.defaultExpanded||t.onSelect!==e.onSelect||t.onCheck!==e.onCheck||t.onExpand!==e.onExpand||t.onCollapse!==e.onCollapse||t.hasCheckbox!==e.hasCheckbox||t.checkProps!==e.checkProps||t.hasBadge!==e.hasBadge||t.customBadgeContent!==e.customBadgeContent||t.badgeProps!==e.badgeProps||t.isCompact!==e.isCompact||t.icon!==e.icon||t.expandedIcon!==e.expandedIcon||t.action!==e.action||t.parentItem!==e.parentItem||t.itemData!==e.itemData)});We.displayName="TreeViewListItem";class Ft extends R.Component{constructor(){super(...arguments),this.displayName="TreeViewRoot",this.treeRef=R.createRef(),this.handleKeys=e=>{var a,o,r,i,l,s,d;if(!this.treeRef.current.contains(e.target)||!e.target.classList.contains(y.treeViewNode))return;const c=document.activeElement,p=e.key,N=Array.from((a=this.treeRef.current)===null||a===void 0?void 0:a.getElementsByClassName(y.treeViewNode)).filter(g=>!g.classList.contains("pf-m-disabled"));if(p===Ie.Space&&(c.click(),e.preventDefault()),ke(e,N,g=>c===g,void 0,[],void 0,!0,!0),["ArrowLeft","ArrowRight"].includes(p)){const g=(r=(o=c?.firstElementChild)===null||o===void 0?void 0:o.firstElementChild)===null||r===void 0?void 0:r.classList.contains(y.treeViewNodeToggle),G=(i=c?.closest("li"))===null||i===void 0?void 0:i.classList.contains("pf-m-expanded");if(p==="ArrowLeft")if(g&&G)c.click();else{const h=(l=c?.closest("ul"))===null||l===void 0?void 0:l.parentElement;if(h?.tagName!=="DIV"){const w=h?.querySelector("button");c.tabIndex=-1,w&&(w.tabIndex=0,w.focus())}}else if(g&&!G){c.tabIndex=-1,c.click();const h=(d=(s=c?.closest("li"))===null||s===void 0?void 0:s.querySelector("ul > li"))===null||d===void 0?void 0:d.querySelector("button");h&&(h.tabIndex=0,h.focus())}e.preventDefault()}},this.handleKeysCheckbox=e=>{var a,o,r,i,l;if(!this.treeRef.current.contains(e.target))return;const s=document.activeElement,d=e.key;d===Ie.Space&&(s.click(),e.preventDefault());const c=Array.from((a=this.treeRef.current)===null||a===void 0?void 0:a.getElementsByClassName(y.treeViewNode));ke(e,c,p=>p.contains(s),p=>p.querySelector("button,input"),[],void 0,!0,!0),["ArrowLeft","ArrowRight"].includes(d)&&(d==="ArrowLeft"?s?.tagName==="INPUT"?!((o=s?.parentElement)===null||o===void 0)&&o.previousSibling&&s.parentElement.previousSibling.focus():s?.previousSibling&&(((r=s.previousElementSibling)===null||r===void 0?void 0:r.tagName)==="SPAN"?s.previousSibling.firstChild.focus():s.previousSibling.focus()):s?.tagName==="INPUT"?!((i=s.parentElement)===null||i===void 0)&&i.nextSibling&&s.parentElement.nextSibling.focus():s?.nextSibling&&(((l=s.nextElementSibling)===null||l===void 0?void 0:l.tagName)==="SPAN"?s.nextSibling.firstChild.focus():s.nextSibling.focus()),e.preventDefault())},this.variantStyleModifiers={default:"",compact:y.modifiers.compact,compactNoBackground:[y.modifiers.compact,y.modifiers.noBackground]}}componentDidMount(){var e;if(xe&&window.addEventListener("keydown",this.props.hasCheckboxes||this.props.hasSelectableNodes?this.handleKeysCheckbox:this.handleKeys),this.props.hasCheckboxes||this.props.hasSelectableNodes){const a=this.treeRef.current.getElementsByClassName(y.treeViewNodeToggle)[0];if(a&&(a.tabIndex=0),this.props.hasCheckboxes){const o=this.treeRef.current.getElementsByTagName("INPUT")[0];o&&(o.tabIndex=0)}if(this.props.hasSelectableNodes){const o=this.treeRef.current.getElementsByClassName(y.treeViewNodeText)[0];o&&(o.tabIndex=0)}}else((e=this.treeRef.current)===null||e===void 0?void 0:e.getElementsByClassName(y.treeViewNode)[0]).tabIndex=0}componentWillUnmount(){xe&&window.removeEventListener("keydown",this.props.hasCheckboxes||this.props.hasSelectableNodes?this.handleKeysCheckbox:this.handleKeys)}render(){const e=this.props,{children:a,hasCheckboxes:o,hasGuides:r,variant:i,className:l,hasSelectableNodes:s}=e,d=ae(e,["children","hasCheckboxes","hasGuides","variant","className","hasSelectableNodes"]);return R.createElement("div",Object.assign({className:_(y.treeView,r&&y.modifiers.guides,this.variantStyleModifiers[i],l),ref:this.treeRef},d),a)}}const Ce=t=>{var{data:e,isNested:a=!1,hasCheckboxes:o=!1,hasBadges:r=!1,hasGuides:i=!1,hasSelectableNodes:l=!1,variant:s="default",defaultAllExpanded:d=!1,allExpanded:c,icon:p,expandedIcon:N,parentItem:g,onSelect:G,onCheck:h,onExpand:w,onCollapse:S,toolbar:M,activeItems:k,compareItems:T=(u,m)=>u.id===m.id,className:x,useMemo:$}=t,L=ae(t,["data","isNested","hasCheckboxes","hasBadges","hasGuides","hasSelectableNodes","variant","defaultAllExpanded","allExpanded","icon","expandedIcon","parentItem","onSelect","onCheck","onExpand","onCollapse","toolbar","activeItems","compareItems","className","useMemo"]);const B=R.createElement(Qe,{isNested:a,toolbar:M},e.map(u=>{var m,C;return R.createElement(We,Object.assign({key:((m=u.id)===null||m===void 0?void 0:m.toString())||((C=u.name)===null||C===void 0?void 0:C.toString()),name:u.name,title:u.title,id:u.id,isExpanded:c,isSelectable:l,defaultExpanded:u.defaultExpanded!==void 0?u.defaultExpanded:d,onSelect:G,onCheck:h,onExpand:w,onCollapse:S,hasCheckbox:u.hasCheckbox!==void 0?u.hasCheckbox:o,checkProps:u.checkProps,hasBadge:u.hasBadge!==void 0?u.hasBadge:r,customBadgeContent:u.customBadgeContent,badgeProps:u.badgeProps,activeItems:k,parentItem:g,itemData:u,icon:u.icon!==void 0?u.icon:p,expandedIcon:u.expandedIcon!==void 0?u.expandedIcon:N,action:u.action,compareItems:T,isCompact:s==="compact"||s==="compactNoBackground",useMemo:$},u.children&&{children:R.createElement(Ce,{data:u.children,isNested:!0,parentItem:u,hasCheckboxes:o,hasBadges:r,hasGuides:i,hasSelectableNodes:l,variant:s,allExpanded:c,defaultAllExpanded:d,onSelect:G,onCheck:h,onExpand:w,onCollapse:S,activeItems:k,icon:p,expandedIcon:N})}))}));return R.createElement(R.Fragment,null,g?B:R.createElement(Ft,Object.assign({hasSelectableNodes:l,hasCheckboxes:o,hasGuides:i,variant:s,className:x},L),B))};Ce.displayName="TreeView";const Ut={name:"TreeIcon",height:512,width:384,svgPath:"M378.31 378.49L298.42 288h30.63c9.01 0 16.98-5 20.78-13.06 3.8-8.04 2.55-17.26-3.28-24.05L268.42 160h28.89c9.1 0 17.3-5.35 20.86-13.61 3.52-8.13 1.86-17.59-4.24-24.08L203.66 4.83c-6.03-6.45-17.28-6.45-23.32 0L70.06 122.31c-6.1 6.49-7.75 15.95-4.24 24.08C69.38 154.65 77.59 160 86.69 160h28.89l-78.14 90.91c-5.81 6.78-7.06 15.99-3.27 24.04C37.97 283 45.93 288 54.95 288h30.63L5.69 378.49c-6 6.79-7.36 16.09-3.56 24.26 3.75 8.05 12 13.25 21.01 13.25H160v24.45l-30.29 48.4c-5.32 10.64 2.42 23.16 14.31 23.16h95.96c11.89 0 19.63-12.52 14.31-23.16L224 440.45V416h136.86c9.01 0 17.26-5.2 21.01-13.25 3.8-8.17 2.44-17.47-3.56-24.26z",yOffset:0,xOffset:0},$t=et(Ut);var Me=Dt(function(t){var e=At(t);return Ae(e)&&(e=void 0),tt(Lt(t,1,Ae,!0),nt(e))});const jt=()=>{const{t}=U(),{clear:e,remove:a,subGroups:o}=X(),{realm:r}=se(),i=re();return Re(()=>{const{pathname:l}=i;(!l.includes("/groups")||l.endsWith("/groups"))&&e()},[i]),o.length!==0?D(at,{children:[n(Se,{children:n(de,{to:`/${r}/groups`,children:t("groups")})},"home"),o.map((l,s)=>{const d=s===o.length-1;return D(Se,{isActive:d,children:[!d&&n(de,{to:i.pathname.substring(0,i.pathname.indexOf(l.id)+l.id.length),onClick:()=>a(l),children:l.name}),d&&(l.id==="search"?l.name:t("groupDetails"))]},l.id)})]}):null},Je=t=>{const e=t.substr(1).split("/");return e.length>1?e.splice(2):void 0},pe=t=>{const e=Je(t);return e?e[e.length-1]:void 0},qt=()=>{const{adminClient:t}=P(),{t:e}=U(),{addAlert:a,addError:o}=W(),r=Le({mode:"onChange"}),i=re(),l=pe(i.pathname),[s,d]=I();ue(()=>t.groups.findOne({id:l}),p=>{rt(p,r.setValue),d(p)},[l]);const c=async p=>{try{const N=ot(p).attributes;await t.groups.update({id:l},{...s,attributes:N}),d({...s,attributes:N}),a(e("groupUpdated"),me.success)}catch(N){o("groupUpdateError",N)}};return n(Be,{variant:Ke.light,children:n(St,{form:r,save:c,fineGrainedAccess:s?.access?.manage,reset:()=>r.reset({attributes:st(s?.attributes)})})})},Ht=({id:t,name:e})=>{const{adminClient:a}=P(),{t:o}=U(),{addAlert:r,addError:i}=W();return n(Tt,{name:e,id:t,type:"groups",save:async s=>{try{const d=s.filter(c=>c.client===void 0).map(c=>c.role).flat();await a.groups.addRealmRoleMappings({id:t,roles:d}),await Promise.all(s.filter(c=>c.client!==void 0).map(c=>a.groups.addClientRoleMappings({id:t,clientUniqueId:c.client.id,roles:[c.role]}))),r(o("roleMappingUpdatedSuccess"),me.success)}catch(d){i("roleMappingUpdatedError",d)}}})},ne=({id:t,rename:e,handleModalToggle:a,refresh:o})=>{const{adminClient:r}=P(),{t:i}=U(),{addAlert:l,addError:s}=W(),d=Le({defaultValues:{name:e?.name}}),{handleSubmit:c,formState:p}=d,N=async g=>{g.name=g.name?.trim();try{t?e?await r.groups.update({id:t},{...e,name:g.name}):await(g.id?r.groups.updateChildGroup({id:t},g):r.groups.createChildGroup({id:t},g)):await r.groups.create(g),o(e?{...e,name:g.name}:void 0),a(),l(i(e?"groupUpdated":"groupCreated"),me.success)}catch(G){s("couldNotCreateGroup",G)}};return n(it,{variant:ct.small,title:i(e?"renameAGroup":"createAGroup"),isOpen:!0,onClose:a,actions:[n(lt,{formState:p,"data-testid":`${e?"rename":"create"}Group`,form:"group-form",allowInvalid:!0,allowNonDirty:!0,children:i(e?"rename":"create")},"confirm"),n(oe,{id:"modal-cancel","data-testid":"cancel",variant:Fe.link,onClick:()=>{a()},children:i("cancel")},"cancel")],children:n(dt,{...d,children:n(ut,{id:"group-form",isHorizontal:!0,onSubmit:c(N),children:n(mt,{name:"name",label:i("name"),rules:{required:i("required")},autoFocus:!0})})})})},Ne=({selectedRows:t,show:e,toggleDialog:a,refresh:o})=>{const{adminClient:r}=P(),{t:i}=U(),{addAlert:l,addError:s}=W(),d=async()=>{try{for(const c of t)await r.groups.del({id:c.id});o(),l(i("groupDeleted",{count:t.length}))}catch(c){s("groupDeleteError",c)}};return n(Mt,{titleKey:i("deleteConfirmTitle",{count:t.length}),messageKey:i("deleteConfirmGroup",{count:t.length,groupName:t[0]?.name}),continueButtonLabel:"delete",continueButtonVariant:Fe.danger,onConfirm:d,open:e,toggleDialog:a})},zt=({toggleCreate:t,toggleDelete:e,kebabDisabled:a})=>{const{t:o}=U(),{currentGroup:r}=X(),{hasAccess:i}=ie(),l=i("manage-users")||r()?.access?.manage,[s,d]=q();return l?D(H,{children:[n(J,{children:n(oe,{"data-testid":"openCreateGroupModal",variant:"primary",onClick:t,children:o("createGroup")})}),n(J,{children:n(fe,{toggle:c=>n(be,{ref:c,isExpanded:s,onClick:d,isDisabled:a,variant:"plain","aria-label":"Actions",children:n(ve,{})}),isOpen:s,children:n(we,{children:n(Q,{component:"button",onClick:()=>{e(),d()},children:o("delete")},"action")})})})]}):n("div",{})},Pt=(t,e)=>e.id?t.groups.updateRoot(e):t.groups.create(e),Qt=async(t,e,a)=>t.groups.updateChildGroup({id:a.id},e),Xe=({source:t,onClose:e,refresh:a})=>{const{adminClient:o}=P(),{t:r}=U(),{addAlert:i,addError:l}=W();return n(_t,{type:"selectOne",filterGroups:[t],text:{title:"moveToGroup",ok:"moveHere"},onClose:e,onConfirm:async d=>{try{await(d?Qt(o,t,d[0]):Pt(o,t)),a(),i(r("moveGroupSuccess"))}catch(c){l("moveGroupError",c)}},isMove:!0})},_e=({refresh:t})=>{const{adminClient:e}=P(),{t:a}=U(),[o,r]=I([]),[i,l]=I(),[s,d]=q(),[c,p]=q(),[N,g]=I(),{currentGroup:G}=X(),[h,w]=I(0),S=()=>w(h+1),[M,k]=I(),T=re(),x=pe(T.pathname),{hasAccess:$}=ie(),L=$("manage-users")||G()?.access?.manage,B=async(u,m)=>{let C;if(x){const v={search:M||"",first:u,max:m,parentId:x};C=await e.groups.listSubGroups(v)}else{const v={search:M||"",first:u||void 0,max:m||void 0};C=await e.groups.find(v)}return C};return D(H,{children:[n(Ne,{show:c,toggleDialog:p,selectedRows:o,refresh:()=>{S(),t(),r([])}}),i&&n(ne,{id:i.id,rename:i,refresh:()=>{S(),t()},handleModalToggle:()=>l(void 0)}),s&&n(ne,{id:o[0]?.id||x,handleModalToggle:d,refresh:()=>{r([]),S(),t()}}),N&&n(Xe,{source:N,refresh:()=>{g(void 0),S(),t()},onClose:()=>g(void 0)}),n(He,{onSelect:u=>r([...u]),canSelectAll:!0,loader:B,ariaLabelKey:"groups",isPaginated:!0,isSearching:!!M,toolbarItem:D(H,{children:[n(J,{children:n(pt,{"data-testid":"group-search",placeholder:a("filterGroups"),value:M,onChange:(u,m)=>{k(m)},onSearch:S,onClear:()=>{k(""),S()}})}),n(zt,{toggleCreate:d,toggleDelete:p,kebabDisabled:o.length===0})]}),actions:L?[{title:a("rename"),onRowClick:async u=>(l(u),!1)},{title:a("moveTo"),onRowClick:async u=>(g(u),!1)},{title:a("createChildGroup"),onRowClick:async u=>(r([u]),d(),!1)},{isSeparator:!0},{title:a("delete"),onRowClick:async u=>(r([u]),p(),!0)}]:[],columns:[{name:"name",displayKey:"groupName",cellRenderer:u=>u.access?.view?n(de,{to:`${T.pathname}/${u.id}`,children:u.name},u.id):n("span",{children:u.name})}],emptyState:n(qe,{hasIcon:!0,message:a(`noGroupsInThis${x?"SubGroup":"Realm"}`),instructions:a(`noGroupsInThis${x?"SubGroup":"Realm"}Instructions`),primaryActionText:a("createGroup"),onPrimaryAction:d})},`${x}${h}`)]})},Wt=t=>n(H,{children:t.membership.map((e,a)=>D(H,{children:[n(Rt,{group:e},e.id+"-"+t.id),t.membership[a+1]?", ":""]}))}),Jt=t=>{const{realm:e}=se();return n(de,{to:ht({realm:e,id:t.id,tab:"settings"}),children:t.username},t.id)},Xt=()=>{const{adminClient:t}=P(),{t:e}=U(),{addAlert:a,addError:o}=W(),r=re(),i=pe(r.pathname),[l,s]=I(!1),{currentGroup:d}=X(),[c,p]=I(),[N,g]=I(!1),[G,h]=I(!1),[w,S]=I([]),{hasAccess:M}=ie();ue(()=>t.groups.findOne({id:d().id}),p,[]);const k=M("manage-users")||c?.access.manageMembership,[T,x]=I(0),$=()=>x(new Date().getTime()),L=async m=>await t.users.listGroups({id:m}),B=async(m,C=0)=>{let v=[];if(!C||!m)return v;const F={parentId:m,first:0,max:C},O=await t.groups.listSubGroups(F);return v=v.concat(O),await Promise.all(O.map(V=>B(V.id,V.subGroupCount))).then(V=>{V.forEach(K=>v=v.concat(K))}),v},u=async(m,C)=>{if(!i)return[];let v=await t.groups.listMembers({id:i,first:m,max:C});if(l&&c?.subGroupCount&&c.id){const O=await B(c.id,c.subGroupCount);await Promise.all(O.map(V=>t.groups.listMembers({id:V.id}))).then(V=>{V.forEach(K=>v=v.concat(K))}),v=gt(v,V=>V.username)}const F=await Promise.all(v.map(O=>L(O.id)));return v.map((O,V)=>({...O,membership:F[V]}))};return c?D(H,{children:[N&&n(Ot,{membersQuery:async()=>await t.groups.listMembers({id:i}),onAdd:async m=>{try{await Promise.all(m.map(C=>t.users.addToGroup({id:C.id,groupId:i}))),a(e("usersAdded",{count:m.length}))}catch(C){o("usersAddedError",C)}},onClose:()=>{g(!1),$()}}),n(He,{"data-testid":"members-table",loader:u,ariaLabelKey:"members",isPaginated:!0,canSelectAll:!0,onSelect:m=>S([...m]),toolbarItem:k&&D(H,{children:[n(J,{children:n(oe,{"data-testid":"addMember",variant:"primary",onClick:()=>g(!0),children:e("addMember")})}),n(J,{children:n($e,{"data-testid":"includeSubGroupsCheck",label:e("includeSubGroups"),id:"kc-include-sub-groups",isChecked:l,onChange:()=>s(!l)})}),n(J,{children:n(fe,{toggle:m=>n(be,{ref:m,variant:"plain",onClick:()=>h(!G),isExpanded:G,isDisabled:w.length===0,"aria-label":"Actions",children:n(ve,{})}),shouldFocusToggleOnSelect:!0,isOpen:G,children:n(we,{children:n(Q,{component:"button",onClick:async()=>{try{await Promise.all(w.map(m=>t.users.delFromGroup({id:m.id,groupId:i}))),h(!1),a(e("usersLeft",{count:w.length}))}catch(m){o("usersLeftError",m)}$()},children:e("leave")},"action")})})})]}),actions:k?[{title:e("leave"),onRowClick:async m=>{try{await t.users.delFromGroup({id:m.id,groupId:i}),a(e("usersLeft",{count:1}))}catch(C){o("usersLeftError",C)}return!0}}]:[],columns:[{name:"username",displayKey:"name",cellRenderer:Jt},{name:"email",displayKey:"email",cellFormatters:[he()]},{name:"firstName",displayKey:"firstName",cellFormatters:[he()]},{name:"lastName",displayKey:"lastName",cellFormatters:[he()]},{name:"membership",displayKey:"membership",cellRenderer:Wt}],emptyState:n(qe,{message:e("noUsersFound"),instructions:k?e("emptyInstructions"):void 0,primaryActionText:k?e("addMember"):void 0,onPrimaryAction:()=>g(!0),secondaryActions:[{text:e("includeSubGroups"),onClick:()=>s(!0)}]})},`${i}${T}${l}`)]}):n(Ue,{})};function Ye(t){let e=t.length;for(const a of t)a.subGroups&&(e+=Ye(a.subGroups));return e}const Yt=({group:t,refresh:e})=>{const{t:a}=U(),[o,r]=q(),[i,l]=q(),[s,d]=q(),[c,p]=q(),[N,g]=q(),G=ye(),{realm:h}=se();return D(H,{children:[i&&n(ne,{id:t.id,rename:t,refresh:()=>{G(te({realm:h})),e()},handleModalToggle:l}),s&&n(ne,{id:t.id,handleModalToggle:d,refresh:e}),c&&n(Xe,{source:t,refresh:e,onClose:p}),n(Ne,{show:N,toggleDialog:g,selectedRows:[t],refresh:()=>{G(te({realm:h})),e()}}),n(fe,{popperProps:{position:"right"},toggle:w=>n(be,{ref:w,onClick:r,isExpanded:o,variant:"plain","aria-label":"Actions",children:n(ve,{})}),isOpen:o,children:D(we,{children:[n(Q,{onClick:l,children:a("rename")},"rename"),n(Q,{onClick:p,children:a("moveTo")},"move"),n(Q,{onClick:d,children:a("createChildGroup")},"create"),n(Oe,{},"separator"),",",n(Q,{onClick:g,children:a("delete")},"delete")]})})]})},le=50,Zt=({refresh:t,canViewDetails:e})=>{const{adminClient:a}=P(),{t:o}=U(),{realm:r}=se(),i=ye(),{addAlert:l}=W(),{hasAccess:s}=ie(),[d,c]=I(),{subGroups:p,clear:N}=X(),[g,G]=I(""),[h,w]=I(20),[S,M]=I(0),k=Ge(0),T=Ge(20),[x,$]=I(0),[L,B]=I(!1),[u,m]=I(),[C,v]=I(0),[F,O]=I(0),V=()=>{O(F+1),t()},K=(b,f)=>({id:b.id,name:n(je,{content:b.name,children:n("span",{children:b.name})}),access:b.access||{},children:b.subGroupCount?[{name:D(H,{children:[n(bt,{size:"sm"})," ",o("spinnerLoading")]})}]:void 0,action:(s("manage-users")||b.access?.manage)&&n(Yt,{group:b,refresh:f}),defaultExpanded:p.map(A=>A.id).includes(b.id)});ue(async()=>{const b=await Ve(a,"groups",Object.assign({first:`${S}`,max:`${h+1}`,exact:`${L}`,global:`${g!==""}`},g===""?null:{search:g}));let f=[];return u&&(f=await Ve(a,`groups/${u.id}/children`,{first:`${C}`,max:`${le}`})),{groups:b,subGroups:f}},({groups:b,subGroups:f})=>{if(u){const A=Y(d||[],u.id,[]);if(A.length&&f.length){const j=A.pop();j.children=[...(Me(j.children||[]).splice(0,le),f.map(z=>K(z,V),"id")),...f.length===le?[{id:"next",name:n(oe,{variant:"plain",onClick:()=>v(C+le),children:n(De,{})})}]:[]]}}g||k.current!==S||T.current!==h?c(b.map(A=>K(A,V))):c(Me(d,b.map(A=>K(A,V)),"id")),$(Ye(b)),k.current=S,T.current=h},[F,S,C,h,g,L,u]);const Y=(b,f,A)=>{for(let j=0;j{if(b.id==="next")return;m(b);const A=Y(f,b.id,[]);p.every(({id:j})=>A.find(z=>z.id===j))||N(),e||A.at(-1)?.access?.view||p.at(-1)?.access?.view?i(te({realm:r,id:A.map(j=>j.id).join("/")})):(l(o("noViewRights"),me.warning),i(te({realm:r})))};return d?n(Vt,{count:x,first:S,max:h,onNextClick:M,onPreviousClick:M,onPerPageSelect:(b,f)=>{M(b),w(f)},inputGroupName:"searchForGroups",inputGroupPlaceholder:o("searchForGroups"),inputGroupOnEnter:G,toolbarItem:D(ft,{className:"pf-v5-u-pt-sm",children:[n(Te,{children:n($e,{id:"exact","data-testid":"exact-search",name:"exact",isChecked:L,onChange:(b,f)=>B(f)})}),n(Te,{children:n("label",{htmlFor:"exact",className:"pf-v5-u-pl-sm",children:o("exactSearch")})})]}),children:d.length>0&&n(Ce,{data:d.slice(0,h),allExpanded:g.length>0,activeItems:u?[u]:void 0,hasGuides:!0,hasSelectableNodes:!0,className:"keycloak_groups_treeview",onExpand:(b,f)=>{ce(f,d)},onSelect:(b,f)=>{ce(f,d)}})}):n(Ue,{})};function Sn(){const{adminClient:t}=P(),{t:e}=U(),[a,o]=I(0),{subGroups:r,setSubGroups:i,currentGroup:l}=X(),{realm:s}=se(),[d,c]=I(),[p,N]=q(),g=ye(),G=re(),h=pe(G.pathname),[w,S]=q(!0),[M,k]=I(0),T=()=>k(M+1),{hasAccess:x}=ie(),L=vt()(wt.AdminFineGrainedAuthz)&&x("manage-authorization","manage-users","manage-clients"),B=x("manage-users")||l()?.access?.manage,u=x("manage-users"),m=x("query-groups","view-users")||x("manage-users","query-groups"),C=x("view-users")||l()?.access?.viewMembers||l()?.access?.manageMembers;return ue(async()=>{const v=Je(G.pathname);if(v&&v.length>r.length){const O=[];for(const V of v){let K;if(V!=="search"?K=await t.groups.findOne({id:V}):K={name:e("searchGroups"),id:"search"},K)O.push(K);else throw new Error(e("notFound"))}return O}return[]},v=>{v.length&&i(v)},[h]),D(H,{children:[n(Ne,{show:p,toggleDialog:N,selectedRows:[l()],refresh:()=>{g(te({realm:s})),T()}}),d&&n(ne,{id:h,rename:d,refresh:v=>{T(),i([...r.slice(0,r.length-1),v])},handleModalToggle:()=>c(void 0)}),n(Be,{variant:Ke.light,className:"pf-v5-u-p-0",children:n(yt,{isInline:!0,isExpanded:w,position:"left",children:n(Ct,{panelContent:n(Nt,{isResizable:!0,children:n(Pe,{children:n(Zt,{refresh:T,canViewDetails:m})})}),children:D(Gt,{children:[n(je,{content:e(w?"hide":"show"),children:n(oe,{"aria-label":e(w?"hide":"show"),variant:"plain",icon:w?n(Et,{}):n($t,{}),onClick:S})}),n(jt,{}),n(xt,{titleKey:h?l()?.name:"groups",subKey:h?"":"groupsDescription",helpUrl:h?"":It.groupsUrl,divider:!h,dropdownItems:h&&B?[n(Q,{"data-testid":"renameGroupAction",onClick:()=>c(l()),children:e("renameGroup")},"renameGroup"),n(Q,{"data-testid":"deleteGroup",onClick:N,children:e("deleteGroup")},"deleteGroup")]:void 0}),r.length>0&&D(Bt,{inset:{default:"insetNone",md:"insetSm",xl:"insetLg","2xl":"inset2xl"},activeKey:a,onSelect:(v,F)=>o(F),isBox:!0,mountOnEnter:!0,unmountOnExit:!0,children:[n(Z,{"data-testid":"groups",eventKey:0,title:n(ee,{children:e("childGroups")}),children:n(_e,{refresh:T})}),C&&n(Z,{"data-testid":"members",eventKey:1,title:n(ee,{children:e("members")}),children:n(Xt,{})}),n(Z,{"data-testid":"attributes",eventKey:2,title:n(ee,{children:e("attributes")}),children:n(qt,{})}),u&&n(Z,{eventKey:3,"data-testid":"role-mapping-tab",title:n(ee,{children:e("roleMapping")}),children:n(Ht,{id:h,name:l()?.name})}),L&&n(Z,{eventKey:4,"data-testid":"permissionsTab",title:n(ee,{children:e("permissions")}),children:n(kt,{id:h,type:"groups"})})]}),r.length===0&&n(_e,{refresh:T})]})})},M)})]})}export{Sn as default};
//# sourceMappingURL=GroupsSection-BcH1Eqbu.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy