LdapConnectionStatus.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import React, { FC } from 'react';
  2. import { AlertBox } from 'app/core/components/AlertBox/AlertBox';
  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. <i className="fa fa-fw fa-check pull-right" />
  29. ) : (
  30. <i className="fa fa-fw fa-exclamation-triangle 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 <AlertBox title="Connection error" severity={AppNotificationSeverity.Error} body={errorElements} />;
  75. };