UserSyncInfo.tsx 1.9 KB

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