blob: 6e3be705c03bdf21d33a36af817e22b1eb407950 [file] [log] [blame]
talig8e9c0652017-12-20 14:30:43 +02001/*!
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 */
16import RestAPIUtil from 'nfvo-utils/RestAPIUtil.js';
17import Configuration from 'sdc-app/config/Configuration.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020018import { actionTypes } from './VersionsPageCreationConstants.js';
19import { modalContentMapper } from 'sdc-app/common/modal/ModalContentMapper.js';
20import { actionTypes as modalActionTypes } from 'nfvo-components/modal/GlobalModalConstants.js';
talig8e9c0652017-12-20 14:30:43 +020021import i18n from 'nfvo-utils/i18n/i18n.js';
22import ItemsHelper from 'sdc-app/common/helpers/ItemsHelper.js';
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020023import { actionTypes as VersionsPageActionTypes } from '../VersionsPageConstants.js';
talig8e9c0652017-12-20 14:30:43 +020024
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020025function baseUrl({ itemId, baseVersion }) {
26 const restPrefix = Configuration.get('restPrefix');
27 return `${restPrefix}/v1.0/items/${itemId}/versions/${baseVersion.id}/`;
talig8e9c0652017-12-20 14:30:43 +020028}
29
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020030function createVersion({
31 itemId,
32 baseVersion,
33 payload: { description, creationMethod }
34}) {
35 return RestAPIUtil.post(baseUrl({ itemId, baseVersion }), {
36 description,
37 creationMethod
38 });
talig8e9c0652017-12-20 14:30:43 +020039}
40
talig8e9c0652017-12-20 14:30:43 +020041export default {
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020042 open(dispatch, { itemType, itemId, additionalProps, baseVersion }) {
43 dispatch({
44 type: actionTypes.OPEN
45 });
talig8e9c0652017-12-20 14:30:43 +020046
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020047 dispatch({
48 type: modalActionTypes.GLOBAL_MODAL_SHOW,
49 data: {
50 modalComponentName: modalContentMapper.VERSION_CREATION,
51 modalComponentProps: {
52 itemType,
53 itemId,
54 additionalProps,
55 baseVersion
56 },
57 title: i18n('New Version - From {name}', {
58 name: baseVersion.name
59 })
60 }
61 });
62 },
talig8e9c0652017-12-20 14:30:43 +020063
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020064 close(dispatch) {
65 dispatch({
66 type: actionTypes.CLOSE
67 });
talig8e9c0652017-12-20 14:30:43 +020068
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020069 dispatch({
70 type: modalActionTypes.GLOBAL_MODAL_CLOSE
71 });
72 },
talig8e9c0652017-12-20 14:30:43 +020073
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020074 createVersion(dispatch, { itemId, baseVersion, payload }) {
75 return createVersion({ itemId, baseVersion, payload }).then(result => {
76 return ItemsHelper.fetchVersions({ itemId }).then(response => {
77 dispatch({
78 type: VersionsPageActionTypes.VERSIONS_LOADED,
79 versions: response.results,
80 itemId
81 });
82 dispatch({
83 type: actionTypes.VERSION_CREATED,
84 result
85 });
86 return result;
87 });
88 });
89 }
talig8e9c0652017-12-20 14:30:43 +020090};