Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / configurationApp / src / views / networkElementSelector.tsx
1 /**
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 import React from 'react';
20 import { RouteComponentProps, withRouter } from 'react-router-dom';
21
22 import { connect, IDispatcher, Connect } from '../../../../framework/src/flux/connect';
23 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
24 import { MaterialTable, MaterialTableCtorType, ColumnType } from '../../../../framework/src/components/material-table';
25
26 import { NetworkElementConnection } from '../models/networkElementConnection';
27 import { createConnectedNetworkElementsProperties, createConnectedNetworkElementsActions } from '../../../configurationApp/src/handlers/connectedNetworkElementsHandler';
28
29
30 const mapProps = (state: IApplicationStoreState) => ({
31   connectedNetworkElementsProperties: createConnectedNetworkElementsProperties(state),
32 });
33
34 const mapDispatch = (dispatcher: IDispatcher) => ({
35   connectedNetworkElementsActions: createConnectedNetworkElementsActions(dispatcher.dispatch),
36 });
37
38 const ConnectedElementTable = MaterialTable as MaterialTableCtorType<NetworkElementConnection>;
39
40 type NetworkElementSelectorComponentProps = RouteComponentProps & Connect<typeof mapProps, typeof mapDispatch>;
41
42 let initialSorted = false;
43
44 class NetworkElementSelectorComponent extends React.Component<NetworkElementSelectorComponentProps> {
45
46   componentDidMount() {
47
48     if (!initialSorted) {
49       initialSorted = true;
50       this.props.connectedNetworkElementsActions.onHandleRequestSort('node-id');
51     } else
52       this.props.connectedNetworkElementsActions.onRefresh();
53   }
54
55   render() {
56     return (
57       <ConnectedElementTable stickyHeader tableId="configurable-elements-table" onHandleClick={(e, row) => { this.props.history.push(`${this.props.match.path}/${row.nodeId}`); }} columns={[
58         { property: 'nodeId', title: 'Node Name', type: ColumnType.text },
59         { property: 'isRequired', title: 'Required', type: ColumnType.boolean },
60         { property: 'host', title: 'Host', type: ColumnType.text },
61         { property: 'port', title: 'Port', type: ColumnType.numeric },
62         { property: 'coreModelCapability', title: 'Core Model', type: ColumnType.text },
63         { property: 'deviceType', title: 'Type', type: ColumnType.text },
64       ]} idProperty="id" {...this.props.connectedNetworkElementsActions} {...this.props.connectedNetworkElementsProperties} asynchronus >
65       </ConnectedElementTable>
66     );
67   }
68 }
69
70 export const NetworkElementSelector = withRouter(connect(mapProps, mapDispatch)(NetworkElementSelectorComponent));
71 export default NetworkElementSelector;
72