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 { IActionHandler } from '../../../../framework/src/flux/action';
21 AddOrUpdateMountedNetworkElement,
22 AllMountedNetworkElementsLoadedAction,
23 LoadAllMountedNetworkElementsAction,
24 RemoveMountedNetworkElement,
25 UpdateConnectionStateMountedNetworkElement,
26 UpdateRequiredMountedNetworkElement
27 } from '../actions/mountedNetworkElementsActions';
29 import { MountedNetworkElementType } from '../models/mountedNetworkElements';
31 export interface IMountedNetworkElementsState {
32 elements: MountedNetworkElementType[];
36 const mountedNetworkElementsStateInit: IMountedNetworkElementsState = {
41 export const mountedNetworkElementsActionHandler: IActionHandler<IMountedNetworkElementsState> = (state = mountedNetworkElementsStateInit, action) => {
42 if (action instanceof LoadAllMountedNetworkElementsAction) {
49 } else if (action instanceof AllMountedNetworkElementsLoadedAction) {
50 if (!action.error && action.mountedNetworkElements) {
53 elements: action.mountedNetworkElements,
62 } else if (action instanceof AddOrUpdateMountedNetworkElement) {
63 if (!action.mountedNetworkElement) return state; // should handle error here
64 const index = state.elements.findIndex(el => el.mountId === (action.mountedNetworkElement && action.mountedNetworkElement.mountId));
69 ...state.elements.slice(0, index),
70 action.mountedNetworkElement,
71 ...state.elements.slice(index + 1)
77 elements: [...state.elements, action.mountedNetworkElement],
80 } else if (action instanceof RemoveMountedNetworkElement) {
83 elements: state.elements.filter(e => e.mountId !== action.mountId),
85 } else if (action instanceof UpdateConnectionStateMountedNetworkElement) {
86 const index = state.elements.findIndex(el => el.mountId === action.mountId);
91 ...state.elements.slice(0, index),
92 { ...state.elements[index], connectionStatus: action.mountId },
93 ...state.elements.slice(index + 1)
97 } else if (action instanceof UpdateRequiredMountedNetworkElement) {
98 const index = state.elements.findIndex(el => el.mountId === action.mountId);
99 if (index > -1 && (state.elements[index].required !== action.required)) {
103 ...state.elements.slice(0, index),
104 { ...state.elements[index], required: action.required },
105 ...state.elements.slice(index + 1)