import React, { PureComponent } from 'react'; import { connect, ConnectedProps } from 'react-redux'; import { Input, Tooltip, Icon, Button, useTheme2, InlineField, InlineFieldRow } from '@grafana/ui'; import { SlideDown } from 'app/core/components/Animations/SlideDown'; import { CloseButton } from 'app/core/components/CloseButton/CloseButton'; import EmptyListCTA from 'app/core/components/EmptyListCTA/EmptyListCTA'; import { UpgradeBox, UpgradeContent, UpgradeContentProps } from 'app/core/components/Upgrade/UpgradeBox'; import { highlightTrial } from 'app/features/admin/utils'; import { StoreState, TeamGroup } from '../../types'; import { addTeamGroup, loadTeamGroups, removeTeamGroup } from './state/actions'; import { getTeamGroups } from './state/selectors'; function mapStateToProps(state: StoreState) { return { groups: getTeamGroups(state.team), }; } const mapDispatchToProps = { loadTeamGroups, addTeamGroup, removeTeamGroup, }; interface OwnProps { isReadOnly: boolean; } interface State { isAdding: boolean; newGroupId: string; } const connector = connect(mapStateToProps, mapDispatchToProps); export type Props = OwnProps & 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) { const { isReadOnly } = this.props; return ( {group.groupId} ); } render() { const { isAdding, newGroupId } = this.state; const { groups, isReadOnly } = this.props; return (
{highlightTrial() && ( )}
{(!highlightTrial() || groups.length > 0) && ( <>

External group sync

)}
{groups.length > 0 && ( )}
{groups.length === 0 && !isAdding && (highlightTrial() ? ( ) : ( ))} {groups.length > 0 && (
{groups.map((group) => this.renderGroup(group))}
External Group ID
)}
); } } export const TeamSyncUpgradeContent = ({ action }: { action?: UpgradeContentProps['action'] }) => { const theme = useTheme2(); return ( ); }; export default connect(mapStateToProps, mapDispatchToProps)(TeamGroupSync);