From 697653bd779f611b180251b6c71832688397a040 Mon Sep 17 00:00:00 2001 From: Joshua Shoemaker Date: Mon, 20 Jul 2020 22:59:24 -0500 Subject: [PATCH] feat: create transform nodule --- src/Collections/Nodules.js | 14 ++++ src/Controllers/CreateNoduleController.js | 14 ++++ src/Controllers/NoduleListController.js | 2 +- .../CreateNodule/CreateFilterNoduleForm.js | 5 ++ src/views/CreateNodule/CreateNodule.js | 11 ++- .../CreateNodule/CreateTransformNoduleForm.js | 73 +++++++++++++++++++ 6 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 src/views/CreateNodule/CreateTransformNoduleForm.js diff --git a/src/Collections/Nodules.js b/src/Collections/Nodules.js index 534f7b0..84d5c80 100644 --- a/src/Collections/Nodules.js +++ b/src/Collections/Nodules.js @@ -39,6 +39,20 @@ class Nodules { } } + addNewTransformNodule = props => { + try { + const newJoinNodule = new TransformNodule({ + id: props.id || uuid(), + label: props.label, + tables: props.tables, + structure: props.structure + }) + this.collection.push(newJoinNodule) + } catch (err) { + console.error(err) + } + } + removeById = id => { const indexToRemove = this.collection.findIndex(n => n.id === id) if (indexToRemove > -1) this.collection.splice(indexToRemove, 1) diff --git a/src/Controllers/CreateNoduleController.js b/src/Controllers/CreateNoduleController.js index 968cc75..97da646 100644 --- a/src/Controllers/CreateNoduleController.js +++ b/src/Controllers/CreateNoduleController.js @@ -35,6 +35,20 @@ class CreateNoduleController { joinBy }) + document.dispatchEvent(this.updatedNodulesEvent) + } + + addNewTransformNodule = props => { + const { label, tablesToImportByLabel, structure} = props + const tables = tablesToImportByLabel.map(label => { + return this.tables.getTableByLabel(label) + }) + + this.nodules.addNewTransformNodule({ + label, + tables, + structure + }) console.log(this.nodules) document.dispatchEvent(this.updatedNodulesEvent) } diff --git a/src/Controllers/NoduleListController.js b/src/Controllers/NoduleListController.js index f0c5cca..322de51 100644 --- a/src/Controllers/NoduleListController.js +++ b/src/Controllers/NoduleListController.js @@ -6,7 +6,7 @@ class NoduleistController { this.updatedNodulesEvent = new Event('updateNodules') } - deleteTable = id => { + deleteNodule = id => { this.nodules.removeById(id) document.dispatchEvent(this.updatedNodulesEvent) } diff --git a/src/views/CreateNodule/CreateFilterNoduleForm.js b/src/views/CreateNodule/CreateFilterNoduleForm.js index b0e5cea..1e7d6d2 100644 --- a/src/views/CreateNodule/CreateFilterNoduleForm.js +++ b/src/views/CreateNodule/CreateFilterNoduleForm.js @@ -28,6 +28,11 @@ class CreateFilterNoduleForm extends Component { this.setState({ filterType: value.value }) } + getFilterProperties = () => { + const { filterType, filterParams } = this.state + return { filterType, filterParams } + } + renderFilterParams = () => { const { filterParams } = this.state diff --git a/src/views/CreateNodule/CreateNodule.js b/src/views/CreateNodule/CreateNodule.js index 19ddbe5..b9ab26c 100644 --- a/src/views/CreateNodule/CreateNodule.js +++ b/src/views/CreateNodule/CreateNodule.js @@ -23,6 +23,7 @@ class CreateNodule extends Component { this.filterNoduleForm = React.createRef() this.joinNoduleForm = React.createRef() + this.transformNoduleForm = React.createRef() this.tableSelect = React.createRef() this.noduleLabelInput = React.createRef() @@ -56,6 +57,14 @@ class CreateNodule extends Component { joinBy: joinProperties }) } + else if (noduleType === 'transform') { + const structureProperties = this.transformNoduleForm.current.getStructureProperties() + this.controller.addNewJoinNodule({ + label: noduleLabel, + tablesToImportByLabel: selectedTableLabels, + structure: structureProperties + }) + } } updateTableList = () => { @@ -67,7 +76,7 @@ class CreateNodule extends Component { if (noduleType === 'filter') return else if (noduleType === 'join') return - else if (noduleType === 'transform') return + else if (noduleType === 'transform') return else return '' } diff --git a/src/views/CreateNodule/CreateTransformNoduleForm.js b/src/views/CreateNodule/CreateTransformNoduleForm.js new file mode 100644 index 0000000..433ad89 --- /dev/null +++ b/src/views/CreateNodule/CreateTransformNoduleForm.js @@ -0,0 +1,73 @@ +import React, { Component } from 'react' +import { Input, Grid, Button, Icon, List } from 'semantic-ui-react' +import './CreateNodule.css' + +class CreateTransformNoduleForm extends Component { + constructor () { + super() + this.state = { + structure: {} + } + + this.initialKeyInput = React.createRef() + this.newKeyInput = React.createRef() + document.addEventListener('updateTables', this.updateTableList) + } + + addStructureInput = () => { + let structure = this.state.structure || {} + + const initialKey = this.initialKeyInput.current.inputRef.current.value + const newKey = this.newKeyInput.current.inputRef.current.value + + if (initialKey && newKey) structure[initialKey] = newKey + + this.setState({ structure: structure }) + } + + getStructureProperties = () => { + return this.state.structure + } + + renderStructure = () => { + const { structure } = this.state + + let initialKeyElements = [] + let newKeyElements = [] + for (let key in structure) { + initialKeyElements.push({key}) + newKeyElements.push({structure[key]}) + } + + return { initialKeyElements, newKeyElements } + } + + render = () => { + const structureElements = this.renderStructure() + return ( +
+ + + + { structureElements.initialKeyElements } + + + + + + { structureElements.newKeyElements } + + + + + +
+ ) + } +} + +export default CreateTransformNoduleForm +