"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[9671],{39539:(e,t,s)=>{s.d(t,{$:()=>c});var a=s(24420),n=s.n(a),i=s(68404),r=s(18745),o=s(45193),d=s(45916);const c=(e,t,s)=>a=>{const c=(0,r.connect)(e,t)(a),l=e=>{const t=(0,r.useDispatch)();return(0,i.useEffect)((()=>function(){t((0,o.e)({stateSelector:s}))}),[t]),(0,d.jsx)(c,Object.assign({},e))};return l.displayName=`ConnectWithCleanUp(${c.displayName})`,n()(l,a),l}},53213:(e,t,s)=>{s.r(t),s.d(t,{TeamList:()=>w,default:()=>k});var a=s(68404),n=s(69783),i=s(28436),r=s(33801),o=s(42147),d=s(98638),c=s(77058),l=s(45916);const m=e=>{let{teamId:t,orgId:s,roleOptions:n,disabled:i,builtinRolesDisabled:r}=e;const[{loading:m,value:h=[]},u]=(0,o.Z)((async()=>{try{return await(0,c._C)(t,s)}catch(e){console.error("Error loading options")}return[]}),[s,t]);(0,a.useEffect)((()=>{u()}),[s,t,u]);return(0,l.jsx)(d.I,{onRolesChange:async e=>{await(0,c.u7)(e,t,s),await u()},roleOptions:n,appliedRoles:h,isLoading:m,disabled:i,builtinRolesDisabled:r})};var h,u,p,g,b,f=s(78837),x=s(8674),v=s(61959),y=s(58170),j=s(39539),T=s(44083),A=s(99574),C=s(71181);function P(e,t,s){return t in e?Object.defineProperty(e,t,{value:s,enumerable:!0,configurable:!0,writable:!0}):e[t]=s,e}class w extends a.PureComponent{constructor(e){super(e),P(this,"deleteTeam",(e=>{this.props.deleteTeam(e.id)})),P(this,"onSearchQueryChange",(e=>{this.props.setSearchQuery(e)})),P(this,"getPaginatedTeams",(e=>{const t=30*(this.props.searchPage-1);return e.slice(t,t+30)})),this.state={roleOptions:[]}}componentDidMount(){this.fetchTeams(),v.Vt.licensedAccessControlEnabled()&&v.Vt.hasPermission(y.bW.ActionRolesList)&&this.fetchRoleOptions()}async fetchTeams(){await this.props.loadTeams()}async fetchRoleOptions(){const e=await(0,c.ul)();this.setState({roleOptions:e})}renderTeam(e){var t,s;const{editorsCanAdmin:a,signedInUser:i}=this.props,r=e.permission,o=`org/teams/edit/${e.id}`,d=(0,C.kC)({permission:r,editorsCanAdmin:a,signedInUser:i}),c=v.Vt.hasAccessInMetadata(y.bW.ActionTeamsDelete,e,d),h=v.Vt.hasAccessInMetadata(y.bW.ActionTeamsRead,e,d),u=v.Vt.hasAccessInMetadata(y.bW.ActionTeamsRolesList,e,!1),p=v.Vt.hasAccess(y.bW.ActionTeamsRolesAdd,!1)||v.Vt.hasAccess(y.bW.ActionTeamsRolesRemove,!1),g=v.Vt.licensedAccessControlEnabled()&&v.Vt.hasPermission(y.bW.ActionTeamsRolesList)&&v.Vt.hasPermission(y.bW.ActionRolesList);return(0,l.jsxs)("tr",{children:[(0,l.jsx)("td",{className:"width-4 text-center link-td",children:h?(0,l.jsx)("a",{href:o,children:(0,l.jsx)("img",{className:"filter-table__avatar",src:e.avatarUrl,alt:"Team avatar"})}):(0,l.jsx)("img",{className:"filter-table__avatar",src:e.avatarUrl,alt:"Team avatar"})}),(0,l.jsx)("td",{className:"link-td",children:h?(0,l.jsx)("a",{href:o,children:e.name}):(0,l.jsx)("div",{style:{padding:"0px 8px"},children:e.name})}),(0,l.jsx)("td",{className:"link-td",children:h?(0,l.jsx)("a",{href:o,"aria-label":(null===(t=e.email)||void 0===t?void 0:t.length)>0?void 0:"Empty email cell",children:e.email}):(0,l.jsx)("div",{style:{padding:"0px 8px"},"aria-label":(null===(s=e.email)||void 0===s?void 0:s.length)>0?void 0:"Empty email cell",children:e.email})}),(0,l.jsx)("td",{className:"link-td",children:h?(0,l.jsx)("a",{href:o,children:e.memberCount}):(0,l.jsx)("div",{style:{padding:"0px 8px"},children:e.memberCount})}),g&&(0,l.jsx)("td",{children:u&&(0,l.jsx)(m,{teamId:e.id,roleOptions:this.state.roleOptions,disabled:!p})}),(0,l.jsx)("td",{className:"text-right",children:(0,l.jsx)(n.DeleteButton,{"aria-label":"Delete team",size:"sm",disabled:!c,onConfirm:()=>this.deleteTeam(e)})})]},e.id)}renderEmptyList(){return(0,l.jsx)(i.Z,{title:"You haven't created any teams yet.",buttonIcon:"users-alt",buttonLink:"org/teams/new",buttonTitle:" New team",buttonDisabled:!v.Vt.hasPermission(y.bW.ActionTeamsCreate),proTip:"Assign folder and dashboard permissions to teams instead of users to ease administration.",proTipLink:"",proTipLinkTitle:"",proTipTarget:"_blank"})}renderTeamList(){const{teams:e,searchQuery:t,editorsCanAdmin:s,searchPage:a,setTeamsSearchPage:i}=this.props,r=v.Vt.hasRole("Admin")||s&&v.Vt.hasRole("Editor"),o=v.Vt.hasAccess(y.bW.ActionTeamsCreate,r),d=v.Vt.licensedAccessControlEnabled()&&v.Vt.hasPermission(y.bW.ActionTeamsRolesList)&&v.Vt.hasPermission(y.bW.ActionRolesList),c=o?"org/teams/new":"#",m=this.getPaginatedTeams(e),f=Math.ceil(e.length/30);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"page-action-bar",children:[(0,l.jsx)("div",{className:"gf-form gf-form--grow",children:(0,l.jsx)(n.FilterInput,{placeholder:"Search teams",value:t,onChange:this.onSearchQueryChange})}),(0,l.jsx)(n.LinkButton,{href:c,disabled:!o,children:"New Team"})]}),(0,l.jsx)("div",{className:"admin-list-table",children:(0,l.jsxs)(n.VerticalGroup,{spacing:"md",children:[(0,l.jsxs)("table",{className:"filter-table filter-table--hover form-inline",children:[(0,l.jsx)("thead",{children:(0,l.jsxs)("tr",{children:[h||(h=(0,l.jsx)("th",{})),u||(u=(0,l.jsx)("th",{children:"Name"})),p||(p=(0,l.jsx)("th",{children:"Email"})),g||(g=(0,l.jsx)("th",{children:"Members"})),d&&(b||(b=(0,l.jsx)("th",{children:"Roles"}))),(0,l.jsx)("th",{style:{width:"1%"}})]})}),(0,l.jsx)("tbody",{children:m.map((e=>this.renderTeam(e)))})]}),(0,l.jsx)(n.HorizontalGroup,{justify:"flex-end",children:(0,l.jsx)(n.Pagination,{onNavigate:i,currentPage:a,numberOfPages:f,hideWhenSinglePage:!0})})]})})]})}renderList(){const{teamsCount:e,hasFetched:t}=this.props;return t?e>0?this.renderTeamList():this.renderEmptyList():null}render(){const{hasFetched:e,navModel:t}=this.props;return(0,l.jsx)(r.Z,{navModel:t,children:(0,l.jsx)(r.Z.Contents,{isLoading:!e,children:this.renderList()})})}}const I={loadTeams:T.jI,deleteTeam:T.fC,setSearchQuery:A.ql,setTeamsSearchPage:A.ot},k=(0,j.$)((function(e){return{navModel:(0,x.h)(e.navIndex,"teams"),teams:(0,C.LK)(e.teams),searchQuery:(0,C.uP)(e.teams),searchPage:(0,C._u)(e.teams),teamsCount:(0,C.v7)(e.teams),hasFetched:e.teams.hasFetched,editorsCanAdmin:f.vc.editorsCanAdmin,signedInUser:v.Vt.user}}),I,(e=>e.teams))(w)},44083:(e,t,s)=>{s.d(t,{A_:()=>f,Lt:()=>u,P5:()=>x,QX:()=>m,ei:()=>h,fC:()=>v,fs:()=>g,jI:()=>l,j_:()=>b,zT:()=>p,zZ:()=>y});var a=s(90923),n=s(36537),i=s(98163),r=s(66728),o=s(58170),d=s(91574),c=s(99574);function l(){return async e=>{if(!i.Vt.hasPermission(o.bW.ActionTeamsRead))return void e((0,c.PL)([]));const t=await(0,a.getBackendSrv)().get("/api/teams/search",(0,r.y)({perpage:1e3,page:1}));e((0,c.PL)(t.teams))}}function m(e){return async t=>{const s=await(0,a.getBackendSrv)().get(`/api/teams/${e}`,(0,r.y)());t((0,c.y$)(s)),t((0,n.RL)((0,d.B)(s)))}}function h(){return async(e,t)=>{const s=t().team.team,n=await(0,a.getBackendSrv)().get(`/api/teams/${s.id}/members`);e((0,c.n2)(n))}}function u(e){return async(t,s)=>{const n=s().team.team;await(0,a.getBackendSrv)().post(`/api/teams/${n.id}/members`,{userId:e}),t(h())}}function p(e){return async(t,s)=>{const n=s().team.team;await(0,a.getBackendSrv)().delete(`/api/teams/${n.id}/members/${e}`),t(h())}}function g(e,t){return async(s,n)=>{const i=n().team.team;await(0,a.getBackendSrv)().put(`/api/teams/${i.id}`,{name:e,email:t}),s(m(i.id))}}function b(){return async(e,t)=>{const s=t().team.team,n=await(0,a.getBackendSrv)().get(`/api/teams/${s.id}/groups`);e((0,c.iI)(n))}}function f(e){return async(t,s)=>{const n=s().team.team;await(0,a.getBackendSrv)().post(`/api/teams/${n.id}/groups`,{groupId:e}),t(b())}}function x(e){return async(t,s)=>{const n=s().team.team;await(0,a.getBackendSrv)().delete(`/api/teams/${n.id}/groups/${encodeURIComponent(e)}`),t(b())}}function v(e){return async t=>{await(0,a.getBackendSrv)().delete(`/api/teams/${e}`),await i.Vt.fetchUserPermissions(),t(l())}}function y(e){return async t=>{await(0,a.getBackendSrv)().put(`/api/teams/${e.teamId}/members/${e.userId}`,{permission:e.permission}),t(h())}}},91574:(e,t,s)=>{s.d(t,{B:()=>l,o:()=>m});var a=s(90923),n=s(17963),i=s(78837),r=s(61959),o=s(65623),d=s(58170);const c={avatarUrl:"public/img/user_profile.png",id:1,name:"Loading",email:"loading",memberCount:0,permission:d.hw.Member};function l(e){const t={img:e.avatarUrl,id:"team-"+e.id,subTitle:"Manage members and settings",url:"",text:e.name,breadcrumbs:[{title:"Teams",url:"org/teams"}],children:[{active:!1,icon:"sliders-v-alt",id:`team-settings-${e.id}`,text:"Settings",url:`org/teams/edit/${e.id}/settings`}]};(e===c||r.Vt.hasPermissionInMetadata(d.bW.ActionTeamsPermissionsRead,e))&&t.children.unshift({active:!1,icon:"users-alt",id:`team-members-${e.id}`,text:"Members",url:`org/teams/edit/${e.id}/members`});const s={active:!1,icon:"sync",id:`team-groupsync-${e.id}`,text:"External group sync",url:`org/teams/edit/${e.id}/groupsync`},l=e===c;return(0,o.d)()&&(s.tabSuffix=()=>(0,n.Z)({experimentId:l?"":"feature-highlights-team-sync-badge",eventVariant:"trial"})),(0,a.featureEnabled)("teamsync")?(l||r.Vt.hasPermissionInMetadata(d.bW.ActionTeamsPermissionsRead,e))&&t.children.push(s):i.ZP.featureToggles.featureHighlights&&t.children.push(Object.assign({},s,{tabSuffix:()=>(0,n.Z)({experimentId:l?"":"feature-highlights-team-sync-badge"})})),t}function m(e){const t=l(c);let s;for(const a of t.children)if(a.id.indexOf(e)>0){a.active=!0,s=a;break}return{main:t,node:s}}},71181:(e,t,s)=>{s.d(t,{JB:()=>r,LK:()=>l,VP:()=>c,YY:()=>m,_u:()=>d,kC:()=>u,uP:()=>n,v7:()=>o,vt:()=>h,xc:()=>i});var a=s(58170);const n=e=>e.searchQuery,i=e=>e.searchMemberQuery,r=e=>e.groups,o=e=>e.teams.length,d=e=>e.searchPage,c=(e,t)=>e.team.id===parseInt(t,10)?e.team:null,l=e=>{const t=RegExp(e.searchQuery,"i");return e.teams.filter((e=>t.test(e.name)))},m=e=>{const t=RegExp(e.searchMemberQuery,"i");return e.members.filter((e=>t.test(e.login)||t.test(e.email)||t.test(e.name)))},h=e=>{const{members:t,signedInUser:s,editorsCanAdmin:n}=e,i=t.find((e=>e.userId===s.id)),r=i?i.permission:a.hw.Member;return u({permission:r,signedInUser:s,editorsCanAdmin:n})},u=e=>{const{permission:t,signedInUser:s,editorsCanAdmin:n}=e,i=s.isGrafanaAdmin||s.orgRole===a.B5.Admin,r=t===a.hw.Admin;return i||r||!n}}}]); //# sourceMappingURL=TeamList.4f158f50a8cfa2e05a8c.js.map