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

fix(core): range default should be inclusive instead of exclusive #654

Merged
merged 1 commit into from
Dec 17, 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
8 changes: 4 additions & 4 deletions src/app/examples/grid-range.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export class GridRangeComponent implements OnInit, OnDestroy {
</ul>
<ul>
<li>note that the examples shown below for the operator, are case sensitive</li>
<li>by default the range are not inclusive which would be the same as defining the filter options to "operator: 'RangeExclusive'" or "operator: OperatoryType.rangeExclusive"</li>
<li>you can also set the inverse (inclusive) by defining the filter options to "operator: 'RangeInclusive'" or "operator: OperatoryType.rangeIncluside"</li>
<li>by default the range is inclusive which would be the same as defining the filter options to "operator: 'RangeInclusive'" or "operator: OperatoryType.rangeInclusive"</li>
<li>you can also set the inverse (exclusive) by defining the filter options to "operator: 'RangeExclusive'" or "operator: OperatoryType.rangeExclusive"</li>
</ul>
<li>Date Range with Flatpickr Date Picker, they will also use the locale, choose a start date then drag or click on the end date</li>
</ul>
Expand Down Expand Up @@ -108,7 +108,7 @@ export class GridRangeComponent implements OnInit, OnDestroy {
filter: {
model: Filters.sliderRange,
maxValue: 100, // or you can use the filterOptions as well
operator: OperatorType.rangeInclusive, // defaults to exclusive
operator: OperatorType.rangeInclusive, // defaults to inclusive
params: { hideSliderNumbers: false }, // you can hide/show the slider numbers on both side
filterOptions: { min: 0, step: 5 } as JQueryUiSliderOption // you can also optionally pass any option of the jQuery UI Slider
}
Expand All @@ -131,7 +131,7 @@ export class GridRangeComponent implements OnInit, OnDestroy {
sortable: true,
filterable: true, filter: {
model: Filters.input,
operator: OperatorType.rangeExclusive // defaults to exclusive
operator: OperatorType.rangeExclusive // defaults to inclusive
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ describe('SliderRangeFilter', () => {
filter.init(filterArguments);
filter.setValues(['2..80']);

expect(spyCallback).toHaveBeenLastCalledWith(expect.anything(), { columnDef: mockColumn, operator: 'RangeExclusive', searchTerms: [2, 80], shouldTriggerQuery: true });
expect(spyCallback).toHaveBeenLastCalledWith(expect.anything(), { columnDef: mockColumn, operator: 'RangeInclusive', searchTerms: [2, 80], shouldTriggerQuery: true });
});

it('should call "setValues" and expect that value to be in the callback when triggered', () => {
Expand All @@ -127,7 +127,7 @@ describe('SliderRangeFilter', () => {
filter.init(filterArguments);
filter.setValues([3, 84]);

expect(spyCallback).toHaveBeenLastCalledWith(expect.anything(), { columnDef: mockColumn, operator: 'RangeExclusive', searchTerms: [3, 84], shouldTriggerQuery: true });
expect(spyCallback).toHaveBeenLastCalledWith(expect.anything(), { columnDef: mockColumn, operator: 'RangeInclusive', searchTerms: [3, 84], shouldTriggerQuery: true });
});

it('should create the input filter with default search terms range when passed as a filter argument', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class DateRangeFilter implements Filter {

/** Getter to know what would be the default operator when none is specified */
get defaultOperator(): OperatorType | OperatorString {
return this.gridOptions.defaultFilterRangeOperator || OperatorType.rangeExclusive;
return this.gridOptions.defaultFilterRangeOperator || OperatorType.rangeInclusive;
}

/** Getter for the Flatpickr Options */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class SliderRangeFilter implements Filter {

/** Getter to know what would be the default operator when none is specified */
get defaultOperator(): OperatorType | OperatorString {
return this.gridOptions.defaultFilterRangeOperator || OperatorType.rangeExclusive;
return this.gridOptions.defaultFilterRangeOperator || OperatorType.rangeInclusive;
}

/** Getter for the Grid Options pulled through the Grid Object */
Expand Down
2 changes: 1 addition & 1 deletion src/app/modules/angular-slickgrid/global-grid-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const GlobalGridOptions: Partial<GridOption> = {
defaultFilter: Filters.input,
enableFilterTrimWhiteSpace: false, // do we want to trim white spaces on all Filters?
defaultFilterPlaceholder: '&#128269;',
defaultFilterRangeOperator: OperatorType.rangeExclusive,
defaultFilterRangeOperator: OperatorType.rangeInclusive,
editable: false,
enableAutoResize: true,
enableAutoSizeColumns: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export interface GridOption {
/** Default placeholder to use in Filters that support placeholder (autocomplete, input, flatpickr, select, ...) */
defaultFilterPlaceholder?: string;

/** Defaults to 'RangeExclusive', allows to change the default filter range operator */
/** Defaults to 'RangeInclusive', allows to change the default filter range operator */
defaultFilterRangeOperator?: OperatorString | OperatorType;

/** Draggable Grouping Plugin options & events */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ describe('GraphqlService', () => {
});

it('should return a query with search having a range of exclusive numbers when the search value contains 2 (..) to represent a range of numbers', () => {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:duration, operator:GT, value:"2"}, {field:duration, operator:LT, value:"33"}]) { totalCount,nodes{ id,company,gender,name } }}`;
const expectation = `query{users(first:10, offset:0, filterBy:[{field:duration, operator:GE, value:"2"}, {field:duration, operator:LE, value:"33"}]) { totalCount,nodes{ id,company,gender,name } }}`;
const mockColumn = { id: 'duration', field: 'duration' } as Column;
const mockColumnFilters = {
duration: { columnId: 'duration', columnDef: mockColumn, searchTerms: ['2..33'] },
Expand Down Expand Up @@ -856,7 +856,7 @@ describe('GraphqlService', () => {
});

it('should return a query with search having a range of exclusive dates when the search value contains 2 (..) to represent a range of dates', () => {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:startDate, operator:GT, value:"2001-01-01"}, {field:startDate, operator:LT, value:"2001-01-31"}]) { totalCount,nodes{ id,company,gender,name } }}`;
const expectation = `query{users(first:10, offset:0, filterBy:[{field:startDate, operator:GE, value:"2001-01-01"}, {field:startDate, operator:LE, value:"2001-01-31"}]) { totalCount,nodes{ id,company,gender,name } }}`;
const mockColumn = { id: 'startDate', field: 'startDate' } as Column;
const mockColumnFilters = {
startDate: { columnId: 'startDate', columnDef: mockColumn, searchTerms: ['2001-01-01..2001-01-31'] },
Expand Down Expand Up @@ -1037,7 +1037,7 @@ describe('GraphqlService', () => {
});

it('should return a query with search having a range of exclusive numbers when the search value contains 2 (..) to represent a range of numbers', () => {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:duration, operator:GT, value:"2"}, {field:duration, operator:LT, value:"33"}]) {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:duration, operator:GE, value:"2"}, {field:duration, operator:LE, value:"33"}]) {
totalCount,nodes{ id,company,gender,duration,startDate } }}`;
const presetFilters = [
{ columnId: 'duration', searchTerms: ['2..33'] },
Expand All @@ -1053,7 +1053,7 @@ describe('GraphqlService', () => {
});

it('should return a query with a filter with range of numbers with decimals when the preset is a filter range with 3 dots (..) separator', () => {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:duration, operator:GT, value:"0.5"}, {field:duration, operator:LT, value:".88"}]) { totalCount,nodes{ id,company,gender,duration,startDate } }}`;
const expectation = `query{users(first:10, offset:0, filterBy:[{field:duration, operator:GE, value:"0.5"}, {field:duration, operator:LE, value:".88"}]) { totalCount,nodes{ id,company,gender,duration,startDate } }}`;
const presetFilters = [
{ columnId: 'duration', searchTerms: ['0.5...88'] },
] as CurrentFilter[];
Expand Down Expand Up @@ -1083,7 +1083,7 @@ describe('GraphqlService', () => {
});

it('should return a query with search having a range of exclusive numbers when 2 searchTerms numbers are provided without any operator', () => {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:duration, operator:GT, value:2}, {field:duration, operator:LT, value:33}]) { totalCount,nodes{ id,company,gender,duration,startDate } }}`;
const expectation = `query{users(first:10, offset:0, filterBy:[{field:duration, operator:GE, value:2}, {field:duration, operator:LE, value:33}]) { totalCount,nodes{ id,company,gender,duration,startDate } }}`;
const presetFilters = [
{ columnId: 'duration', searchTerms: [2, 33] },
] as CurrentFilter[];
Expand All @@ -1098,7 +1098,7 @@ describe('GraphqlService', () => {
});

it('should return a query with search having a range of exclusive dates when the search value contains 2 (..) to represent a range of dates', () => {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:startDate, operator:GT, value:"2001-01-01"}, {field:startDate, operator:LT, value:"2001-01-31"}]) { totalCount,nodes{ id,company,gender,duration,startDate } }}`;
const expectation = `query{users(first:10, offset:0, filterBy:[{field:startDate, operator:GE, value:"2001-01-01"}, {field:startDate, operator:LE, value:"2001-01-31"}]) { totalCount,nodes{ id,company,gender,duration,startDate } }}`;
const presetFilters = [
{ columnId: 'startDate', searchTerms: ['2001-01-01..2001-01-31'] },
] as CurrentFilter[];
Expand Down Expand Up @@ -1128,7 +1128,7 @@ describe('GraphqlService', () => {
});

it('should return a query with search having a range of exclusive dates when 2 searchTerms dates are provided without any operator', () => {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:startDate, operator:GT, value:"2001-01-01"}, {field:startDate, operator:LT, value:"2001-01-31"}]) { totalCount,nodes{ id,company,gender,duration,startDate } }}`;
const expectation = `query{users(first:10, offset:0, filterBy:[{field:startDate, operator:GE, value:"2001-01-01"}, {field:startDate, operator:LE, value:"2001-01-31"}]) { totalCount,nodes{ id,company,gender,duration,startDate } }}`;
const presetFilters = [
{ columnId: 'startDate', searchTerms: ['2001-01-01', '2001-01-31'] },
] as CurrentFilter[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const DEFAULT_ITEMS_PER_PAGE = 25;
const DEFAULT_PAGE_SIZE = 20;

const gridOptionMock = {
defaultFilterRangeOperator: 'RangeExclusive',
defaultFilterRangeOperator: 'RangeInclusive',
enablePagination: true,
backendServiceApi: {
service: undefined,
Expand Down Expand Up @@ -1409,7 +1409,7 @@ describe('GridOdataService', () => {

it('should return a query with a filter with range of numbers when the preset is a filter range with 2 dots (..) separator', () => {
serviceOptions.columnDefinitions = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'duration', field: 'duration', type: FieldType.number }];
const expectation = `$top=10&$filter=(Duration gt 4 and Duration lt 88)`;
const expectation = `$top=10&$filter=(Duration ge 4 and Duration le 88)`;
const presetFilters = [
{ columnId: 'duration', searchTerms: ['4..88'] },
] as CurrentFilter[];
Expand All @@ -1425,7 +1425,7 @@ describe('GridOdataService', () => {

it('should return a query with a filter with range of numbers with decimals when the preset is a filter range with 3 dots (...) separator', () => {
serviceOptions.columnDefinitions = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'duration', field: 'duration', type: FieldType.number }];
const expectation = `$top=10&$filter=(Duration gt 0.5 and Duration lt .88)`;
const expectation = `$top=10&$filter=(Duration ge 0.5 and Duration le .88)`;
const presetFilters = [
{ columnId: 'duration', searchTerms: ['0.5...88'] },
] as CurrentFilter[];
Expand Down Expand Up @@ -1457,7 +1457,7 @@ describe('GridOdataService', () => {

it('should return a query with a filter with range of dates when the preset is a filter range with 2 dots (..) separator', () => {
serviceOptions.columnDefinitions = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'finish', field: 'finish', type: FieldType.date }];
const expectation = `$top=10&$filter=(Finish gt DateTime'2001-01-01T00:00:00Z' and Finish lt DateTime'2001-01-31T00:00:00Z')`;
const expectation = `$top=10&$filter=(Finish ge DateTime'2001-01-01T00:00:00Z' and Finish le DateTime'2001-01-31T00:00:00Z')`;
const presetFilters = [
{ columnId: 'finish', searchTerms: ['2001-01-01..2001-01-31'] },
] as CurrentFilter[];
Expand Down Expand Up @@ -1489,7 +1489,7 @@ describe('GridOdataService', () => {

it('should return a query with a filter with range of dates inclusive when the preset is a filter range with 2 searchTerms without an operator', () => {
serviceOptions.columnDefinitions = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'finish', field: 'finish', type: FieldType.date }];
const expectation = `$top=10&$filter=(Finish gt DateTime'2001-01-01T00:00:00Z' and Finish lt DateTime'2001-01-31T00:00:00Z')`;
const expectation = `$top=10&$filter=(Finish ge DateTime'2001-01-01T00:00:00Z' and Finish le DateTime'2001-01-31T00:00:00Z')`;
const presetFilters = [
{ columnId: 'finish', searchTerms: ['2001-01-01', '2001-01-31'] },
] as CurrentFilter[];
Expand Down Expand Up @@ -1526,7 +1526,7 @@ describe('GridOdataService', () => {

it('should return a query with a filter with range of numbers when the preset is a filter range with 2 dots (..) separator but without pagination when "enablePagination" is set to False', () => {
serviceOptions.columnDefinitions = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'duration', field: 'duration', type: FieldType.number }];
const expectation = `$filter=(Duration gt 4 and Duration lt 88)`;
const expectation = `$filter=(Duration ge 4 and Duration le 88)`;
const presetFilters = [
{ columnId: 'duration', searchTerms: ['4..88'] },
] as CurrentFilter[];
Expand Down
4 changes: 2 additions & 2 deletions src/app/modules/angular-slickgrid/services/graphql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ export class GraphqlService implements BackendService {
if (Array.isArray(searchTerms) && searchTerms.length === 1 && typeof searchTerms[0] === 'string' && searchTerms[0].indexOf('..') > 0) {
searchTerms = searchTerms[0].split('..');
if (!operator) {
operator = OperatorType.rangeExclusive;
operator = OperatorType.rangeInclusive;
}
}

Expand All @@ -429,7 +429,7 @@ export class GraphqlService implements BackendService {
searchValue = searchTerms.join(',');
} else if (searchTerms && searchTerms.length === 2 && (!operator || operator === OperatorType.rangeExclusive || operator === OperatorType.rangeInclusive)) {
if (!operator) {
operator = OperatorType.rangeExclusive;
operator = OperatorType.rangeInclusive;
}
searchByArray.push({ field: fieldName, operator: (operator === OperatorType.rangeInclusive ? 'GE' : 'GT'), value: searchTerms[0] });
searchByArray.push({ field: fieldName, operator: (operator === OperatorType.rangeInclusive ? 'LE' : 'LT'), value: searchTerms[1] });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class GridOdataService implements BackendService {
if (Array.isArray(searchTerms) && searchTerms.length === 1 && typeof searchTerms[0] === 'string' && searchTerms[0].indexOf('..') > 0) {
searchTerms = searchTerms[0].split('..');
if (!operator) {
operator = OperatorType.rangeExclusive;
operator = OperatorType.rangeInclusive;
}
}

Expand Down