Skip to content

Commit

Permalink
DataGrid - Hides the 'between' operation for a lookup column (T889066) (
Browse files Browse the repository at this point in the history
  • Loading branch information
NickMitrokhin committed May 22, 2020
1 parent 4b390c9 commit e379f9e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
3 changes: 2 additions & 1 deletion js/ui/filter_builder/between.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ function getConfig(caption, context) {
icon: 'range',
valueSeparator: SEPARATOR,
dataTypes: ['number', 'date', 'datetime'],
editorTemplate: editorTemplate.bind(context)
editorTemplate: editorTemplate.bind(context),
notForLookup: true
};
}

Expand Down
5 changes: 3 additions & 2 deletions js/ui/filter_builder/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ function getCustomOperation(customOperations, name) {

function getAvailableOperations(field, filterOperationDescriptions, customOperations) {
const filterOperations = getFilterOperations(field);

const isLookupField = !!field.lookup;
customOperations.forEach(function(customOperation) {
if(!field.filterOperations && filterOperations.indexOf(customOperation.name) === -1) {
const dataTypes = customOperation && customOperation.dataTypes;
if(dataTypes && dataTypes.indexOf(field.dataType || DEFAULT_DATA_TYPE) >= 0) {
const isOperationForbidden = isLookupField ? !!customOperation.notForLookup : false;
if(!isOperationForbidden && dataTypes && dataTypes.indexOf(field.dataType || DEFAULT_DATA_TYPE) >= 0) {
filterOperations.push(customOperation.name);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ const groupOperations = [{
value: '!or'
}];
const filterOperationsDescriptions = {
between: 'Is between',
contains: 'Contains',
endsWith: 'Ends with',
equal: 'Equals',
notEqual: 'Does not equal',
lessThan: 'Is less than',
lessThanOrEqual: 'Is less than or equal to',
greaterThan: 'Is greater than',
greaterThanOrEqual: 'Is greater than or equal to',
startsWith: 'Starts with',
contains: 'Contains',
notContains: 'Does not contain',
endsWith: 'Ends with',
isBlank: 'Is blank',
isNotBlank: 'Is not blank'
isNotBlank: 'Is not blank',
lessThan: 'Is less than',
lessThanOrEqual: 'Is less than or equal to',
notContains: 'Does not contain',
notEqual: 'Does not equal',
startsWith: 'Starts with'
};

QUnit.module('Errors', function() {
Expand Down Expand Up @@ -1121,6 +1122,54 @@ QUnit.module('getAvailableOperations', {
// assert
assert.strictEqual(operations[0].text, 'Last Days');
});

// T889066
QUnit.test('a custom operation with enabled notForLookup option should not be listed for a lookup column', function(assert) {
// arrange, act
const customOperations = [
{
name: 'test1',
notForLookup: true,
dataTypes: ['number']
},
{
name: 'test2',
notForLookup: false,
dataTypes: ['number']
},
{
name: 'test3',
dataTypes: ['number']
}
];
const field1 = {
dataField: 'test',
dataType: 'number'
};
const field2 = {
dataField: 'test',
dataType: 'number',
lookup: {}
};

// act
let operations = utils.getAvailableOperations(field1, filterOperationsDescriptions, customOperations);
let operationValues = operations.map(operation => operation.value);

// assert
assert.ok(operationValues.indexOf('test1') >= 0, 'test1 is in the list');
assert.ok(operationValues.indexOf('test2') >= 0, 'test2 is in the list');
assert.ok(operationValues.indexOf('test3') >= 0, 'test3 is in the list');

// act
operations = utils.getAvailableOperations(field2, filterOperationsDescriptions, customOperations);
operationValues = operations.map(operation => operation.value);

// assert
assert.equal(operationValues.indexOf('test1'), -1, 'test1 is not listed');
assert.ok(operationValues.indexOf('test2') >= 0, 'test2 is in the list');
assert.ok(operationValues.indexOf('test3') >= 0, 'test3 is in the list');
});
});

QUnit.module('Custom filter expressions', {
Expand Down

0 comments on commit e379f9e

Please sign in to comment.