import React, { PureComponent } from 'react'; import { dateTime } from '@grafana/data'; import { LdapUserSyncInfo } from 'app/types'; interface Props { disableSync: boolean; syncInfo: LdapUserSyncInfo; onSync?: () => void; } interface State { isSyncing: boolean; } const syncTimeFormat = 'dddd YYYY-MM-DD HH:mm zz'; export class UserSyncInfo extends PureComponent { state = { isSyncing: false, }; handleSyncClick = async () => { const { onSync } = this.props; this.setState({ isSyncing: true }); try { if (onSync) { await onSync(); } } finally { this.setState({ isSyncing: false }); } }; render() { const { syncInfo, disableSync } = this.props; const { isSyncing } = this.state; const nextSyncTime = syncInfo.nextSync ? dateTime(syncInfo.nextSync).format(syncTimeFormat) : ''; const prevSyncSuccessful = syncInfo && syncInfo.prevSync; const prevSyncTime = prevSyncSuccessful ? dateTime(syncInfo.prevSync).format(syncTimeFormat) : ''; const isDisabled = isSyncing || disableSync; return ( <>

LDAP

{prevSyncSuccessful && }
Last synchronisation {prevSyncTime}Successful
Next scheduled synchronisation {nextSyncTime}
); } }