Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / faultApp / src / components / refreshAlarmLogDialog.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 Button from '@mui/material/Button';
21 import Dialog from '@mui/material/Dialog';
22 import DialogActions from '@mui/material/DialogActions';
23 import DialogContent from '@mui/material/DialogContent';
24 import DialogContentText from '@mui/material/DialogContentText';
25 import DialogTitle from '@mui/material/DialogTitle';
26
27 import { connect, Connect, IDispatcher } from '../../../../framework/src/flux/connect';
28 import { alarmLogEntriesReloadAction } from '../handlers/alarmLogEntriesHandler';
29 import { Fault } from '../models/fault';
30
31 export enum RefreshAlarmLogDialogMode {
32   None = 'none',
33   RefreshAlarmLogTable = 'RefreshAlarmLogTable',
34 }
35
36 const mapDispatch = (dispatcher: IDispatcher) => ({
37   refreshAlarmLog: () => dispatcher.dispatch(alarmLogEntriesReloadAction),
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   [RefreshAlarmLogDialogMode.None]: {
52     dialogTitle: '',
53     dialogDescription: '',
54     applyButtonText: '',
55     cancelButtonText: '',
56     enableMountIdEditor: false,
57     enableUsernameEditor: false,
58     enableExtendedEditor: false,
59   },
60   [RefreshAlarmLogDialogMode.RefreshAlarmLogTable]: {
61     dialogTitle: 'Do you want to refresh the Alarm Log?',
62     dialogDescription: '',
63     applyButtonText: 'Yes',
64     cancelButtonText: 'Cancel',
65     enableMountIdEditor: true,
66     enableUsernameEditor: true,
67     enableExtendedEditor: true,
68   },
69 };
70
71 type RefreshAlarmLogDialogComponentProps = Connect<undefined, typeof mapDispatch> & {
72   mode: RefreshAlarmLogDialogMode;
73   onClose: () => void;
74 };
75
76 type RefreshAlarmLogDialogComponentState = Fault & { isNameValid: boolean; isHostSet: boolean };
77
78 class RefreshAlarmLogDialogComponent extends React.Component<RefreshAlarmLogDialogComponentProps, RefreshAlarmLogDialogComponentState> {
79   render(): JSX.Element {
80     const setting = settings[this.props.mode];
81     return (
82       <Dialog open={this.props.mode !== RefreshAlarmLogDialogMode.None}>
83         <DialogTitle id="form-dialog-title" aria-label={`${setting.dialogTitle.replace(/ /g, '-').toLowerCase()}-dialog`}>{setting.dialogTitle}</DialogTitle>
84         <DialogContent>
85           <DialogContentText>
86             {setting.dialogDescription}
87           </DialogContentText>
88         </DialogContent>
89         <DialogActions>
90           <Button aria-label="dialog-confirm-button" onClick={() => {
91             this.onRefresh();
92           }} color="inherit" > {setting.applyButtonText} </Button>
93           <Button aria-label="dialog-cancel-button" onClick={() => {
94             this.onCancel();
95           }} color="secondary"> {setting.cancelButtonText} </Button>
96         </DialogActions>
97       </Dialog>
98     );
99   }
100
101   private onRefresh = () => {
102     this.props.refreshAlarmLog();
103     this.props.onClose();
104   };
105
106   private onCancel = () => {
107     this.props.onClose();
108   };
109 }
110
111 export const RefreshAlarmLogDialog = connect(undefined, mapDispatch)(RefreshAlarmLogDialogComponent);
112 export default RefreshAlarmLogDialog;