blob: 5b8c29b7197936209a381eb341bd32902ae27c2a [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}) {
az2497644017c2017-08-10 17:49:40 +030025 //TODO check icon sdc-ui
AviZi280f8012017-06-09 02:39:56 +030026 if (isHeader) {
27 return (
28 <span className='date-header' onClick={onSort}>
29 <span>{data}</span>
30 <span className={`header-sort-arrow ${isDes ? 'up' : 'down'}`}></span>
31 </span>
32 );
33 }
34 return (
35 <span className='date-cell'>
36 <span>{i18n.dateNormal(data, {
37 year: 'numeric', month: 'numeric', day: 'numeric'
38 })}</span>
39 <span>{i18n.dateNormal(data, {
40 hour: 'numeric', minute: 'numeric',
41 hour12: true
42 })}</span>
43 </span>
44 );
45}
46
47function ActivityLogStatus({status, isHeader}) {
48 if (isHeader) {
49 return <span>{status}</span>;
50 }
51 let {message, success} = status;
52 return (
53 <span>
54 <span className={`status-icon ${success}`}>{`${success ? i18n('Success') : i18n('Failure')}`}</span>
az2497644017c2017-08-10 17:49:40 +030055 {success && <SVGIcon name='checkCircle' color='positive'/>}
AviZi280f8012017-06-09 02:39:56 +030056 {!success && <OverlayTrigger placement='bottom' overlay={<Tooltip className='activity-log-message-tooltip' id={'activity-log-message-tooltip'}>
57 <div className='message-block'>{message}</div>
58 </Tooltip>}>
59 <span className='message-further-info-icon'>{'?'}</span>
60 </OverlayTrigger>}
61 </span>
62 );
63}
64
65export function ActivityListItem({activity, isHeader, isDes, onSort}) {
66 let {type, timestamp, comment, user, status} = activity;
67 return (
68 <li className={`activity-list-item ${isHeader ? 'header' : ''}`} data-test-id='activity-list-item'>
69 <div className='table-cell activity-date' data-test-id='activity-date'><ActivityLogSortableCellHeader isHeader={isHeader} data={timestamp} isDes={isDes} onSort={onSort}/></div>
talig8e9c0652017-12-20 14:30:43 +020070 <div className='table-cell activity-action' data-test-id='activity-action'>{i18n(type)}</div>
71 <div className='table-cell activity-comment' title={isHeader ? '' : comment} data-test-id='activity-comment'><span>{i18n(comment)}</span></div>
72 <div className='table-cell activity-username' data-test-id='activity-username'>{isHeader ? i18n(activity.user) : `${i18n(user.name)} (${user.id})`}</div>
AviZi280f8012017-06-09 02:39:56 +030073 <div className='table-cell activity-status' data-test-id='activity-status'><ActivityLogStatus isHeader={isHeader} status={status}/></div>
74 </li>
75 );
76}
77
78class ActivityLogView extends Component {
79
80 state = {
81 localFilter: '',
82 sortDescending: true
83 };
84
85 render() {
86 return (
87 <div className='activity-log-view'>
Avi Zivb8e2faf2017-07-18 19:45:38 +030088 <LogDetails display={this.state.localFilter}/>
AviZi280f8012017-06-09 02:39:56 +030089 <ListEditorView
90 title={i18n('Activity Log')}
91 filterValue={this.state.localFilter}
92 onFilter={filter => this.setState({localFilter: filter})}>
93 <ActivityListItem
AviZi280f8012017-06-09 02:39:56 +030094 activity={{timestamp: 'Date', type: 'Action', comment: 'Comment', user: 'Username', status: 'Status'}}
95 isDes={this.state.sortDescending}
talig8e9c0652017-12-20 14:30:43 +020096 onSort={() => this.setState({sortDescending: !this.state.sortDescending})}
97 isHeader/>
AviZi280f8012017-06-09 02:39:56 +030098 {this.sortActivities(this.filterActivities(), this.state.sortDescending).map(activity => <ActivityListItem key={activity.id} activity={activity}/>)}
99 </ListEditorView>
100 </div>
101 );
102 }
103
104 filterActivities() {
105 let {activities} = this.props;
106 let {localFilter} = this.state;
107 if (localFilter.trim()) {
108 const filter = new RegExp(escape(localFilter), 'i');
talig8e9c0652017-12-20 14:30:43 +0200109 return activities.filter(({user = {id: '', name: ''}, comment = '', type = ''}) =>
110 escape(user.id).match(filter) || escape(user.name).match(filter) || escape(comment).match(filter) || escape(type).match(filter));
AviZi280f8012017-06-09 02:39:56 +0300111 }
112 else {
113 return activities;
114 }
115 }
116
117 sortActivities(activities) {
118 if (this.state.sortDescending) {
119 return activities.sort((a, b) => a.timestamp - b.timestamp);
120 }
121 else {
122 return activities.reverse();
123 }
124 }
125
126}
127
128export default ActivityLogView;