import { useMemo } from 'react'; import { Alert, CellProps, Column, Icon, InteractiveTable, Stack, Text, Tooltip } from '@grafana/ui'; import { Trans } from 'app/core/internationalization'; import { AppNotificationSeverity, LdapConnectionInfo, LdapServerInfo } from 'app/types'; interface Props { ldapConnectionInfo: LdapConnectionInfo; } interface ServerInfo { host: string; port: number; available: boolean; } export const LdapConnectionStatus = ({ ldapConnectionInfo }: Props) => { const columns = useMemo>>( () => [ { id: 'host', header: 'Host', disableGrow: true, }, { id: 'port', header: 'Port', disableGrow: true, }, { id: 'available', cell: (serverInfo: CellProps) => { return serverInfo.cell.value ? ( ) : ( ); }, }, ], [] ); const data = useMemo(() => ldapConnectionInfo, [ldapConnectionInfo]); return (
LDAP Connection serverInfo.host + serverInfo.port} />
); }; interface LdapConnectionErrorProps { ldapConnectionInfo: LdapConnectionInfo; } export const LdapErrorBox = ({ ldapConnectionInfo }: LdapConnectionErrorProps) => { const hasError = ldapConnectionInfo.some((info) => info.error); if (!hasError) { return null; } const connectionErrors: LdapServerInfo[] = []; ldapConnectionInfo.forEach((info) => { if (info.error) { connectionErrors.push(info); } }); const errorElements = connectionErrors.map((info, index) => (
{`${info.host}:${info.port}`}
{info.error} {index !== connectionErrors.length - 1 && ( <>

)}
)); return ( {errorElements} ); };