2019-09-16 10:56:01 -05:00
|
|
|
import React, { PureComponent } from 'react';
|
2020-04-27 08:28:06 -05:00
|
|
|
import { dateTimeFormat } from '@grafana/data';
|
2019-09-16 10:56:01 -05:00
|
|
|
import { LdapUserSyncInfo } from 'app/types';
|
2020-04-12 15:20:02 -05:00
|
|
|
import { Icon } from '@grafana/ui';
|
2019-09-16 10:56:01 -05:00
|
|
|
|
|
|
|
interface Props {
|
2019-11-07 07:31:44 -06:00
|
|
|
disableSync: boolean;
|
2019-09-16 10:56:01 -05:00
|
|
|
syncInfo: LdapUserSyncInfo;
|
|
|
|
onSync?: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface State {
|
|
|
|
isSyncing: boolean;
|
|
|
|
}
|
|
|
|
|
2020-04-27 08:28:06 -05:00
|
|
|
const format = 'dddd YYYY-MM-DD HH:mm zz';
|
2019-09-16 10:56:01 -05:00
|
|
|
|
|
|
|
export class UserSyncInfo extends PureComponent<Props, State> {
|
|
|
|
state = {
|
|
|
|
isSyncing: false,
|
|
|
|
};
|
|
|
|
|
2020-01-13 10:10:19 -06:00
|
|
|
onSyncClick = async () => {
|
2019-09-16 10:56:01 -05:00
|
|
|
const { onSync } = this.props;
|
|
|
|
this.setState({ isSyncing: true });
|
|
|
|
try {
|
|
|
|
if (onSync) {
|
|
|
|
await onSync();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
this.setState({ isSyncing: false });
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
2019-11-07 07:31:44 -06:00
|
|
|
const { syncInfo, disableSync } = this.props;
|
2019-09-16 10:56:01 -05:00
|
|
|
const { isSyncing } = this.state;
|
2020-04-27 08:28:06 -05:00
|
|
|
const nextSyncSuccessful = syncInfo && syncInfo.nextSync;
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
const nextSyncTime = nextSyncSuccessful ? dateTimeFormat(syncInfo.nextSync!, { format }) : '';
|
2019-09-16 10:56:01 -05:00
|
|
|
const prevSyncSuccessful = syncInfo && syncInfo.prevSync;
|
Chore: Fix all Typescript strict null errors (#26204)
* Chore: Fix typescript strict null errors
* Added new limit
* Fixed ts issue
* fixed tests
* trying to fix type inference
* Fixing more ts errors
* Revert tsconfig option
* Fix
* Fixed code
* More fixes
* fix tests
* Updated snapshot
* Chore: More ts strict null fixes
* More fixes in some really messed up azure config components
* More fixes, current count: 441
* 419
* More fixes
* Fixed invalid initial state in explore
* Fixing tests
* Fixed tests
* Explore fix
* More fixes
* Progress
* Sub 300
* Now at 218
* Progress
* Update
* Progress
* Updated tests
* at 159
* fixed tests
* Progress
* YAy blow 100! at 94
* 10,9,8,7,6,5,4,3,2,1... lift off
* Fixed tests
* Fixed more type errors
Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
2020-07-10 05:46:59 -05:00
|
|
|
const prevSyncTime = prevSyncSuccessful ? dateTimeFormat(syncInfo.prevSync!, { format }) : '';
|
2019-11-07 07:31:44 -06:00
|
|
|
const isDisabled = isSyncing || disableSync;
|
2019-09-16 10:56:01 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2020-01-13 10:10:19 -06:00
|
|
|
<button className={`btn btn-secondary pull-right`} onClick={this.onSyncClick} disabled={isDisabled}>
|
2019-11-07 07:31:44 -06:00
|
|
|
<span className="btn-title">Sync user</span>
|
2020-04-12 15:20:02 -05:00
|
|
|
{isSyncing && <Icon name="fa fa-spinner" className="fa-fw fa-spin run-icon" />}
|
2019-11-07 07:31:44 -06:00
|
|
|
</button>
|
|
|
|
|
|
|
|
<div className="clearfix" />
|
|
|
|
|
|
|
|
<h3 className="page-heading">LDAP</h3>
|
2019-09-16 10:56:01 -05:00
|
|
|
<div className="gf-form-group">
|
|
|
|
<div className="gf-form">
|
|
|
|
<table className="filter-table form-inline">
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td>Last synchronisation</td>
|
|
|
|
<td>{prevSyncTime}</td>
|
|
|
|
{prevSyncSuccessful && <td className="pull-right">Successful</td>}
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Next scheduled synchronisation</td>
|
|
|
|
<td colSpan={2}>{nextSyncTime}</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|