LdapSyncInfo.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import React, { PureComponent } from 'react';
  2. import { dateTime } from '@grafana/data';
  3. import { SyncInfo } from 'app/types';
  4. interface Props {
  5. ldapSyncInfo: SyncInfo;
  6. }
  7. interface State {
  8. isSyncing: boolean;
  9. }
  10. const syncTimeFormat = 'dddd YYYY-MM-DD HH:mm zz';
  11. export class LdapSyncInfo extends PureComponent<Props, State> {
  12. state = {
  13. isSyncing: false,
  14. };
  15. handleSyncClick = () => {
  16. console.log('Bulk-sync now');
  17. this.setState({ isSyncing: !this.state.isSyncing });
  18. };
  19. render() {
  20. const { ldapSyncInfo } = this.props;
  21. const { isSyncing } = this.state;
  22. const nextSyncTime = dateTime(ldapSyncInfo.nextSync).format(syncTimeFormat);
  23. const prevSyncSuccessful = ldapSyncInfo && ldapSyncInfo.prevSync;
  24. const prevSyncTime = prevSyncSuccessful ? dateTime(ldapSyncInfo.prevSync.started).format(syncTimeFormat) : '';
  25. return (
  26. <>
  27. <h3 className="page-heading">
  28. LDAP Synchronisation
  29. <button className={`btn btn-secondary pull-right`} onClick={this.handleSyncClick} hidden={true}>
  30. <span className="btn-title">Bulk-sync now</span>
  31. {isSyncing && <i className="fa fa-spinner fa-fw fa-spin run-icon" />}
  32. </button>
  33. </h3>
  34. <div className="gf-form-group">
  35. <div className="gf-form">
  36. <table className="filter-table form-inline">
  37. <tbody>
  38. <tr>
  39. <td>Active synchronisation</td>
  40. <td colSpan={2}>{ldapSyncInfo.enabled ? 'Enabled' : 'Disabled'}</td>
  41. </tr>
  42. <tr>
  43. <td>Scheduled</td>
  44. <td>{ldapSyncInfo.schedule}</td>
  45. </tr>
  46. <tr>
  47. <td>Next scheduled synchronisation</td>
  48. <td>{nextSyncTime}</td>
  49. </tr>
  50. <tr>
  51. <td>Last synchronisation</td>
  52. {prevSyncSuccessful && (
  53. <>
  54. <td>{prevSyncTime}</td>
  55. <td>Successful</td>
  56. </>
  57. )}
  58. </tr>
  59. </tbody>
  60. </table>
  61. </div>
  62. </div>
  63. </>
  64. );
  65. }
  66. }