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 { DataSourceTypes } from './DataSourceTypes'; class DataSourceManager extends React.Component { constructor(props) { super(props); this.state = { currentUser: authenticationService.currentUserValue, showModal: false, appId: props.appId, options: { host: '', port: '5432', database: 'production', username: 'root', password: 'root' } }; } componentDidMount() { console.log('props',this.props); this.state = { appId: this.props.appId } } selectDataSource = (source) => { this.setState({ selectedDataSource: source }); } optionchanged = (option, value) => { this.setState( { options: { ...this.state.options, [option]: value } } ); } createDataSource = () => { let _self = this; const { appId, options, selectedDataSource } = this.state; const name = selectedDataSource.name; 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 (
{!showModal && } Add new datasource {!selectedDataSource &&
{DataSourceTypes.map((dataSource) => (
this.selectDataSource(dataSource)}>




{dataSource.name}
))}
} {selectedDataSource &&
{selectedDataSource.kind === 'postgresql' &&
this.optionchanged('host', e.target.value)} value={options.host} />
this.optionchanged('port', e.target.value)} value={options.port} />
this.optionchanged('database', e.target.value)} value={options.database} />
this.optionchanged('username', e.target.value)} value={options.username} />
this.optionchanged('password', e.target.value)} value={options.password} />
}
}
) } } export { DataSourceManager };