2018-06-14 09:14:32 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { Component } from 'react';
|
|
|
|
|
|
|
|
import { NOTIFICATION_TYPE } from '../constants';
|
|
|
|
|
|
|
|
export type Props = {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display appearance for the component, passed directly to the
|
|
|
|
* notification.
|
|
|
|
*/
|
|
|
|
appearance: string,
|
|
|
|
|
2021-09-22 14:05:42 +00:00
|
|
|
/**
|
|
|
|
* Whether or not the title and description should be concatenated.
|
|
|
|
*/
|
|
|
|
concatText?: boolean,
|
|
|
|
|
2019-05-03 17:25:33 +00:00
|
|
|
/**
|
|
|
|
* Callback invoked when the custom button is clicked.
|
|
|
|
*/
|
2021-11-10 11:19:40 +00:00
|
|
|
customActionHandler: Function[],
|
2019-05-03 17:25:33 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The text to display as button in the notification for the custom action.
|
|
|
|
*/
|
2021-11-10 11:19:40 +00:00
|
|
|
customActionNameKey: string[],
|
2019-05-03 17:25:33 +00:00
|
|
|
|
2018-06-14 09:14:32 +00:00
|
|
|
/**
|
|
|
|
* The text to display in the body of the notification. If not passed
|
|
|
|
* in, the passed in descriptionKey will be used.
|
|
|
|
*/
|
|
|
|
defaultTitleKey: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A description string that can be used in addition to the prop
|
|
|
|
* descriptionKey.
|
|
|
|
*/
|
|
|
|
description: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translation arguments that may be necessary for the description.
|
|
|
|
*/
|
|
|
|
descriptionArguments: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translation key to use as the body of the notification.
|
|
|
|
*/
|
|
|
|
descriptionKey: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the support link should be hidden in the case of an error
|
|
|
|
* message.
|
|
|
|
*/
|
|
|
|
hideErrorSupportLink: boolean,
|
|
|
|
|
2021-12-17 12:39:15 +00:00
|
|
|
/**
|
|
|
|
* The type of icon to be displayed. If not passed in, the appearance
|
|
|
|
* type will be used.
|
|
|
|
*/
|
|
|
|
icon?: String,
|
|
|
|
|
2020-05-28 22:42:02 +00:00
|
|
|
/**
|
|
|
|
* Maximum lines of the description.
|
|
|
|
*/
|
|
|
|
maxLines: ?number,
|
|
|
|
|
2018-06-14 09:14:32 +00:00
|
|
|
/**
|
|
|
|
* Callback invoked when the user clicks to dismiss the notification.
|
|
|
|
*/
|
|
|
|
onDismissed: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoked to obtain translated strings.
|
|
|
|
*/
|
|
|
|
t: Function,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The text to display at the top of the notification. If not passed in,
|
|
|
|
* the passed in titleKey will be used.
|
|
|
|
*/
|
|
|
|
title: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translation arguments that may be necessary for the title.
|
|
|
|
*/
|
|
|
|
titleArguments: Object,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The translation key to display as the title of the notification if
|
|
|
|
* no title is provided.
|
|
|
|
*/
|
|
|
|
titleKey: string,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The unique identifier for the notification.
|
|
|
|
*/
|
2021-06-23 11:23:44 +00:00
|
|
|
uid: string
|
2018-06-14 09:14:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Abstract class for {@code Notification} component.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-06-14 09:14:32 +00:00
|
|
|
*/
|
|
|
|
export default class AbstractNotification<P: Props> extends Component<P> {
|
|
|
|
/**
|
|
|
|
* Default values for {@code Notification} component's properties.
|
|
|
|
*
|
|
|
|
* @static
|
|
|
|
*/
|
|
|
|
static defaultProps = {
|
2022-05-06 10:43:27 +00:00
|
|
|
appearance: NOTIFICATION_TYPE.NORMAL
|
2018-06-14 09:14:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes a new {@code Notification} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
|
|
|
constructor(props: P) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
// Bind event handler so it is only bound once for every instance.
|
|
|
|
this._onDismissed = this._onDismissed.bind(this);
|
|
|
|
}
|
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
_getDescription: () => Array<string>;
|
2018-06-14 09:14:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the description array to be displayed.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {Array<string>}
|
|
|
|
*/
|
|
|
|
_getDescription() {
|
|
|
|
const {
|
|
|
|
description,
|
|
|
|
descriptionArguments,
|
|
|
|
descriptionKey,
|
|
|
|
t
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const descriptionArray = [];
|
|
|
|
|
|
|
|
descriptionKey
|
|
|
|
&& descriptionArray.push(t(descriptionKey, descriptionArguments));
|
|
|
|
|
|
|
|
description && descriptionArray.push(description);
|
|
|
|
|
|
|
|
return descriptionArray;
|
|
|
|
}
|
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
_getDescriptionKey: () => string;
|
2020-07-10 15:28:57 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the description key that was used if any.
|
|
|
|
*
|
|
|
|
* @protected
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
|
|
|
_getDescriptionKey() {
|
|
|
|
return this.props.descriptionKey;
|
|
|
|
}
|
|
|
|
|
2018-06-14 09:14:32 +00:00
|
|
|
_onDismissed: () => void;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback to dismiss the notification.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_onDismissed() {
|
|
|
|
this.props.onDismissed(this.props.uid);
|
|
|
|
}
|
|
|
|
}
|