talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | /*! |
| 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 | */ |
| 16 | import React from 'react'; |
| 17 | import Form from 'nfvo-components/input/validation/Form.jsx'; |
| 18 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
| 19 | import ShowMore from 'react-show-more'; |
| 20 | import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js'; |
| 21 | |
| 22 | import ListEditorView from 'nfvo-components/listEditor/ListEditorView.jsx'; |
| 23 | import ListEditorItemView from 'nfvo-components/listEditor/ListEditorItemView.jsx'; |
| 24 | import ListEditorItemViewField from 'nfvo-components/listEditor/ListEditorItemViewField.jsx'; |
| 25 | |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 26 | class RevisionsView extends React.Component { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 27 | constructor(props) { |
| 28 | super(props); |
| 29 | this.state = { |
| 30 | revertId: null |
| 31 | }; |
| 32 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 33 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame^] | 34 | 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 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | export default RevisionsView; |