Files
grafana/public/app/features/admin/UserSyncInfo.tsx
Ivana Huckova 1c58202b26 @grafana/ui: Replace various icons using Icon component (#23442)
* Replace icons in dashboard and settings

* Replace icons in alerting

* Update batch of icons

* Implement icons accross various files

* Style updates

* Search: Fix recent and starred icons

* Update styling and details

* Replace new icon created by unicons

* Fix e2e test, styling

* Minor styling updates

Co-authored-by: Clarity-89 <homes89@ukr.net>
2020-04-12 22:20:02 +02:00

74 lines
2.1 KiB
TypeScript

import React, { PureComponent } from 'react';
import { dateTime } from '@grafana/data';
import { LdapUserSyncInfo } from 'app/types';
import { Icon } from '@grafana/ui';
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<Props, State> {
state = {
isSyncing: false,
};
onSyncClick = 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 (
<>
<button className={`btn btn-secondary pull-right`} onClick={this.onSyncClick} disabled={isDisabled}>
<span className="btn-title">Sync user</span>
{isSyncing && <Icon name="fa fa-spinner" className="fa-fw fa-spin run-icon" />}
</button>
<div className="clearfix" />
<h3 className="page-heading">LDAP</h3>
<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>
</>
);
}
}