2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing
14 * permissions and limitations under the License.
17 import React from 'react';
18 import PropTypes from 'prop-types';
19 import ReactDOM from 'react-dom';
20 import classnames from 'classnames';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
22 import { notificationType } from './UserNotificationsConstants.js';
23 import ShowMore from 'react-show-more-text';
25 const Notification = ({
29 getNotificationTypeDesc
31 const { eventType, read, eventAttributes, dateTime } = notification;
40 const { fullName: userName } = users.find(user => user.userId === userId);
42 <div className={classnames('notification', { unread: !read })}>
43 <div className="notification-data">
44 <div className="item-name">
47 <span> v{versionName}</span>
49 {!read && <div className="unread-circle-icon" />}
51 <div className="flex-items">
52 <div className="type">
53 {getNotificationTypeDesc(
59 <div className="separator" />
60 <div className="user-name">{`${i18n(
62 )} ${userName}`}</div>
64 {(description || versionName) && (
65 <div className="description">
68 anchorClass="more-less"
75 {eventType === notificationType.ITEM_CHANGED.SUBMIT && (
79 'Version {versionName} was submitted.',
80 { versionName: versionName }
87 <div className="date">{dateTime}</div>
89 <div className="notification-action">
91 className={classnames('action-button', { hidden: read })}
92 onClick={() => onActionClicked(notification)}>
93 {eventType === notificationType.PERMISSION_CHANGED ||
94 eventType === notificationType.ITEM_DELETED ||
95 eventType === notificationType.ITEM_ARCHIVED ||
96 eventType === notificationType.ITEM_RESTORED
105 function getNotificationTypeDesc(eventType, permission, granted) {
107 case notificationType.PERMISSION_CHANGED:
108 const grantedStr = granted ? i18n('Granted') : i18n('Taken');
109 return `${i18n('Permission')} ${grantedStr}: ${permission}`;
110 case notificationType.ITEM_CHANGED.COMMIT:
111 return i18n('Your Copy Is Out Of Sync');
112 case notificationType.ITEM_CHANGED.SUBMIT:
113 return i18n('Version Submitted');
114 case notificationType.ITEM_DELETED:
115 return i18n('Item was deleted');
116 case notificationType.ITEM_ARCHIVED:
117 return i18n('Item was archived');
118 case notificationType.ITEM_RESTORED:
119 return i18n('Item was restored from archive');
123 class UserNotifications extends React.Component {
125 currentScreen: PropTypes.object,
126 notificationsList: PropTypes.array,
127 usersList: PropTypes.array,
128 lastScanned: PropTypes.string,
129 endOfPage: PropTypes.string,
130 onLoadPrevNotifications: PropTypes.func,
131 onSync: PropTypes.func,
132 updateNotification: PropTypes.func,
133 onLoadItemsLists: PropTypes.func
138 notificationsList = [],
145 <div className="user-notifications">
146 <div className="notifications-title">
147 {i18n('Notifications')}
150 className="notifications-list"
151 ref="notificationList"
153 this.loadPrevNotifications(lastScanned, endOfPage)
155 {notificationsList.map(notification => (
157 key={notification.eventId}
158 notification={notification}
160 onActionClicked={notification =>
161 this.onActionClicked(notification)
163 getNotificationTypeDesc={getNotificationTypeDesc}
171 onActionClicked(notification) {
180 eventAttributes: { itemId, itemName, versionId, versionName }
183 eventType !== notificationType.PERMISSION_CHANGED &&
184 eventType !== notificationType.ITEM_DELETED &&
185 eventType !== notificationType.ITEM_ARCHIVED &&
186 eventType !== notificationType.ITEM_RESTORED
188 onSync({ itemId, itemName, versionId, versionName, currentScreen });
192 updateNotification(notification);
195 loadPrevNotifications(lastScanned, endOfPage) {
196 if (endOfPage && lastScanned) {
197 let element = ReactDOM.findDOMNode(this.refs['notificationList']);
198 const { onLoadPrevNotifications } = this.props;
202 element.clientHeight + element.scrollTop ===
205 onLoadPrevNotifications(lastScanned, endOfPage);
211 export default UserNotifications;