2 * Copyright © 2016-2018 European Support Limited
3 * Modifications Copyright (C) 2021 Nordix Foundation.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing
15 * permissions and limitations under the License.
17 import { connect } from 'react-redux';
18 import SoftwareProductCreationActionHelper from './SoftwareProductCreationActionHelper.js';
19 import SoftwareProductCreationView from './SoftwareProductCreationView.jsx';
20 import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
21 import SoftwareProductActionHelper from '../SoftwareProductActionHelper.js';
22 import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js';
23 import { itemTypes as versionItemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
24 import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
25 import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
26 import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js';
27 import UniqueTypesHelper from 'sdc-app/common/helpers/UniqueTypesHelper.js';
28 import i18n from 'nfvo-utils/i18n/i18n.js';
29 import { itemType } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
31 export const mapStateToProps = ({
32 finalizedLicenseModelList,
34 archivedSoftwareProductList,
36 finalizedSoftwareProductList,
38 softwareProductCreation,
39 softwareProductCategories,
43 let { genericFieldInfo, vendorList = [] } = softwareProductCreation;
44 let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
48 ...softwareProductList,
49 ...finalizedSoftwareProductList,
50 ...archivedSoftwareProductList
52 allVspList.map(item => {
53 VSPNames[item.name.toLowerCase()] = item.id;
57 data: softwareProductCreation.data,
58 selectedVendorId: softwareProductCreation.selectedVendorId,
59 disableVendor: softwareProductCreation.disableVendor,
60 softwareProductCategories,
61 finalizedLicenseModelList,
65 formReady: softwareProductCreation.formReady,
72 export const mapActionsToProps = dispatch => {
74 onDataChanged: (deltaData, formName, customValidations) => {
75 ValidationHelper.dataChanged(dispatch, {
81 onCancel: () => SoftwareProductCreationActionHelper.resetData(dispatch),
82 onSubmit: (softwareProduct, usersList) => {
83 SoftwareProductCreationActionHelper.resetData(dispatch);
84 SoftwareProductCreationActionHelper.createSoftwareProduct(
88 let { itemId, version } = response;
89 SoftwareProductActionHelper.fetchSoftwareProductList(
92 PermissionsActionHelper.fetchItemUsers(dispatch, {
96 VersionsPageActionHelper.fetchVersions(dispatch, {
97 itemType: versionItemTypes.SOFTWARE_PRODUCT,
100 ScreensHelper.loadScreen(dispatch, {
102 enums.SCREEN.SOFTWARE_PRODUCT_LANDING_PAGE,
103 screenType: screenTypes.SOFTWARE_PRODUCT,
104 props: { softwareProductId: itemId, version }
111 onValidateForm: formName =>
112 ValidationHelper.validateForm(dispatch, formName),
113 isNameUnique: (value, name, formName) =>
114 UniqueTypesHelper.isNameUnique(dispatch, {
119 'Software product by the name'
120 )} ${value} ${i18n('already exists')}. ${i18n(
121 'Software product name must be unique'
123 itemType: itemType.VSP
128 export default connect(mapStateToProps, mapActionsToProps, null, {
130 })(SoftwareProductCreationView);