47999ed501979a96fb0d04def81b8df7ae24ecbc
[oam/oam-controller.git] /
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 React from 'react';
19
20 import { TextField } from '@mui/material';
21 import Button from '@mui/material/Button';
22 import Dialog from '@mui/material/Dialog';
23 import DialogActions from '@mui/material/DialogActions';
24 import DialogContent from '@mui/material/DialogContent';
25 import DialogContentText from '@mui/material/DialogContentText';
26 import DialogTitle from '@mui/material/DialogTitle';
27
28 import { connect, Connect } from '../../../../framework/src/flux/connect';
29
30 import { FaultLog } from '../models/unmFault';
31
32 export enum ViewAlarmDetailsDialogMode {
33   None = 'none',
34   ViewAlarmDetails = 'viewDetails',
35 }
36
37 const mapDispatch = () => ({
38 });
39
40 type DialogSettings = {
41   dialogTitle: string;
42   dialogDescription: string;
43   applyButtonText: string;
44   cancelButtonText: string;
45   enableMountIdEditor: boolean;
46   enableUsernameEditor: boolean;
47   enableExtendedEditor: boolean;
48 };
49
50 const settings: { [key: string]: DialogSettings } = {
51   [ViewAlarmDetailsDialogMode.None]: {
52     dialogTitle: '',
53     dialogDescription: '',
54     applyButtonText: '',
55     cancelButtonText: '',
56     enableMountIdEditor: false,
57     enableUsernameEditor: false,
58     enableExtendedEditor: false,
59   },
60   [ViewAlarmDetailsDialogMode.ViewAlarmDetails]: {
61     dialogTitle: 'Alarm Details',
62     dialogDescription: 'Details',
63     applyButtonText: 'Save',
64     cancelButtonText: 'Cancel',
65     enableMountIdEditor: false,
66     enableUsernameEditor: true,
67     enableExtendedEditor: false,
68   },
69 };
70
71 type ViewAlarmDetailsDialogComponentProps = Connect<undefined, typeof mapDispatch> & {
72   initialAlarmDetails: FaultLog;
73   mode: ViewAlarmDetailsDialogMode;
74   onClose: () => void;
75 };
76
77 type ViewAlarmDetailsDialogComponentState = FaultLog & {
78 };
79
80 class UnmFaultManagementAlarmDetailsComponent extends React.Component<ViewAlarmDetailsDialogComponentProps, ViewAlarmDetailsDialogComponentState> {
81   constructor(props: ViewAlarmDetailsDialogComponentProps) {
82     super(props);
83     this.state = {
84       nodeId: this.props.initialAlarmDetails.nodeId,
85       counter: this.props.initialAlarmDetails.counter,
86       timestamp: this.props.initialAlarmDetails.timestamp,
87       objectId: this.props.initialAlarmDetails.objectId,
88       severity: this.props.initialAlarmDetails.severity,
89       problem: this.props.initialAlarmDetails.problem,
90       sourceType: this.props.initialAlarmDetails.sourceType,
91     };
92   }
93
94   render(): JSX.Element {
95     const setting = settings[this.props.mode];
96     return (
97       <Dialog open={this.props.mode !== ViewAlarmDetailsDialogMode.None}>
98         <DialogTitle id="form-dialog-title" aria-label={`${setting.dialogTitle.replace(/ /g, '-').toLowerCase()}-dialog`}>{setting.dialogTitle}</DialogTitle>
99         <DialogContent>
100           <DialogContentText>
101             {setting.dialogDescription}
102           </DialogContentText>
103           <TextField variant="standard" disabled spellCheck={false} autoFocus margin="dense"
104             id="nodeId" label="Node ID" aria-label="nodeId" type="text" fullWidth value={this.state.nodeId} />
105
106           <TextField variant="standard" disabled spellCheck={false} margin="dense"
107             id="objectId" label="Object Id" aria-label="objectId" type="text" fullWidth value={this.state.objectId} />
108
109           <TextField variant="standard" disabled spellCheck={false} margin="dense"
110             id="timestamp" label="Timestamp" aria-label="timestamp" type="text" fullWidth value={this.state.timestamp} />
111
112           <TextField variant="standard" disabled spellCheck={false} autoFocus margin="dense"
113             id="severity" label="Severity" aria-label="severity" type="text" fullWidth value={this.state.severity} />
114
115           <TextField variant="standard" disabled spellCheck={false} margin="dense"
116             id="problem" label="Problem" aria-label="problem" type="text" fullWidth value={this.state.problem} />
117
118           <TextField variant="standard" disabled spellCheck={false} margin="dense"
119             id="sourceType" label="Source Type" aria-label="sourceType" type="text" fullWidth value={this.state.sourceType} />
120
121           <TextField variant="standard" spellCheck={false} margin="dense"
122             id="comment" label="Comment" aria-label="comment" type="text" fullWidth value={this.state.comment}
123             onChange={(event) => { this.setState({ comment: event.target.value }); }} />
124
125         </DialogContent>
126         <DialogActions>
127           <Button aria-label="dialog-confirm-button" onClick={(event) => {
128             event.preventDefault();
129             event.stopPropagation();
130           }} color="inherit" > {setting.applyButtonText} </Button>
131           <Button aria-label="dialog-cancel-button" onClick={(event) => {
132             this.onCancel();
133             event.preventDefault();
134             event.stopPropagation();
135           }} color="secondary"> {setting.cancelButtonText} </Button>
136         </DialogActions>
137       </Dialog>
138     );
139   }
140
141   public componentDidMount() {
142   }
143
144
145   private onApply = () => {
146     if (this.props.onClose) this.props.onClose();
147
148     switch (this.props.mode) {
149       case ViewAlarmDetailsDialogMode.ViewAlarmDetails:
150         break;
151     }
152   };
153
154   private onCancel = () => {
155     if (this.props.onClose) this.props.onClose();
156   };
157
158   static getDerivedStateFromProps(props: ViewAlarmDetailsDialogComponentProps, state: ViewAlarmDetailsDialogComponentState & { initialAlarmDetails: FaultLog }): ViewAlarmDetailsDialogComponentState & { initialAlarmDetails: FaultLog } {
159     let returnState = state;
160     if (props.initialAlarmDetails !== state.initialAlarmDetails) {
161       returnState = {
162         ...state,
163         ...props.initialAlarmDetails,
164         initialAlarmDetails: props.initialAlarmDetails,
165       };
166     }
167     return returnState;
168   }
169 }
170
171 export const ViewAlarmDetailsDialog = connect(undefined, mapDispatch)(UnmFaultManagementAlarmDetailsComponent);
172 export default ViewAlarmDetailsDialog;