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 * as React from 'react';
20 import Button from '@material-ui/core/Button';
21 import TextField from '@material-ui/core/TextField';
22 import Dialog from '@material-ui/core/Dialog';
23 import DialogActions from '@material-ui/core/DialogActions';
24 import DialogContent from '@material-ui/core/DialogContent';
25 import DialogContentText from '@material-ui/core/DialogContentText';
26 import DialogTitle from '@material-ui/core/DialogTitle';
28 import { IDispatcher, connect, Connect } from '../../../../framework/src/flux/connect';
30 import { addAvaliableMediatorServerAsyncActionCreator, removeAvaliableMediatorServerAsyncActionCreator, updateAvaliableMediatorServerAsyncActionCreator } from '../actions/avaliableMediatorServersActions';
31 import { MediatorServer } from '../models/mediatorServer';
33 export enum EditMediatorServerDialogMode {
35 AddMediatorServer = "addMediatorServer",
36 EditMediatorServer = "editMediatorServer",
37 RemoveMediatorServer = "removeMediatorServer",
40 const mapDispatch = (dispatcher: IDispatcher) => ({
41 addMediatorServer: (element: MediatorServer) => {
42 dispatcher.dispatch(addAvaliableMediatorServerAsyncActionCreator(element));
44 updateMediatorServer: (element: MediatorServer) => {
45 dispatcher.dispatch(updateAvaliableMediatorServerAsyncActionCreator(element));
47 removeMediatorServer: (element: MediatorServer) => {
48 dispatcher.dispatch(removeAvaliableMediatorServerAsyncActionCreator(element));
52 type DialogSettings = {
54 dialogDescription: string;
55 applyButtonText: string;
56 cancelButtonText: string;
60 const settings: { [key: string]: DialogSettings } = {
61 [EditMediatorServerDialogMode.None]: {
63 dialogDescription: "",
68 [EditMediatorServerDialogMode.AddMediatorServer]: {
69 dialogTitle: "Add Mediator Server",
70 dialogDescription: "",
71 applyButtonText: "Add",
72 cancelButtonText: "Cancel",
75 [EditMediatorServerDialogMode.EditMediatorServer]: {
76 dialogTitle: "Edit Mediator Server",
77 dialogDescription: "",
78 applyButtonText: "Update",
79 cancelButtonText: "Cancel",
82 [EditMediatorServerDialogMode.RemoveMediatorServer]: {
83 dialogTitle: "Remove Mediator Server",
84 dialogDescription: "",
85 applyButtonText: "Remove",
86 cancelButtonText: "Cancel",
91 type EditMediatorServerDialogComponentProps = Connect<undefined, typeof mapDispatch> & {
92 mode: EditMediatorServerDialogMode;
93 mediatorServer: MediatorServer;
97 type EditMediatorServerDialogComponentState = MediatorServer;
99 class EditMediatorServerDialogComponent extends React.Component<EditMediatorServerDialogComponentProps, EditMediatorServerDialogComponentState> {
100 constructor (props: EditMediatorServerDialogComponentProps) {
104 ...this.props.mediatorServer
108 render(): JSX.Element {
109 const setting = settings[this.props.mode];
111 <Dialog open={this.props.mode !== EditMediatorServerDialogMode.None}>
112 <DialogTitle id="form-dialog-title">{setting.dialogTitle}</DialogTitle>
115 {setting.dialogDescription}
117 {/* <TextField disabled spellCheck={false} autoFocus margin="dense" id="id" label="Id" type="text" fullWidth value={ this.state._id } onChange={(event)=>{ this.setState({_id: event.target.value}); } } /> */}
118 <TextField disabled={setting.readonly} spellCheck={false} margin="dense" id="name" label="Name" type="text" fullWidth value={this.state.name} onChange={(event) => { this.setState({ name: event.target.value }); }} />
119 <TextField disabled={setting.readonly} spellCheck={false} margin="dense" id="url" label="Url" type="text" fullWidth value={this.state.url} onChange={(event) => { this.setState({ url: event.target.value }); }} />
122 <Button onClick={(event) => {
125 name: this.state.name,
128 event.preventDefault();
129 event.stopPropagation();
130 }} > {setting.applyButtonText} </Button>
131 <Button onClick={(event) => {
133 event.preventDefault();
134 event.stopPropagation();
135 }} color="secondary"> {setting.cancelButtonText} </Button>
141 private onApply = (element: MediatorServer) => {
142 this.props.onClose && this.props.onClose();
143 switch (this.props.mode) {
144 case EditMediatorServerDialogMode.AddMediatorServer:
145 element && this.props.addMediatorServer(element);
147 case EditMediatorServerDialogMode.EditMediatorServer:
148 element && this.props.updateMediatorServer(element);
150 case EditMediatorServerDialogMode.RemoveMediatorServer:
151 element && this.props.removeMediatorServer(element);
156 private onCancel = () => {
157 this.props.onClose && this.props.onClose();
160 static getDerivedStateFromProps(props: EditMediatorServerDialogComponentProps, state: EditMediatorServerDialogComponentState & { _initialMediatorServer: MediatorServer }): EditMediatorServerDialogComponentState & { _initialMediatorServer: MediatorServer } {
161 if (props.mediatorServer !== state._initialMediatorServer) {
164 ...props.mediatorServer,
165 _initialMediatorServer: props.mediatorServer,
172 export const EditMediatorServerDialog = connect(undefined, mapDispatch)(EditMediatorServerDialogComponent);
173 export default EditMediatorServerDialog;