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 { LtpIds } from '../models/availableLtps';
22 import { PerformanceHistoryService } from '../services/performanceHistoryService';
25 * Represents the base action.
27 export class BaseAction extends Action { }
30 * Represents an action causing the store to load available ltps.
32 export class LoadAllAvailableLtpsAction extends BaseAction { }
35 * Represents an action causing the store to update available ltps.
37 export class AllAvailableLtpsLoadedAction extends BaseAction {
39 * Initialize this instance.
40 * @param availableLtps The available ltps which are returned from the database.
42 constructor(public availableLtps: LtpIds[] | null, public error?: string) {
47 export class SetInitialLoadedAction extends BaseAction {
48 constructor(public initialLoaded: boolean) {
53 export class NoLtpsFoundAction extends BaseAction { }
55 export class ResetLtpsAction extends BaseAction { }
57 const getDistinctLtps = (distinctLtps: LtpIds[], selectedLtp: string, selectFirstLtp?: Function, resetLtp?: Function) => {
58 let ltpNotSelected: boolean = true;
59 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
60 selectFirstLtp && selectFirstLtp(distinctLtps[0].key);
61 distinctLtps.forEach((value: LtpIds) => {
62 if (value.key === selectedLtp) {
63 ltpNotSelected = false;
66 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
67 resetLtp && resetLtp(ltpNotSelected);
72 * Represents an asynchronous thunk action to load available distinctLtps by networkElement from the database and set the returned first Ltp as default.
73 * @param networkElement The network element sent to database to get its available distinct Ltps.
74 * @param selectedTimePeriod The time period selected sent to database to get the distinct Ltps of the selected network element.
75 * @param selectedLtp The Ltp which is selected in the dropdown.
76 * @param selectFirstLtp The function to get the first ltp returned from the database to be selected as default on selection upon network element.
77 * @param resetLtp The function to verify if the selected ltp is also available in the selected time period database else reset the Ltp dropdown to select.
79 export const loadDistinctLtpsbyNetworkElementAsync = (networkElement: string, selectedTimePeriod: string, selectedLtp: string, selectFirstLtp?: Function, resetLtp?: Function) => (dispatch: Dispatch) => {
80 dispatch(new LoadAllAvailableLtpsAction());
81 PerformanceHistoryService.getDistinctLtpsFromDatabase(networkElement, selectedTimePeriod).then(distinctLtps => {
83 const ltps = getDistinctLtps(distinctLtps, selectedLtp, selectFirstLtp, resetLtp);
84 dispatch(new AllAvailableLtpsLoadedAction(ltps));
88 dispatch(new NoLtpsFoundAction());
91 dispatch(new AllAvailableLtpsLoadedAction(null, error));