"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[8039],{86129:(e,s,t)=>{t.r(s),t.d(s,{UsersListPage:()=>D,default:()=>_});var n=t(68404),r=t(18745),i=t(43215),a=t(69783),l=t(33801),o=t(8674),c=t(61959),h=t(69778),d=t(45916);const u={revokeInvite:h.GY},x=(0,r.connect)(null,u);class g extends n.PureComponent{render(){const{invitee:e,revokeInvite:s}=this.props;return(0,d.jsxs)("tr",{children:[(0,d.jsx)("td",{children:e.email}),(0,d.jsx)("td",{children:e.name}),(0,d.jsxs)("td",{className:"text-right",children:[(0,d.jsx)(a.ClipboardButton,{variant:"secondary",size:"sm",getText:()=>e.url,children:"Copy Invite"})," "]}),(0,d.jsx)("td",{children:(0,d.jsx)(a.Button,{variant:"destructive",size:"sm",icon:"times",onClick:()=>s(e.code)})})]})}}const m=x(g);var v,p,j;class f extends n.PureComponent{render(){const{invitees:e}=this.props;return(0,d.jsxs)("table",{className:"filter-table form-inline",children:[(0,d.jsx)("thead",{children:(0,d.jsxs)("tr",{children:[v||(v=(0,d.jsx)("th",{children:"Email"})),p||(p=(0,d.jsx)("th",{children:"Name"})),j||(j=(0,d.jsx)("th",{})),(0,d.jsx)("th",{style:{width:"34px"}})]})}),(0,d.jsx)("tbody",{children:e.map(((e,s)=>(0,d.jsx)(m,{invitee:e},`${e.id}-${s}`)))})]})}}var I=t(98335),b=t(73931);const{selectAll:U,selectById:w,selectTotal:y}=b.wl,C=(0,I.P1)([U,(e,s)=>s],((e,s)=>{const t=new RegExp(s,"i");return e.filter((e=>t.test(e.name)||t.test(e.email)))}));var P=t(98163),M=t(58170),N=t(28911);const k=e=>{const s=new RegExp(e.searchQuery,"i");return e.users.filter((e=>s.test(e.login)||s.test(e.email)||s.test(e.name)))},S=e=>e.searchQuery,R=e=>e.searchPage;var L;class B extends n.PureComponent{render(){const{canInvite:e,externalUserMngLinkName:s,externalUserMngLinkUrl:t,searchQuery:n,pendingInvitesCount:r,setUsersSearchQuery:i,onShowInvites:l,showInvites:o}=this.props,c=[{label:"Users",value:"users"},{label:`Pending Invites (${r})`,value:"invites"}],h=P.Vt.hasAccess(M.bW.UsersCreate,e);return(0,d.jsxs)("div",{className:"page-action-bar","data-testid":"users-action-bar",children:[(0,d.jsx)("div",{className:"gf-form gf-form--grow",children:(0,d.jsx)(a.FilterInput,{value:n,onChange:i,placeholder:"Search user by login, email or name"})}),r>0&&(0,d.jsx)("div",{style:{marginLeft:"1rem"},children:(0,d.jsx)(a.RadioButtonGroup,{value:o?"invites":"users",options:c,onChange:l})}),h&&(L||(L=(0,d.jsx)(a.LinkButton,{href:"org/users/invite",children:"Invite"}))),t&&(0,d.jsx)(a.LinkButton,{href:t,target:"_blank",rel:"noopener",children:s})]})}}const A={setUsersSearchQuery:N.oX},V=(0,r.connect)((function(e){return{searchQuery:S(e.users),pendingInvitesCount:y(e.invites),externalUserMngLinkName:e.users.externalUserMngLinkName,externalUserMngLinkUrl:e.users.externalUserMngLinkUrl,canInvite:e.users.canInvite}}),A)(B);var W=t(50641),E=t(90923),Q=t(66728);function O(){return async e=>{const s=await(0,E.getBackendSrv)().get("/api/org/users",(0,Q.y)());e((0,N.eT)(s))}}function T(e,s,t){return s in e?Object.defineProperty(e,s,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[s]=t,e}const $={loadUsers:O,fetchInvitees:h.nW,setUsersSearchQuery:N.oX,setUsersSearchPage:N.TQ,updateUser:function(e){return async s=>{await(0,E.getBackendSrv)().patch(`/api/org/users/${e.userId}`,{role:e.role}),s(O())}},removeUser:function(e){return async s=>{await(0,E.getBackendSrv)().delete(`/api/org/users/${e}`),s(O())}}},F=(0,r.connect)((function(e){const s=S(e.users);return{navModel:(0,o.h)(e.navIndex,"users"),users:k(e.users),searchQuery:S(e.users),searchPage:R(e.users),invitees:C(e.invites,s),externalUserMngInfo:e.users.externalUserMngInfo,hasFetched:e.users.hasFetched}}),$);class D extends n.PureComponent{constructor(e){super(e),T(this,"onRoleChange",((e,s)=>{const t=Object.assign({},s,{role:e});this.props.updateUser(t)})),T(this,"onShowInvites",(()=>{this.setState((e=>({showInvites:!e.showInvites})))})),T(this,"getPaginatedUsers",(e=>{const s=30*(this.props.searchPage-1);return e.slice(s,s+30)})),this.props.externalUserMngInfo&&(this.externalUserMngInfoHtml=(0,i.renderMarkdown)(this.props.externalUserMngInfo)),this.state={showInvites:!1}}componentDidMount(){this.fetchUsers(),this.fetchInvitees()}async fetchUsers(){return await this.props.loadUsers()}async fetchInvitees(){return await this.props.fetchInvitees()}renderTable(){const{invitees:e,users:s,setUsersSearchPage:t}=this.props,n=this.getPaginatedUsers(s),r=Math.ceil(s.length/30);return this.state.showInvites?(0,d.jsx)(f,{invitees:e}):(0,d.jsxs)(a.VerticalGroup,{spacing:"md",children:[(0,d.jsx)(W.Z,{users:n,orgId:c.Vt.user.orgId,onRoleChange:(e,s)=>this.onRoleChange(e,s),onRemoveUser:e=>this.props.removeUser(e.userId)}),(0,d.jsx)(a.HorizontalGroup,{justify:"flex-end",children:(0,d.jsx)(a.Pagination,{onNavigate:t,currentPage:this.props.searchPage,numberOfPages:r,hideWhenSinglePage:!0})})]})}render(){const{navModel:e,hasFetched:s}=this.props,t=this.externalUserMngInfoHtml;return(0,d.jsx)(l.Z,{navModel:e,children:(0,d.jsx)(l.Z.Contents,{isLoading:!s,children:(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(V,{onShowInvites:this.onShowInvites,showInvites:this.state.showInvites}),t&&(0,d.jsx)("div",{className:"grafana-info-box",dangerouslySetInnerHTML:{__html:t}}),s&&this.renderTable()]})})})}}const _=F(D)},50641:(e,s,t)=>{t.d(s,{Z:()=>p});var n,r,i,a,l,o,c=t(68404),h=t(69783),d=t(57497),u=t(77058),x=t(98163),g=t(58170),m=t(8936),v=t(45916);const p=e=>{const{users:s,orgId:t,onRoleChange:p,onRemoveUser:j}=e,[f,I]=(0,c.useState)(null),[b,U]=(0,c.useState)([]),[w,y]=(0,c.useState)({});return(0,c.useEffect)((()=>{x.Vt.licensedAccessControlEnabled()&&async function(){try{if(x.Vt.hasPermission(g.bW.ActionRolesList)){let e=await(0,u.ul)(t);U(e)}if(x.Vt.accessControlBuiltInRoleAssignmentEnabled()&&x.Vt.hasPermission(g.bW.ActionBuiltinRolesList)){const e=await(0,u.fh)(t);y(e)}}catch(e){console.error("Error loading options")}}()}),[t]),(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)("table",{className:"filter-table form-inline",children:[(0,v.jsx)("thead",{children:(0,v.jsxs)("tr",{children:[n||(n=(0,v.jsx)("th",{})),r||(r=(0,v.jsx)("th",{children:"Login"})),i||(i=(0,v.jsx)("th",{children:"Email"})),a||(a=(0,v.jsx)("th",{children:"Name"})),l||(l=(0,v.jsx)("th",{children:"Seen"})),o||(o=(0,v.jsx)("th",{children:"Role"})),(0,v.jsx)("th",{style:{width:"34px"}})]})}),(0,v.jsx)("tbody",{children:s.map(((e,s)=>(0,v.jsxs)("tr",{children:[(0,v.jsx)("td",{className:"width-2 text-center",children:(0,v.jsx)("img",{className:"filter-table__avatar",src:e.avatarUrl,alt:"User avatar"})}),(0,v.jsx)("td",{className:"max-width-6",children:(0,v.jsx)("span",{className:"ellipsis",title:e.login,children:e.login})}),(0,v.jsx)("td",{className:"max-width-5",children:(0,v.jsx)("span",{className:"ellipsis",title:e.email,children:e.email})}),(0,v.jsx)("td",{className:"max-width-5",children:(0,v.jsx)("span",{className:"ellipsis",title:e.name,children:e.name})}),(0,v.jsx)("td",{className:"width-1",children:e.lastSeenAtAge}),(0,v.jsx)("td",{className:"width-8",children:x.Vt.licensedAccessControlEnabled()?(0,v.jsx)(d.R,{userId:e.userId,orgId:t,builtInRole:e.role,onBuiltinRoleChange:s=>p(s,e),roleOptions:b,builtInRoles:w,disabled:!x.Vt.hasPermissionInMetadata(g.bW.OrgUsersWrite,e)}):(0,v.jsx)(m.A,{"aria-label":"Role",value:e.role,disabled:!x.Vt.hasPermissionInMetadata(g.bW.OrgUsersWrite,e),onChange:s=>p(s,e)})}),x.Vt.hasPermissionInMetadata(g.bW.OrgUsersRemove,e)&&(0,v.jsx)("td",{children:(0,v.jsx)(h.Button,{size:"sm",variant:"destructive",onClick:()=>{I(e)},icon:"times","aria-label":"Delete user"})})]},`${e.userId}-${s}`)))})]}),Boolean(f)&&(0,v.jsx)(h.ConfirmModal,{body:`Are you sure you want to delete user ${null==f?void 0:f.login}?`,confirmText:"Delete",title:"Delete",onDismiss:()=>{I(null)},isOpen:!0,onConfirm:()=>{f&&(j(f),I(null))}})]})}}}]); //# sourceMappingURL=UsersListPage.9b63bff5372bebea07b7.js.map