Merge pull request #3 from frankolson/linter_dependencies

Linter dependencies
This commit is contained in:
Gary Menzel
2017-11-23 13:45:41 +11:00
committed by GitHub
7 changed files with 401 additions and 400 deletions
+20 -16
View File
@@ -30,12 +30,14 @@ export default {
defaultFiltered: [],
defaultResized: [],
defaultExpanded: {},
// eslint-disable-next-line no-unused-vars
defaultFilterMethod: (filter, row, column) => {
const id = filter.pivotId || filter.id
return row[id] !== undefined
? String(row[id]).startsWith(filter.value)
: true
},
// eslint-disable-next-line no-unused-vars
defaultSortMethod: (a, b, desc) => {
// force null and undefined to the bottom
a = a === null || a === undefined ? '' : a
@@ -50,7 +52,8 @@ export default {
if (a < b) {
return -1
}
// returning 0, undefined or any falsey value will use subsequent sorts or the index as a tiebreaker
// returning 0, undefined or any falsey value will use subsequent sorts or
// the index as a tiebreaker
return 0
},
@@ -177,24 +180,24 @@ export default {
TbodyComponent: _.makeTemplateComponent('rt-tbody', 'Tbody'),
TrGroupComponent: _.makeTemplateComponent('rt-tr-group', 'TrGroup'),
TrComponent: _.makeTemplateComponent('rt-tr', 'Tr'),
ThComponent: ({ toggleSort, className, children, ...rest }) => {
return (
<div
className={classnames(className, 'rt-th')}
onClick={e => {
toggleSort && toggleSort(e)
}}
{...rest}
>
{children}
</div>
)
},
ThComponent: ({ toggleSort, className, children, ...rest }) => (
<div
className={classnames(className, 'rt-th')}
onClick={e => (
toggleSort && toggleSort(e)
)}
role="button"
tabIndex={0}
{...rest}
>
{children}
</div>
),
TdComponent: _.makeTemplateComponent('rt-td', 'Td'),
TfootComponent: _.makeTemplateComponent('rt-tfoot', 'Tfoot'),
FilterComponent: ({ filter, onChange }) => (
<input
type='text'
type="text"
style={{
width: '100%',
}}
@@ -216,6 +219,7 @@ export default {
const previewValues = subRows
.filter(d => typeof d[column.id] !== 'undefined')
.map((row, i) => (
// eslint-disable-next-line react/no-array-index-key
<span key={i}>
{row[column.id]}
{i < subRows.length - 1 ? ', ' : ''}
@@ -237,7 +241,7 @@ export default {
className={classnames('-loading', { '-active': loading }, className)}
{...rest}
>
<div className='-loading-inner'>
<div className="-loading-inner">
{loadingText}
</div>
</div>
+233 -231
View File
@@ -142,27 +142,25 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const hasColumnFooter = allVisibleColumns.some(d => d.Footer)
const hasFilters = filterable || allVisibleColumns.some(d => d.filterable)
const recurseRowsViewIndex = (rows, path = [], index = -1) => {
return [
rows.map((row, i) => {
index++
const rowWithViewIndex = {
...row,
_viewIndex: index,
}
const newPath = path.concat([i])
if (rowWithViewIndex[subRowsKey] && _.get(expanded, newPath)) {
;[rowWithViewIndex[subRowsKey], index] = recurseRowsViewIndex(
rowWithViewIndex[subRowsKey],
newPath,
index
)
}
return rowWithViewIndex
}),
index,
]
}
const recurseRowsViewIndex = (rows, path = [], index = -1) => ([
rows.map((row, i) => {
index += 1
const rowWithViewIndex = {
...row,
_viewIndex: index,
}
const newPath = path.concat([i])
if (rowWithViewIndex[subRowsKey] && _.get(expanded, newPath)) {
[rowWithViewIndex[subRowsKey], index] = recurseRowsViewIndex(
rowWithViewIndex[subRowsKey],
newPath,
index,
)
}
return rowWithViewIndex
}),
index,
])
;[pageRows] = recurseRowsViewIndex(pageRows)
const canPrevious = page > 0
@@ -172,7 +170,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
allVisibleColumns.map(d => {
const resizedColumn = resized.find(x => x.id === d.id) || {}
return _.getFirstDefined(resizedColumn.value, d.width, d.minWidth)
})
}),
)
let rowIndex = -1
@@ -190,59 +188,45 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
rowMinWidth,
}
// Visual Components
const rootProps = _.splitProps(
getProps(finalState, undefined, undefined, this),
)
const tableProps = _.splitProps(
getTableProps(finalState, undefined, undefined, this),
)
const tBodyProps = _.splitProps(
getTbodyProps(finalState, undefined, undefined, this),
)
const loadingProps = getLoadingProps(finalState, undefined, undefined, this)
const noDataProps = getNoDataProps(finalState, undefined, undefined, this)
const resizerProps = getResizerProps(finalState, undefined, undefined, this)
const makeHeaderGroups = () => {
const theadGroupProps = _.splitProps(
getTheadGroupProps(finalState, undefined, undefined, this)
)
const theadGroupTrProps = _.splitProps(
getTheadGroupTrProps(finalState, undefined, undefined, this)
)
return (
<TheadComponent
className={classnames('-headerGroups', theadGroupProps.className)}
style={{
...theadGroupProps.style,
minWidth: `${rowMinWidth}px`,
}}
{...theadGroupProps.rest}
>
<TrComponent
className={theadGroupTrProps.className}
style={theadGroupTrProps.style}
{...theadGroupTrProps.rest}
>
{headerGroups.map(makeHeaderGroup)}
</TrComponent>
</TheadComponent>
)
}
// Visual Components
const makeHeaderGroup = (column, i) => {
const resizedValue = col =>
(resized.find(x => x.id === col.id) || {}).value
const flex = _.sum(
column.columns.map(
col => (col.width || resizedValue(col) ? 0 : col.minWidth)
)
col => (col.width || resizedValue(col) ? 0 : col.minWidth),
),
)
const width = _.sum(
column.columns.map(col =>
_.getFirstDefined(resizedValue(col), col.width, col.minWidth)
)
_.getFirstDefined(resizedValue(col), col.width, col.minWidth),
),
)
const maxWidth = _.sum(
column.columns.map(col =>
_.getFirstDefined(resizedValue(col), col.width, col.maxWidth)
)
_.getFirstDefined(resizedValue(col), col.width, col.maxWidth),
),
)
const theadGroupThProps = _.splitProps(
getTheadGroupThProps(finalState, undefined, column, this)
getTheadGroupThProps(finalState, undefined, column, this),
)
const columnHeaderProps = _.splitProps(
column.getHeaderProps(finalState, undefined, column, this)
column.getHeaderProps(finalState, undefined, column, this),
)
const classes = [
@@ -270,7 +254,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
return (
<ThComponent
key={i + '-' + column.id}
key={`${i}-${column.id}`}
className={classnames(classes)}
style={{
...styles,
@@ -280,34 +264,34 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
>
{_.normalizeComponent(column.Header, {
data: sortedData,
column: column,
column,
})}
</ThComponent>
)
}
const makeHeaders = () => {
const theadProps = _.splitProps(
getTheadProps(finalState, undefined, undefined, this)
const makeHeaderGroups = () => {
const theadGroupProps = _.splitProps(
getTheadGroupProps(finalState, undefined, undefined, this),
)
const theadTrProps = _.splitProps(
getTheadTrProps(finalState, undefined, undefined, this)
const theadGroupTrProps = _.splitProps(
getTheadGroupTrProps(finalState, undefined, undefined, this),
)
return (
<TheadComponent
className={classnames('-header', theadProps.className)}
className={classnames('-headerGroups', theadGroupProps.className)}
style={{
...theadProps.style,
...theadGroupProps.style,
minWidth: `${rowMinWidth}px`,
}}
{...theadProps.rest}
{...theadGroupProps.rest}
>
<TrComponent
className={theadTrProps.className}
style={theadTrProps.style}
{...theadTrProps.rest}
className={theadGroupTrProps.className}
style={theadGroupTrProps.style}
{...theadGroupTrProps.rest}
>
{allVisibleColumns.map(makeHeader)}
{headerGroups.map(makeHeaderGroup)}
</TrComponent>
</TheadComponent>
)
@@ -321,18 +305,18 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
column.minWidth,
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
column.maxWidth,
)
const theadThProps = _.splitProps(
getTheadThProps(finalState, undefined, column, this)
getTheadThProps(finalState, undefined, column, this),
)
const columnHeaderProps = _.splitProps(
column.getHeaderProps(finalState, undefined, column, this)
column.getHeaderProps(finalState, undefined, column, this),
)
const classes = [
@@ -365,7 +349,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
return (
<ThComponent
key={i + '-' + column.id}
key={`${i}-${column.id}`}
className={classnames(
classes,
isResizable && 'rt-resizable-header',
@@ -374,7 +358,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
!show && '-hidden',
pivotBy &&
pivotBy.slice(0, -1).includes(column.id) &&
'rt-header-pivot'
'rt-header-pivot',
)}
style={{
...styles,
@@ -390,7 +374,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
<div className={classnames(isResizable && 'rt-resizable-header-content')}>
{_.normalizeComponent(column.Header, {
data: sortedData,
column: column,
column,
})}
</div>
{resizer}
@@ -398,28 +382,28 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const makeFilters = () => {
const theadFilterProps = _.splitProps(
getTheadFilterProps(finalState, undefined, undefined, this)
const makeHeaders = () => {
const theadProps = _.splitProps(
getTheadProps(finalState, undefined, undefined, this),
)
const theadFilterTrProps = _.splitProps(
getTheadFilterTrProps(finalState, undefined, undefined, this)
const theadTrProps = _.splitProps(
getTheadTrProps(finalState, undefined, undefined, this),
)
return (
<TheadComponent
className={classnames('-filters', theadFilterProps.className)}
className={classnames('-header', theadProps.className)}
style={{
...theadFilterProps.style,
...theadProps.style,
minWidth: `${rowMinWidth}px`,
}}
{...theadFilterProps.rest}
{...theadProps.rest}
>
<TrComponent
className={theadFilterTrProps.className}
style={theadFilterTrProps.style}
{...theadFilterTrProps.rest}
className={theadTrProps.className}
style={theadTrProps.style}
{...theadTrProps.rest}
>
{allVisibleColumns.map(makeFilter)}
{allVisibleColumns.map(makeHeader)}
</TrComponent>
</TheadComponent>
)
@@ -430,18 +414,18 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
column.minWidth,
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
column.maxWidth,
)
const theadFilterThProps = _.splitProps(
getTheadFilterThProps(finalState, undefined, column, this)
getTheadFilterThProps(finalState, undefined, column, this),
)
const columnHeaderProps = _.splitProps(
column.getHeaderProps(finalState, undefined, column, this)
column.getHeaderProps(finalState, undefined, column, this),
)
const classes = [
@@ -468,12 +452,12 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const isFilterable = _.getFirstDefined(
column.filterable,
filterable,
false
false,
)
return (
<ThComponent
key={i + '-' + column.id}
key={`${i}-${column.id}`}
className={classnames(classes)}
style={{
...styles,
@@ -491,21 +475,48 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
filter,
onChange: value => this.filterColumn(column, value),
},
defaultProps.column.Filter
defaultProps.column.Filter,
)
: null}
</ThComponent>
)
}
const makeFilters = () => {
const theadFilterProps = _.splitProps(
getTheadFilterProps(finalState, undefined, undefined, this),
)
const theadFilterTrProps = _.splitProps(
getTheadFilterTrProps(finalState, undefined, undefined, this),
)
return (
<TheadComponent
className={classnames('-filters', theadFilterProps.className)}
style={{
...theadFilterProps.style,
minWidth: `${rowMinWidth}px`,
}}
{...theadFilterProps.rest}
>
<TrComponent
className={theadFilterTrProps.className}
style={theadFilterTrProps.style}
{...theadFilterTrProps.rest}
>
{allVisibleColumns.map(makeFilter)}
</TrComponent>
</TheadComponent>
)
}
const makePageRow = (row, i, path = []) => {
const rowInfo = {
original: row[originalKey],
row: row,
row,
index: row[indexKey],
viewIndex: ++rowIndex,
pageSize: pageSize,
page: page,
viewIndex: rowIndex += 1,
pageSize,
page,
level: path.length,
nestingPath: path.concat([i]),
aggregated: row[aggregatedKey],
@@ -515,14 +526,14 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const isExpanded = _.get(expanded, rowInfo.nestingPath)
const trGroupProps = getTrGroupProps(finalState, rowInfo, undefined, this)
const trProps = _.splitProps(
getTrProps(finalState, rowInfo, undefined, this)
getTrProps(finalState, rowInfo, undefined, this),
)
return (
<TrGroupComponent key={rowInfo.nestingPath.join('_')} {...trGroupProps}>
<TrComponent
className={classnames(
trProps.className,
row._viewIndex % 2 ? '-even' : '-odd'
row._viewIndex % 2 ? '-even' : '-odd',
)}
style={trProps.style}
{...trProps.rest}
@@ -534,18 +545,18 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
column.minWidth,
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
column.maxWidth,
)
const tdProps = _.splitProps(
getTdProps(finalState, rowInfo, column, this)
getTdProps(finalState, rowInfo, column, this),
)
const columnProps = _.splitProps(
column.getProps(finalState, rowInfo, column, this)
column.getProps(finalState, rowInfo, column, this),
)
const classes = [
@@ -595,10 +606,10 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
{
expanded: newExpanded,
},
() => {
() => (
onExpandedChange &&
onExpandedChange(newExpanded, cellInfo.nestingPath, e)
}
),
)
}
@@ -606,7 +617,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
let resolvedCell = _.normalizeComponent(
column.Cell,
cellInfo,
value
value,
)
// Resolve Renderers
@@ -633,7 +644,8 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
// Make it expandable by defualt
cellInfo.expandable = true
useOnExpanderClick = true
// If pivoted, has no subRows, and does not have a subComponent, do not make expandable
// If pivoted, has no subRows, and does not have a subComponent,
// do not make expandable
if (cellInfo.pivoted && !cellInfo.subRows && !SubComponent) {
cellInfo.expandable = false
}
@@ -656,14 +668,14 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
...cellInfo,
value: row[pivotValKey],
},
row[pivotValKey]
row[pivotValKey],
)
} else if (isPreview) {
// Show the pivot preview
resolvedCell = _.normalizeComponent(
ResolvedAggregatedComponent,
cellInfo,
value
value,
)
} else {
resolvedCell = null
@@ -672,7 +684,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
resolvedCell = _.normalizeComponent(
ResolvedAggregatedComponent,
cellInfo,
value
value,
)
}
@@ -680,7 +692,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
resolvedCell = _.normalizeComponent(
ResolvedExpanderComponent,
cellInfo,
row[pivotValKey]
row[pivotValKey],
)
if (pivotBy) {
if (cellInfo.groupedByPivot) {
@@ -696,7 +708,9 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
? onExpanderClick
: () => {}
// If there are multiple onClick events, make sure they don't override eachother. This should maybe be expanded to handle all function attributes
// If there are multiple onClick events, make sure they don't
// override eachother. This should maybe be expanded to handle all
// function attributes
const interactionProps = {
onClick: resolvedOnExpanderClick,
}
@@ -716,12 +730,13 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
// Return the cell
return (
<TdComponent
key={i2 + '-' + column.id}
// eslint-disable-next-line react/no-array-index-key
key={`${i2}-${column.id}`}
className={classnames(
classes,
!show && 'hidden',
cellInfo.expandable && 'rt-expandable',
(isBranch || isPreview) && 'rt-pivot'
(isBranch || isPreview) && 'rt-pivot',
)}
style={{
...styles,
@@ -741,7 +756,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
{rowInfo.subRows &&
isExpanded &&
rowInfo.subRows.map((d, i) =>
makePageRow(d, i, rowInfo.nestingPath)
makePageRow(d, i, rowInfo.nestingPath),
)}
{SubComponent &&
!rowInfo.subRows &&
@@ -751,52 +766,26 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const makePadRow = (row, i) => {
const trGroupProps = getTrGroupProps(
finalState,
undefined,
undefined,
this
)
const trProps = _.splitProps(
getTrProps(finalState, undefined, undefined, this)
)
return (
<TrGroupComponent key={i} {...trGroupProps}>
<TrComponent
className={classnames(
'-padRow',
(pageRows.length + i) % 2 ? '-even' : '-odd',
trProps.className
)}
style={trProps.style || {}}
>
{allVisibleColumns.map(makePadColumn)}
</TrComponent>
</TrGroupComponent>
)
}
const makePadColumn = (column, i) => {
const resizedCol = resized.find(x => x.id === column.id) || {}
const show =
typeof column.show === 'function' ? column.show() : column.show
let width = _.getFirstDefined(
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
column.minWidth,
)
let flex = width
let maxWidth = _.getFirstDefined(
const flex = width
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
column.maxWidth,
)
const tdProps = _.splitProps(
getTdProps(finalState, undefined, column, this)
getTdProps(finalState, undefined, column, this),
)
const columnProps = _.splitProps(
column.getProps(finalState, undefined, column, this)
column.getProps(finalState, undefined, column, this),
)
const classes = [
@@ -813,7 +802,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
return (
<TdComponent
key={i + '-' + column.id}
key={`${i}-${column.id}`}
className={classnames(classes, !show && 'hidden')}
style={{
...styles,
@@ -828,10 +817,96 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const makePadRow = (row, i) => {
const trGroupProps = getTrGroupProps(
finalState,
undefined,
undefined,
this,
)
const trProps = _.splitProps(
getTrProps(finalState, undefined, undefined, this),
)
return (
<TrGroupComponent key={i} {...trGroupProps}>
<TrComponent
className={classnames(
'-padRow',
(pageRows.length + i) % 2 ? '-even' : '-odd',
trProps.className,
)}
style={trProps.style || {}}
>
{allVisibleColumns.map(makePadColumn)}
</TrComponent>
</TrGroupComponent>
)
}
const makeColumnFooter = (column, i) => {
const resizedCol = resized.find(x => x.id === column.id) || {}
const show =
typeof column.show === 'function' ? column.show() : column.show
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth,
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth,
)
const tFootTdProps = _.splitProps(
getTfootTdProps(finalState, undefined, undefined, this),
)
const columnProps = _.splitProps(
column.getProps(finalState, undefined, column, this),
)
const columnFooterProps = _.splitProps(
column.getFooterProps(finalState, undefined, column, this),
)
const classes = [
tFootTdProps.className,
column.className,
columnProps.className,
columnFooterProps.className,
]
const styles = {
...tFootTdProps.style,
...column.style,
...columnProps.style,
...columnFooterProps.style,
}
return (
<TdComponent
key={`${i}-${column.id}`}
className={classnames(classes, !show && 'hidden')}
style={{
...styles,
flex: `${width} 0 auto`,
width: _.asPx(width),
maxWidth: _.asPx(maxWidth),
}}
{...columnProps.rest}
{...tFootTdProps.rest}
{...columnFooterProps.rest}
>
{_.normalizeComponent(column.Footer, {
data: sortedData,
column,
})}
</TdComponent>
)
}
const makeColumnFooters = () => {
const tFootProps = getTfootProps(finalState, undefined, undefined, this)
const tFootTrProps = _.splitProps(
getTfootTrProps(finalState, undefined, undefined, this)
getTfootTrProps(finalState, undefined, undefined, this),
)
return (
<TfootComponent
@@ -853,69 +928,9 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const makeColumnFooter = (column, i) => {
const resizedCol = resized.find(x => x.id === column.id) || {}
const show =
typeof column.show === 'function' ? column.show() : column.show
const width = _.getFirstDefined(
resizedCol.value,
column.width,
column.minWidth
)
const maxWidth = _.getFirstDefined(
resizedCol.value,
column.width,
column.maxWidth
)
const tFootTdProps = _.splitProps(
getTfootTdProps(finalState, undefined, undefined, this)
)
const columnProps = _.splitProps(
column.getProps(finalState, undefined, column, this)
)
const columnFooterProps = _.splitProps(
column.getFooterProps(finalState, undefined, column, this)
)
const classes = [
tFootTdProps.className,
column.className,
columnProps.className,
columnFooterProps.className,
]
const styles = {
...tFootTdProps.style,
...column.style,
...columnProps.style,
...columnFooterProps.style,
}
return (
<TdComponent
key={i + '-' + column.id}
className={classnames(classes, !show && 'hidden')}
style={{
...styles,
flex: `${width} 0 auto`,
width: _.asPx(width),
maxWidth: _.asPx(maxWidth),
}}
{...columnProps.rest}
{...tFootTdProps.rest}
{...columnFooterProps.rest}
>
{_.normalizeComponent(column.Footer, {
data: sortedData,
column: column,
})}
</TdComponent>
)
}
const makePagination = () => {
const paginationProps = _.splitProps(
getPaginationProps(finalState, undefined, undefined, this)
getPaginationProps(finalState, undefined, undefined, this),
)
return (
<PaginationComponent
@@ -932,19 +947,6 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
)
}
const rootProps = _.splitProps(
getProps(finalState, undefined, undefined, this)
)
const tableProps = _.splitProps(
getTableProps(finalState, undefined, undefined, this)
)
const tBodyProps = _.splitProps(
getTbodyProps(finalState, undefined, undefined, this)
)
const loadingProps = getLoadingProps(finalState, undefined, undefined, this)
const noDataProps = getNoDataProps(finalState, undefined, undefined, this)
const resizerProps = getResizerProps(finalState, undefined, undefined, this)
const makeTable = () => {
const pagination = makePagination()
return (
@@ -957,14 +959,14 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
{...rootProps.rest}
>
{showPagination && showPaginationTop
? <div className='pagination-top'>
? <div className="pagination-top">
{pagination}
</div>
: null}
<TableComponent
className={classnames(
tableProps.className,
currentlyResizing ? 'rt-resizing' : ''
currentlyResizing ? 'rt-resizing' : '',
)}
style={tableProps.style}
{...tableProps.rest}
@@ -986,7 +988,7 @@ export default class ReactTable extends Methods(Lifecycle(Component)) {
{hasColumnFooter ? makeColumnFooters() : null}
</TableComponent>
{showPagination && showPaginationBottom
? <div className='pagination-bottom'>
? <div className="pagination-bottom">
{pagination}
</div>
: null}
+4 -4
View File
@@ -64,7 +64,7 @@ export default Base =>
if (freezeWhenExpanded) {
// if any rows are expanded, freeze the existing data and sorting
const keys = Object.keys(newResolvedState.expanded)
for (var i = 0; i < keys.length; i++) {
for (let i = 0; i < keys.length; i += 1) {
if (newResolvedState.expanded[keys[i]]) {
newResolvedState.frozen = true
break
@@ -109,18 +109,18 @@ export default Base =>
newResolvedState.pages = newResolvedState.manual
? newResolvedState.pages
: Math.ceil(
newResolvedState.sortedData.length / newResolvedState.pageSize
newResolvedState.sortedData.length / newResolvedState.pageSize,
)
newResolvedState.page = Math.max(
newResolvedState.page >= newResolvedState.pages
? newResolvedState.pages - 1
: newResolvedState.page,
0
0,
)
}
return this.setState(newResolvedState, () => {
cb && cb()
if (cb) { cb() }
if (
oldState.page !== newResolvedState.page ||
oldState.pageSize !== newResolvedState.pageSize ||
+93 -101
View File
@@ -42,7 +42,7 @@ export default Base =>
let expanderColumn = columns.find(
col =>
col.expander ||
(col.columns && col.columns.some(col2 => col2.expander))
(col.columns && col.columns.some(col2 => col2.expander)),
)
// The actual expander might be in the columns field of a group column
if (expanderColumn && !expanderColumn.expander) {
@@ -91,48 +91,48 @@ export default Base =>
if (dcol.accessor && !dcol.id) {
console.warn(dcol)
throw new Error(
'A column id is required if using a non-string accessor for column above.'
'A column id is required if using a non-string accessor for column above.',
)
}
// Fall back to an undefined accessor
if (!dcol.accessor) {
dcol.accessor = d => undefined
dcol.accessor = () => undefined
}
return dcol
}
const allDecoratedColumns = []
// Decorate the columns
const decorateAndAddToAll = (column, parentColumn) => {
const decoratedColumn = makeDecoratedColumn(column, parentColumn)
allDecoratedColumns.push(decoratedColumn)
return decoratedColumn
}
const allDecoratedColumns = []
const decoratedColumns = columnsWithExpander.map((column, i) => {
const decoratedColumns = columnsWithExpander.map(column => {
if (column.columns) {
return {
...column,
columns: column.columns.map(d => decorateAndAddToAll(d, column)),
}
} else {
return decorateAndAddToAll(column)
}
return decorateAndAddToAll(column)
})
// Build the visible columns, headers and flat column list
let visibleColumns = decoratedColumns.slice()
let allVisibleColumns = []
visibleColumns = visibleColumns.map((column, i) => {
visibleColumns = visibleColumns.map(column => {
if (column.columns) {
const visibleSubColumns = column.columns.filter(
d =>
pivotBy.indexOf(d.id) > -1
? false
: _.getFirstDefined(d.show, true)
)
const visibleSubColumns = column.columns.filter(d => (
pivotBy.indexOf(d.id) > -1
? false
: _.getFirstDefined(d.show, true)
))
return {
...column,
columns: visibleSubColumns,
@@ -141,13 +141,13 @@ export default Base =>
return column
})
visibleColumns = visibleColumns.filter(column => {
return column.columns
visibleColumns = visibleColumns.filter(column => (
column.columns
? column.columns.length
: pivotBy.indexOf(column.id) > -1
? false
: _.getFirstDefined(column.show, true)
})
))
// Find any custom pivot location
const pivotIndex = visibleColumns.findIndex(col => col.pivot)
@@ -163,10 +163,10 @@ export default Base =>
}
})
let PivotParentColumn = pivotColumns.reduce(
const PivotParentColumn = pivotColumns.reduce(
(prev, current) =>
prev && prev === current.parentColumn && current.parentColumn,
pivotColumns[0].parentColumn
pivotColumns[0].parentColumn,
)
let PivotGroupHeader = hasHeaderGroups && PivotParentColumn.Header
@@ -202,13 +202,13 @@ export default Base =>
headerGroups.push({
...this.props.column,
...column,
columns: columns,
columns,
})
currentSpan = []
}
// Build flast list of allVisibleColumns and HeaderGroups
visibleColumns.forEach((column, i) => {
visibleColumns.forEach(column => {
if (column.columns) {
allVisibleColumns = allVisibleColumns.concat(column.columns)
if (currentSpan.length > 0) {
@@ -238,13 +238,18 @@ export default Base =>
})
if (row[subRowsKey]) {
row[subRowsKey] = row[subRowsKey].map((d, i) =>
accessRow(d, i, level + 1)
accessRow(d, i, level + 1),
)
}
return row
}
let resolvedData = data.map((d, i) => accessRow(d, i))
// TODO: Make it possible to fabricate nested rows without pivoting
const aggregatingColumns = allVisibleColumns.filter(
d => !d.expander && d.aggregate,
)
// If pivoting, recursively group the data
const aggregate = rows => {
const aggregationValues = {}
@@ -254,11 +259,6 @@ export default Base =>
})
return aggregationValues
}
// TODO: Make it possible to fabricate nested rows without pivoting
const aggregatingColumns = allVisibleColumns.filter(
d => !d.expander && d.aggregate
)
if (pivotBy.length) {
const groupRecursively = (rows, keys, i = 0) => {
// This is the last level, just return the rows
@@ -267,20 +267,18 @@ export default Base =>
}
// Group the rows together for this level
let groupedRows = Object.entries(
_.groupBy(rows, keys[i])
).map(([key, value]) => {
return {
[pivotIDKey]: keys[i],
[pivotValKey]: key,
[keys[i]]: key,
[subRowsKey]: value,
[nestingLevelKey]: i,
[groupedByPivotKey]: true,
}
})
_.groupBy(rows, keys[i]),
).map(([key, value]) => ({
[pivotIDKey]: keys[i],
[pivotValKey]: key,
[keys[i]]: key,
[subRowsKey]: value,
[nestingLevelKey]: i,
[groupedByPivotKey]: true,
}))
// Recurse into the subRows
groupedRows = groupedRows.map(rowGroup => {
let subRows = groupRecursively(rowGroup[subRowsKey], keys, i + 1)
const subRows = groupRecursively(rowGroup[subRowsKey], keys, i + 1)
return {
...rowGroup,
[subRowsKey]: subRows,
@@ -329,10 +327,10 @@ export default Base =>
resolvedData,
filtered,
defaultFilterMethod,
allVisibleColumns
allVisibleColumns,
),
sorted,
sortMethodsByColumnID
sortMethodsByColumnID,
),
}
}
@@ -366,11 +364,10 @@ export default Base =>
// If 'filterAll' is set to true, pass the entire dataset to the filter method
if (column.filterAll) {
return filterMethod(nextFilter, filteredSoFar, column)
} else {
return filteredSoFar.filter(row => {
return filterMethod(nextFilter, row, column)
})
}
return filteredSoFar.filter(row => (
filterMethod(nextFilter, row, column)
))
}, filteredData)
// Apply the filter to the subrows if we are pivoting, and then
@@ -386,7 +383,7 @@ export default Base =>
row[this.props.subRowsKey],
filtered,
defaultFilterMethod,
allVisibleColumns
allVisibleColumns,
),
}
})
@@ -411,16 +408,16 @@ export default Base =>
sorted.map(sort => {
// Support custom sorting methods for each column
if (sortMethodsByColumnID[sort.id]) {
return (a, b) => {
return sortMethodsByColumnID[sort.id](a[sort.id], b[sort.id], sort.desc)
}
}
return (a, b) => {
return this.props.defaultSortMethod(a[sort.id], b[sort.id], sort.desc)
return (a, b) => (
sortMethodsByColumnID[sort.id](a[sort.id], b[sort.id], sort.desc)
)
}
return (a, b) => (
this.props.defaultSortMethod(a[sort.id], b[sort.id], sort.desc)
)
}),
sorted.map(d => !d.desc),
this.props.indexKey
this.props.indexKey,
)
sortedData.forEach(row => {
@@ -430,7 +427,7 @@ export default Base =>
row[this.props.subRowsKey] = this.sortData(
row[this.props.subRowsKey],
sorted,
sortMethodsByColumnID
sortMethodsByColumnID,
)
})
@@ -440,7 +437,7 @@ export default Base =>
getMinRows () {
return _.getFirstDefined(
this.props.minRows,
this.getStateOrProp('pageSize')
this.getStateOrProp('pageSize'),
)
}
@@ -452,9 +449,9 @@ export default Base =>
if (collapseOnPageChange) {
newState.expanded = {}
}
this.setStateWithData(newState, () => {
this.setStateWithData(newState, () => (
onPageChange && onPageChange(page)
})
))
}
onPageSizeChange (newPageSize) {
@@ -470,16 +467,16 @@ export default Base =>
pageSize: newPageSize,
page: newPage,
},
() => {
() => (
onPageSizeChange && onPageSizeChange(newPageSize, newPage)
}
),
)
}
sortColumn (column, additive) {
const { sorted, skipNextSort, defaultSortDesc } = this.getResolvedState()
const firstSortDirection = column.hasOwnProperty('defaultSortDesc')
const firstSortDirection = Object.prototype.hasOwnProperty.call(column, 'defaultSortDesc')
? column.defaultSortDesc
: defaultSortDesc
const secondSortDirection = !firstSortDirection
@@ -519,20 +516,18 @@ export default Base =>
newSorted = [existing]
}
}
} else if (additive) {
newSorted.push({
id: column.id,
desc: firstSortDirection,
})
} else {
if (additive) {
newSorted.push({
newSorted = [
{
id: column.id,
desc: firstSortDirection,
})
} else {
newSorted = [
{
id: column.id,
desc: firstSortDirection,
},
]
}
},
]
}
} else {
// Multi-Sort
@@ -556,21 +551,19 @@ export default Base =>
if (!additive) {
newSorted = newSorted.slice(existingIndex, column.length)
}
} else {
// New Sort Column
if (additive) {
newSorted = newSorted.concat(
column.map(d => ({
id: d.id,
desc: firstSortDirection,
}))
)
} else {
newSorted = column.map(d => ({
// New Sort Column
} else if (additive) {
newSorted = newSorted.concat(
column.map(d => ({
id: d.id,
desc: firstSortDirection,
}))
}
})),
)
} else {
newSorted = column.map(d => ({
id: d.id,
desc: firstSortDirection,
}))
}
}
@@ -582,9 +575,9 @@ export default Base =>
: this.state.page,
sorted: newSorted,
},
() => {
() => (
onSortedChange && onSortedChange(newSorted, column, additive)
}
),
)
}
@@ -593,16 +586,14 @@ export default Base =>
const { onFilteredChange } = this.props
// Remove old filter first if it exists
const newFiltering = (filtered || []).filter(x => {
if (x.id !== column.id) {
return true
}
})
const newFiltering = (filtered || []).filter(x => (
x.id !== column.id
))
if (value !== '') {
newFiltering.push({
id: column.id,
value: value,
value,
})
}
@@ -610,9 +601,9 @@ export default Base =>
{
filtered: newFiltering,
},
() => {
() => (
onFilteredChange && onFilteredChange(newFiltering, column, value)
}
),
)
}
@@ -634,7 +625,7 @@ export default Base =>
currentlyResizing: {
id: column.id,
startX: pageX,
parentWidth: parentWidth,
parentWidth,
},
},
() => {
@@ -647,7 +638,7 @@ export default Base =>
document.addEventListener('mouseup', this.resizeColumnEnd)
document.addEventListener('mouseleave', this.resizeColumnEnd)
}
}
},
)
}
@@ -667,10 +658,11 @@ export default Base =>
pageX = event.pageX
}
// Set the min size to 10 to account for margin and border or else the group headers don't line up correctly
// Set the min size to 10 to account for margin and border or else the
// group headers don't line up correctly
const newWidth = Math.max(
currentlyResizing.parentWidth + pageX - currentlyResizing.startX,
11
11,
)
newResized.push({
@@ -682,15 +674,15 @@ export default Base =>
{
resized: newResized,
},
() => {
() => (
onResizedChange && onResizedChange(newResized, event)
}
),
)
}
resizeColumnEnd (event) {
event.stopPropagation()
let isTouch = event.type === 'touchend' || event.type === 'touchcancel'
const isTouch = event.type === 'touchend' || event.type === 'touchcancel'
if (isTouch) {
document.removeEventListener('touchmove', this.resizeColumnMoving)
+18 -19
View File
@@ -4,7 +4,7 @@ import classnames from 'classnames'
// import _ from './utils'
const defaultButton = props => (
<button type='button' {...props} className='-btn'>
<button type="button" {...props} className="-btn">
{props.children}
</button>
)
@@ -42,7 +42,7 @@ export default class ReactTablePagination extends Component {
}
applyPage (e) {
e && e.preventDefault()
if (e) { e.preventDefault() }
const page = this.state.page
this.changePage(page === '' ? this.props.page : page)
}
@@ -70,9 +70,9 @@ export default class ReactTablePagination extends Component {
className={classnames(className, '-pagination')}
style={this.props.paginationStyle}
>
<div className='-previous'>
<div className="-previous">
<PreviousComponent
onClick={e => {
onClick={() => {
if (!canPrevious) return
this.changePage(page - 1)
}}
@@ -81,11 +81,11 @@ export default class ReactTablePagination extends Component {
{this.props.previousText}
</PreviousComponent>
</div>
<div className='-center'>
<span className='-pageInfo'>
<div className="-center">
<span className="-pageInfo">
{this.props.pageText}{' '}
{showPageJump
? <div className='-pageJump'>
? <div className="-pageJump">
<input
type={this.state.page === '' ? 'text' : 'number'}
onChange={e => {
@@ -105,31 +105,30 @@ export default class ReactTablePagination extends Component {
}}
/>
</div>
: <span className='-currentPage'>
: <span className="-currentPage">
{page + 1}
</span>}{' '}
{this.props.ofText}{' '}
<span className='-totalPages'>{pages || 1}</span>
<span className="-totalPages">{pages || 1}</span>
</span>
{showPageSizeOptions &&
<span className='select-wrap -pageSizeOptions'>
<span className="select-wrap -pageSizeOptions">
<select
onChange={e => onPageSizeChange(Number(e.target.value))}
value={pageSize}
>
{pageSizeOptions.map((option, i) => {
return (
<option key={i} value={option}>
{option} {this.props.rowsText}
</option>
)
})}
{pageSizeOptions.map((option, i) => (
// eslint-disable-next-line react/no-array-index-key
<option key={i} value={option}>
{option} {this.props.rowsText}
</option>
))}
</select>
</span>}
</div>
<div className='-next'>
<div className="-next">
<NextComponent
onClick={e => {
onClick={() => {
if (!canNext) return
this.changePage(page + 1)
}}
+15 -14
View File
@@ -1,4 +1,4 @@
import PropTypes from "prop-types";
import PropTypes from 'prop-types'
export default {
// General
@@ -85,37 +85,37 @@ export default {
Cell: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func
PropTypes.func,
]),
Header: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func
PropTypes.func,
]),
Footer: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func
PropTypes.func,
]),
Aggregated: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func
PropTypes.func,
]),
Pivot: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func
PropTypes.func,
]),
PivotValue: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func
PropTypes.func,
]),
Expander: PropTypes.oneOfType([
PropTypes.element,
PropTypes.string,
PropTypes.func
PropTypes.func,
]),
Filter: PropTypes.oneOfType([PropTypes.element, PropTypes.func]),
@@ -145,8 +145,8 @@ export default {
getFooterProps: PropTypes.object,
filterMethod: PropTypes.func,
filterAll: PropTypes.bool,
sortMethod: PropTypes.func
})
sortMethod: PropTypes.func,
}),
),
// Global Expander Column Defaults
@@ -154,7 +154,7 @@ export default {
sortable: PropTypes.bool,
resizable: PropTypes.bool,
filterable: PropTypes.bool,
width: PropTypes.number
width: PropTypes.number,
}),
pivotDefaults: PropTypes.object,
@@ -181,7 +181,8 @@ export default {
ExpanderComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
PivotValueComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
AggregatedComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
PivotComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]), // this is a computed default generated using
// this is a computed default generated using
PivotComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
// the ExpanderComponent and PivotValueComponent at run-time in methods.js
PaginationComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
PreviousComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
@@ -189,5 +190,5 @@ export default {
LoadingComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
NoDataComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
ResizerComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
PadRowComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element])
};
PadRowComponent: PropTypes.oneOfType([PropTypes.func, PropTypes.element]),
}
+18 -15
View File
@@ -30,7 +30,9 @@ function get (obj, path, def) {
let val
try {
val = pathObj.reduce((current, pathPart) => current[pathPart], obj)
} catch (e) {}
} catch (e) {
// continue regardless of error
}
return typeof val !== 'undefined' ? val : def
}
@@ -59,7 +61,7 @@ function last (arr) {
function range (n) {
const arr = []
for (let i = 0; i < n; i++) {
for (let i = 0; i < n; i += 1) {
arr.push(n)
}
return arr
@@ -67,7 +69,7 @@ function range (n) {
function orderBy (arr, funcs, dirs, indexKey) {
return arr.sort((rowA, rowB) => {
for (let i = 0; i < funcs.length; i++) {
for (let i = 0; i < funcs.length; i += 1) {
const comp = funcs[i]
const desc = dirs[i] === false || dirs[i] === 'desc'
const sortInt = comp(rowA, rowB)
@@ -83,8 +85,8 @@ function orderBy (arr, funcs, dirs, indexKey) {
}
function remove (a, b) {
return a.filter(function (o, i) {
var r = b(o)
return a.filter((o, i) => {
const r = b(o)
if (r) {
a.splice(i, 1)
return true
@@ -101,7 +103,7 @@ function clone (a) {
return value.toString()
}
return value
})
}),
)
} catch (e) {
return a
@@ -109,7 +111,7 @@ function clone (a) {
}
function getFirstDefined (...args) {
for (var i = 0; i < args.length; i++) {
for (let i = 0; i < args.length; i += 1) {
if (typeof args[i] !== 'undefined') {
return args[i]
}
@@ -117,9 +119,9 @@ function getFirstDefined (...args) {
}
function sum (arr) {
return arr.reduce((a, b) => {
return a + b
}, 0)
return arr.reduce((a, b) => (
a + b
), 0)
}
function makeTemplateComponent (compClass, displayName) {
@@ -146,7 +148,7 @@ function groupBy (xs, key) {
function asPx (value) {
value = Number(value)
return Number.isNaN(value) ? null : value + 'px'
return Number.isNaN(value) ? null : `${value}px`
}
function isArray (a) {
@@ -169,7 +171,7 @@ function flattenDeep (arr, newArr = []) {
if (!isArray(arr)) {
newArr.push(arr)
} else {
for (var i = 0; i < arr.length; i++) {
for (let i = 0; i < arr.length; i += 1) {
flattenDeep(arr[i], newArr)
}
}
@@ -186,15 +188,16 @@ function splitProps ({ className, style, ...rest }) {
function compactObject (obj) {
const newObj = {}
for (var key in obj) {
Object.keys(obj).map(key => {
if (
obj.hasOwnProperty(key) &&
Object.prototype.hasOwnProperty.call(obj, key) &&
obj[key] !== undefined &&
typeof obj[key] !== 'undefined'
) {
newObj[key] = obj[key]
}
}
return true
})
return newObj
}