import React, { Component } from 'react' import { Button, Input, Header, Dropdown } from 'semantic-ui-react' import CreateFilterNoduleForm from './CreateFilterNoduleForm' import './CreateNodule.css' import Tables from '../../Collections/Tables' import CreateNoduleController from '../../Controllers/CreateNoduleController' import CreateJoinNoduleForm from './CreateJoinNoduleForm' import CreateTransformNoduleForm from './CreateTransformNoduleForm' import TableSelect from './TableSelect' class CreateNodule extends Component { constructor () { super() this.state = { noduleType: '', tablesToImportByLabel: [] } this.tables = new Tables() this.controller = new CreateNoduleController() this.filterNoduleForm = React.createRef() this.joinNoduleForm = React.createRef() this.transformNoduleForm = React.createRef() this.tableSelect = React.createRef() this.noduleLabelInput = React.createRef() document.addEventListener('updateTables', this.updateTableList) } handleChange = (e, value) => { this.setState({ noduleType: value.value }) } handleSubmit = () => { const { noduleType } = this.state const noduleLabel = this.noduleLabelInput.current.inputRef.current.value const selectedTableLabels = this.tableSelect.current.getSelectedTableLabels() if (noduleType === 'filter') { const filterProperties = this.filterNoduleForm.current.getFilterProperties() this.controller.addNewFilterNodule({ label: noduleLabel, tablesToImportByLabel: selectedTableLabels, filterType: filterProperties.filterType, filterParams: filterProperties.filterParams }) } else if (noduleType === 'join') { const joinProperties = this.joinNoduleForm.current.getJoinProperties() this.controller.addNewJoinNodule({ label: noduleLabel, tablesToImportByLabel: selectedTableLabels, joinBy: joinProperties }) } else if (noduleType === 'transform') { const structureProperties = this.transformNoduleForm.current.getStructureProperties() this.controller.addNewJoinNodule({ label: noduleLabel, tablesToImportByLabel: selectedTableLabels, structure: structureProperties }) } } updateTableList = () => { this.setState({tables: this.tables.getCollectionProps()}) } renderNoduleForm = () => { const { noduleType, tablesToImportByLabel } = this.state if (noduleType === 'filter') return else if (noduleType === 'join') return else if (noduleType === 'transform') return else return '' } render = () => { return (
Create Nodule

{ this.renderNoduleForm() }
) } } export default CreateNodule