2017-11-16 18:26:14 +00:00
|
|
|
// @flow
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
import Flag from '@atlaskit/flag';
|
|
|
|
import EditorInfoIcon from '@atlaskit/icon/glyph/editor/info';
|
2017-11-03 19:05:03 +00:00
|
|
|
import ErrorIcon from '@atlaskit/icon/glyph/error';
|
|
|
|
import WarningIcon from '@atlaskit/icon/glyph/warning';
|
|
|
|
import { colors } from '@atlaskit/theme';
|
2018-06-14 09:14:32 +00:00
|
|
|
import React from 'react';
|
2017-07-28 17:56:49 +00:00
|
|
|
|
2019-03-27 14:00:10 +00:00
|
|
|
import { translate } from '../../../base/i18n';
|
|
|
|
import { NOTIFICATION_TYPE } from '../../constants';
|
2018-06-14 09:14:32 +00:00
|
|
|
import AbstractNotification, {
|
|
|
|
type Props
|
2019-03-27 14:00:10 +00:00
|
|
|
} from '../AbstractNotification';
|
2018-06-14 09:14:32 +00:00
|
|
|
|
2017-11-03 19:05:03 +00:00
|
|
|
declare var interfaceConfig: Object;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Secondary colors for notification icons.
|
|
|
|
*
|
|
|
|
* @type {{error, info, normal, success, warning}}
|
|
|
|
*/
|
|
|
|
const ICON_COLOR = {
|
|
|
|
error: colors.R400,
|
|
|
|
info: colors.N500,
|
|
|
|
normal: colors.N0,
|
|
|
|
success: colors.G400,
|
|
|
|
warning: colors.Y200
|
|
|
|
};
|
|
|
|
|
2017-07-28 17:56:49 +00:00
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} to display a notification.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
2018-06-14 09:14:32 +00:00
|
|
|
class Notification extends AbstractNotification<Props> {
|
2017-07-28 17:56:49 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
const {
|
2017-11-03 19:05:03 +00:00
|
|
|
appearance,
|
2017-11-21 17:38:40 +00:00
|
|
|
hideErrorSupportLink,
|
2017-07-28 17:56:49 +00:00
|
|
|
isDismissAllowed,
|
|
|
|
onDismissed,
|
|
|
|
t,
|
|
|
|
title,
|
2017-11-21 17:38:40 +00:00
|
|
|
titleArguments,
|
|
|
|
titleKey,
|
2017-07-28 17:56:49 +00:00
|
|
|
uid
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Flag
|
2017-11-03 19:05:03 +00:00
|
|
|
actions = { this._mapAppearanceToButtons(hideErrorSupportLink) }
|
|
|
|
appearance = { appearance }
|
2017-11-16 17:25:04 +00:00
|
|
|
description = { this._renderDescription() }
|
2017-11-03 19:05:03 +00:00
|
|
|
icon = { this._mapAppearanceToIcon() }
|
2017-07-28 17:56:49 +00:00
|
|
|
id = { uid }
|
|
|
|
isDismissAllowed = { isDismissAllowed }
|
|
|
|
onDismissed = { onDismissed }
|
2017-11-21 17:38:40 +00:00
|
|
|
title = { title || t(titleKey, titleArguments) } />
|
2017-07-28 17:56:49 +00:00
|
|
|
);
|
|
|
|
}
|
2017-11-03 19:05:03 +00:00
|
|
|
|
2018-06-14 09:14:32 +00:00
|
|
|
_getDescription: () => Array<string>
|
|
|
|
|
2017-11-16 18:26:14 +00:00
|
|
|
_onDismissed: () => void;
|
|
|
|
|
2017-11-16 17:25:04 +00:00
|
|
|
/**
|
|
|
|
* Creates a {@code ReactElement} for displaying the contents of the
|
|
|
|
* notification.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_renderDescription() {
|
|
|
|
return (
|
|
|
|
<div>
|
2018-06-14 09:14:32 +00:00
|
|
|
{
|
|
|
|
this._getDescription()
|
|
|
|
}
|
2017-11-16 17:25:04 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-11-03 19:05:03 +00:00
|
|
|
/**
|
|
|
|
* Opens the support page.
|
|
|
|
*
|
|
|
|
* @returns {void}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
_onOpenSupportLink() {
|
|
|
|
window.open(interfaceConfig.SUPPORT_URL, '_blank', 'noopener');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates action button configurations for the notification based on
|
|
|
|
* notification appearance.
|
|
|
|
*
|
|
|
|
* @param {boolean} hideErrorSupportLink - Indicates if the support link
|
|
|
|
* should be hidden in the error messages.
|
|
|
|
* @private
|
|
|
|
* @returns {Object[]}
|
|
|
|
*/
|
|
|
|
_mapAppearanceToButtons(hideErrorSupportLink) {
|
|
|
|
switch (this.props.appearance) {
|
|
|
|
case NOTIFICATION_TYPE.ERROR: {
|
|
|
|
const buttons = [
|
|
|
|
{
|
|
|
|
content: this.props.t('dialog.dismiss'),
|
|
|
|
onClick: this._onDismissed
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!hideErrorSupportLink) {
|
|
|
|
buttons.push({
|
|
|
|
content: this.props.t('dialog.contactSupport'),
|
|
|
|
onClick: this._onOpenSupportLink
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return buttons;
|
|
|
|
}
|
|
|
|
case NOTIFICATION_TYPE.WARNING:
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
content: this.props.t('dialog.Ok'),
|
|
|
|
onClick: this._onDismissed
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
default:
|
2019-05-03 17:25:33 +00:00
|
|
|
if (this.props.customActionNameKey && this.props.customActionHandler) {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
content: this.props.t(this.props.customActionNameKey),
|
|
|
|
onClick: () => {
|
|
|
|
if (this.props.customActionHandler()) {
|
|
|
|
this._onDismissed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-11-03 19:05:03 +00:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates an icon component depending on the configured notification
|
|
|
|
* appearance.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
_mapAppearanceToIcon() {
|
|
|
|
const appearance = this.props.appearance;
|
|
|
|
const secIconColor = ICON_COLOR[this.props.appearance];
|
|
|
|
const iconSize = 'medium';
|
|
|
|
|
|
|
|
switch (appearance) {
|
|
|
|
case NOTIFICATION_TYPE.ERROR:
|
|
|
|
return (
|
|
|
|
<ErrorIcon
|
|
|
|
label = { appearance }
|
|
|
|
secondaryColor = { secIconColor }
|
|
|
|
size = { iconSize } />
|
|
|
|
);
|
|
|
|
|
|
|
|
case NOTIFICATION_TYPE.WARNING:
|
|
|
|
return (
|
|
|
|
<WarningIcon
|
|
|
|
label = { appearance }
|
|
|
|
secondaryColor = { secIconColor }
|
|
|
|
size = { iconSize } />
|
|
|
|
);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (
|
|
|
|
<EditorInfoIcon
|
|
|
|
label = { appearance }
|
|
|
|
secondaryColor = { secIconColor }
|
|
|
|
size = { iconSize } />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2017-07-28 17:56:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(Notification);
|