refact: table + nodule list item as sub components
This commit is contained in:
parent
3fd414b3cc
commit
3f85aa3ce2
@ -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 =>
|
||||
<Card key={n.id} id={n.id}>
|
||||
<Card.Content>
|
||||
<Card.Header>{ n.label }</Card.Header>
|
||||
<Card.Meta>{`${n.tables.length} tables`}</Card.Meta>
|
||||
</Card.Content>
|
||||
<CardContent extra>
|
||||
<span
|
||||
onClick={() => { this.controller.deleteNodule(n.id) }}
|
||||
style={{ cursor: 'pointer' }}>
|
||||
Delete <Icon name='trash' />
|
||||
</span>
|
||||
<span
|
||||
onClick={() => { this.controller.logExportById(n.id) }}
|
||||
style={{ cursor: 'pointer' }}>
|
||||
View <Icon name='table' />
|
||||
</span>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
const noduleListElements = nodules.map(n => <NoduleListItem nodule={n} /> )
|
||||
return noduleListElements
|
||||
}
|
||||
|
||||
|
38
src/views/NoduleList/NoduleListItem.js
Normal file
38
src/views/NoduleList/NoduleListItem.js
Normal file
@ -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 (
|
||||
<Card key={nodule.id} id={nodule.id}>
|
||||
<Card.Content>
|
||||
<Card.Header>{ nodule.label }</Card.Header>
|
||||
<Card.Meta>{`${nodule.tables.length} tables`}</Card.Meta>
|
||||
</Card.Content>
|
||||
<Card.Content extra>
|
||||
<span
|
||||
onClick={() => { this.controller.deleteNodule(nodule.id) }}
|
||||
style={{ cursor: 'pointer' }}>
|
||||
Delete <Icon name='trash' />
|
||||
</span>
|
||||
<span
|
||||
onClick={() => { this.controller.logExportById(nodule.id) }}
|
||||
style={{ cursor: 'pointer' }}>
|
||||
View <Icon name='table' />
|
||||
</span>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default NoduleListItem
|
@ -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 =>
|
||||
<Card key={t.id} id={t.id}>
|
||||
<Card.Content>
|
||||
<Card.Header>{ t.label }</Card.Header>
|
||||
<Card.Meta>{`${t.rows.length} rows`}</Card.Meta>
|
||||
</Card.Content>
|
||||
<CardContent
|
||||
extra
|
||||
onClick={() => { this.controller.deleteTable(t.id) }}
|
||||
style={{ cursor: 'pointer' }}
|
||||
>
|
||||
Delete <Icon name='trash' />
|
||||
</CardContent>
|
||||
</Card>
|
||||
)
|
||||
const tableListElements = tables.map(t => <TableListItem table={t} /> )
|
||||
return tableListElements
|
||||
}
|
||||
|
||||
|
33
src/views/TableList/TableListItem.js
Normal file
33
src/views/TableList/TableListItem.js
Normal file
@ -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 (
|
||||
<Card key={table.id} id={table.id}>
|
||||
<Card.Content>
|
||||
<Card.Header>{ table.label }</Card.Header>
|
||||
<Card.Meta>{`${table.rows.length} rows`}</Card.Meta>
|
||||
</Card.Content>
|
||||
<Card.Content
|
||||
extra
|
||||
onClick={() => { this.controller.deleteTable(table.id) }}
|
||||
style={{ cursor: 'pointer' }}
|
||||
>
|
||||
Delete <Icon name='trash' />
|
||||
</Card.Content>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default TableListItem
|
Loading…
x
Reference in New Issue
Block a user