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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
18 import React from 'react';
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';
28 import { connect, Connect } from '../../../../framework/src/flux/connect';
30 import { FaultLog } from '../models/unmFault';
32 export enum ViewAlarmDetailsDialogMode {
34 ViewAlarmDetails = 'viewDetails',
37 const mapDispatch = () => ({
40 type DialogSettings = {
42 dialogDescription: string;
43 applyButtonText: string;
44 cancelButtonText: string;
45 enableMountIdEditor: boolean;
46 enableUsernameEditor: boolean;
47 enableExtendedEditor: boolean;
50 const settings: { [key: string]: DialogSettings } = {
51 [ViewAlarmDetailsDialogMode.None]: {
53 dialogDescription: '',
56 enableMountIdEditor: false,
57 enableUsernameEditor: false,
58 enableExtendedEditor: false,
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,
71 type ViewAlarmDetailsDialogComponentProps = Connect<undefined, typeof mapDispatch> & {
72 initialAlarmDetails: FaultLog;
73 mode: ViewAlarmDetailsDialogMode;
77 type ViewAlarmDetailsDialogComponentState = FaultLog & {
80 class UnmFaultManagementAlarmDetailsComponent extends React.Component<ViewAlarmDetailsDialogComponentProps, ViewAlarmDetailsDialogComponentState> {
81 constructor(props: ViewAlarmDetailsDialogComponentProps) {
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,
94 render(): JSX.Element {
95 const setting = settings[this.props.mode];
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>
101 {setting.dialogDescription}
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} />
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} />
109 <TextField variant="standard" disabled spellCheck={false} margin="dense"
110 id="timestamp" label="Timestamp" aria-label="timestamp" type="text" fullWidth value={this.state.timestamp} />
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} />
115 <TextField variant="standard" disabled spellCheck={false} margin="dense"
116 id="problem" label="Problem" aria-label="problem" type="text" fullWidth value={this.state.problem} />
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} />
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 }); }} />
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) => {
133 event.preventDefault();
134 event.stopPropagation();
135 }} color="secondary"> {setting.cancelButtonText} </Button>
141 public componentDidMount() {
145 private onApply = () => {
146 if (this.props.onClose) this.props.onClose();
148 switch (this.props.mode) {
149 case ViewAlarmDetailsDialogMode.ViewAlarmDetails:
154 private onCancel = () => {
155 if (this.props.onClose) this.props.onClose();
158 static getDerivedStateFromProps(props: ViewAlarmDetailsDialogComponentProps, state: ViewAlarmDetailsDialogComponentState & { initialAlarmDetails: FaultLog }): ViewAlarmDetailsDialogComponentState & { initialAlarmDetails: FaultLog } {
159 let returnState = state;
160 if (props.initialAlarmDetails !== state.initialAlarmDetails) {
163 ...props.initialAlarmDetails,
164 initialAlarmDetails: props.initialAlarmDetails,
171 export const ViewAlarmDetailsDialog = connect(undefined, mapDispatch)(UnmFaultManagementAlarmDetailsComponent);
172 export default ViewAlarmDetailsDialog;