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 | * permissions and limitations under the License. |
| 15 | */ |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 16 | import { |
| 17 | actionTypes, |
| 18 | rules, |
| 19 | dataRules, |
| 20 | SyncStates |
| 21 | } from './MergeEditorConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 22 | import cloneDeep from 'lodash/cloneDeep.js'; |
| 23 | import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js'; |
| 24 | import Configuration from 'sdc-app/config/Configuration.js'; |
| 25 | import ItemsHelper from '../../common/helpers/ItemsHelper.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 26 | import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js'; |
| 27 | import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 28 | import i18n from 'nfvo-utils/i18n/i18n.js'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 29 | import { optionsInputValues as laOptionsValues } from 'sdc-app/onboarding/licenseModel/licenseAgreement/LicenseAgreementConstants.js'; |
| 30 | import { optionsInputValues as processOptionValues } from 'sdc-app/onboarding/softwareProduct/components/processes/SoftwareProductComponentProcessesConstants.js'; |
| 31 | import { selectValues as limitSelectValues } from 'sdc-app/onboarding/licenseModel/limits/LimitEditorConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 32 | import FeatureGroupsActionHelper from 'sdc-app/onboarding/licenseModel/featureGroups/FeatureGroupsActionHelper.js'; |
| 33 | import LicenseAgreementActionHelper from 'sdc-app/onboarding/licenseModel/licenseAgreement/LicenseAgreementActionHelper.js'; |
| 34 | import moment from 'moment'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 35 | import { DATE_FORMAT } from 'sdc-app/onboarding/OnboardingConstants.js'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 36 | import ScreensHelper from 'sdc-app/common/helpers/ScreensHelper.js'; |
| 37 | |
| 38 | function softwareProductCategoriesUrl() { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 39 | const restCatalogPrefix = Configuration.get('restCatalogPrefix'); |
| 40 | return `${restCatalogPrefix}/v1/categories/resources/`; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | function versionUrl(itemId, versionId) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 44 | const restPrefix = Configuration.get('restPrefix'); |
| 45 | return `${restPrefix}/v1.0/items/${itemId}/versions/${versionId}`; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | function baseUrl(itemId, version, conflictId) { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 49 | const versionId = version.id; |
| 50 | const restPrefix = Configuration.get('restPrefix'); |
| 51 | let baseUrl = `${restPrefix}/v1.0/items/${itemId}/versions/${versionId}/conflicts`; |
| 52 | return conflictId ? `${baseUrl}/${conflictId}` : baseUrl; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 53 | } |
| 54 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 55 | function fetchConflicts({ itemId, version }) { |
| 56 | return RestAPIUtil.fetch(`${baseUrl(itemId, version)}`); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 57 | } |
| 58 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 59 | function fetchConflictById({ itemId, version, cid }) { |
| 60 | return RestAPIUtil.fetch(`${baseUrl(itemId, version, cid)}`); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 61 | } |
| 62 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 63 | function resolveConflict({ itemId, version, conflictId, resolution }) { |
| 64 | return RestAPIUtil.put(`${baseUrl(itemId, version, conflictId)}`, { |
| 65 | resolution |
| 66 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | function fetchCategories() { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 70 | return RestAPIUtil.fetch(softwareProductCategoriesUrl()); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 71 | } |
| 72 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 73 | function fetchVersion({ vendorId, licensingVersion }) { |
| 74 | return RestAPIUtil.fetch(versionUrl(vendorId, licensingVersion)); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 77 | function createCategoryStr(data, { categories }) { |
| 78 | let { category, subCategory } = data; |
| 79 | let foundCat = categories.find(element => element.uniqueId === category); |
| 80 | if (!foundCat) { |
| 81 | return ''; |
| 82 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 83 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 84 | let catName = foundCat.name; |
| 85 | let foundSub = foundCat.subcategories.find( |
| 86 | element => element.uniqueId === subCategory |
| 87 | ); |
| 88 | if (!foundSub) { |
| 89 | return `${catName}`; |
| 90 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 91 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 92 | let subcatName = foundSub.name; |
| 93 | return `${catName} - ${subcatName}`; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 96 | function getEnumValues({ enums, list }) { |
| 97 | if (!list) { |
| 98 | return ''; |
| 99 | } |
| 100 | return list.map(item => enums.find(el => el.enum === item).title); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | const MergeEditorActionHelper = { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 104 | analyzeSyncResult(dispatch, { itemId, version }) { |
| 105 | return ItemsHelper.checkItemStatus(dispatch, { |
| 106 | itemId, |
| 107 | versionId: version.id |
| 108 | }).then(response => { |
| 109 | let inMerge = |
| 110 | response && |
| 111 | response.state && |
| 112 | response.state.synchronizationState === SyncStates.MERGE; |
| 113 | if (inMerge) { |
| 114 | MergeEditorActionHelper.fetchConflicts(dispatch, { |
| 115 | itemId, |
| 116 | version |
| 117 | }).then(() => |
| 118 | dispatch({ |
| 119 | type: modalActionTypes.GLOBAL_MODAL_SHOW, |
| 120 | data: { |
| 121 | modalComponentName: modalContentMapper.MERGE_EDITOR, |
| 122 | modalClassName: 'merge-editor-modal', |
| 123 | title: `${i18n('Merge Required')} - ${ |
| 124 | version.description |
| 125 | }`, |
| 126 | onDeclined: () => { |
| 127 | dispatch({ |
| 128 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 129 | }); |
| 130 | }, |
| 131 | modalComponentProps: { |
| 132 | size: 'lg', |
| 133 | type: 'default' |
| 134 | } |
| 135 | } |
| 136 | }) |
| 137 | ); |
| 138 | } |
| 139 | return Promise.resolve({ |
| 140 | updatedVersion: response, |
| 141 | inMerge, |
| 142 | isDirty: response.state.dirty |
| 143 | }); |
| 144 | }); |
| 145 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 146 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 147 | fetchConflicts(dispatch, { itemId, version }) { |
| 148 | return fetchConflicts({ itemId, version }).then(data => { |
| 149 | dispatch({ |
| 150 | type: actionTypes.LOAD_CONFLICTS, |
| 151 | data |
| 152 | }); |
| 153 | return data; |
| 154 | }); |
| 155 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 156 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 157 | fetchConflict(dispatch, { itemId, version, cid }) { |
| 158 | fetchConflictById({ itemId, version, cid }).then(data => { |
| 159 | let newData = {}; |
| 160 | newData = MergeEditorActionHelper.processConflict(dispatch, { |
| 161 | conflict: data, |
| 162 | itemId, |
| 163 | cid, |
| 164 | version |
| 165 | }); |
| 166 | dispatch({ |
| 167 | type: actionTypes.LOAD_CONFLICT, |
| 168 | data: newData |
| 169 | }); |
| 170 | }); |
| 171 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 172 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 173 | resolveConflict( |
| 174 | dispatch, |
| 175 | { itemId, version, conflictId, resolution, currentScreen } |
| 176 | ) { |
| 177 | resolveConflict({ itemId, version, conflictId, resolution }).then( |
| 178 | () => { |
| 179 | MergeEditorActionHelper.fetchConflicts(dispatch, { |
| 180 | itemId, |
| 181 | version |
| 182 | }).then(conflicts => { |
| 183 | if ( |
| 184 | conflicts.conflictInfoList && |
| 185 | conflicts.conflictInfoList.length === 0 |
| 186 | ) { |
| 187 | dispatch({ |
| 188 | type: modalActionTypes.GLOBAL_MODAL_CLOSE |
| 189 | }); |
| 190 | ScreensHelper.loadLandingScreen(dispatch, { |
| 191 | previousScreenName: currentScreen.screen, |
| 192 | props: currentScreen.props |
| 193 | }); |
| 194 | ItemsHelper.checkItemStatus(dispatch, { |
| 195 | itemId, |
| 196 | versionId: version.id |
| 197 | }); |
| 198 | } |
| 199 | }); |
| 200 | } |
| 201 | ); |
| 202 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 203 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 204 | createConflictObject( |
| 205 | data, |
| 206 | { cid, conflict, dispatch, itemId, version, isYours } |
| 207 | ) { |
| 208 | let newData = {}; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 209 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 210 | for (let key in data) { |
| 211 | if (data.hasOwnProperty(key)) { |
| 212 | let value = data[key]; |
| 213 | let fieldRule = |
| 214 | (dataRules[conflict.type] && |
| 215 | dataRules[conflict.type][key]) || |
| 216 | dataRules.general[key]; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 217 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 218 | if (fieldRule) { |
| 219 | switch (fieldRule.rule) { |
| 220 | case rules.SKIP: |
| 221 | break; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 222 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 223 | case rules.BOOLEAN: |
| 224 | let { trueValue, falseValue } = fieldRule; |
| 225 | newData[key] = |
| 226 | value === trueValue |
| 227 | ? true |
| 228 | : value === falseValue ? false : undefined; |
| 229 | break; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 230 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 231 | case rules.PARSE: |
| 232 | let { moveFields, subFields } = fieldRule; |
| 233 | if (moveFields) { |
| 234 | let fields = subFields || Object.keys(value); |
| 235 | fields.forEach(field => { |
| 236 | newData[ |
| 237 | field |
| 238 | ] = MergeEditorActionHelper.createConflictObject( |
| 239 | value[field], |
| 240 | { |
| 241 | cid, |
| 242 | conflict, |
| 243 | dispatch, |
| 244 | itemId, |
| 245 | version, |
| 246 | isYours |
| 247 | } |
| 248 | ); |
| 249 | }); |
| 250 | } else { |
| 251 | newData[ |
| 252 | key |
| 253 | ] = MergeEditorActionHelper.createConflictObject( |
| 254 | value, |
| 255 | { |
| 256 | cid, |
| 257 | conflict, |
| 258 | dispatch, |
| 259 | itemId, |
| 260 | version, |
| 261 | isYours |
| 262 | } |
| 263 | ); |
| 264 | } |
| 265 | break; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 266 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 267 | case rules.FUNCTION: |
| 268 | let { args, functionName } = fieldRule; |
| 269 | newData[key] = MergeEditorActionHelper[ |
| 270 | functionName |
| 271 | ](data, { |
| 272 | cid, |
| 273 | conflict, |
| 274 | dispatch, |
| 275 | version, |
| 276 | fieldName: key, |
| 277 | isYours, |
| 278 | itemId, |
| 279 | args |
| 280 | }); |
| 281 | break; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 282 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 283 | default: |
| 284 | newData[key] = value; |
| 285 | break; |
| 286 | } |
| 287 | } else { |
| 288 | newData[key] = value; |
| 289 | } |
| 290 | } |
| 291 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 292 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 293 | return newData; |
| 294 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 295 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 296 | getNamesFromIDs( |
| 297 | data, |
| 298 | { version, cid, dispatch, itemId, fieldName, isYours, args } |
| 299 | ) { |
| 300 | let idList = data[fieldName] || []; |
| 301 | let { fetchFunction, fetchField } = args; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 302 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 303 | let promises = idList.map( |
| 304 | id => |
| 305 | new Promise(resolve => |
| 306 | MergeEditorActionHelper[fetchFunction](dispatch, { |
| 307 | licenseModelId: itemId, |
| 308 | [fetchField]: id, |
| 309 | version |
| 310 | }).then(item => resolve(item.name)) |
| 311 | ) |
| 312 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 313 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 314 | Promise.all(promises).then(fetchedItems => { |
| 315 | let yoursOrTheirs = isYours ? 'yoursField' : 'theirsField'; |
| 316 | dispatch({ |
| 317 | type: actionTypes.DATA_PROCESSED, |
| 318 | data: { |
| 319 | cid, |
| 320 | [yoursOrTheirs]: { name: fieldName, value: fetchedItems } |
| 321 | } |
| 322 | }); |
| 323 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 324 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 325 | return idList; |
| 326 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 327 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 328 | getFeatureGroups( |
| 329 | data, |
| 330 | { version, cid, dispatch, itemId, fieldName, isYours } |
| 331 | ) { |
| 332 | let featureGroups = data[fieldName] || []; |
| 333 | if (!(featureGroups instanceof Array)) { |
| 334 | featureGroups = [featureGroups]; |
| 335 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 336 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 337 | let promises = featureGroups.map( |
| 338 | featureGroupId => |
| 339 | new Promise(resolve => |
| 340 | FeatureGroupsActionHelper.fetchFeatureGroup(dispatch, { |
| 341 | licenseModelId: itemId, |
| 342 | featureGroupId, |
| 343 | version |
| 344 | }) |
| 345 | .then(featureGroup => resolve(featureGroup.name)) |
| 346 | .catch(reason => |
| 347 | console.log( |
| 348 | `getFeatureGroups Promise rejected ('${reason}')` |
| 349 | ) |
| 350 | ) |
| 351 | ) |
| 352 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 353 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 354 | Promise.all(promises).then(fetchedGroups => { |
| 355 | let yoursOrTheirs = isYours ? 'yoursField' : 'theirsField'; |
| 356 | dispatch({ |
| 357 | type: actionTypes.DATA_PROCESSED, |
| 358 | data: { |
| 359 | cid, |
| 360 | [yoursOrTheirs]: { name: fieldName, value: fetchedGroups } |
| 361 | } |
| 362 | }); |
| 363 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 364 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 365 | return featureGroups; |
| 366 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 367 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 368 | getLicenseAgreements( |
| 369 | data, |
| 370 | { version, cid, dispatch, itemId, fieldName, isYours } |
| 371 | ) { |
| 372 | let licenseAgreements = data[fieldName] || []; |
| 373 | if (!(licenseAgreements instanceof Array)) { |
| 374 | licenseAgreements = [licenseAgreements]; |
| 375 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 376 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 377 | let promises = licenseAgreements.map( |
| 378 | licenseAgreementId => |
| 379 | new Promise(resolve => |
| 380 | LicenseAgreementActionHelper.fetchLicenseAgreement( |
| 381 | dispatch, |
| 382 | { |
| 383 | licenseModelId: itemId, |
| 384 | licenseAgreementId, |
| 385 | version |
| 386 | } |
| 387 | ) |
| 388 | .then(licenseAgreement => |
| 389 | resolve(licenseAgreement.name) |
| 390 | ) |
| 391 | .catch(reason => |
| 392 | console.log( |
| 393 | `getLicenseAgreements Promise rejected ('${reason}')` |
| 394 | ) |
| 395 | ) |
| 396 | ) |
| 397 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 398 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 399 | Promise.all(promises).then(fetchedAgreements => { |
| 400 | let yoursOrTheirs = isYours ? 'yoursField' : 'theirsField'; |
| 401 | dispatch({ |
| 402 | type: actionTypes.DATA_PROCESSED, |
| 403 | data: { |
| 404 | cid, |
| 405 | [yoursOrTheirs]: { |
| 406 | name: fieldName, |
| 407 | value: fetchedAgreements |
| 408 | } |
| 409 | } |
| 410 | }); |
| 411 | }); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 412 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 413 | return licenseAgreements; |
| 414 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 415 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 416 | processConflict(dispatch, { conflict, cid, version, itemId }) { |
| 417 | let { id, type, yours, theirs } = conflict; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 418 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 419 | let newYours = MergeEditorActionHelper.createConflictObject( |
| 420 | cloneDeep(yours), |
| 421 | { cid, conflict, dispatch, itemId, version, isYours: true } |
| 422 | ); |
| 423 | let newTheirs = MergeEditorActionHelper.createConflictObject( |
| 424 | cloneDeep(theirs), |
| 425 | { cid, conflict, dispatch, itemId, version, isYours: false } |
| 426 | ); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 427 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 428 | return { |
| 429 | id, |
| 430 | type, |
| 431 | yours: newYours, |
| 432 | theirs: newTheirs |
| 433 | }; |
| 434 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 435 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 436 | reduceList(data, { fieldName, args }) { |
| 437 | let { subField } = args; |
| 438 | return data[fieldName].map(el => el[subField]); |
| 439 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 440 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 441 | getEnumList({ fieldName }) { |
| 442 | const enumLists = { |
| 443 | licenseTerm: laOptionsValues.LICENSE_MODEL_TYPE, |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 444 | processType: processOptionValues.PROCESS_TYPE, |
| 445 | limitType: [ |
| 446 | { title: 'Service Provider', enum: 'ServiceProvider' }, |
| 447 | { title: 'Vendor', enum: 'Vendor' } |
| 448 | ], |
| 449 | limitUnit: limitSelectValues.UNIT |
| 450 | }; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 451 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 452 | return enumLists[fieldName]; |
| 453 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 454 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 455 | getEnumValue(data, { fieldName, args = {} }) { |
| 456 | let value = data[fieldName]; |
| 457 | let enumValues = MergeEditorActionHelper.getEnumList({ |
| 458 | fieldName: args.listName || fieldName |
| 459 | }); |
| 460 | let enumValue = enumValues.find(el => el.enum === value); |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 461 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 462 | return (enumValue && enumValue.title) || value; |
| 463 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 464 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 465 | processChoice(data, { fieldName, args = {} }) { |
| 466 | let value = data[fieldName]; |
| 467 | let enumValues = MergeEditorActionHelper.getEnumList({ |
| 468 | fieldName: args.listName || fieldName |
| 469 | }); |
| 470 | let newValue = |
| 471 | value.other || |
| 472 | (enumValues && |
| 473 | enumValues.find(el => el.enum === value.choice).title) || |
| 474 | value.choice; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 475 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 476 | return newValue; |
| 477 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 478 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 479 | processChoices(data, { fieldName, args = {} }) { |
| 480 | let value = data[fieldName]; |
| 481 | let enumValues = MergeEditorActionHelper.getEnumList({ |
| 482 | fieldName: args.listName || fieldName |
| 483 | }); |
| 484 | let newValue = |
| 485 | value.other || |
| 486 | getEnumValues({ enums: enumValues, list: value.choices }) || |
| 487 | value.choices; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 488 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 489 | return newValue; |
| 490 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 491 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 492 | convertArrayToObject(data, { fieldName }) { |
| 493 | let value = data[fieldName]; |
| 494 | let newValue = {}; |
| 495 | value.forEach((el, index) => { |
| 496 | newValue[index] = el; |
| 497 | }); |
| 498 | return newValue; |
| 499 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 500 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 501 | fetchCategory(data, { cid, isYours, fieldName, dispatch }) { |
| 502 | fetchCategories().then(categories => { |
| 503 | let value = createCategoryStr(data, { categories }); |
| 504 | let yoursOrTheirs = isYours ? 'yoursField' : 'theirsField'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 505 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 506 | dispatch({ |
| 507 | type: actionTypes.DATA_PROCESSED, |
| 508 | data: { |
| 509 | cid, |
| 510 | [yoursOrTheirs]: { name: fieldName, value } |
| 511 | } |
| 512 | }); |
| 513 | }); |
| 514 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 515 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 516 | fetchLMVersion(data, { cid, dispatch, isYours }) { |
| 517 | let { licensingVersion, vendorId } = data; |
| 518 | let yoursOrTheirs = isYours ? 'yoursField' : 'theirsField'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 519 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 520 | if (licensingVersion) { |
| 521 | fetchVersion({ licensingVersion, vendorId }).then(response => { |
| 522 | dispatch({ |
| 523 | type: actionTypes.DATA_PROCESSED, |
| 524 | data: { |
| 525 | cid, |
| 526 | [yoursOrTheirs]: { |
| 527 | name: 'licensingVersion', |
| 528 | value: response.name |
| 529 | } |
| 530 | } |
| 531 | }); |
| 532 | }); |
| 533 | } |
| 534 | }, |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 535 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 536 | parseDate(data, { fieldName }) { |
| 537 | let date = data[fieldName]; |
| 538 | return date && moment(date, DATE_FORMAT).format(DATE_FORMAT); |
| 539 | } |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 540 | }; |
| 541 | |
| 542 | export default MergeEditorActionHelper; |