Fix odlux bugs
[ccsdk/features.git] / sdnr / wt / odlux / apps / eventLogApp / src / views / eventLog.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 import * as React from "react";
19
20 import { Connect, connect, IDispatcher } from '../../../../framework/src/flux/connect';
21 import { MaterialTable, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
22
23 import { EventLogType } from '../models/eventLogType';
24 import { IApplicationStoreState } from "../../../../framework/src/store/applicationStore";
25 import { createEventLogProperties, createEventLogActions } from "../handlers/eventLogHandler";
26
27 const EventLogTable = MaterialTable as MaterialTableCtorType<EventLogType & { _id: string }>;
28
29 const mapProps = (state: IApplicationStoreState) => ({
30   eventLogProperties: createEventLogProperties(state),
31   eventLog: state.eventLog.logEntries
32 });
33
34 const mapDispatch = (dispatcher: IDispatcher) => ({
35   eventLogActions: createEventLogActions(dispatcher.dispatch)
36 });
37
38 let initalSorted = false;
39
40 class EventLogComponent extends React.Component<Connect<typeof mapProps, typeof mapDispatch>> {
41   render() {
42     return <EventLogTable stickyHeader title="Event Log" idProperty="_id" columns={[
43       { property: "nodeId", title: "Node Name" },
44       { property: "counter", title: "Counter" },
45       { property: "timestamp", title: "Timestamp" },
46       { property: "objectId", title: "Object ID" },
47       { property: "attributeName", title: "Attribute Name" },
48       { property: "newValue", title: "Message" },
49       { property: "sourceType", title: "Source" }
50     ]}  {...this.props.eventLogActions} {...this.props.eventLogProperties} >
51     </EventLogTable>
52   }
53
54   componentDidMount() {
55
56     if (!initalSorted) {
57       initalSorted = true;
58       this.props.eventLogActions.onHandleExplicitRequestSort("timestamp", "desc");
59     } else {
60       this.props.eventLogActions.onRefresh();
61     }
62   }
63 }
64
65 export const EventLog = connect(mapProps, mapDispatch)(EventLogComponent);
66 export default EventLog;