Skip to content

Commit

Permalink
Adds the notForLookup option
Browse files Browse the repository at this point in the history
  • Loading branch information
NickMitrokhin committed May 21, 2020
1 parent c271598 commit 83921d3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 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
10 changes: 4 additions & 6 deletions js/ui/filter_builder/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const DEFAULT_FORMAT = {
'datetime': 'shortDateShortTime'
};
const LOOKUP_OPERATIONS = ['=', '<>', 'isblank', 'isnotblank'];
const FORBIDDEN_LOOKUP_OPERATIONS = ['between'];
const AVAILABLE_FIELD_PROPERTIES = [
'caption',
'customizeText',
Expand Down Expand Up @@ -195,13 +194,12 @@ function getCustomOperation(customOperations, name) {

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

const isLookupField = !!field.lookup;
customOperations.forEach(function(customOperation) {
const isLookupField = !!field.lookup;
const isOperationForbidden = isLookupField ? FORBIDDEN_LOOKUP_OPERATIONS.indexOf(customOperation.name) >= 0 : false;
if(!field.filterOperations && !isOperationForbidden && filterOperations.indexOf(customOperation.name) === -1) {
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 @@ -1124,29 +1124,51 @@ QUnit.module('getAvailableOperations', {
});

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

const operations = utils.getAvailableOperations(field, filterOperationsDescriptions, customOperations);
const betweenOperation = operations.filter(operation => operation.value === 'between');
// 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(betweenOperation.length, 0, 'the \'between\' operation should not be found');
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');
});
});

Expand Down

0 comments on commit 83921d3

Please sign in to comment.