import React, { PureComponent } from 'react'; import { connect, ConnectedProps } from 'react-redux'; import { SelectableValue } from '@grafana/data'; import { Button, FilterInput, Label } from '@grafana/ui'; import { SlideDown } from 'app/core/components/Animations/SlideDown'; import { CloseButton } from 'app/core/components/CloseButton/CloseButton'; import { UserPicker } from 'app/core/components/Select/UserPicker'; import { TagBadge } from 'app/core/components/TagFilter/TagBadge'; import { WithFeatureToggle } from 'app/core/components/WithFeatureToggle'; import { config } from 'app/core/config'; import { contextSrv } from 'app/core/services/context_srv'; import { TeamMember, OrgUser } from 'app/types'; import TeamMemberRow from './TeamMemberRow'; import { addTeamMember } from './state/actions'; import { setSearchMemberQuery } from './state/reducers'; import { getSearchMemberQuery, isSignedInUserTeamAdmin } from './state/selectors'; function mapStateToProps(state: any) { return { searchMemberQuery: getSearchMemberQuery(state.team), editorsCanAdmin: config.editorsCanAdmin, // this makes the feature toggle mockable/controllable from tests, signedInUser: contextSrv.user, // this makes the feature toggle mockable/controllable from tests, }; } const mapDispatchToProps = { addTeamMember, setSearchMemberQuery, }; const connector = connect(mapStateToProps, mapDispatchToProps); interface OwnProps { members: TeamMember[]; syncEnabled: boolean; } export type Props = ConnectedProps & OwnProps; export interface State { isAdding: boolean; newTeamMember?: SelectableValue | null; } export class TeamMembers extends PureComponent { constructor(props: Props) { super(props); this.state = { isAdding: false, newTeamMember: null }; } onSearchQueryChange = (value: string) => { this.props.setSearchMemberQuery(value); }; onToggleAdding = () => { this.setState({ isAdding: !this.state.isAdding }); }; onUserSelected = (user: SelectableValue) => { this.setState({ newTeamMember: user }); }; onAddUserToTeam = async () => { this.props.addTeamMember(this.state.newTeamMember!.id); this.setState({ newTeamMember: null }); }; renderLabels(labels: string[]) { if (!labels) { return ; } return ( {labels.map((label) => ( {}} /> ))} ); } render() { const { isAdding } = this.state; const { searchMemberQuery, members, syncEnabled, editorsCanAdmin, signedInUser } = this.props; const isTeamAdmin = isSignedInUserTeamAdmin({ members, editorsCanAdmin, signedInUser }); return (
{this.state.newTeamMember && ( )}
{syncEnabled && {members && members.map((member) => ( ))}
Login Email Name Permission }
); } } export default connector(TeamMembers);