import React from 'react'; import { datasourceService, authenticationService } from '@/_services'; import Modal from 'react-bootstrap/Modal'; import Button from 'react-bootstrap/Button'; import { ToastContainer, toast } from 'react-toastify'; import 'react-toastify/dist/ReactToastify.css'; import { dataBaseSources, apiSources, DataSourceTypes } from './DataSourceTypes'; import { Elasticsearch } from './Elasticsearch'; import { Redis } from './Redis'; import { Postgresql } from './Postgresql'; import { Mysql } from './Mysql'; const defaultOptions = { 'postgresql': { host: 'localhost', port: 5432, username: '', password: '' }, 'mysql': { host: 'localhost', port: 3306, username: '', password: '' }, 'redis': { host: 'localhost', port: 6379, username: '', password: '' }, 'elasticsearch': { host: 'localhost', port: 9000, username: '', password: '' } } class DataSourceManager extends React.Component { constructor(props) { super(props); this.state = { currentUser: authenticationService.currentUserValue, showModal: false, appId: props.appId, options: { } }; } componentDidMount() { console.log('props',this.props); this.setState({ appId: this.props.appId }) } selectDataSource = (source) => { this.setState({ selectedDataSource: source, options: defaultOptions[source.kind], name: source.kind }); } onNameChanged = (newName) => { this.setState({ name: newName }) } optionchanged = (option, value) => { this.setState( { options: { ...this.state.options, [option]: value } } ); } hideModal = () => { this.setState({ showModal: false, selectedDataSource: null }); } createDataSource = () => { let _self = this; const { appId, options, selectedDataSource, name } = this.state; const kind = selectedDataSource.kind; datasourceService.create(appId, name, kind, options).then((data) => { this.setState( { showModal: false } ); toast.success('Datasource Added', { hideProgressBar: true, position: "top-center", }); this.props.dataSourcesChanged(); }); } render() { const { showModal, selectedDataSource, options } = this.state; return (