2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 import { connect } from 'react-redux';
17 import SoftwareProductCreationActionHelper from './SoftwareProductCreationActionHelper.js';
18 import SoftwareProductCreationView from './SoftwareProductCreationView.jsx';
19 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
20 import SoftwareProductActionHelper from '../SoftwareProductActionHelper.js';
21 import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js';
22 import { itemTypes as versionItemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
23 import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
24 import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
25 import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js';
26 import UniqueTypesHelper from 'sdc-app/common/helpers/UniqueTypesHelper.js';
27 import i18n from 'nfvo-utils/i18n/i18n.js';
28 import { itemType } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
30 export const mapStateToProps = ({
31 finalizedLicenseModelList,
33 archivedSoftwareProductList,
35 finalizedSoftwareProductList,
36 softwareProduct: { softwareProductCreation, softwareProductCategories }
38 let { genericFieldInfo, vendorList = [] } = softwareProductCreation;
39 let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
43 ...softwareProductList,
44 ...finalizedSoftwareProductList,
45 ...archivedSoftwareProductList
47 allVspList.map(item => {
48 VSPNames[item.name.toLowerCase()] = item.id;
52 data: softwareProductCreation.data,
53 selectedVendorId: softwareProductCreation.selectedVendorId,
54 disableVendor: softwareProductCreation.disableVendor,
55 softwareProductCategories,
56 finalizedLicenseModelList,
59 formReady: softwareProductCreation.formReady,
66 export const mapActionsToProps = dispatch => {
68 onDataChanged: (deltaData, formName, customValidations) =>
69 ValidationHelper.dataChanged(dispatch, {
74 onCancel: () => SoftwareProductCreationActionHelper.resetData(dispatch),
75 onSubmit: (softwareProduct, usersList) => {
76 SoftwareProductCreationActionHelper.resetData(dispatch);
77 SoftwareProductCreationActionHelper.createSoftwareProduct(
81 let { itemId, version } = response;
82 SoftwareProductActionHelper.fetchSoftwareProductList(
85 PermissionsActionHelper.fetchItemUsers(dispatch, {
89 VersionsPageActionHelper.fetchVersions(dispatch, {
90 itemType: versionItemTypes.SOFTWARE_PRODUCT,
93 ScreensHelper.loadScreen(dispatch, {
95 enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE,
96 screenType: screenTypes.SOFTWARE_PRODUCT,
97 props: { softwareProductId: itemId, version }
104 onValidateForm: formName =>
105 ValidationHelper.validateForm(dispatch, formName),
106 isNameUnique: (value, name, formName) =>
107 UniqueTypesHelper.isNameUnique(dispatch, {
112 'Software product by the name'
113 )} ${value} ${i18n('already exists')}. ${i18n(
114 'Software product name must be unique'
116 itemType: itemType.VSP
121 export default connect(mapStateToProps, mapActionsToProps, null, {
123 })(SoftwareProductCreationView);