mirror of
https://github.com/gosticks/react-table.git
synced 2026-10-04 14:56:59 +00:00
fix: fix path getters, better plugin hook integration, renaming things
This commit is contained in:
@@ -17,7 +17,7 @@ addActions('toggleExpanded', 'useExpanded')
|
||||
|
||||
const propTypes = {
|
||||
manualExpandedKey: PropTypes.string,
|
||||
nestExpandedRows: PropTypes.bool,
|
||||
paginateExpandedRows: PropTypes.bool,
|
||||
}
|
||||
|
||||
export const useExpanded = hooks => {
|
||||
@@ -34,16 +34,16 @@ function useMain(instance) {
|
||||
debug,
|
||||
rows,
|
||||
manualExpandedKey = 'expanded',
|
||||
paginateExpandedRows = true,
|
||||
hooks,
|
||||
state: [{ expanded }, setState],
|
||||
nestExpandedRows,
|
||||
} = instance
|
||||
|
||||
const toggleExpandedByPath = (path, set) => {
|
||||
return setState(old => {
|
||||
const { expanded } = old
|
||||
const existing = getBy(expanded, path)
|
||||
set = getFirstDefined(set, !existing)
|
||||
set = getFirstDefined(set, existing ? undefined : true)
|
||||
return {
|
||||
...old,
|
||||
expanded: setBy(expanded, path, set),
|
||||
@@ -85,13 +85,16 @@ function useMain(instance) {
|
||||
(row.original && row.original[manualExpandedKey]) ||
|
||||
getBy(expanded, row.path)
|
||||
|
||||
if (!nestExpandedRows || (nestExpandedRows && row.depth === 0)) {
|
||||
expandedRows.push(row)
|
||||
}
|
||||
expandedRows.push(row)
|
||||
|
||||
row.canExpand = row.subRows && !!row.subRows.length
|
||||
|
||||
if (row.isExpanded && row.subRows && row.subRows.length) {
|
||||
if (
|
||||
paginateExpandedRows &&
|
||||
row.isExpanded &&
|
||||
row.subRows &&
|
||||
row.subRows.length
|
||||
) {
|
||||
row.subRows.forEach(handleRow)
|
||||
}
|
||||
|
||||
@@ -101,7 +104,7 @@ function useMain(instance) {
|
||||
rows.forEach(handleRow)
|
||||
|
||||
return expandedRows
|
||||
}, [debug, rows, manualExpandedKey, expanded, nestExpandedRows])
|
||||
}, [debug, rows, manualExpandedKey, expanded, paginateExpandedRows])
|
||||
|
||||
const expandedDepth = findExpandedDepth(expanded)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user