blob: c6a0702a57d110f37e7fe2b6a8b12279a013f36f [file] [log] [blame]
svishnev091edfd2018-03-19 12:15:19 +02001/*
2 * Copyright © 2016-2018 European Support Limited
AviZi280f8012017-06-09 02:39:56 +03003 *
Michael Landoefa037d2017-02-19 12:57:33 +02004 * 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
svishnev091edfd2018-03-19 12:15:19 +02007 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
Michael Landoefa037d2017-02-19 12:57:33 +020010 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
svishnev091edfd2018-03-19 12:15:19 +020012 * 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.
Michael Landoefa037d2017-02-19 12:57:33 +020015 */
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020016import { connect } from 'react-redux';
svishnevea5e43c2018-04-15 09:06:57 +030017import featureToggle from 'sdc-app/features/featureToggle.js';
18import { featureToggleNames } from 'sdc-app/features/FeaturesConstants.js';
Michael Landoefa037d2017-02-19 12:57:33 +020019import LicenseModelCreationActionHelper from './LicenseModelCreationActionHelper.js';
20import LicenseModelCreationView from './LicenseModelCreationView.jsx';
svishnevea5e43c2018-04-15 09:06:57 +030021import LicenseModelCreationViewWithFilter from './LicenseModelCreationViewWithFilter.jsx';
22
AviZi280f8012017-06-09 02:39:56 +030023import ValidationHelper from 'sdc-app/common/helpers/ValidationHelper.js';
24import LicenseModelActionHelper from 'sdc-app/onboarding/licenseModel/LicenseModelActionHelper.js';
talig8e9c0652017-12-20 14:30:43 +020025import VersionsPageActionHelper from 'sdc-app/onboarding/versionsPage/VersionsPageActionHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020026import { itemTypes as versionItemTypes } from 'sdc-app/onboarding/versionsPage/VersionsPageConstants.js';
talig8e9c0652017-12-20 14:30:43 +020027import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020028import { enums, screenTypes } from 'sdc-app/onboarding/OnboardingConstants.js';
talig8e9c0652017-12-20 14:30:43 +020029import PermissionsActionHelper from 'sdc-app/onboarding/permissions/PermissionsActionHelper.js';
svishnevea5e43c2018-04-15 09:06:57 +030030import UniqueTypesHelper from 'sdc-app/common/helpers/UniqueTypesHelper.js';
31import i18n from 'nfvo-utils/i18n/i18n.js';
32import { itemType } from 'sdc-app/common/helpers/ItemsHelperConstants.js';
33
34const ToggledLicenseModelCreationView = featureToggle(
35 featureToggleNames.FILTER
36)({
37 OnComp: LicenseModelCreationViewWithFilter,
38 OffComp: LicenseModelCreationView
39});
Michael Landoefa037d2017-02-19 12:57:33 +020040
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020041export const mapStateToProps = ({
42 users: { usersList },
43 licenseModelList,
44 finalizedLicenseModelList,
45 archivedLicenseModelList,
46 licenseModel: { licenseModelCreation }
47}) => {
48 let { genericFieldInfo } = licenseModelCreation;
49 let isFormValid = ValidationHelper.checkFormValid(genericFieldInfo);
50 let VLMNames = {};
svishnev091edfd2018-03-19 12:15:19 +020051
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020052 const allVlmList = [
53 ...licenseModelList,
54 ...finalizedLicenseModelList,
55 ...archivedLicenseModelList
56 ];
57 allVlmList.map(item => {
58 VLMNames[item.name.toLowerCase()] = item.id;
59 });
AviZi280f8012017-06-09 02:39:56 +030060
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020061 return {
62 ...licenseModelCreation,
63 isFormValid: isFormValid,
64 VLMNames,
65 usersList
66 };
AviZi280f8012017-06-09 02:39:56 +030067};
68
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020069export const mapActionsToProps = dispatch => {
70 return {
71 onDataChanged: (deltaData, formName, customValidations) =>
72 ValidationHelper.dataChanged(dispatch, {
73 deltaData,
74 formName,
75 customValidations
76 }),
77 onCancel: () => LicenseModelCreationActionHelper.close(dispatch),
78 onSubmit: (licenseModel, usersList) => {
79 LicenseModelCreationActionHelper.close(dispatch);
80 LicenseModelCreationActionHelper.createLicenseModel(dispatch, {
81 licenseModel
82 }).then(response => {
83 let { itemId, version } = response;
84 LicenseModelActionHelper.fetchLicenseModels(dispatch).then(() =>
85 PermissionsActionHelper.fetchItemUsers(dispatch, {
86 itemId,
87 allUsers: usersList
88 }).then(() =>
89 VersionsPageActionHelper.fetchVersions(dispatch, {
90 itemType: versionItemTypes.LICENSE_MODEL,
91 itemId
92 }).then(() =>
93 ScreensHelper.loadScreen(dispatch, {
94 screen: enums.SCREEN.LICENSE_MODEL_OVERVIEW,
95 screenType: screenTypes.LICENSE_MODEL,
96 props: { licenseModelId: itemId, version }
97 })
98 )
99 )
100 );
101 });
102 },
103 onValidateForm: formName =>
svishnevea5e43c2018-04-15 09:06:57 +0300104 ValidationHelper.validateForm(dispatch, formName),
105 isNameUnique: (value, name, formName) =>
106 UniqueTypesHelper.isNameUnique(dispatch, {
107 value,
108 name,
109 formName,
110 errorText: `${i18n(
111 'License model by the name'
112 )} ${value} ${i18n('already exists')}. ${i18n(
113 'License model name must be unique'
114 )}`,
115 itemType: itemType.VLM
116 })
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200117 };
Michael Landoefa037d2017-02-19 12:57:33 +0200118};
119
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200120export default connect(mapStateToProps, mapActionsToProps)(
svishnevea5e43c2018-04-15 09:06:57 +0300121 ToggledLicenseModelCreationView
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +0200122);