Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / 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 import Refresh from '@mui/icons-material/Refresh';
23
24 import { EventLogType } from '../models/eventLogType';
25 import { IApplicationStoreState } from "../../../../framework/src/store/applicationStore";
26 import { createEventLogProperties, createEventLogActions } from "../handlers/eventLogHandler";
27 import RefreshEventLogDialog, { RefreshEventLogDialogMode } from '../components/refreshEventLogDialog';
28
29 const EventLogTable = MaterialTable as MaterialTableCtorType<EventLogType & { _id: string }>;
30
31 const mapProps = (state: IApplicationStoreState) => ({
32   eventLogProperties: createEventLogProperties(state),
33   eventLog: state.eventLog.logEntries
34 });
35
36 const mapDispatch = (dispatcher: IDispatcher) => ({
37   eventLogActions: createEventLogActions(dispatcher.dispatch)
38 });
39
40 type EventLogComponentProps = Connect<typeof mapProps, typeof mapDispatch>;
41 type EventLogComponentState = {
42   refreshEventLogEditorMode: RefreshEventLogDialogMode
43 }
44 let initalSorted = false;
45
46 class EventLogComponent extends React.Component<EventLogComponentProps, EventLogComponentState> {
47   constructor(props: EventLogComponentProps) {
48     super(props);
49
50     this.state = {
51       refreshEventLogEditorMode: RefreshEventLogDialogMode.None
52     };
53   }
54
55   render(): JSX.Element {
56
57     const refreshEventLogAction = {
58       icon: Refresh, tooltip: 'Refresh Event log', ariaLabel:'refresh', onClick: () => {
59         this.setState({
60           refreshEventLogEditorMode: RefreshEventLogDialogMode.RefreshEventLogTable
61         });
62       }
63     };
64     return (
65       <>
66         <EventLogTable stickyHeader title="Event Log" tableId="event-log-table" idProperty="_id" customActionButtons={[refreshEventLogAction]}
67           columns={[
68             { property: "nodeId", title: "Node Name" },
69             { property: "counter", title: "Counter" },
70             { property: "timestamp", title: "Timestamp" },
71             { property: "objectId", title: "Object ID" },
72             { property: "attributeName", title: "Attribute Name" },
73             { property: "newValue", title: "Message" },
74             { property: "sourceType", title: "Source" }
75           ]}  {...this.props.eventLogActions} {...this.props.eventLogProperties} >
76         </EventLogTable>
77         <RefreshEventLogDialog
78           mode={this.state.refreshEventLogEditorMode}
79           onClose={this.onCloseRefreshEventLogDialog}
80         />
81       </>
82     )
83   }
84
85   private onCloseRefreshEventLogDialog = () => {
86     this.setState({
87       refreshEventLogEditorMode: RefreshEventLogDialogMode.None
88     });
89   }
90   componentDidMount() {
91
92     if (!initalSorted) {
93       initalSorted = true;
94       this.props.eventLogActions.onHandleExplicitRequestSort("timestamp", "desc");
95     } else {
96       this.props.eventLogActions.onRefresh();
97     }
98   }
99 }
100
101 export const EventLog = connect(mapProps, mapDispatch)(EventLogComponent);
102 export default EventLog;