2018-10-03 02:43:10 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { setUsersSearchQuery } from './state/reducers';
|
2018-10-03 02:43:10 -05:00
|
|
|
import { getInviteesCount, getUsersSearchQuery } from './state/selectors';
|
2019-02-12 09:22:57 -06:00
|
|
|
import { FilterInput } from 'app/core/components/FilterInput/FilterInput';
|
2020-04-15 09:49:20 -05:00
|
|
|
import { RadioButtonGroup, LinkButton } from '@grafana/ui';
|
2021-04-22 05:19:41 -05:00
|
|
|
import { contextSrv } from 'app/core/core';
|
|
|
|
import { AccessControlAction } from 'app/types';
|
2018-10-03 02:43:10 -05:00
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
searchQuery: string;
|
|
|
|
setUsersSearchQuery: typeof setUsersSearchQuery;
|
2018-10-03 03:54:15 -05:00
|
|
|
onShowInvites: () => void;
|
2018-10-03 02:43:10 -05:00
|
|
|
pendingInvitesCount: number;
|
|
|
|
canInvite: boolean;
|
2018-10-03 06:04:31 -05:00
|
|
|
showInvites: boolean;
|
2018-10-03 02:43:10 -05:00
|
|
|
externalUserMngLinkUrl: string;
|
|
|
|
externalUserMngLinkName: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class UsersActionBar extends PureComponent<Props> {
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
canInvite,
|
|
|
|
externalUserMngLinkName,
|
|
|
|
externalUserMngLinkUrl,
|
|
|
|
searchQuery,
|
|
|
|
pendingInvitesCount,
|
|
|
|
setUsersSearchQuery,
|
2018-10-03 03:54:15 -05:00
|
|
|
onShowInvites,
|
2018-10-03 06:04:31 -05:00
|
|
|
showInvites,
|
2018-10-03 02:43:10 -05:00
|
|
|
} = this.props;
|
2020-04-15 09:49:20 -05:00
|
|
|
const options = [
|
|
|
|
{ label: 'Users', value: 'users' },
|
|
|
|
{ label: `Pending Invites (${pendingInvitesCount})`, value: 'invites' },
|
|
|
|
];
|
2021-04-22 05:19:41 -05:00
|
|
|
const canAddToOrg = contextSrv.hasPermission(AccessControlAction.OrgUsersAdd);
|
2018-10-03 06:04:31 -05:00
|
|
|
|
2018-10-03 02:43:10 -05:00
|
|
|
return (
|
|
|
|
<div className="page-action-bar">
|
|
|
|
<div className="gf-form gf-form--grow">
|
2019-02-12 09:22:57 -06:00
|
|
|
<FilterInput
|
|
|
|
value={searchQuery}
|
|
|
|
onChange={setUsersSearchQuery}
|
2020-07-01 02:34:36 -05:00
|
|
|
placeholder="Search user by login, email or name"
|
2019-02-12 09:22:57 -06:00
|
|
|
/>
|
2018-10-03 02:43:10 -05:00
|
|
|
</div>
|
2021-04-30 03:04:01 -05:00
|
|
|
{pendingInvitesCount > 0 && (
|
|
|
|
<div style={{ marginLeft: '1rem' }}>
|
|
|
|
<RadioButtonGroup value={showInvites ? 'invites' : 'users'} options={options} onChange={onShowInvites} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{canInvite && canAddToOrg && <LinkButton href="org/users/invite">Invite</LinkButton>}
|
|
|
|
{externalUserMngLinkUrl && (
|
|
|
|
<LinkButton href={externalUserMngLinkUrl} target="_blank" rel="noopener">
|
|
|
|
{externalUserMngLinkName}
|
|
|
|
</LinkButton>
|
|
|
|
)}
|
2018-10-03 02:43:10 -05:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-11 10:05:45 -05:00
|
|
|
function mapStateToProps(state: any) {
|
2018-10-03 02:43:10 -05:00
|
|
|
return {
|
|
|
|
searchQuery: getUsersSearchQuery(state.users),
|
|
|
|
pendingInvitesCount: getInviteesCount(state.users),
|
|
|
|
externalUserMngLinkName: state.users.externalUserMngLinkName,
|
|
|
|
externalUserMngLinkUrl: state.users.externalUserMngLinkUrl,
|
|
|
|
canInvite: state.users.canInvite,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
setUsersSearchQuery,
|
|
|
|
};
|
|
|
|
|
2019-11-19 07:59:39 -06:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(UsersActionBar);
|