Case-insensitive filter for text (#4153)

* Case-sensetive filter for text

* Nit

* Resolved merge conflict

* Update: added check if the value is present
This commit is contained in:
Rajat Dabade 2022-11-08 17:21:20 +05:30 committed by GitHub
parent 51a9ca83de
commit 18d3978b82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 8 deletions

View file

@ -335,6 +335,19 @@ describe('src/cardFilter', () => {
expect(result[0]).toEqual(card1)
})
})
describe('verfiy applyFilterGroup method for case-sensitive search', () => {
test('should return array with card1 when search by test as Card1', () => {
const filterClauseNotContains = createFilterClause({propertyId: 'title', condition: 'contains', values: ['Card1']})
const filterGroup = createFilterGroup({
operation: 'and',
filters: [
filterClauseNotContains,
],
})
const result = CardFilter.applyFilterGroup(filterGroup, [], [card1])
expect(result.length).toEqual(1)
})
})
describe('verify applyFilter for title', () => {
test('should not return array with card1', () => {
const filterClauseNotContains = createFilterClause({propertyId: 'title', condition: 'notContains', values: ['card1']})

View file

@ -46,7 +46,7 @@ class CardFilter {
static isClauseMet(filter: FilterClause, templates: readonly IPropertyTemplate[], card: Card): boolean {
let value = card.fields.properties[filter.propertyId]
if (filter.propertyId === 'title') {
value = card.title
value = card.title.toLowerCase()
}
switch (filter.condition) {
case 'includes': {
@ -77,43 +77,43 @@ class CardFilter {
if (filter.values.length === 0) {
return true
}
return filter.values[0] === value
return filter.values[0]?.toLowerCase() === value
}
case 'contains': {
if (filter.values.length === 0) {
return true
}
return (value as string || '').includes(filter.values[0])
return (value as string || '').includes(filter.values[0]?.toLowerCase())
}
case 'notContains': {
if (filter.values.length === 0) {
return true
}
return !(value as string || '').includes(filter.values[0])
return !(value as string || '').includes(filter.values[0]?.toLowerCase())
}
case 'startsWith': {
if (filter.values.length === 0) {
return true
}
return (value as string || '').startsWith(filter.values[0])
return (value as string || '').startsWith(filter.values[0]?.toLowerCase())
}
case 'notStartsWith': {
if (filter.values.length === 0) {
return true
}
return !(value as string || '').startsWith(filter.values[0])
return !(value as string || '').startsWith(filter.values[0]?.toLowerCase())
}
case 'endsWith': {
if (filter.values.length === 0) {
return true
}
return (value as string || '').endsWith(filter.values[0])
return (value as string || '').endsWith(filter.values[0]?.toLowerCase())
}
case 'notEndsWith': {
if (filter.values.length === 0) {
return true
}
return !(value as string || '').endsWith(filter.values[0])
return !(value as string || '').endsWith(filter.values[0]?.toLowerCase())
}
default: {
Utils.assertFailure(`Invalid filter condition ${filter.condition}`)