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==========================================================================
19 import { IActionHandler } from '../../../../framework/src/flux/action';
20 import { ViewSpecification } from '../models/uiModels';
21 import { EnableValueSelector, SetSelectedValue, UpdateDeviceDescription, SetCollectingSelectionData, UpdateViewDescription, UpdateOutputData } from '../actions/deviceActions';
23 export interface IValueSelectorState {
24 collectingData: boolean;
25 keyProperty: string | undefined;
26 listSpecification: ViewSpecification | null;
28 onValueSelected: (value: any) => void;
31 const dummyFunc = () => { };
32 const valueSelectorStateInit: IValueSelectorState = {
33 collectingData: false,
34 keyProperty: undefined,
35 listSpecification: null,
37 onValueSelected: dummyFunc,
40 export const valueSelectorHandler: IActionHandler<IValueSelectorState> = (state = valueSelectorStateInit, action) => {
41 if (action instanceof SetCollectingSelectionData) {
44 collectingData: action.busy,
46 } else if (action instanceof EnableValueSelector) {
49 collectingData: false,
50 keyProperty: action.keyProperty,
51 listSpecification: action.listSpecification,
52 onValueSelected: action.onValueSelected,
53 listData: action.listData,
55 } else if (action instanceof SetSelectedValue) {
56 if (state.keyProperty) {
57 state.onValueSelected(action.value[state.keyProperty]);
61 collectingData: false,
62 keyProperty: undefined,
63 listSpecification: null,
64 onValueSelected: dummyFunc,
67 } else if (action instanceof UpdateDeviceDescription || action instanceof UpdateViewDescription || action instanceof UpdateOutputData) {
70 collectingData: false,
71 keyProperty: undefined,
72 listSpecification: null,
73 onValueSelected: dummyFunc,