fix(usefilters): fix filter type fallback and autoRemove functionality AGAIN

This commit is contained in:
tannerlinsley
2019-07-26 11:22:23 -06:00
parent 8988660618
commit 24f6a2750d
3 changed files with 11 additions and 8 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
module.exports = {
hooks: {
'pre-commit': 'lint-staged',
'prepare-commit-msg': 'exec < /dev/tty && git cz --hook',
// 'prepare-commit-msg': 'exec < /dev/tty && git cz --hook',
},
}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "react-table",
"version": "7.0.0-alpha.10",
"version": "7.0.0-alpha.11",
"description": "A fast, lightweight, opinionated table and datagrid built on React",
"license": "MIT",
"homepage": "https://github.com/tannerlinsley/react-table#readme",
+9 -6
View File
@@ -48,14 +48,12 @@ export const useFilters = props => {
filterTypes
)
const { autoRemove } = filterMethod
return setState(old => {
const newFilter =
typeof updater === 'function' ? updater(old.filters[id]) : updater
//
if (shouldAutoRemove(autoRemove, newFilter)) {
if (shouldAutoRemove(filterMethod.autoRemove, newFilter)) {
const { [id]: remove, ...newFilters } = old.filters
return {
...old,
@@ -81,13 +79,13 @@ export const useFilters = props => {
Object.keys(newFilters).forEach(id => {
const newFilter = newFilters[id]
const column = columns.find(d => d.id === id)
const autoRemove = getFilterMethod(
const filterMethod = getFilterMethod(
column.filter,
userFilterTypes || {},
filterTypes
)
if (shouldAutoRemove(autoRemove, newFilter)) {
if (shouldAutoRemove(filterMethod.autoRemove, newFilter)) {
delete newFilters[id]
}
})
@@ -220,5 +218,10 @@ function shouldAutoRemove(autoRemove, value) {
}
function getFilterMethod(filter, userFilterTypes, filterTypes) {
return isFunction(filter) || userFilterTypes[filter] || filterTypes[filter]
return (
isFunction(filter) ||
userFilterTypes[filter] ||
filterTypes[filter] ||
filterTypes.text
)
}