blob: da5f3be8125f64264aad0e99646608fdd84122fb [file] [log] [blame]
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03001/*
2 * Copyright © 2016-2018 European Support Limited
talig8e9c0652017-12-20 14:30:43 +02003 *
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 *
Einav Weiss Keidar1801b242018-08-13 16:19:46 +03008 * http://www.apache.org/licenses/LICENSE-2.0
talig8e9c0652017-12-20 14:30:43 +02009 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
talig8e9c0652017-12-20 14:30:43 +020015 */
16import React from 'react';
17import PropTypes from 'prop-types';
18import i18n from 'nfvo-utils/i18n/i18n.js';
19import Input from 'nfvo-components/input/validation/Input.jsx';
20import Form from 'nfvo-components/input/validation/Form.jsx';
21
22const VersionPropType = PropTypes.shape({
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020023 name: PropTypes.string,
24 description: PropTypes.string,
25 creationMethod: PropTypes.string
talig8e9c0652017-12-20 14:30:43 +020026});
27
28class VersionsPageCreationView extends React.Component {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020029 static propTypes = {
30 data: VersionPropType,
31 availableMethods: PropTypes.array,
32 onDataChanged: PropTypes.func.isRequired,
33 onSubmit: PropTypes.func.isRequired,
34 onCancel: PropTypes.func.isRequired
35 };
talig8e9c0652017-12-20 14:30:43 +020036
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020037 render() {
38 let {
39 data = {},
40 genericFieldInfo,
41 baseVersion,
42 onDataChanged,
43 onCancel
44 } = this.props;
45 let { additionalInfo: { OptionalCreationMethods } } = baseVersion;
46 let { description, creationMethod } = data;
talig8e9c0652017-12-20 14:30:43 +020047
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020048 return (
49 <div className="version-creation-page">
50 {genericFieldInfo && (
51 <Form
52 ref={validationForm =>
53 (this.validationForm = validationForm)
54 }
55 hasButtons={true}
Einav Weiss Keidar1801b242018-08-13 16:19:46 +030056 btnClassName="sdc-modal__footer"
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020057 onSubmit={() => this.submit()}
58 submitButtonText={i18n('Create')}
59 onReset={() => onCancel()}
60 labledButtons={true}
61 isValid={this.props.isFormValid}
62 formReady={this.props.formReady}
63 onValidateForm={() => this.validate()}>
64 <div className="version-form-row">
65 <Input
66 label={i18n('Version Category')}
67 value={creationMethod}
68 onChange={e => this.onSelectMethod(e)}
69 type="select"
70 overlayPos="bottom"
71 data-test-id="new-version-category"
72 isValid={
73 genericFieldInfo.creationMethod.isValid
74 }
75 errorText={
76 genericFieldInfo.creationMethod.errorText
77 }
78 isRequired>
79 <option key="" value="">
80 {i18n('Please select…')}
81 </option>
82 {OptionalCreationMethods.map(method => (
83 <option key={method} value={method}>
84 {i18n(method)}
85 </option>
86 ))}
87 </Input>
88 </div>
talig8e9c0652017-12-20 14:30:43 +020089
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020090 <div className="version-form-row">
91 <Input
92 label={i18n('Description')}
93 value={description}
94 type="text"
95 overlayPos="bottom"
96 data-test-id="new-version-description"
97 isValid={genericFieldInfo.description.isValid}
98 errorText={
99 genericFieldInfo.description.errorText
100 }
101 onChange={description =>
102 onDataChanged({ description })
103 }
104 isRequired
Einav Weiss Keidar1801b242018-08-13 16:19:46 +0300105 groupClassName="no-bottom-margin"
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200106 />
107 </div>
108 </Form>
109 )}
110 </div>
111 );
112 }
talig8e9c0652017-12-20 14:30:43 +0200113
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200114 onSelectMethod(e) {
115 const selectedIndex = e.target.selectedIndex;
116 const creationMethod = e.target.options[selectedIndex].value;
117 this.props.onDataChanged({ creationMethod });
118 }
talig8e9c0652017-12-20 14:30:43 +0200119
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200120 submit() {
121 let { baseVersion, data: { description, creationMethod } } = this.props;
122 this.props.onSubmit({
123 baseVersion,
124 payload: { description, creationMethod }
125 });
126 }
talig8e9c0652017-12-20 14:30:43 +0200127
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200128 validate() {
129 this.props.onValidateForm();
130 }
talig8e9c0652017-12-20 14:30:43 +0200131}
132
133export default VersionsPageCreationView;