Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / eventLogApp / src / components / refreshEventLogDialog.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 { eventLogReloadAction } from '../handlers/eventLogHandler';
28 import { IDispatcher, connect, Connect } from '../../../../framework/src/flux/connect';
29
30 import { EventLogType } from '../models/eventLogType';
31
32 export enum RefreshEventLogDialogMode {
33   None = "none",
34   RefreshEventLogTable = "RefreshEventLogTable",
35 }
36
37 const mapDispatch = (dispatcher: IDispatcher) => ({
38   refreshEventLog: () => dispatcher.dispatch(eventLogReloadAction)
39 });
40
41 type DialogSettings = {
42   dialogTitle: string,
43   dialogDescription: string,
44   applyButtonText: string,
45   cancelButtonText: string,
46   enableMountIdEditor: boolean,
47   enableUsernameEditor: boolean,
48   enableExtendedEditor: boolean,
49 }
50
51 const settings: { [key: string]: DialogSettings } = {
52   [RefreshEventLogDialogMode.None]: {
53     dialogTitle: "",
54     dialogDescription: "",
55     applyButtonText: "",
56     cancelButtonText: "",
57     enableMountIdEditor: false,
58     enableUsernameEditor: false,
59     enableExtendedEditor: false,
60   },
61   [RefreshEventLogDialogMode.RefreshEventLogTable]: {
62     dialogTitle: "Do you want to refresh the Event Log?",
63     dialogDescription: "",
64     applyButtonText: "Yes",
65     cancelButtonText: "Cancel",
66     enableMountIdEditor: true,
67     enableUsernameEditor: true,
68     enableExtendedEditor: true,
69   }
70 }
71
72 type RefreshEventLogDialogComponentProps = Connect<undefined, typeof mapDispatch> & {
73   mode: RefreshEventLogDialogMode;
74   onClose: () => void;
75 };
76
77 type RefreshEventLogDialogComponentState = EventLogType & { isNameValid: boolean, isHostSet: boolean };
78
79 class RefreshEventLogDialogComponent extends React.Component<RefreshEventLogDialogComponentProps, RefreshEventLogDialogComponentState> {
80   constructor(props: RefreshEventLogDialogComponentProps) {
81     super(props);
82   }
83
84   render(): JSX.Element {
85     const setting = settings[this.props.mode];
86     return (
87       <Dialog open={this.props.mode !== RefreshEventLogDialogMode.None}>
88         <DialogTitle id="form-dialog-title" aria-label={`${setting.dialogTitle.replace(/ /g, "-").toLowerCase()}-dialog`}>{setting.dialogTitle}</DialogTitle>
89         <DialogContent>
90           <DialogContentText>
91             {setting.dialogDescription}
92           </DialogContentText>
93         </DialogContent>
94         <DialogActions>
95           <Button aria-label="dialog-confirm-button" onClick={(event) => {
96             this.onRefresh();
97           }} color="inherit" > {setting.applyButtonText} </Button>
98           <Button aria-label="dialog-cancel-button" onClick={(event) => {
99             this.onCancel();
100           }} color="secondary"> {setting.cancelButtonText} </Button>
101         </DialogActions>
102       </Dialog>
103     );
104   }
105
106   private onRefresh = () => {
107     this.props.refreshEventLog();
108     this.props.onClose();
109   };
110
111   private onCancel = () => {
112     this.props.onClose();
113   }
114 }
115
116 export const RefreshEventLogDialog = connect(undefined, mapDispatch)(RefreshEventLogDialogComponent);
117 export default RefreshEventLogDialog;