LdapConnectionStatus.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import React, { FC } from 'react';
  2. import { Alert, Icon } from '@grafana/ui';
  3. import { AppNotificationSeverity, LdapConnectionInfo, LdapServerInfo } from 'app/types';
  4. interface Props {
  5. ldapConnectionInfo: LdapConnectionInfo;
  6. }
  7. export const LdapConnectionStatus: FC<Props> = ({ ldapConnectionInfo }) => {
  8. return (
  9. <>
  10. <h3 className="page-heading">LDAP Connection</h3>
  11. <div className="gf-form-group">
  12. <div className="gf-form">
  13. <table className="filter-table form-inline">
  14. <thead>
  15. <tr>
  16. <th>Host</th>
  17. <th colSpan={2}>Port</th>
  18. </tr>
  19. </thead>
  20. <tbody>
  21. {ldapConnectionInfo &&
  22. ldapConnectionInfo.map((serverInfo, index) => (
  23. <tr key={index}>
  24. <td>{serverInfo.host}</td>
  25. <td>{serverInfo.port}</td>
  26. <td>
  27. {serverInfo.available ? (
  28. <Icon name="check" className="pull-right" />
  29. ) : (
  30. <Icon name="exclamation-triangle" className="pull-right" />
  31. )}
  32. </td>
  33. </tr>
  34. ))}
  35. </tbody>
  36. </table>
  37. </div>
  38. <div className="gf-form-group">
  39. <LdapErrorBox ldapConnectionInfo={ldapConnectionInfo} />
  40. </div>
  41. </div>
  42. </>
  43. );
  44. };
  45. interface LdapConnectionErrorProps {
  46. ldapConnectionInfo: LdapConnectionInfo;
  47. }
  48. export const LdapErrorBox: FC<LdapConnectionErrorProps> = ({ ldapConnectionInfo }) => {
  49. const hasError = ldapConnectionInfo.some((info) => info.error);
  50. if (!hasError) {
  51. return null;
  52. }
  53. const connectionErrors: LdapServerInfo[] = [];
  54. ldapConnectionInfo.forEach((info) => {
  55. if (info.error) {
  56. connectionErrors.push(info);
  57. }
  58. });
  59. const errorElements = connectionErrors.map((info, index) => (
  60. <div key={index}>
  61. <span style={{ fontWeight: 500 }}>
  62. {info.host}:{info.port}
  63. <br />
  64. </span>
  65. <span>{info.error}</span>
  66. {index !== connectionErrors.length - 1 && (
  67. <>
  68. <br />
  69. <br />
  70. </>
  71. )}
  72. </div>
  73. ));
  74. return (
  75. <Alert title="Connection error" severity={AppNotificationSeverity.Error}>
  76. {errorElements}
  77. </Alert>
  78. );
  79. };