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.
16 import React, {Component} from 'react';
17 import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js';
18 import Tooltip from 'react-bootstrap/lib/Tooltip.js';
19 import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
20 import SVGIcon from 'nfvo-components/icon/SVGIcon.jsx';
21 import i18n from 'nfvo-utils/i18n/i18n.js';
23 function ActivityLogSortableCellHeader({isHeader, data, isDes, onSort}) {
26 <span className='date-header' onClick={onSort}>
28 <span className={`header-sort-arrow ${isDes ? 'up' : 'down'}`}></span>
33 <span className='date-cell'>
34 <span>{i18n.dateNormal(data, {
35 year: 'numeric', month: 'numeric', day: 'numeric'
37 <span>{i18n.dateNormal(data, {
38 hour: 'numeric', minute: 'numeric',
45 function ActivityLogStatus({status, isHeader}) {
47 return <span>{status}</span>;
49 let {message, success} = status;
52 <span className={`status-icon ${success}`}>{`${success ? i18n('Success') : i18n('Failure')}`}</span>
53 {success && <SVGIcon name='check-circle'/>}
54 {!success && <OverlayTrigger placement='bottom' overlay={<Tooltip className='activity-log-message-tooltip' id={'activity-log-message-tooltip'}>
55 <div className='message-block'>{message}</div>
57 <span className='message-further-info-icon'>{'?'}</span>
63 export function ActivityListItem({activity, isHeader, isDes, onSort}) {
64 let {type, timestamp, comment, user, status} = activity;
66 <li className={`activity-list-item ${isHeader ? 'header' : ''}`} data-test-id='activity-list-item'>
67 <div className='table-cell activity-date' data-test-id='activity-date'><ActivityLogSortableCellHeader isHeader={isHeader} data={timestamp} isDes={isDes} onSort={onSort}/></div>
68 <div className='table-cell activity-action' data-test-id='activity-action'>{type}</div>
69 <div className='table-cell activity-comment' title={comment} data-test-id='activity-comment'><span>{comment}</span></div>
70 <div className='table-cell activity-username' data-test-id='activity-username'>{user}</div>
71 <div className='table-cell activity-status' data-test-id='activity-status'><ActivityLogStatus isHeader={isHeader} status={status}/></div>
76 class ActivityLogView extends Component {
85 <div className='activity-log-view'>
87 title={i18n('Activity Log')}
88 filterValue={this.state.localFilter}
89 onFilter={filter => this.setState({localFilter: filter})}>
92 activity={{timestamp: 'Date', type: 'Action', comment: 'Comment', user: 'Username', status: 'Status'}}
93 isDes={this.state.sortDescending}
94 onSort={() => this.setState({sortDescending: !this.state.sortDescending})}/>
95 {this.sortActivities(this.filterActivities(), this.state.sortDescending).map(activity => <ActivityListItem key={activity.id} activity={activity}/>)}
102 let {activities} = this.props;
103 let {localFilter} = this.state;
104 if (localFilter.trim()) {
105 const filter = new RegExp(escape(localFilter), 'i');
106 return activities.filter(({user = '', comment = '', type = ''}) => escape(user).match(filter) || escape(comment).match(filter) || escape(type).match(filter));
113 sortActivities(activities) {
114 if (this.state.sortDescending) {
115 return activities.sort((a, b) => a.timestamp - b.timestamp);
118 return activities.reverse();
124 export default ActivityLogView;