"use strict";(self.webpackChunkgrafana=self.webpackChunkgrafana||[]).push([[1337],{94928:(e,s,t)=>{t.r(s),t.d(s,{default:()=>W,getStyles:()=>L});var n,i=t(68490),a=t(71757),c=t.n(a),l=t(76687),o=t(46958),r=t(70534),d=t(97726),u=t(36131),h=t(58601),m=t(31271),v=t(3276),x=t(99462),p=t(19017),b=t(35333),g=t(52010);const j=e=>`Edit service account's ${e} details`,f=e=>e?"Disabled":"Enabled",A=(0,l.memo)((e=>{let{serviceAccount:s,onRoleChange:t,roleOptions:a,builtInRoles:c,onSetToRemove:l}=e;const o=`org/serviceaccounts/${s.id}`,d=(0,r.useStyles2)(L),u=m.Vt.hasPermissionInMetadata(x.bW.ServiceAccountsWrite,s),h=m.Vt.hasPermission(x.bW.ActionRolesList)&&m.Vt.hasPermission(x.bW.ActionUserRolesList),v=m.Vt.hasPermission(x.bW.OrgUsersWrite)&&u;return(0,g.jsxs)("tr",{children:[(0,g.jsx)("td",{className:"width-4 text-center link-td",children:(0,g.jsx)("a",{href:o,"aria-label":j(s.name),children:(0,g.jsx)("img",{className:"filter-table__avatar",src:s.avatarUrl,alt:`Avatar for user ${s.name}`})})}),(0,g.jsx)("td",{className:"link-td max-width-10",children:(0,g.jsx)("a",{className:"ellipsis",href:o,title:s.name,"aria-label":j(s.name),children:s.name})}),(0,g.jsx)("td",{className:"link-td max-width-10",children:(0,g.jsx)("a",{className:"ellipsis",href:o,title:s.login,"aria-label":j(s.name),children:s.login})}),m.Vt.licensedAccessControlEnabled()?(0,g.jsx)("td",{className:(0,i.cx)("link-td",d.iconRow),children:h&&(0,g.jsx)(p.R,{userId:s.id,orgId:s.orgId,builtInRole:s.role,onBuiltinRoleChange:e=>t(e,s),roleOptions:a,builtInRoles:c,disabled:!v})}):(0,g.jsx)("td",{className:(0,i.cx)("link-td",d.iconRow),children:(0,g.jsx)(b.A,{"aria-label":"Role",value:s.role,disabled:!u,onChange:e=>t(e,s)})}),(0,g.jsx)("td",{className:"link-td max-width-10",children:(0,g.jsx)("a",{className:"ellipsis",href:o,title:f(s.isDisabled),"aria-label":j(s.name),children:f(s.isDisabled)})}),(0,g.jsx)("td",{className:"link-td max-width-10",children:(0,g.jsxs)("a",{className:"ellipsis",href:o,title:"Tokens","aria-label":j(s.name),children:[n||(n=(0,g.jsx)("span",{children:(0,g.jsx)(r.Icon,{name:"key-skeleton-alt"})}))," ",s.tokens]})}),m.Vt.hasPermissionInMetadata(x.bW.ServiceAccountsDelete,s)&&(0,g.jsx)("td",{children:(0,g.jsx)(r.Button,{size:"sm",variant:"destructive",onClick:()=>{l(s)},icon:"times","aria-label":"Delete service account"})})]},s.id)}));A.displayName="ServiceAccountListItem";const k=A;var y,R,S,C,I,T,w,N,$,D=t(79920);const O={fetchServiceAccounts:D.Xd,fetchACOptions:D.bX,updateServiceAccount:D.TL,removeServiceAccount:D.IR,setServiceAccountToRemove:D.cl,changeFilter:D.M6,changeQuery:D.R5},V=(0,o.connect)((function(e){return Object.assign({navModel:(0,v.h)(e.navIndex,"serviceaccounts")},e.serviceAccounts)}),O),L=e=>({table:i.css`
      margin-top: ${e.spacing(3)};
    `,filter:i.css`
      margin: 0 ${e.spacing(1)};
    `,iconRow:i.css`
      svg {
        margin-left: ${e.spacing(.5)};
      }
    `,row:i.css`
      display: flex;
      align-items: center;
      height: 100% !important;

      a {
        padding: ${e.spacing(.5)} 0 !important;
      }
    `,unitTooltip:i.css`
      display: flex;
      flex-direction: column;
    `,unitItem:i.css`
      cursor: pointer;
      padding: ${e.spacing(.5)} 0;
      margin-right: ${e.spacing(1)};
    `,disabled:i.css`
      color: ${e.colors.text.disabled};
    `,link:i.css`
      color: inherit;
      cursor: pointer;
      text-decoration: underline;
    `}),W=V((e=>{var s;let{fetchServiceAccounts:t,removeServiceAccount:n,fetchACOptions:a,updateServiceAccount:o,setServiceAccountToRemove:v,navModel:p,serviceAccounts:b,isLoading:j,roleOptions:f,builtInRoles:A,changeFilter:D,changeQuery:O,query:V,filters:W,serviceAccountToRemove:P}=e;const E=(0,r.useStyles2)(L);(0,l.useEffect)((()=>{(async()=>{await t(),m.Vt.licensedAccessControlEnabled()&&await a()})()}),[t,a]);const M=async(e,s)=>{const n=Object.assign({},s,{role:e});await o(n),await t(),m.Vt.licensedAccessControlEnabled()&&a()};return(0,g.jsx)(u.Z,{navModel:p,children:(0,g.jsxs)(u.Z.Contents,{children:[y||(y=(0,g.jsx)("h2",{children:"Service accounts"})),(0,g.jsxs)("div",{className:"page-action-bar",style:{justifyContent:"flex-end"},children:[(0,g.jsx)(r.FilterInput,{placeholder:"Search service account by name.",autoFocus:!0,value:V,onChange:O}),(0,g.jsx)(r.RadioButtonGroup,{options:[{label:"All service accounts",value:!1},{label:"Expired tokens",value:!0}],onChange:e=>D({name:"expiredTokens",value:e}),value:null===(s=W.find((e=>"expiredTokens"===e.name)))||void 0===s?void 0:s.value,className:E.filter}),0!==b.length&&m.Vt.hasPermission(x.bW.ServiceAccountsCreate)&&(R||(R=(0,g.jsx)(r.LinkButton,{href:"org/serviceaccounts/create",variant:"primary",children:"Add service account"})))]}),j&&(S||(S=(0,g.jsx)(h.Z,{}))),!j&&0===b.length&&(0,g.jsx)(g.Fragment,{children:(0,g.jsx)(d.Z,{title:"You haven't created any service accounts yet.",buttonIcon:"key-skeleton-alt",buttonLink:"org/serviceaccounts/create",buttonTitle:"Add service account",buttonDisabled:!m.Vt.hasPermission(x.bW.ServiceAccountsCreate),proTip:"Remember, you can provide specific permissions for API access to other applications.",proTipLink:"",proTipLinkTitle:"",proTipTarget:"_blank"})}),!j&&0!==b.length&&(0,g.jsx)(g.Fragment,{children:(0,g.jsx)("div",{className:(0,i.cx)(E.table,"admin-list-table"),children:(0,g.jsxs)("table",{className:"filter-table form-inline filter-table--hover",children:[(0,g.jsx)("thead",{children:(0,g.jsxs)("tr",{children:[C||(C=(0,g.jsx)("th",{})),I||(I=(0,g.jsx)("th",{children:"Account"})),T||(T=(0,g.jsx)("th",{children:"ID"})),w||(w=(0,g.jsx)("th",{children:"Roles"})),N||(N=(0,g.jsx)("th",{children:"Status"})),$||($=(0,g.jsx)("th",{children:"Tokens"})),(0,g.jsx)("th",{style:{width:"34px"}})]})}),(0,g.jsx)("tbody",{children:b.map((e=>(0,g.jsx)(k,{serviceAccount:e,builtInRoles:A,roleOptions:f,onRoleChange:M,onSetToRemove:v},e.id)))})]})})}),P&&(0,g.jsx)(r.ConfirmModal,{body:(0,g.jsxs)("div",{children:["Are you sure you want to delete '",P.name,"'",Boolean(P.tokens)&&` and ${P.tokens} accompanying ${c()("token",P.tokens)}`,"?"]}),confirmText:"Delete",title:"Delete service account",onDismiss:()=>{v(null)},isOpen:!0,onConfirm:()=>{n(P.id),v(null)}})]})})}))}}]);
//# sourceMappingURL=ServiceAccountsPage.92df3fa60ff129dfe444.js.map