2021-04-23 09:07:48 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2021-03-26 05:22:50 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2022-02-15 04:20:50 +08:00
|
|
|
import Button from '/imports/ui/components/common/button/component';
|
2021-03-26 05:22:50 +08:00
|
|
|
import ConnectionStatusModalContainer from '/imports/ui/components/connection-status/modal/container';
|
|
|
|
import ConnectionStatusService from '/imports/ui/components/connection-status/service';
|
2021-04-23 09:07:48 +08:00
|
|
|
import Icon from '/imports/ui/components/connection-status/icon/component';
|
2021-11-09 04:11:14 +08:00
|
|
|
import Styled from './styles';
|
2021-03-26 05:22:50 +08:00
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
label: {
|
|
|
|
id: 'app.connection-status.label',
|
|
|
|
description: 'Connection status button label',
|
|
|
|
},
|
|
|
|
description: {
|
|
|
|
id: 'app.connection-status.description',
|
|
|
|
description: 'Connection status button description',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-04-23 09:07:48 +08:00
|
|
|
class ConnectionStatusButton extends PureComponent {
|
|
|
|
renderIcon(level = 'normal') {
|
|
|
|
return(
|
2021-11-09 04:11:14 +08:00
|
|
|
<Styled.IconWrapper>
|
2021-04-23 09:07:48 +08:00
|
|
|
<Icon
|
|
|
|
level={level}
|
|
|
|
grayscale
|
|
|
|
/>
|
2021-11-09 04:11:14 +08:00
|
|
|
</Styled.IconWrapper>
|
2021-04-23 09:07:48 +08:00
|
|
|
);
|
2021-03-26 05:22:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
connected,
|
2021-04-23 09:07:48 +08:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (!connected) {
|
|
|
|
return (
|
2021-11-09 04:11:14 +08:00
|
|
|
<Styled.ButtonWrapper>
|
2021-04-23 09:07:48 +08:00
|
|
|
<Button
|
|
|
|
customIcon={this.renderIcon()}
|
|
|
|
label={intl.formatMessage(intlMessages.label)}
|
|
|
|
hideLabel
|
|
|
|
aria-label={intl.formatMessage(intlMessages.description)}
|
|
|
|
size="sm"
|
|
|
|
disabled
|
|
|
|
ghost
|
|
|
|
circle
|
|
|
|
onClick={() => {}}
|
|
|
|
data-test="connectionStatusButton"
|
|
|
|
/>
|
2021-11-09 04:11:14 +08:00
|
|
|
</Styled.ButtonWrapper>
|
2021-04-23 09:07:48 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
2021-03-26 05:22:50 +08:00
|
|
|
stats,
|
|
|
|
mountModal,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
let color;
|
2021-04-23 09:07:48 +08:00
|
|
|
switch (stats) {
|
|
|
|
case 'warning':
|
|
|
|
color = 'success';
|
|
|
|
break;
|
|
|
|
case 'danger':
|
|
|
|
color = 'warning';
|
|
|
|
ConnectionStatusService.notification('warning', intl);
|
|
|
|
break;
|
|
|
|
case 'critical':
|
|
|
|
color = 'danger';
|
|
|
|
ConnectionStatusService.notification('error', intl);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
color = 'success';
|
2021-03-26 05:22:50 +08:00
|
|
|
}
|
|
|
|
|
2021-04-23 09:07:48 +08:00
|
|
|
const level = stats ? stats : 'normal';
|
|
|
|
|
2021-03-26 05:22:50 +08:00
|
|
|
return (
|
2021-11-09 04:11:14 +08:00
|
|
|
<Styled.ButtonWrapper>
|
2021-04-23 09:07:48 +08:00
|
|
|
<Button
|
|
|
|
customIcon={this.renderIcon(level)}
|
|
|
|
label={intl.formatMessage(intlMessages.label)}
|
|
|
|
hideLabel
|
|
|
|
aria-label={intl.formatMessage(intlMessages.description)}
|
|
|
|
size="sm"
|
|
|
|
color={color}
|
|
|
|
circle
|
|
|
|
onClick={() => mountModal(<ConnectionStatusModalContainer />)}
|
|
|
|
data-test="connectionStatusButton"
|
|
|
|
/>
|
2021-11-09 04:11:14 +08:00
|
|
|
</Styled.ButtonWrapper>
|
2021-03-26 05:22:50 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(withModalMounter(ConnectionStatusButton));
|