diff --git a/src/Collections/Nodules.js b/src/Collections/Nodules.js
index 24736bb..3c1a92e 100644
--- a/src/Collections/Nodules.js
+++ b/src/Collections/Nodules.js
@@ -27,14 +27,12 @@ class Nodules {
removeById = id => {
const indexToRemove = this.collection.findIndex(n => n.id === id)
- if (this.collection.length === 1 && indexToRemove > -1) {
- this.collection = []
- }
- else {
- const modifiedCollection = this.collection.splice(indexToRemove, 1)
- this.collection = modifiedCollection
- }
+ if (indexToRemove > -1) this.collection.splice(indexToRemove, 1)
}
+
+ getCollectionProps = () => this.collection.map(nodule => nodule.getProperties())
+
+ getTableByLabel = label => this.collection.find(n => label === n.label)
}
export default Nodules
\ No newline at end of file
diff --git a/src/Controllers/CreateNoduleController.js b/src/Controllers/CreateNoduleController.js
index d9373a4..29317cb 100644
--- a/src/Controllers/CreateNoduleController.js
+++ b/src/Controllers/CreateNoduleController.js
@@ -20,12 +20,11 @@ class CreateNoduleController {
filterParams,
tables
})
- console.log(this.nodules)
document.dispatchEvent(this.updatedNodulesEvent)
}
deleteNodule = id => {
- this.nodules.removeTableById(id)
+ this.nodules.removeById(id)
document.dispatchEvent(this.updatedNodulesEvent)
}
}
diff --git a/src/Controllers/NoduleListController.js b/src/Controllers/NoduleListController.js
new file mode 100644
index 0000000..f0c5cca
--- /dev/null
+++ b/src/Controllers/NoduleListController.js
@@ -0,0 +1,15 @@
+import Nodules from '../Collections/Nodules'
+
+class NoduleistController {
+ constructor() {
+ this.nodules = new Nodules()
+ this.updatedNodulesEvent = new Event('updateNodules')
+ }
+
+ deleteTable = id => {
+ this.nodules.removeById(id)
+ document.dispatchEvent(this.updatedNodulesEvent)
+ }
+}
+
+export default NoduleistController
\ No newline at end of file
diff --git a/src/Controllers/TableListController.js b/src/Controllers/TableListController.js
index a678cdb..fc9bb29 100644
--- a/src/Controllers/TableListController.js
+++ b/src/Controllers/TableListController.js
@@ -7,7 +7,7 @@ class TableListController {
}
deleteTable = id => {
- this.tables.removeTableById(id)
+ this.tables.removeById(id)
document.dispatchEvent(this.updatedTablesEvent)
}
}
diff --git a/src/index.js b/src/index.js
index cfb65a2..a020ca2 100644
--- a/src/index.js
+++ b/src/index.js
@@ -4,9 +4,7 @@ import App from './views/App'
import * as serviceWorker from './serviceWorker'
ReactDOM.render(
-
-
- ,
+ ,
document.getElementById('root')
)
diff --git a/src/views/App.js b/src/views/App.js
index b4d6f74..0ca63b9 100644
--- a/src/views/App.js
+++ b/src/views/App.js
@@ -4,6 +4,7 @@ import 'semantic-ui-css/semantic.min.css'
import CreateTableForm from './CreateTable/CreateTableForm'
import TableList from './TableList/TableList'
import CreateNodule from './CreateNodule/CreateNodule'
+import NoduleList from './NoduleList/NoduleList'
class App extends Component {
render = () => {
@@ -12,6 +13,7 @@ class App extends Component {
+
)
}
diff --git a/src/views/CreateNodule/CreateFilterNoduleForm.js b/src/views/CreateNodule/CreateFilterNoduleForm.js
index 38c4b8d..b0e5cea 100644
--- a/src/views/CreateNodule/CreateFilterNoduleForm.js
+++ b/src/views/CreateNodule/CreateFilterNoduleForm.js
@@ -1,44 +1,48 @@
import React, { Component } from 'react'
-import { Input, Dropdown, Grid } from 'semantic-ui-react'
+import { Input, Dropdown, Grid, Button, Icon, List } from 'semantic-ui-react'
import './CreateNodule.css'
class CreateFilterNoduleForm extends Component {
constructor () {
super()
- this.state = { filterType: '' }
+ this.state = {
+ filterType: '',
+ filterParams: {}
+ }
- this.keyInput1 = React.createRef()
- this.keyInput2 = React.createRef()
- this.keyInput3 = React.createRef()
- this.valueInput1 = React.createRef()
- this.valueInput2 = React.createRef()
- this.valueInput3 = React.createRef()
+ this.keyInput = React.createRef()
+ this.valueInput = React.createRef()
document.addEventListener('updateTables', this.updateTableList)
}
+ addKeyValueInput = () => {
+ let filterParams = this.state.filterParams || {}
+
+ if (this.keyInput.current.inputRef.current.value)
+ filterParams[this.keyInput.current.inputRef.current.value] = this.valueInput.current.inputRef.current.value
+
+ this.setState({ filterParams: filterParams })
+ }
+
handleChange = (e, value) => {
this.setState({ filterType: value.value })
}
- getFilterProperties = () => {
- let filterParams = {}
+ renderFilterParams = () => {
+ const { filterParams } = this.state
- if (this.keyInput1.current.inputRef.current.value)
- filterParams[this.keyInput1.current.inputRef.current.value] = this.valueInput1.current.inputRef.current.value
-
- if (this.keyInput2.current.inputRef.current.value)
- filterParams[this.keyInput2.current.inputRef.current.value] = this.valueInput2.current.inputRef.current.value
-
- if (this.keyInput3.current.inputRef.current.value)
- filterParams[this.keyInput3.current.inputRef.current.value] = this.valueInput3.current.inputRef.current.value
-
- return {
- filterType: this.state.filterType,
- filterParams
+ let filterKeyElements = []
+ let filterValueElements = []
+ for (let key in filterParams) {
+ filterKeyElements.push({key})
+ filterValueElements.push({filterParams[key]})
}
+
+ return { filterKeyElements, filterValueElements }
}
render = () => {
+ const filterParamElements = this.renderFilterParams()
return (
-
-
-
+
+ { filterParamElements.filterKeyElements }
+
+
-
-
-
+
+ { filterParamElements.filterValueElements }
+
+
+
diff --git a/src/views/CreateNodule/CreateNodule.js b/src/views/CreateNodule/CreateNodule.js
index 74c468a..44294d1 100644
--- a/src/views/CreateNodule/CreateNodule.js
+++ b/src/views/CreateNodule/CreateNodule.js
@@ -1,5 +1,5 @@
import React, { Component } from 'react'
-import { Button, Input, Header, Dropdown, Table } from 'semantic-ui-react'
+import { Button, Input, Header, Dropdown } from 'semantic-ui-react'
import CreateFilterNoduleForm from './CreateFilterNoduleForm'
import './CreateNodule.css'
@@ -20,6 +20,8 @@ class CreateNodule extends Component {
this.controller = new CreateNoduleController()
this.filterNoduleForm = React.createRef()
+ this.tableSelect = React.createRef()
+ this.noduleLabelInput = React.createRef()
document.addEventListener('updateTables', this.updateTableList)
}
@@ -29,8 +31,19 @@ class CreateNodule extends Component {
}
handleSubmit = () => {
- if (this.state.noduleType === 'filter')
- console.log(this.filterNoduleForm.current.getFilterProperties())
+
+ const noduleLabel = this.noduleLabelInput.current.inputRef.current.value
+ const selectedTableLabels = this.tableSelect.current.getSelectedTableLabels()
+
+ if (this.state.noduleType === 'filter') {
+ const filterProperties = this.filterNoduleForm.current.getFilterProperties()
+ this.controller.addNewFilterNodule({
+ label: noduleLabel,
+ tablesToImportByLabel: selectedTableLabels,
+ filterType: filterProperties.filterType,
+ filterParams: filterProperties.filterParams
+ })
+ }
}
updateTableList = () => {
@@ -49,7 +62,7 @@ class CreateNodule extends Component {
@@ -68,7 +81,7 @@ class CreateNodule extends Component {
onChange={this.handleChange}
/>
-
+
{ this.renderNoduleForm() }
diff --git a/src/views/NoduleList/NoduleList.css b/src/views/NoduleList/NoduleList.css
new file mode 100644
index 0000000..e69de29
diff --git a/src/views/NoduleList/NoduleList.js b/src/views/NoduleList/NoduleList.js
new file mode 100644
index 0000000..b819331
--- /dev/null
+++ b/src/views/NoduleList/NoduleList.js
@@ -0,0 +1,54 @@
+import React, { Component } from 'react'
+import { Card, Icon, CardContent } from 'semantic-ui-react'
+import './NoduleList.css'
+
+import Nodule from '../../Collections/Nodules'
+import NoduleListController from '../../Controllers/NoduleListController'
+
+class NoduleList extends Component {
+ constructor () {
+ super()
+
+ this.nodules = new Nodule()
+ this.controller = new NoduleListController()
+ this.state = { nodules: this.nodules.getCollectionProps() }
+
+ document.addEventListener('updateNodules', this.updateNoduleList)
+ }
+
+ updateNoduleList = () => {
+ this.setState({nodules: this.nodules.getCollectionProps()})
+ }
+
+ renderTableListElements = () => {
+ const { nodules } = this.state
+ const noduleListElements = nodules.map(n =>
+
+
+ { n.label }
+ {`${n.tables.length} tables`}
+
+ { this.controller.deleteNodule(n.id) }}
+ style={{ cursor: 'pointer' }}
+ >
+ Delete
+
+
+ )
+ return noduleListElements
+ }
+
+ render = () => {
+ return (
+
+
+ { this.renderTableListElements() }
+
+
+ )
+ }
+}
+
+export default NoduleList