Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/table-core/src/fns/filterFns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ const filterFn_between = Object.assign(
Number(filterValues[0]) > Number(filterValues[1])) ||
(['', undefined] as Array<any>).includes(filterValues[1]) ||
filterFn_lessThan(row, columnId, filterValues[1])),
{ autoRemove: (val: any) => !val },
{
autoRemove: (val: any) =>
testFalsy(val) || (testFalsy(val[0]) && testFalsy(val[1])),
},
)

/**
Expand All @@ -238,7 +241,10 @@ const filterFn_betweenInclusive = Object.assign(
Number(filterValues[0]) > Number(filterValues[1])) ||
(['', undefined] as Array<any>).includes(filterValues[1]) ||
filterFn_lessThanOrEqualTo(row, columnId, filterValues[1])),
{ autoRemove: (val: any) => !val },
{
autoRemove: (val: any) =>
testFalsy(val) || (testFalsy(val[0]) && testFalsy(val[1])),
},
)

/**
Expand Down
51 changes: 51 additions & 0 deletions packages/table-core/tests/unit/fns/filterFns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
filterFn_lessThan,
filterFn_lessThanOrEqualTo,
filterFn_weakEquals,
filterFns,
} from '../../../src'
import { getStaticTestData } from '../../fixtures/data/generateTestData'

Expand Down Expand Up @@ -512,4 +513,54 @@ describe('Filter Functions', () => {
})
})
})

describe('Range Filters', () => {
describe('filterFns.between.autoRemove', () => {
const autoRemove = filterFns.between.autoRemove!

it('should auto-remove when both endpoints are undefined', () => {
expect(autoRemove([undefined, undefined])).toBe(true)
})
it('should auto-remove when both endpoints are null', () => {
expect(autoRemove([null, null])).toBe(true)
})
it('should auto-remove when both endpoints are empty strings', () => {
expect(autoRemove(['', ''])).toBe(true)
})
it('should NOT auto-remove when both endpoints are valid numbers', () => {
expect(autoRemove([5, 10])).toBe(false)
})
it('should NOT auto-remove when lower bound is 0 (falsy number)', () => {
expect(autoRemove([0, 10])).toBe(false)
})
it('should NOT auto-remove when only one endpoint is provided', () => {
expect(autoRemove([undefined, 10])).toBe(false)
expect(autoRemove([5, undefined])).toBe(false)
})
})

describe('filterFns.betweenInclusive.autoRemove', () => {
const autoRemove = filterFns.betweenInclusive.autoRemove!

it('should auto-remove when both endpoints are undefined', () => {
expect(autoRemove([undefined, undefined])).toBe(true)
})
it('should auto-remove when both endpoints are null', () => {
expect(autoRemove([null, null])).toBe(true)
})
it('should auto-remove when both endpoints are empty strings', () => {
expect(autoRemove(['', ''])).toBe(true)
})
it('should NOT auto-remove when both endpoints are valid numbers', () => {
expect(autoRemove([5, 10])).toBe(false)
})
it('should NOT auto-remove when lower bound is 0 (falsy number)', () => {
expect(autoRemove([0, 10])).toBe(false)
})
it('should NOT auto-remove when only one endpoint is provided', () => {
expect(autoRemove([undefined, 10])).toBe(false)
expect(autoRemove([5, undefined])).toBe(false)
})
})
})
})
Loading