2023-01-09 02:54:33 -06:00
|
|
|
import React from 'react';
|
|
|
|
import { connect, ConnectedProps } from 'react-redux';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-09-29 02:35:41 -05:00
|
|
|
import { RadioButtonGroup, LinkButton, FilterInput } from '@grafana/ui';
|
2021-04-22 05:19:41 -05:00
|
|
|
import { contextSrv } from 'app/core/core';
|
2022-07-08 06:07:00 -05:00
|
|
|
import { AccessControlAction, StoreState } from 'app/types';
|
2018-10-03 02:43:10 -05:00
|
|
|
|
2022-04-22 08:33:13 -05:00
|
|
|
import { selectTotal } from '../invites/state/selectors';
|
|
|
|
|
2023-01-09 02:54:33 -06:00
|
|
|
import { changeSearchQuery } from './state/actions';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { getUsersSearchQuery } from './state/selectors';
|
|
|
|
|
2023-01-09 02:54:33 -06:00
|
|
|
export interface OwnProps {
|
2018-10-03 06:04:31 -05:00
|
|
|
showInvites: boolean;
|
2023-01-09 02:54:33 -06:00
|
|
|
onShowInvites: () => void;
|
2018-10-03 02:43:10 -05:00
|
|
|
}
|
|
|
|
|
2022-07-08 06:07:00 -05:00
|
|
|
function mapStateToProps(state: StoreState) {
|
2018-10-03 02:43:10 -05:00
|
|
|
return {
|
|
|
|
searchQuery: getUsersSearchQuery(state.users),
|
2022-02-21 05:37:49 -06:00
|
|
|
pendingInvitesCount: selectTotal(state.invites),
|
2018-10-03 02:43:10 -05:00
|
|
|
externalUserMngLinkName: state.users.externalUserMngLinkName,
|
|
|
|
externalUserMngLinkUrl: state.users.externalUserMngLinkUrl,
|
|
|
|
canInvite: state.users.canInvite,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
2023-01-09 02:54:33 -06:00
|
|
|
changeSearchQuery,
|
|
|
|
};
|
|
|
|
|
|
|
|
const connector = connect(mapStateToProps, mapDispatchToProps);
|
|
|
|
|
|
|
|
export type Props = ConnectedProps<typeof connector> & OwnProps;
|
|
|
|
|
|
|
|
export const UsersActionBarUnconnected = ({
|
|
|
|
canInvite,
|
|
|
|
externalUserMngLinkName,
|
|
|
|
externalUserMngLinkUrl,
|
|
|
|
searchQuery,
|
|
|
|
pendingInvitesCount,
|
|
|
|
changeSearchQuery,
|
|
|
|
onShowInvites,
|
|
|
|
showInvites,
|
|
|
|
}: Props): JSX.Element => {
|
|
|
|
const options = [
|
|
|
|
{ label: 'Users', value: 'users' },
|
|
|
|
{ label: `Pending Invites (${pendingInvitesCount})`, value: 'invites' },
|
|
|
|
];
|
|
|
|
const canAddToOrg: boolean = contextSrv.hasAccess(AccessControlAction.OrgUsersAdd, canInvite);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="page-action-bar" data-testid="users-action-bar">
|
|
|
|
<div className="gf-form gf-form--grow">
|
|
|
|
<FilterInput
|
|
|
|
value={searchQuery}
|
|
|
|
onChange={changeSearchQuery}
|
|
|
|
placeholder="Search user by login, email or name"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
{pendingInvitesCount > 0 && (
|
|
|
|
<div style={{ marginLeft: '1rem' }}>
|
|
|
|
<RadioButtonGroup value={showInvites ? 'invites' : 'users'} options={options} onChange={onShowInvites} />
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{canAddToOrg && <LinkButton href="org/users/invite">Invite</LinkButton>}
|
|
|
|
{externalUserMngLinkUrl && (
|
|
|
|
<LinkButton href={externalUserMngLinkUrl} target="_blank" rel="noopener">
|
|
|
|
{externalUserMngLinkName}
|
|
|
|
</LinkButton>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2018-10-03 02:43:10 -05:00
|
|
|
};
|
|
|
|
|
2023-01-09 02:54:33 -06:00
|
|
|
export const UsersActionBar = connector(UsersActionBarUnconnected);
|