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';
19 import { Theme, Tooltip } from '@mui/material';
21 import { WithStyles } from '@mui/styles';
22 import withStyles from '@mui/styles/withStyles';
23 import createStyles from '@mui/styles/createStyles';
25 import AddIcon from '@mui/icons-material/Add';
26 import IconButton from '@mui/material/IconButton';
27 import EditIcon from '@mui/icons-material/Edit';
28 import DeleteIcon from '@mui/icons-material/Delete';
29 import Refresh from '@mui/icons-material/Refresh';
31 import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore';
32 import { connect, IDispatcher, Connect } from '../../../../framework/src/flux/connect';
33 import MaterialTable, { MaterialTableCtorType, ColumnType } from '../../../../framework/src/components/material-table';
35 import { createAvaliableMediatorServersProperties, createAvaliableMediatorServersActions } from '../handlers/avaliableMediatorServersHandler';
37 import { MediatorServer } from '../models/mediatorServer';
38 import EditMediatorServerDialog, { EditMediatorServerDialogMode } from '../components/editMediatorServerDialog';
39 import RefreshMediatorDialog, { RefreshMediatorDialogMode } from '../components/refreshMediatorDialog';
40 import { NavigateToApplication } from '../../../../framework/src/actions/navigationActions';
42 const MediatorServersTable = MaterialTable as MaterialTableCtorType<MediatorServer>;
44 const styles = (theme: Theme) => createStyles({
51 marginLeft: theme.spacing(1),
52 marginRight: theme.spacing(1),
57 const mapProps = (state: IApplicationStoreState) => ({
58 mediatorServersProperties: createAvaliableMediatorServersProperties(state),
61 const mapDispatch = (dispatcher: IDispatcher) => ({
62 mediatorServersActions: createAvaliableMediatorServersActions(dispatcher.dispatch),
63 selectMediatorServer: (mediatorServerId: string) => mediatorServerId && dispatcher.dispatch(new NavigateToApplication("mediator", mediatorServerId)),
66 const emptyMediatorServer: MediatorServer = {
72 type MediatorServerSelectionComponentProps = Connect<typeof mapProps, typeof mapDispatch> & WithStyles<typeof styles>;
74 type MediatorServerSelectionComponentState = {
75 mediatorServerToEdit: MediatorServer,
76 mediatorServerEditorMode: EditMediatorServerDialogMode,
77 refreshMediatorEditorMode: RefreshMediatorDialogMode
80 let initialSorted = false;
82 class MediatorServerSelectionComponent extends React.Component<MediatorServerSelectionComponentProps, MediatorServerSelectionComponentState> {
84 constructor(props: MediatorServerSelectionComponentProps) {
88 mediatorServerEditorMode: EditMediatorServerDialogMode.None,
89 mediatorServerToEdit: emptyMediatorServer,
90 refreshMediatorEditorMode: RefreshMediatorDialogMode.None
95 const { classes } = this.props;
96 const refreshMediatorAction = {
97 icon: Refresh, tooltip: 'Refresh Mediator Server Table', ariaLabel:'refresh', onClick: () => {
99 refreshMediatorEditorMode: RefreshMediatorDialogMode.RefreshMediatorTable
104 const addMediatorServerActionButton = {
105 icon: AddIcon, tooltip: 'Add', ariaLabel:'add-element', onClick: () => {
107 mediatorServerEditorMode: EditMediatorServerDialogMode.AddMediatorServer,
108 mediatorServerToEdit: emptyMediatorServer,
113 <MediatorServersTable stickyHeader title={"Mediator"} tableId={null} customActionButtons={[refreshMediatorAction, addMediatorServerActionButton]} idProperty={"id"}
114 {...this.props.mediatorServersActions} {...this.props.mediatorServersProperties} columns={[
115 { property: "name", title: "Name", type: ColumnType.text },
116 { property: "url", title: "Url", type: ColumnType.text },
118 property: "actions", title: "Actions", type: ColumnType.custom, customControl: ({ rowData }) => (
119 <div className={classes.spacer}>
120 <Tooltip disableInteractive title={"Edit"} ><IconButton
121 className={classes.button}
122 onClick={event => { this.onEditMediatorServer(event, rowData); }}
123 size="large"><EditIcon /></IconButton></Tooltip>
124 <Tooltip disableInteractive title={"Remove"} ><IconButton
125 className={classes.button}
126 onClick={event => { this.onRemoveMediatorServer(event, rowData); }}
127 size="large"><DeleteIcon /></IconButton></Tooltip>
131 ]} onHandleClick={this.onSelectMediatorServer} />
132 <EditMediatorServerDialog
133 mediatorServer={this.state.mediatorServerToEdit}
134 mode={this.state.mediatorServerEditorMode}
135 onClose={this.onCloseEditMediatorServerDialog} />
136 <RefreshMediatorDialog
137 mode={this.state.refreshMediatorEditorMode}
138 onClose={this.onCloseRefreshMediatorDialog}
143 public componentDidMount() {
145 if (!initialSorted) {
146 initialSorted = true;
147 this.props.mediatorServersActions.onHandleRequestSort("name");
149 this.props.mediatorServersActions.onRefresh();
153 private onSelectMediatorServer = (event: React.MouseEvent<HTMLElement>, server: MediatorServer) => {
154 event.preventDefault();
155 event.stopPropagation();
156 this.props.selectMediatorServer(server && server.id);
160 private onEditMediatorServer = (event: React.MouseEvent<HTMLElement>, server: MediatorServer) => {
161 event.preventDefault();
162 event.stopPropagation();
164 mediatorServerEditorMode: EditMediatorServerDialogMode.EditMediatorServer,
165 mediatorServerToEdit: server,
169 private onRemoveMediatorServer = (event: React.MouseEvent<HTMLElement>, server: MediatorServer) => {
170 event.preventDefault();
171 event.stopPropagation();
173 mediatorServerEditorMode: EditMediatorServerDialogMode.RemoveMediatorServer,
174 mediatorServerToEdit: server,
178 private onCloseEditMediatorServerDialog = () => {
180 mediatorServerEditorMode: EditMediatorServerDialogMode.None,
181 mediatorServerToEdit: emptyMediatorServer,
184 private onCloseRefreshMediatorDialog = () => {
186 refreshMediatorEditorMode: RefreshMediatorDialogMode.None
192 export const MediatorServerSelection = withStyles(styles)(connect(mapProps, mapDispatch)(MediatorServerSelectionComponent));
193 export default MediatorServerSelection;