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 '../flux/action';
19 import { SetTitleAction } from '../actions/titleActions';
21 import { AddSnackbarNotification, RemoveSnackbarNotification } from '../actions/snackbarActions';
22 import { AddErrorInfoAction, RemoveErrorInfoAction, ClearErrorInfoAction } from '../actions/errorActions';
23 import { MenuAction, MenuClosedByUser } from '../actions/menuAction'
24 import { IconType } from '../models/iconDefinition';
26 import { ErrorInfo } from '../models/errorInfo';
27 import { SnackbarItem } from '../models/snackbarItem';
28 import { SetWebsocketAction } from '../actions/websocketAction';
30 export interface IApplicationState {
35 isMenuClosedByUser: boolean;
37 snackBars: SnackbarItem[];
38 isWebsocketAvailable: boolean | undefined;
41 const applicationStateInit: IApplicationState = { title: "Loading ...", errors: [], snackBars: [], isMenuOpen: true, isMenuClosedByUser: false, isWebsocketAvailable: undefined };
43 export const applicationStateHandler: IActionHandler<IApplicationState> = (state = applicationStateInit, action) => {
44 if (action instanceof SetTitleAction) {
51 } else if (action instanceof AddErrorInfoAction) {
59 } else if (action instanceof RemoveErrorInfoAction) {
60 const index = state.errors.indexOf(action.errorInfo);
65 ...state.errors.slice(0, index),
66 ...state.errors.slice(index + 1)
70 } else if (action instanceof ClearErrorInfoAction) {
71 if (state.errors && state.errors.length) {
77 } else if (action instanceof AddSnackbarNotification) {
85 } else if (action instanceof RemoveSnackbarNotification) {
88 snackBars: state.snackBars.filter(s => s.key !== action.key)
90 } else if (action instanceof MenuAction) {
93 isMenuOpen: action.isOpen
95 } else if (action instanceof MenuClosedByUser) {
98 isMenuClosedByUser: action.isClosed
101 else if (action instanceof SetWebsocketAction) {
104 isWebsocketAvailable: action.isConnected