Skip to content

Commit

Permalink
Support case sensitivity option in the dataQuery (24_2) (#27663)
Browse files Browse the repository at this point in the history
Co-authored-by: Rochmar Nicolas (DevExpress) <[email protected]>
Co-authored-by: Mikhail Preyskurantov <[email protected]>
  • Loading branch information
3 people authored Jul 12, 2024
1 parent 52cd9fc commit 8fa33a4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion packages/devextreme/js/core/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ export const toComparable = function(value, caseSensitive, options = {}) {
return value.valueOf();
}

if(!caseSensitive && typeof value === 'string') {
const isCaseSensitive = options?.collatorOptions?.sensitivity === 'case' || caseSensitive;
if(!isCaseSensitive && typeof value === 'string') {
if(options?.collatorOptions?.sensitivity === 'base') {
const REMOVE_DIACRITICAL_MARKS_REGEXP = /[\u0300-\u036f]/g;

Expand Down
5 changes: 3 additions & 2 deletions packages/devextreme/js/data/query.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ export interface Query {

/**
* @docid Utils.query
* @publicName query(array)
* @publicName query(array, queryOptions)
* @param2 queryOptions:object
* @namespace DevExpress.data
* @public
*/
declare function query(array: Array<any>): Query;
declare function query(array: Array<any>, queryOptions?: any): Query;

/**
* @docid Utils.query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,44 @@ QUnit.test('filter with functional getter', function(assert) {
});
});

QUnit.test('filter with undefined "langParams"', function(assert) {
const input = [{ ID: 'AAA', Name: 'Name 2' }, { ID: 'aaa', Name: 'Name 3' }];
const filterLength = QUERY(input).filter(['ID', '=', 'aaa']).toArray().length;
assert.equal(filterLength, 2);
});

QUnit.test('filter with collatorOptions.sensitivity set to "case"', function(assert) {
const input = [{ ID: 'AAA', Name: 'Name 2' }, { ID: 'aaa', Name: 'Name 3' }];

const array = QUERY(input, {
langParams: {
collatorOptions: {
sensitivity: 'case'
}
}
}).filter(['ID', '=', 'aaa']).toArray();

assert.equal(array.length, 1);
assert.equal(array[0].ID, 'aaa');
});

QUnit.test('filter with collatorOptions.sensitivity set to "base"', function(assert) {
const input = [{ ID: 'bbb', Name: 'Name 1' }, { ID: 'ááá', Name: 'Name 2' }, { ID: 'aaa', Name: 'Name 3' }];

const array = QUERY(input, {
langParams: {
collatorOptions: {
sensitivity: 'base'
}
}
}).filter(['ID', '=', 'aaa']).toArray();

assert.equal(array.length, 2);

const containsUnwantedValue = array.some(item => item.ID === 'bbb');
assert.false(containsUnwantedValue);
});

QUnit.test('missing operation means equal', function(assert) {
assert.expect(1);

Expand Down
4 changes: 2 additions & 2 deletions packages/devextreme/ts/dx.all.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6361,9 +6361,9 @@ declare module DevExpress.data {
};
}
/**
* [descr:Utils.query(array)]
* [descr:Utils.query(array, queryOptions)]
*/
export function query(array: Array<any>): Query;
export function query(array: Array<any>, queryOptions?: any): Query;
/**
* [descr:Utils.query(url, queryOptions)]
*/
Expand Down

0 comments on commit 8fa33a4

Please sign in to comment.