theme.keycloak.v2.admin.resources.assets.GroupsSection-C2OkoLCc.js Maven / Gradle / Ivy
import{jsxs as L,jsx as n,Fragment as H}from"react/jsx-runtime";import*as O from"react";import E,{useState as I,useEffect as Oe,useRef as Ge}from"react";import{_ as ae,m as _,ce as ge,ar as Re,bG as Ee,cf as Ze,n as De,aM as Ie,cg as ke,ch as Se,o as et,ci as tt,cj as nt,a as U,ck as X,c as se,bL as re,cl as at,cm as xe,L as de,u as Q,f as J,g as Le,w as ue,P as Be,cn as Fe,bQ as st,Q as rt,S as ot,k as me,M as it,q as ct,h as lt,i as oe,B as Ke,F as dt,r as ut,y as mt,b3 as ie,a2 as P,J as fe,K as be,aB as ve,N as we,D as W,co as pt,a3 as Ue,bS as $e,aC as he,bx as ht,cp as gt,d as Ce,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 Ct,ct as yt,cu as Nt,cv as Gt,cb as Et,au as It}from"./main-C7ps2lmX.js";import{P as kt}from"./PermissionTab-CKEvhIGg.js";import{V as St}from"./ViewHeader-B7eeFzFA.js";import{u as q}from"./useToggle-K3Kx99tM.js";import{A as xt}from"./AttributeForm-CdFbESi6.js";import{R as Tt}from"./AddRoleMappingModal-DW8o4W0z.js";import{L as qe,P as Vt}from"./PaginatingTableToolbar-Cjsz5Jh4.js";import{l as At,i as Ae,K as He}from"./KeycloakDataTable-DbY4la1D.js";import{C as Mt}from"./ConfirmDialog-hx7XKLbN.js";import{G as _t,a as Ot}from"./GroupPickerDialog-C09EjRTA.js";import{M as Rt}from"./MembersModal-CiM-HKQc.js";import{b as Dt,a as Lt}from"./_baseFlatten-eIEJR-AJ.js";import{T as Bt,a as Z,b as ee}from"./Tabs-CMdqT4Cg.js";import"react-dom";import"./Trans-DcGUccv9.js";import"./Td-D2hVFK0Z.js";import"./grip-vertical-icon-BxF7V59o.js";import"./FormAccess-DyLNkc18.js";import"./copy-icon-ACZmDH8e.js";import"./KeyValueInput-B0tpVTv9.js";import"./KeySelect-jKxsKqdI.js";import"./EmptyStateFooter-DqmBOP2I.js";import"./filter-icon-DO0QNij3.js";import"./EmptyStateActions-DWNUFByn.js";import"./DataListItemRow-BC0LurDd.js";const ze=t=>{var{className:e="",children:a,hasNoPadding:o=!1}=t,r=ae(t,["className","children","hasNoPadding"]);return O.createElement("div",Object.assign({className:_(ge.drawerBody,o&&ge.modifiers.noPadding,e)},r),a)};ze.displayName="DrawerPanelBody";const Qe=t=>{var{className:e="",children:a,hasNoPadding:o=!1}=t,r=ae(t,["className","children","hasNoPadding"]);return O.createElement(ze,{hasNoPadding:o},O.createElement("div",Object.assign({className:_(ge.drawerHead,e)},r),a))};Qe.displayName="DrawerHead";const C={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"},We=t=>{var{isNested:e=!1,toolbar:a,children:o}=t,r=ae(t,["isNested","toolbar","children"]);return O.createElement(O.Fragment,null,a&&O.createElement(O.Fragment,null,a,O.createElement(Re,null)),O.createElement("ul",Object.assign({className:_(`${C.treeView}__list`),role:e?"group":"tree"},r),o))};We.displayName="TreeViewList";const Ft=({name:t,title:e,id:a,isExpanded:o,defaultExpanded:r=!1,children:i=null,onSelect:l,onExpand:s,onCollapse:d,onCheck:c,hasCheckbox:h=!1,checkProps:N={checked:!1},hasBadge:g=!1,customBadgeContent:G,badgeProps:p={isRead:!0},isSelectable:w=!1,isCompact:x,activeItems:M=[],itemData:k,parentItem:T,icon:S,expandedIcon:j,action:B,compareItems:F,useMemo:u})=>{const[m,y]=I(r);Oe(()=>{o!=null?y(o):r!=null&&y(m||r)},[o,r]);let v="button";h?v="label":w&&(v="div");const $=h||w?"button":"span",R=b=>E.createElement($,Object.assign({className:_(C.treeViewNodeToggle),onClick:f=>{(w||h)&&(m?d&&d(f,k,T):s&&s(f,k,T),y(!m)),w&&f.stopPropagation()}},(h||w)&&{"aria-labelledby":`label-${b}`},$==="button"&&{type:"button"},{tabIndex:-1}),E.createElement("span",{className:_(C.treeViewNodeToggleIcon)},E.createElement(De,{"aria-hidden":"true"}))),V=b=>E.createElement("span",{className:_(C.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}))),D=E.createElement("span",{className:_(C.treeViewNodeIcon)},!m&&S,m&&(j||S)),Y=()=>{const b=E.createElement(E.Fragment,null,x&&e&&E.createElement("span",{className:_(C.treeViewNodeTitle)},e),w?E.createElement("button",{tabIndex:-1,className:_(C.treeViewNodeText),type:"button"},t):E.createElement("span",{className:_(C.treeViewNodeText)},t));return x?E.createElement("span",{className:_(C.treeViewNodeContent)},b):b},ce=E.createElement(E.Fragment,null,g&&i&&E.createElement("span",{className:_(C.treeViewNodeCount)},E.createElement(Ee,Object.assign({},p),G||i.props.data.length)),g&&!i&&G!==void 0&&E.createElement("span",{className:_(C.treeViewNodeCount)},E.createElement(Ee,Object.assign({},p),G)));return E.createElement("li",{id:a,className:_(C.treeViewListItem,m&&C.modifiers.expanded),"aria-expanded":m,role:"treeitem",tabIndex:-1},E.createElement("div",{className:_(C.treeViewContent)},E.createElement(Ze,{prefix:w?"selectable-id":"checkbox-id"},b=>E.createElement(v,Object.assign({className:_(C.treeViewNode,i&&(w||h)&&C.modifiers.selectable,(!i||w)&&M&&M.length>0&&M.some(f=>F&&f&&F(f,k))?C.modifiers.current:""),onClick:f=>{h||(l&&l(f,k,T),!w&&i&&f.isDefaultPrevented()!==!0&&(m?d&&d(f,k,T):s&&s(f,k,T),y(!m)))}},h&&{htmlFor:b},(h||w&&i)&&{id:`label-${b}`},v==="button"&&{type:"button"}),E.createElement("span",{className:_(C.treeViewNodeContainer)},i&&R(b),h&&V(b),S&&D,Y(),ce))),B&&E.createElement("div",{className:_(C.treeViewAction)},B)),m&&i)},Je=E.memo(Ft,(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)});Je.displayName="TreeViewListItem";class Kt extends O.Component{constructor(){super(...arguments),this.displayName="TreeViewRoot",this.treeRef=O.createRef(),this.handleKeys=e=>{var a,o,r,i,l,s,d;if(!this.treeRef.current.contains(e.target)||!e.target.classList.contains(C.treeViewNode))return;const c=document.activeElement,h=e.key,N=Array.from((a=this.treeRef.current)===null||a===void 0?void 0:a.getElementsByClassName(C.treeViewNode)).filter(g=>!g.classList.contains("pf-m-disabled"));if(h===Ie.Space&&(c.click(),e.preventDefault()),ke(e,N,g=>c===g,void 0,[],void 0,!0,!0),["ArrowLeft","ArrowRight"].includes(h)){const g=(r=(o=c?.firstElementChild)===null||o===void 0?void 0:o.firstElementChild)===null||r===void 0?void 0:r.classList.contains(C.treeViewNodeToggle),G=(i=c?.closest("li"))===null||i===void 0?void 0:i.classList.contains("pf-m-expanded");if(h==="ArrowLeft")if(g&&G)c.click();else{const p=(l=c?.closest("ul"))===null||l===void 0?void 0:l.parentElement;if(p?.tagName!=="DIV"){const w=p?.querySelector("button");c.tabIndex=-1,w&&(w.tabIndex=0,w.focus())}}else if(g&&!G){c.tabIndex=-1,c.click();const p=(d=(s=c?.closest("li"))===null||s===void 0?void 0:s.querySelector("ul > li"))===null||d===void 0?void 0:d.querySelector("button");p&&(p.tabIndex=0,p.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(C.treeViewNode));ke(e,c,h=>h.contains(s),h=>h.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:C.modifiers.compact,compactNoBackground:[C.modifiers.compact,C.modifiers.noBackground]}}componentDidMount(){var e;if(Se&&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(C.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(C.treeViewNodeText)[0];o&&(o.tabIndex=0)}}else((e=this.treeRef.current)===null||e===void 0?void 0:e.getElementsByClassName(C.treeViewNode)[0]).tabIndex=0}componentWillUnmount(){Se&&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 O.createElement("div",Object.assign({className:_(C.treeView,r&&C.modifiers.guides,this.variantStyleModifiers[i],l),ref:this.treeRef},d),a)}}const ye=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:h,expandedIcon:N,parentItem:g,onSelect:G,onCheck:p,onExpand:w,onCollapse:x,toolbar:M,activeItems:k,compareItems:T=(u,m)=>u.id===m.id,className:S,useMemo:j}=t,B=ae(t,["data","isNested","hasCheckboxes","hasBadges","hasGuides","hasSelectableNodes","variant","defaultAllExpanded","allExpanded","icon","expandedIcon","parentItem","onSelect","onCheck","onExpand","onCollapse","toolbar","activeItems","compareItems","className","useMemo"]);const F=O.createElement(We,{isNested:a,toolbar:M},e.map(u=>{var m,y;return O.createElement(Je,Object.assign({key:((m=u.id)===null||m===void 0?void 0:m.toString())||((y=u.name)===null||y===void 0?void 0:y.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:p,onExpand:w,onCollapse:x,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:h,expandedIcon:u.expandedIcon!==void 0?u.expandedIcon:N,action:u.action,compareItems:T,isCompact:s==="compact"||s==="compactNoBackground",useMemo:j},u.children&&{children:O.createElement(ye,{data:u.children,isNested:!0,parentItem:u,hasCheckboxes:o,hasBadges:r,hasGuides:i,hasSelectableNodes:l,variant:s,allExpanded:c,defaultAllExpanded:d,onSelect:G,onCheck:p,onExpand:w,onCollapse:x,activeItems:k,icon:h,expandedIcon:N})}))}));return O.createElement(O.Fragment,null,g?F:O.createElement(Kt,Object.assign({hasSelectableNodes:l,hasCheckboxes:o,hasGuides:i,variant:s,className:S},B),F))};ye.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 Oe(()=>{const{pathname:l}=i;(!l.includes("/groups")||l.endsWith("/groups"))&&e()},[i]),o.length!==0?L(at,{children:[n(xe,{children:n(de,{to:`/${r}/groups`,children:t("groups")})},"home"),o.map((l,s)=>{const d=s===o.length-1;return L(xe,{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},Pe=t=>{const e=t.substr(1).split("/");return e.length>1?e.splice(2):void 0},pe=t=>{const e=Pe(t);return e?e[e.length-1]:void 0},qt=()=>{const{adminClient:t}=Q(),{t:e}=U(),{addAlert:a,addError:o}=J(),r=Le({mode:"onChange"}),i=re(),l=pe(i.pathname),[s,d]=I();ue(()=>t.groups.findOne({id:l}),h=>{rt(h,r.setValue),d(h)},[l]);const c=async h=>{try{const N=ot(h).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:Fe.light,children:n(xt,{form:r,save:c,fineGrainedAccess:s?.access?.manage,reset:()=>r.reset({attributes:st(s?.attributes)})})})},Ht=({id:t,name:e})=>{const{adminClient:a}=Q(),{t:o}=U(),{addAlert:r,addError:i}=J();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}=Q(),{t:i}=U(),{addAlert:l,addError:s}=J(),d=Le({defaultValues:{name:e?.name}}),{handleSubmit:c,formState:h}=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:h,"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:Ke.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}=Q(),{t:i}=U(),{addAlert:l,addError:s}=J(),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:Ke.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?L(H,{children:[n(P,{children:n(oe,{"data-testid":"openCreateGroupModal",variant:"primary",onClick:t,children:o("createGroup")})}),n(P,{children:n(fe,{onOpenChange:d,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(W,{component:"button",onClick:()=>{e(),d()},children:o("delete")},"action")})})})]}):n("div",{})},Qt=(t,e)=>e.id?t.groups.updateRoot(e):t.groups.create(e),Wt=async(t,e,a)=>t.groups.updateChildGroup({id:a.id},e),Xe=({source:t,onClose:e,refresh:a})=>{const{adminClient:o}=Q(),{t:r}=U(),{addAlert:i,addError:l}=J();return n(_t,{type:"selectOne",filterGroups:[t],text:{title:"moveToGroup",ok:"moveHere"},onClose:e,onConfirm:async d=>{try{await(d?Wt(o,t,d[0]):Qt(o,t)),a(),i(r("moveGroupSuccess"))}catch(c){l("moveGroupError",c)}},isMove:!0})},_e=({refresh:t})=>{const{adminClient:e}=Q(),{t:a}=U(),[o,r]=I([]),[i,l]=I(),[s,d]=q(),[c,h]=q(),[N,g]=I(),{currentGroup:G}=X(),[p,w]=I(0),x=()=>w(p+1),[M,k]=I(),T=re(),S=pe(T.pathname),{hasAccess:j}=ie(),B=j("manage-users")||G()?.access?.manage,F=async(u,m)=>{let y;if(S){const v={search:M||"",first:u,max:m,parentId:S};y=await e.groups.listSubGroups(v)}else{const v={search:M||"",first:u||void 0,max:m||void 0};y=await e.groups.find(v)}return y};return L(H,{children:[n(Ne,{show:c,toggleDialog:h,selectedRows:o,refresh:()=>{x(),t(),r([])}}),i&&n(ne,{id:i.id,rename:i,refresh:()=>{x(),t()},handleModalToggle:()=>l(void 0)}),s&&n(ne,{id:o[0]?.id||S,handleModalToggle:d,refresh:()=>{r([]),x(),t()}}),N&&n(Xe,{source:N,refresh:()=>{g(void 0),x(),t()},onClose:()=>g(void 0)}),n(He,{onSelect:u=>r([...u]),canSelectAll:!0,loader:F,ariaLabelKey:"groups",isPaginated:!0,isSearching:!!M,toolbarItem:L(H,{children:[n(P,{children:n(pt,{"data-testid":"group-search",placeholder:a("filterGroups"),value:M,onChange:(u,m)=>{k(m)},onSearch:x,onClear:()=>{k(""),x()}})}),n(zt,{toggleCreate:d,toggleDelete:h,kebabDisabled:o.length===0})]}),actions:B?[{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]),h(),!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${S?"SubGroup":"Realm"}`),instructions:a(`noGroupsInThis${S?"SubGroup":"Realm"}Instructions`),primaryActionText:a("createGroup"),onPrimaryAction:d})},`${S}${p}`)]})},Jt=t=>n(H,{children:t.membership.map((e,a)=>L(H,{children:[n(Ot,{group:e},e.id+"-"+t.id),t.membership[a+1]?", ":""]}))}),Pt=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}=Q(),{t:e}=U(),{addAlert:a,addError:o}=J(),r=re(),i=pe(r.pathname),[l,s]=I(!1),{currentGroup:d}=X(),[c,h]=I(),[N,g]=I(!1),[G,p]=I(!1),[w,x]=I([]),{hasAccess:M}=ie();ue(()=>t.groups.findOne({id:d().id}),h,[]);const k=M("manage-users")||c?.access.manageMembership,[T,S]=I(0),j=()=>S(new Date().getTime()),B=async m=>await t.users.listGroups({id:m}),F=async(m,y=0)=>{let v=[];if(!y||!m)return v;const $={parentId:m,first:0,max:y},R=await t.groups.listSubGroups($);return v=v.concat(R),await Promise.all(R.map(V=>F(V.id,V.subGroupCount))).then(V=>{V.forEach(D=>v=v.concat(D))}),v},u=async(m,y)=>{if(!i)return[];let v=await t.groups.listMembers({id:i,first:m,max:y});if(l&&c?.subGroupCount&&c.id){const R=await F(c.id,c.subGroupCount);await Promise.all(R.map(V=>t.groups.listMembers({id:V.id}))).then(V=>{V.forEach(D=>v=v.concat(D))}),v=gt(v,V=>V.username)}const $=await Promise.all(v.map(R=>B(R.id)));return v.map((R,V)=>({...R,membership:$[V]}))};return c?L(H,{children:[N&&n(Rt,{membersQuery:async()=>await t.groups.listMembers({id:i}),onAdd:async m=>{try{await Promise.all(m.map(y=>t.users.addToGroup({id:y.id,groupId:i}))),a(e("usersAdded",{count:m.length}))}catch(y){o("usersAddedError",y)}},onClose:()=>{g(!1),j()}}),n(He,{"data-testid":"members-table",loader:u,ariaLabelKey:"members",isPaginated:!0,canSelectAll:!0,onSelect:m=>x([...m]),toolbarItem:k&&L(H,{children:[n(P,{children:n(oe,{"data-testid":"addMember",variant:"primary",onClick:()=>g(!0),children:e("addMember")})}),n(P,{children:n($e,{"data-testid":"includeSubGroupsCheck",label:e("includeSubGroups"),id:"kc-include-sub-groups",isChecked:l,onChange:()=>s(!l)})}),n(P,{children:n(fe,{onOpenChange:m=>p(m),toggle:m=>n(be,{ref:m,variant:"plain",onClick:()=>p(!G),isExpanded:G,isDisabled:w.length===0,"aria-label":"Actions",children:n(ve,{})}),shouldFocusToggleOnSelect:!0,isOpen:G,children:n(we,{children:n(W,{component:"button",onClick:async()=>{try{await Promise.all(w.map(m=>t.users.delFromGroup({id:m.id,groupId:i}))),p(!1),a(e("usersLeft",{count:w.length}))}catch(m){o("usersLeftError",m)}j()},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(y){o("usersLeftError",y)}return!0}}]:[],columns:[{name:"username",displayKey:"name",cellRenderer:Pt},{name:"email",displayKey:"email",cellFormatters:[he()]},{name:"firstName",displayKey:"firstName",cellFormatters:[he()]},{name:"lastName",displayKey:"lastName",cellFormatters:[he()]},{name:"membership",displayKey:"membership",cellRenderer:Jt}],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,h]=q(),[N,g]=q(),G=Ce(),{realm:p}=se();return L(H,{children:[i&&n(ne,{id:t.id,rename:t,refresh:()=>{G(te({realm:p})),e()},handleModalToggle:l}),s&&n(ne,{id:t.id,handleModalToggle:d,refresh:e}),c&&n(Xe,{source:t,refresh:e,onClose:h}),n(Ne,{show:N,toggleDialog:g,selectedRows:[t],refresh:()=>{G(te({realm:p})),e()}}),n(fe,{popperProps:{position:"right"},onOpenChange:r,toggle:w=>n(be,{ref:w,onClick:r,isExpanded:o,variant:"plain","aria-label":"Actions",children:n(ve,{})}),isOpen:o,children:L(we,{children:[n(W,{onClick:l,children:a("rename")},"rename"),n(W,{onClick:h,children:a("moveTo")},"move"),n(W,{onClick:d,children:a("createChildGroup")},"create"),n(Re,{},"separator"),",",n(W,{onClick:g,children:a("delete")},"delete")]})})]})},le=50,Zt=()=>{const{t}=U();return L(H,{children:[n(bt,{size:"sm"})," ",t("spinnerLoading")]})},en=[{name:n(Zt,{})}],tn=({refresh:t,canViewDetails:e})=>{const{adminClient:a}=Q(),{t:o}=U(),{realm:r}=se(),i=Ce(),{addAlert:l}=J(),{hasAccess:s}=ie(),[d,c]=I(),{subGroups:h,clear:N}=X(),[g,G]=I(""),[p,w]=I(20),[x,M]=I(0),k=Ge(0),T=Ge(20),[S,j]=I(0),[B,F]=I(!1),[u,m]=I(),[y,v]=I(0),[$,R]=I(0),V=()=>{R($+1),t()},D=(b,f)=>{const A=b.subGroupCount;return{id:b.id,name:n(je,{content:b.name,children:n("span",{children:b.name})}),access:b.access||{},children:A?g.length===0?en:b.subGroups?.map(K=>D(K,f)):void 0,action:(s("manage-users")||b.access?.manage)&&n(Yt,{group:b,refresh:f}),defaultExpanded:h.map(K=>K.id).includes(b.id)}};ue(async()=>{const b=await Ve(a,"groups",Object.assign({first:`${x}`,max:`${p+1}`,exact:`${B}`,global:`${g!==""}`},g===""?null:{search:g}));let f=[];return u&&(f=await Ve(a,`groups/${u.id}/children`,{first:`${y}`,max:`${le}`})),{groups:b,subGroups:f}},({groups:b,subGroups:f})=>{if(u){const A=Y(d||[],u.id,[]);if(A.length&&f.length){const K=A.pop();K.children=[...(Me(K.children||[]).splice(0,le),f.map(z=>D(z,V),"id")),...f.length===le?[{id:"next",name:n(oe,{variant:"plain",onClick:()=>v(y+le),children:n(De,{})})}]:[]]}}g||k.current!==x||T.current!==p?c(b.map(A=>D(A,V))):c(Me(d,b.map(A=>D(A,V)),"id")),j(Ye(b)),k.current=x,T.current=p},[$,x,y,p,g,B,u]);const Y=(b,f,A)=>{for(let K=0;K{if(b.id==="next")return;m(b);const A=Y(f,b.id,[]);h.every(({id:K})=>A.find(z=>z.id===K))||N(),e||A.at(-1)?.access?.view||h.at(-1)?.access?.view?i(te({realm:r,id:A.map(K=>K.id).join("/")})):(l(o("noViewRights"),me.warning),i(te({realm:r})))};return d?n(Vt,{count:S,first:x,max:p,onNextClick:M,onPreviousClick:M,onPerPageSelect:(b,f)=>{M(b),w(f)},inputGroupName:"searchForGroups",inputGroupPlaceholder:o("searchForGroups"),inputGroupOnEnter:G,toolbarItem:L(ft,{className:"pf-v5-u-pt-sm",children:[n(Te,{children:n($e,{id:"exact","data-testid":"exact-search",name:"exact",isChecked:B,onChange:(b,f)=>F(f)})}),n(Te,{children:n("label",{htmlFor:"exact",className:"pf-v5-u-pl-sm",children:o("exactSearch")})})]}),children:d.length>0&&n(ye,{data:d.slice(0,p),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 Vn(){const{adminClient:t}=Q(),{t:e}=U(),[a,o]=I(0),{subGroups:r,setSubGroups:i,currentGroup:l}=X(),{realm:s}=se(),[d,c]=I(),[h,N]=q(),g=Ce(),G=re(),p=pe(G.pathname),[w,x]=q(!0),[M,k]=I(0),T=()=>k(M+1),{hasAccess:S}=ie(),B=vt()(wt.AdminFineGrainedAuthz)&&S("manage-authorization","manage-users","manage-clients"),F=S("manage-users")||l()?.access?.manage,u=S("manage-users"),m=S("query-groups","view-users")||S("manage-users","query-groups"),y=S("view-users")||l()?.access?.viewMembers||l()?.access?.manageMembers;return ue(async()=>{const v=Pe(G.pathname);if(v&&v.length>r.length){const R=[];for(const V of v){let D;if(V!=="search"?D=await t.groups.findOne({id:V}):D={name:e("searchGroups"),id:"search"},D)R.push(D);else throw new Error(e("notFound"))}return R}return[]},v=>{v.length&&i(v)},[p]),L(H,{children:[n(Ne,{show:h,toggleDialog:N,selectedRows:[l()],refresh:()=>{g(te({realm:s})),T()}}),d&&n(ne,{id:p,rename:d,refresh:v=>{T(),i([...r.slice(0,r.length-1),v])},handleModalToggle:()=>c(void 0)}),n(Be,{variant:Fe.light,className:"pf-v5-u-p-0",children:n(Ct,{isInline:!0,isExpanded:w,position:"left",children:n(yt,{panelContent:n(Nt,{isResizable:!0,children:n(Qe,{children:n(tn,{refresh:T,canViewDetails:m})})}),children:L(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:x})}),n(jt,{}),n(St,{titleKey:p?l()?.name:"groups",subKey:p?"":"groupsDescription",helpUrl:p?"":It.groupsUrl,divider:!p,dropdownItems:p&&F?[n(W,{"data-testid":"renameGroupAction",onClick:()=>c(l()),children:e("renameGroup")},"renameGroup"),n(W,{"data-testid":"deleteGroup",onClick:N,children:e("deleteGroup")},"deleteGroup")]:void 0}),r.length>0&&L(Bt,{inset:{default:"insetNone",md:"insetSm",xl:"insetLg","2xl":"inset2xl"},activeKey:a,onSelect:(v,$)=>o($),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})}),y&&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:p,name:l()?.name})}),B&&n(Z,{eventKey:4,"data-testid":"permissionsTab",title:n(ee,{children:e("permissions")}),children:n(kt,{id:p,type:"groups"})})]}),r.length===0&&n(_e,{refresh:T})]})})},M)})]})}export{Vn as default};
//# sourceMappingURL=GroupsSection-C2OkoLCc.js.map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy