Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid - Hides the 'between' operation for a lookup column (T889066) #13156

Merged
merged 3 commits into from
May 22, 2020
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
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