1 import * as React from 'react';
3 import { withRouter, RouteComponentProps } from 'react-router-dom';
5 import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
6 import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
8 import { MaterialTable, ColumnType, MaterialTableCtorType } from '../../../../framework/src/components/material-table';
9 import { Panel } from '../../../../framework/src/components/material-ui';
11 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
12 import connect, { Connect, IDispatcher } from '../../../../framework/src/flux/connect';
14 import { Fault } from '../models/fault';
15 import { PanelId } from '../models/panelId';
17 import { createCurrentProblemsProperties, createCurrentProblemsActions, currentProblemsReloadAction } from '../handlers/currentProblemsHandler';
18 import { createAlarmLogEntriesProperties, createAlarmLogEntriesActions, alarmLogEntriesReloadAction } from '../handlers/alarmLogEntriesHandler';
19 import { SetPanelAction } from '../actions/panelChangeActions';
21 const mapProps = (state: IApplicationStoreState) => ({
22 activePanel: state.fault.currentOpenPanel,
23 currentProblemsProperties: createCurrentProblemsProperties(state),
24 faultNotifications: state.fault.faultNotifications,
25 alarmLogEntriesProperties: createAlarmLogEntriesProperties(state)
28 const mapDisp = (dispatcher: IDispatcher) => ({
29 currentProblemsActions: createCurrentProblemsActions(dispatcher.dispatch),
30 alarmLogEntriesActions: createAlarmLogEntriesActions(dispatcher.dispatch),
31 reloadCurrentProblems: () => dispatcher.dispatch(currentProblemsReloadAction),
32 reloadAlarmLogEntries: () => dispatcher.dispatch(alarmLogEntriesReloadAction),
33 setCurrentPanel: (panelId: PanelId) => dispatcher.dispatch(new SetPanelAction(panelId))
36 type FaultApplicationComponentProps = RouteComponentProps & Connect<typeof mapProps, typeof mapDisp>;
39 const FaultTable = MaterialTable as MaterialTableCtorType<Fault>;
41 class FaultApplicationComponent extends React.Component<FaultApplicationComponentProps>{
43 render(): JSX.Element {
45 const { activePanel } = this.props;
47 const onTogglePanel = (panelId: PanelId) => {
48 const nextActivePanel = panelId === this.props.activePanel ? null : panelId;
49 this.props.setCurrentPanel(nextActivePanel);
51 switch (nextActivePanel) {
52 case 'CurrentProblem':
53 this.props.reloadCurrentProblems();
56 this.props.reloadAlarmLogEntries();
58 case 'AlarmNotifications':
68 <Panel activePanel={ activePanel } panelId={ 'CurrentProblem' } onToggle={ onTogglePanel } title={ 'Current Problem List' }>
69 <FaultTable idProperty={ '_id' } columns={ [
70 { property: "icon", title: "", type: ColumnType.custom, customControl: this.renderIcon },
71 { property: "timeStamp", type: ColumnType.text, title: "Time Stamp" },
72 { property: "nodeName", title: "Node Name", type: ColumnType.text },
73 { property: "counter", title: "Count", type: ColumnType.numeric, width: "100px" },
74 { property: "objectId", title: "Object Id", type: ColumnType.text } ,
75 { property: "problem", title: "Alarm Type", type: ColumnType.text },
76 { property: "severity", title: "Severity", type: ColumnType.text, width: "140px" },
77 ] } { ...this.props.currentProblemsProperties } { ...this.props.currentProblemsActions } />
79 <Panel activePanel={ activePanel } panelId={ 'AlarmNotifications' } onToggle={ onTogglePanel } title={ `Alarm Notifications ${this.props.faultNotifications.faults.length} since ${this.props.faultNotifications.since}` }>
80 <FaultTable rows={ this.props.faultNotifications.faults } asynchronus columns={ [
81 { property: "icon", title: "", type: ColumnType.custom, customControl: this.renderIcon },
82 { property: "timeStamp", title: "Time Stamp" },
83 { property: "nodeName", title: "Node Name" },
84 { property: "counter", title: "Count", width: "100px" },
85 { property: "objectId", title: "Object Id" },
86 { property: "problem", title: "Alarm Type" },
87 { property: "severity", title: "Severity", width: "140px" },
88 ] } idProperty={ '_id' } />
90 <Panel activePanel={ activePanel } panelId={ 'AlarmLog' } onToggle={ onTogglePanel } title={ 'Alarm Log' }>
91 <FaultTable idProperty={ '_id' } columns={ [
92 { property: "icon", title: "", type: ColumnType.custom, customControl: this.renderIcon },
93 { property: "timeStamp", title: "Time Stamp" },
94 { property: "nodeName", title: "Node Name" },
95 { property: "counter", title: "Count", type: ColumnType.numeric, width: "100px" },
96 { property: "objectId", title: "Object Id" },
97 { property: "problem", title: "Alarm Type" },
98 { property: "severity", title: "Severity", width: "140px" },
99 ] } { ...this.props.alarmLogEntriesProperties } { ...this.props.alarmLogEntriesActions }/>
105 private renderIcon = (props: { rowData: Fault }) => {
107 <FontAwesomeIcon icon={ faExclamationTriangle } />
113 export const FaultApplication = withRouter(connect(mapProps, mapDisp)(FaultApplicationComponent));
114 export default FaultApplication;