feat: SelectedTable get headers
This commit is contained in:
parent
f9728c33f1
commit
f186f8fad7
@ -1,4 +1,5 @@
|
|||||||
import Tables from '../Models/Tables'
|
import Tables from '../Models/Tables'
|
||||||
|
import SelectedTable from '../Models/SelectedTable'
|
||||||
|
|
||||||
class TableListController {
|
class TableListController {
|
||||||
constructor() {
|
constructor() {
|
||||||
@ -10,6 +11,11 @@ class TableListController {
|
|||||||
this.tables.removeById(id)
|
this.tables.removeById(id)
|
||||||
document.dispatchEvent(this.updatedTablesEvent)
|
document.dispatchEvent(this.updatedTablesEvent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logExportById = id => {
|
||||||
|
const selectedTable = new SelectedTable(this.tables.getById(id))
|
||||||
|
console.log(selectedTable.headers)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default TableListController
|
export default TableListController
|
@ -1,15 +1,29 @@
|
|||||||
class SelectedTable {
|
class SelectedTable {
|
||||||
constructor (props) {
|
constructor (table) {
|
||||||
this.table = props.table
|
this.assignTable(table)
|
||||||
}
|
}
|
||||||
|
|
||||||
getHeaders = () => {
|
assignTable = table => {
|
||||||
|
if (table.type === "Nodule") {
|
||||||
|
this.table = table.asTable()
|
||||||
|
} else if (table.type === 'Table') {
|
||||||
|
this.table = table
|
||||||
|
} else {
|
||||||
|
this.table = {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get headers () {
|
||||||
const rows = this.table.rows
|
const rows = this.table.rows
|
||||||
const length = rows.length
|
const length = rows.length
|
||||||
let lengthToSlice = 49
|
let lengthToSlice = 49
|
||||||
if (length < 50) lengthToSlice = length - 1
|
if (length < 50) lengthToSlice = length - 1
|
||||||
const firstSliceOfRows = rows.slice(0, lengthToSlice)
|
const firstSliceOfRows = rows.slice(0, lengthToSlice)
|
||||||
console.log(firstSliceOfRows)
|
const headersOfSplicedRows = firstSliceOfRows.map(r => Object.keys(r))
|
||||||
// const uniqueHeaderSet = new Set(firstSliceOfRows)
|
const flatenedHeaders = headersOfSplicedRows.flat()
|
||||||
|
const uniqueHeaders = Array.from(new Set(flatenedHeaders))
|
||||||
|
return uniqueHeaders
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default SelectedTable
|
||||||
|
@ -30,7 +30,7 @@ class Tables {
|
|||||||
|
|
||||||
getCollectionProps = () => this.collection.map(table => table.getProperties())
|
getCollectionProps = () => this.collection.map(table => table.getProperties())
|
||||||
|
|
||||||
getTableByLabel = label => this.collection.find(t => label === t.label)
|
getById = id => this.collection.find(t => id === t.id)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Tables
|
export default Tables
|
||||||
|
@ -39,7 +39,7 @@ class TableSelect extends Component {
|
|||||||
const tableLabelElements = tables.map(t => {
|
const tableLabelElements = tables.map(t => {
|
||||||
const isSelected = selectedTablesLabels.includes(t.label)
|
const isSelected = selectedTablesLabels.includes(t.label)
|
||||||
return (
|
return (
|
||||||
<Label onClick={() => this.toggleSelect(t.label)} color={isSelected ? 'blue' : 'grey'} style={{ cursor: 'pointer' }}>
|
<Label key={t.label} onClick={() => this.toggleSelect(t.label)} color={isSelected ? 'blue' : 'grey'} style={{ cursor: 'pointer' }}>
|
||||||
{t.label}
|
{t.label}
|
||||||
{ isSelected ? <Icon name='delete' /> : '' }
|
{ isSelected ? <Icon name='delete' /> : '' }
|
||||||
</Label>
|
</Label>
|
||||||
|
0
src/views/DataTable/DataTable.js
Normal file
0
src/views/DataTable/DataTable.js
Normal file
@ -1,5 +1,5 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import { Card, Icon, CardContent } from 'semantic-ui-react'
|
import { Card } from 'semantic-ui-react'
|
||||||
import NoduleListItem from './NoduleListItem'
|
import NoduleListItem from './NoduleListItem'
|
||||||
import './NoduleList.css'
|
import './NoduleList.css'
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ class TableList extends Component {
|
|||||||
|
|
||||||
renderTableListElements = () => {
|
renderTableListElements = () => {
|
||||||
const { tables } = this.state
|
const { tables } = this.state
|
||||||
const tableListElements = tables.map(t => <TableListItem table={t} /> )
|
const tableListElements = tables.map(t => <TableListItem key={t.id} table={t} /> )
|
||||||
return tableListElements
|
return tableListElements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,12 +18,17 @@ class TableListItem extends Component {
|
|||||||
<Card.Header>{ table.label }</Card.Header>
|
<Card.Header>{ table.label }</Card.Header>
|
||||||
<Card.Meta>{`${table.rows.length} rows`}</Card.Meta>
|
<Card.Meta>{`${table.rows.length} rows`}</Card.Meta>
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
<Card.Content
|
<Card.Content extra>
|
||||||
extra
|
<span
|
||||||
onClick={() => { this.controller.deleteTable(table.id) }}
|
onClick={() => { this.controller.deleteTable(table.id) }}
|
||||||
style={{ cursor: 'pointer' }}
|
style={{ cursor: 'pointer' }}>
|
||||||
>
|
Delete <Icon name='trash' />
|
||||||
Delete <Icon name='trash' />
|
</span>
|
||||||
|
<span
|
||||||
|
onClick={() => { this.controller.logExportById(table.id) }}
|
||||||
|
style={{ cursor: 'pointer' }}>
|
||||||
|
View <Icon name='table' />
|
||||||
|
</span>
|
||||||
</Card.Content>
|
</Card.Content>
|
||||||
</Card>
|
</Card>
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user