2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt odlux
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 import { Action } from '../../../../framework/src/flux/action';
19 import { Dispatch } from '../../../../framework/src/flux/store';
21 import { AddSnackbarNotification } from '../../../../framework/src/actions/snackbarActions';
23 import { NetworkElementConnection, ConnectionStatus, UpdateNetworkElement } from '../models/networkElementConnection';
24 import { connectService } from '../services/connectService';
25 import { updateCurrentViewAsyncAction } from './commonNetworkElementsActions';
26 import { unmountNetworkElementAsyncActionCreator } from './mountedNetworkElementsActions';
28 /** Represents the base action. */
29 export class BaseAction extends Action { }
31 /** Represents an async thunk action creator to add an element to the network elements/nodes. */
32 export const addNewNetworkElementAsyncActionCreator = (element: NetworkElementConnection) => async (dispatch: Dispatch) => {
33 await connectService.createNetworkElement({ ...element });
34 dispatch(updateCurrentViewAsyncAction());
35 dispatch(new AddSnackbarNotification({ message: `Successfully added [${element.nodeId}]`, options: { variant: 'success' } }));
38 /** Represents an async thunk action creator to edit network element/node. */
39 export const editNetworkElementAsyncActionCreator = (element: UpdateNetworkElement) => async (dispatch: Dispatch) => {
40 const connectionStatus: ConnectionStatus[] = (await connectService.getNetworkElementConnectionStatus(element.id).then(ne => (ne))) || [];
41 const currentConnectionStatus = connectionStatus[0].status;
42 if (currentConnectionStatus === 'Disconnected') {
43 await connectService.deleteNetworkElement(element);
45 await connectService.updateNetworkElement(element);
47 dispatch(updateCurrentViewAsyncAction());
48 dispatch(new AddSnackbarNotification({ message: `Successfully modified [${element.id}]`, options: { variant: 'success' } }));
52 /** Represents an async thunk action creator to delete an element from network elements/nodes. */
53 export const removeNetworkElementAsyncActionCreator = (element: UpdateNetworkElement) => async (dispatch: Dispatch) => {
54 await connectService.deleteNetworkElement(element);
55 await dispatch(unmountNetworkElementAsyncActionCreator(element && element.id));
56 await dispatch(updateCurrentViewAsyncAction());