blob: d6ef604a221de85f2453663796ed4ccc800262c5 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
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 * revisions and limitations under the License.
15 */
16import React from 'react';
17import Form from 'nfvo-components/input/validation/Form.jsx';
18import i18n from 'nfvo-utils/i18n/i18n.js';
19import ShowMore from 'react-show-more';
20import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
21
22import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx';
23import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx';
24import ListEditorItemViewField from 'nfvo-components/listEditor/ListEditorItemViewField.jsx';
25
26
27class RevisionsView extends React.Component {
28 constructor(props) {
29 super(props);
30 this.state = {
31 revertId : null
32 };
33 }
34
35 render() {
36 let {onCancel, onRevert, revisions, users} = this.props;
37 return (
38 <div className='manage-revisions-page'>
39 <Form
40 hasButtons={true}
41 onSubmit={() => onRevert(this.state.revertId)}
42 onReset={() => onCancel() }
43 submitButtonText={i18n('Revert')}
44 labledButtons={true}>
45 <ListEditorView
46 title={i18n('Select a Commit')}
47 isReadOnlyMode={false}>
48 {revisions.map((revision) => {
49 return (
50 <div key={revision.id} data-test-id='revision-list-item' className={`revision-list-item ${this.state.revertId === revision.id ? 'selected' : ''}`}>
51 <ListEditorItemView
52 isReadOnlyMode={false}
53 onSelect={() => this.setState({revertId : revision.id})}>
54 <ListEditorItemViewField>
55 <div className='revision-list-item-fields'>
56 <div data-test-id='revision-user' className='revision-user'>
57 <SVGIcon name='user' label={users.find(userObject => userObject.userId === revision.user).fullName} labelPosition='right'/>
58 </div>
59 <div className='revision-date' data-test-id='revision-date'>
60 <span className='revision-date'>{i18n.dateNormal(revision.time, {
61 year: 'numeric', month: 'numeric', day: 'numeric'
62 })}</span>
63 <span className='revision-time'>{i18n.dateNormal(revision.time, {
64 hour: 'numeric', minute: 'numeric',
65 hour12: true
66 })}</span>
67 </div>
68 <div className='revision-message'data-test-id='revision-message'>
69 {revision.message && <ShowMore anchorClass='more-less' lines={2} more={i18n('More')} less={i18n('Less')}>
70 {revision.message}
71 </ShowMore>}</div>
72 </div>
73 </ListEditorItemViewField>
74 </ListEditorItemView>
75 </div>
76
77 );
78 })}
79 </ListEditorView>
80 </Form>
81 </div>
82 );
83 }
84
85}
86
87export default RevisionsView;