blob: 1fc8c069251189c365e5960d7f7c3c0d6cc7916e [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
talig8e9c0652017-12-20 14:30:43 +020026class RevisionsView extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020027 constructor(props) {
28 super(props);
29 this.state = {
30 revertId: null
31 };
32 }
talig8e9c0652017-12-20 14:30:43 +020033
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020034 render() {
35 let { onCancel, onRevert, revisions, users } = this.props;
36 return (
37 <div className="manage-revisions-page">
38 <Form
39 hasButtons={true}
40 onSubmit={() => onRevert(this.state.revertId)}
41 onReset={() => onCancel()}
42 submitButtonText={i18n('Revert')}
43 labledButtons={true}>
44 <ListEditorView
45 title={i18n('Select a Commit')}
46 isReadOnlyMode={false}>
47 {revisions.map(revision => {
48 return (
49 <div
50 key={revision.id}
51 data-test-id="revision-list-item"
52 className={`revision-list-item ${
53 this.state.revertId === revision.id
54 ? 'selected'
55 : ''
56 }`}>
57 <ListEditorItemView
58 isReadOnlyMode={false}
59 onSelect={() =>
60 this.setState({
61 revertId: revision.id
62 })
63 }>
64 <ListEditorItemViewField>
65 <div className="revision-list-item-fields">
66 <div
67 data-test-id="revision-user"
68 className="revision-user">
69 <SVGIcon
70 name="user"
71 label={
72 users.find(
73 userObject =>
74 userObject.userId ===
75 revision.user
76 ).fullName
77 }
78 labelPosition="right"
79 />
80 </div>
81 <div
82 className="revision-date"
83 data-test-id="revision-date">
84 <span className="revision-date">
85 {i18n.dateNormal(
86 revision.time,
87 {
88 year: 'numeric',
89 month:
90 'numeric',
91 day: 'numeric'
92 }
93 )}
94 </span>
95 <span className="revision-time">
96 {i18n.dateNormal(
97 revision.time,
98 {
99 hour: 'numeric',
100 minute:
101 'numeric',
102 hour12: true
103 }
104 )}
105 </span>
106 </div>
107 <div
108 className="revision-message"
109 data-test-id="revision-message">
110 {revision.message && (
111 <ShowMore
112 anchorClass="more-less"
113 lines={2}
114 more={i18n('More')}
115 less={i18n('Less')}>
116 {revision.message}
117 </ShowMore>
118 )}
119 </div>
120 </div>
121 </ListEditorItemViewField>
122 </ListEditorItemView>
123 </div>
124 );
125 })}
126 </ListEditorView>
127 </Form>
128 </div>
129 );
130 }
talig8e9c0652017-12-20 14:30:43 +0200131}
132
133export default RevisionsView;