import React, { Component } from 'react' import { Card, Icon, CardContent } from 'semantic-ui-react' import './TableList.css' import Tables from '../../Models/Tables' import TableListController from '../../Controllers/TableListController' class TableList extends Component { constructor () { super() this.tables = new Tables() this.controller = new TableListController() this.state = { tables: this.tables.getCollectionProps() } document.addEventListener('updateTables', this.updateTableList) } updateTableList = () => { this.setState({tables: this.tables.getCollectionProps()}) } 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 ) return tableListElements } render = () => { return (
{ this.renderTableListElements() }
) } } export default TableList