blob: 19ab570fd9fe79748e2a9db1d9ae42180da4df4c [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001/*!
2 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16import React, {Component} from 'react';
17import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js';
18import Tooltip from 'react-bootstrap/lib/Tooltip.js';
19import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
Avi Zivb8e2faf2017-07-18 19:45:38 +030020import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
AviZi280f8012017-06-09 02:39:56 +030021import i18n from 'nfvo-utils/i18n/i18n.js';
Avi Zivb8e2faf2017-07-18 19:45:38 +030022import LogDetails from './LogixUtil.jsx';
AviZi280f8012017-06-09 02:39:56 +030023
24function ActivityLogSortableCellHeader({isHeader, data, isDes, onSort}) {
25 if (isHeader) {
26 return (
27 <span className='date-header' onClick={onSort}>
28 <span>{data}</span>
29 <span className={`header-sort-arrow ${isDes ? 'up' : 'down'}`}></span>
30 </span>
31 );
32 }
33 return (
34 <span className='date-cell'>
35 <span>{i18n.dateNormal(data, {
36 year: 'numeric', month: 'numeric', day: 'numeric'
37 })}</span>
38 <span>{i18n.dateNormal(data, {
39 hour: 'numeric', minute: 'numeric',
40 hour12: true
41 })}</span>
42 </span>
43 );
44}
45
46function ActivityLogStatus({status, isHeader}) {
47 if (isHeader) {
48 return <span>{status}</span>;
49 }
50 let {message, success} = status;
51 return (
52 <span>
53 <span className={`status-icon ${success}`}>{`${success ? i18n('Success') : i18n('Failure')}`}</span>
Avi Zivb8e2faf2017-07-18 19:45:38 +030054 {success && <SVGIcon name='checkCircle'/>}
AviZi280f8012017-06-09 02:39:56 +030055 {!success && <OverlayTrigger placement='bottom' overlay={<Tooltip className='activity-log-message-tooltip' id={'activity-log-message-tooltip'}>
56 <div className='message-block'>{message}</div>
57 </Tooltip>}>
58 <span className='message-further-info-icon'>{'?'}</span>
59 </OverlayTrigger>}
60 </span>
61 );
62}
63
64export function ActivityListItem({activity, isHeader, isDes, onSort}) {
65 let {type, timestamp, comment, user, status} = activity;
66 return (
67 <li className={`activity-list-item ${isHeader ? 'header' : ''}`} data-test-id='activity-list-item'>
68 <div className='table-cell activity-date' data-test-id='activity-date'><ActivityLogSortableCellHeader isHeader={isHeader} data={timestamp} isDes={isDes} onSort={onSort}/></div>
69 <div className='table-cell activity-action' data-test-id='activity-action'>{type}</div>
70 <div className='table-cell activity-comment' title={comment} data-test-id='activity-comment'><span>{comment}</span></div>
71 <div className='table-cell activity-username' data-test-id='activity-username'>{user}</div>
72 <div className='table-cell activity-status' data-test-id='activity-status'><ActivityLogStatus isHeader={isHeader} status={status}/></div>
73 </li>
74 );
75}
76
77class ActivityLogView extends Component {
78
79 state = {
80 localFilter: '',
81 sortDescending: true
82 };
83
84 render() {
85 return (
86 <div className='activity-log-view'>
Avi Zivb8e2faf2017-07-18 19:45:38 +030087 <LogDetails display={this.state.localFilter}/>
AviZi280f8012017-06-09 02:39:56 +030088 <ListEditorView
89 title={i18n('Activity Log')}
90 filterValue={this.state.localFilter}
91 onFilter={filter => this.setState({localFilter: filter})}>
92 <ActivityListItem
93 isHeader={true}
94 activity={{timestamp: 'Date', type: 'Action', comment: 'Comment', user: 'Username', status: 'Status'}}
95 isDes={this.state.sortDescending}
96 onSort={() => this.setState({sortDescending: !this.state.sortDescending})}/>
97 {this.sortActivities(this.filterActivities(), this.state.sortDescending).map(activity => <ActivityListItem key={activity.id} activity={activity}/>)}
98 </ListEditorView>
99 </div>
100 );
101 }
102
103 filterActivities() {
104 let {activities} = this.props;
105 let {localFilter} = this.state;
106 if (localFilter.trim()) {
107 const filter = new RegExp(escape(localFilter), 'i');
108 return activities.filter(({user = '', comment = '', type = ''}) => escape(user).match(filter) || escape(comment).match(filter) || escape(type).match(filter));
109 }
110 else {
111 return activities;
112 }
113 }
114
115 sortActivities(activities) {
116 if (this.state.sortDescending) {
117 return activities.sort((a, b) => a.timestamp - b.timestamp);
118 }
119 else {
120 return activities.reverse();
121 }
122 }
123
124}
125
126export default ActivityLogView;