import React, { PureComponent } from 'react'; import { connect, ConnectedProps } from 'react-redux'; import { SlideDown } from 'app/core/components/Animations/SlideDown'; import { LegacyForms, Tooltip, Icon, Button } from '@grafana/ui'; const { Input } = LegacyForms; import { StoreState, TeamGroup } from '../../types'; import { addTeamGroup, loadTeamGroups, removeTeamGroup } from './state/actions'; import { getTeamGroups } from './state/selectors'; import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; import { CloseButton } from 'app/core/components/CloseButton/CloseButton'; function mapStateToProps(state: StoreState) { return { groups: getTeamGroups(state.team), }; } const mapDispatchToProps = { loadTeamGroups, addTeamGroup, removeTeamGroup, }; interface State { isAdding: boolean; newGroupId: string; } const connector = connect(mapStateToProps, mapDispatchToProps); export type Props = ConnectedProps; const headerTooltip = `Sync LDAP or OAuth groups with your Grafana teams.`; export class TeamGroupSync extends PureComponent { constructor(props: Props) { super(props); this.state = { isAdding: false, newGroupId: '' }; } componentDidMount() { this.fetchTeamGroups(); } async fetchTeamGroups() { await this.props.loadTeamGroups(); } onToggleAdding = () => { this.setState({ isAdding: !this.state.isAdding }); }; onNewGroupIdChanged = (event: any) => { this.setState({ newGroupId: event.target.value }); }; onAddGroup = (event: any) => { event.preventDefault(); this.props.addTeamGroup(this.state.newGroupId); this.setState({ isAdding: false, newGroupId: '' }); }; onRemoveGroup = (group: TeamGroup) => { this.props.removeTeamGroup(group.groupId); }; isNewGroupValid() { return this.state.newGroupId.length > 1; } renderGroup(group: TeamGroup) { return ( {group.groupId} ); } render() { const { isAdding, newGroupId } = this.state; const groups = this.props.groups; return (

External group sync

{groups.length > 0 && ( )}
Add External Group
{groups.length === 0 && !isAdding && ( )} {groups.length > 0 && (
{groups.map((group) => this.renderGroup(group))}
External Group ID
)}
); } } export default connect(mapStateToProps, mapDispatchToProps)(TeamGroupSync);