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 2 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
5 changes: 4 additions & 1 deletion js/ui/filter_builder/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ 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 @@ -196,7 +197,9 @@ function getAvailableOperations(field, filterOperationDescriptions, customOperat
const filterOperations = getFilterOperations(field);

customOperations.forEach(function(customOperation) {
if(!field.filterOperations && filterOperations.indexOf(customOperation.name) === -1) {
const isLookupField = !!field.lookup;
const isOperationForbidden = isLookupField ? FORBIDDEN_LOOKUP_OPERATIONS.indexOf(customOperation.name) >= 0 : false;
if(!field.filterOperations && !isOperationForbidden && filterOperations.indexOf(customOperation.name) === -1) {
const dataTypes = customOperation && customOperation.dataTypes;
if(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,32 @@ QUnit.module('getAvailableOperations', {
// assert
assert.strictEqual(operations[0].text, 'Last Days');
});

// T889066
QUnit.test('the \'between\' operation should not be listed for a lookup field (dataType === number)', function(assert) {
// arrange, act
const customOperations = [
{
name: 'between',
dataTypes: ['number']
},
{
name: 'anyof',
dataTypes: ['number']
}
];
const field = {
dataField: 'test',
dataType: 'number',
lookup: {}
};

const operations = utils.getAvailableOperations(field, filterOperationsDescriptions, customOperations);
const betweenOperation = operations.filter(operation => operation.value === 'between');

// assert
assert.equal(betweenOperation.length, 0, 'the \'between\' operation should not be found');
});
});

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