From 3f85aa3ce286a37b092f31297b5947f450b50005 Mon Sep 17 00:00:00 2001 From: Joshua Shoemaker Date: Tue, 28 Jul 2020 13:44:31 -0500 Subject: [PATCH] refact: table + nodule list item as sub components --- src/views/NoduleList/NoduleList.js | 22 ++------------- src/views/NoduleList/NoduleListItem.js | 38 ++++++++++++++++++++++++++ src/views/TableList/TableList.js | 19 ++----------- src/views/TableList/TableListItem.js | 33 ++++++++++++++++++++++ 4 files changed, 76 insertions(+), 36 deletions(-) create mode 100644 src/views/NoduleList/NoduleListItem.js create mode 100644 src/views/TableList/TableListItem.js diff --git a/src/views/NoduleList/NoduleList.js b/src/views/NoduleList/NoduleList.js index 4882c45..c14914d 100644 --- a/src/views/NoduleList/NoduleList.js +++ b/src/views/NoduleList/NoduleList.js @@ -1,5 +1,6 @@ import React, { Component } from 'react' import { Card, Icon, CardContent } from 'semantic-ui-react' +import NoduleListItem from './NoduleListItem' import './NoduleList.css' import Nodule from '../../Models/Nodules' @@ -22,26 +23,7 @@ class NoduleList extends Component { 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 - - { this.controller.logExportById(n.id) }} - style={{ cursor: 'pointer' }}> - View - - - - ) + const noduleListElements = nodules.map(n => ) return noduleListElements } diff --git a/src/views/NoduleList/NoduleListItem.js b/src/views/NoduleList/NoduleListItem.js new file mode 100644 index 0000000..00757ce --- /dev/null +++ b/src/views/NoduleList/NoduleListItem.js @@ -0,0 +1,38 @@ +import React, { Component } from 'react' +import { Card, Icon } from 'semantic-ui-react' +import './NoduleList.css' + +import NoduleListController from '../../Controllers/NoduleListController' + +class NoduleListItem extends Component { + constructor () { + super() + this.controller = new NoduleListController() + } + + render = () => { + const { nodule } = this.props + return ( + + + { nodule.label } + {`${nodule.tables.length} tables`} + + + { this.controller.deleteNodule(nodule.id) }} + style={{ cursor: 'pointer' }}> + Delete + + { this.controller.logExportById(nodule.id) }} + style={{ cursor: 'pointer' }}> + View + + + + ) + } +} + +export default NoduleListItem diff --git a/src/views/TableList/TableList.js b/src/views/TableList/TableList.js index e674edf..56f1ec0 100644 --- a/src/views/TableList/TableList.js +++ b/src/views/TableList/TableList.js @@ -1,5 +1,6 @@ import React, { Component } from 'react' -import { Card, Icon, CardContent } from 'semantic-ui-react' +import { Card } from 'semantic-ui-react' +import TableListItem from './TableListItem' import './TableList.css' import Tables from '../../Models/Tables' @@ -22,21 +23,7 @@ class TableList extends Component { renderTableListElements = () => { const { tables } = this.state - const tableListElements = tables.map(t => - - - { t.label } - {`${t.rows.length} rows`} - - { this.controller.deleteTable(t.id) }} - style={{ cursor: 'pointer' }} - > - Delete - - - ) + const tableListElements = tables.map(t => ) return tableListElements } diff --git a/src/views/TableList/TableListItem.js b/src/views/TableList/TableListItem.js new file mode 100644 index 0000000..d35f982 --- /dev/null +++ b/src/views/TableList/TableListItem.js @@ -0,0 +1,33 @@ +import React, { Component } from 'react' +import { Card, Icon } from 'semantic-ui-react' +import './TableList.css' + +import TableListController from '../../Controllers/TableListController' + +class TableListItem extends Component { + constructor () { + super() + this.controller = new TableListController() + } + + render = () => { + const { table } = this.props + return ( + + + { table.label } + {`${table.rows.length} rows`} + + { this.controller.deleteTable(table.id) }} + style={{ cursor: 'pointer' }} + > + Delete + + + ) + } +} + +export default TableListItem