2016-05-26 12:11:55 -07:00
// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import React from 'react' ;
import * as Utils from 'utils/utils.jsx' ;
2016-06-28 14:53:36 -04:00
import { FormattedMessage , FormattedHTMLMessage } from 'react-intl' ;
2016-05-26 12:11:55 -07:00
2017-01-27 11:39:13 +01:00
import { recycleDatabaseConnection } from 'actions/admin_actions.jsx' ;
2016-05-26 12:11:55 -07:00
export default class RecycleDbButton extends React . Component {
constructor ( props ) {
super ( props ) ;
this . handleRecycle = this . handleRecycle . bind ( this ) ;
this . state = {
loading : false ,
fail : null
} ;
}
handleRecycle ( e ) {
e . preventDefault ( ) ;
this . setState ( {
loading : true ,
fail : null
} ) ;
2017-01-27 11:39:13 +01:00
recycleDatabaseConnection (
2016-05-26 12:11:55 -07:00
( ) => {
this . setState ( {
loading : false
} ) ;
} ,
( err ) => {
this . setState ( {
loading : false ,
fail : err . message + ' - ' + err . detailed _error
} ) ;
}
) ;
}
render ( ) {
2016-06-04 11:22:42 -07:00
if ( global . window . mm _license . IsLicensed !== 'true' ) {
2016-09-23 12:29:54 -04:00
return < div / > ;
2016-06-04 11:22:42 -07:00
}
2016-05-26 12:11:55 -07:00
let testMessage = null ;
if ( this . state . fail ) {
testMessage = (
< div className = 'alert alert-warning' >
2016-09-23 12:29:54 -04:00
< i className = 'fa fa-warning' / >
2016-05-26 12:11:55 -07:00
< FormattedMessage
id = 'admin.recycle.reloadFail'
defaultMessage = 'Recycling unsuccessful: {error}'
values = { {
error : this . state . fail
} }
/ >
< / div >
) ;
}
2016-09-23 12:29:54 -04:00
const helpText = (
2016-06-28 14:53:36 -04:00
< FormattedHTMLMessage
id = 'admin.recycle.recycleDescription'
2016-06-30 08:41:58 -04:00
defaultMessage = 'Deployments using multiple databases can switch from one master database to another without restarting the Mattermost server by updating "config.json" to the new desired configuration and using the <a href="../general/configuration"><b>Configuration > Reload Configuration from Disk</b></a> feature to load the new settings while the server is running. The administrator should then use <b>Recycle Database Connections</b> feature to recycle the database connections based on the new settings.'
2016-06-28 14:53:36 -04:00
/ >
) ;
2016-05-26 12:11:55 -07:00
let contents = null ;
if ( this . state . loading ) {
contents = (
< span >
2016-07-06 00:46:36 +05:00
< span className = 'fa fa-refresh icon--rotate' / >
2016-05-26 12:11:55 -07:00
{ Utils . localizeMessage ( 'admin.recycle.loading' , ' Recycling...' ) }
< / span >
) ;
} else {
contents = (
< FormattedMessage
id = 'admin.recycle.button'
defaultMessage = 'Recycle Database Connections'
/ >
) ;
}
return (
< div className = 'form-group recycle-db' >
< div className = 'col-sm-offset-4 col-sm-8' >
< div >
< button
className = 'btn btn-default'
onClick = { this . handleRecycle }
>
{ contents }
< / button >
{ testMessage }
< / div >
2016-06-28 14:53:36 -04:00
< div className = 'help-text' >
{ helpText }
< / div >
2016-05-26 12:11:55 -07:00
< / div >
< / div >
) ;
}
}