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 #203

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
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,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 @@ -126,7 +126,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
2 changes: 1 addition & 1 deletion packages/common/src/filters/dateRangeFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,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
2 changes: 1 addition & 1 deletion packages/common/src/filters/sliderRangeFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,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 packages/common/src/global-grid-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const GlobalGridOptions: GridOption = {
defaultFilter: Filters.input,
enableFilterTrimWhiteSpace: false, // do we want to trim white spaces on all Filters?
defaultFilterPlaceholder: '🔍',
defaultFilterRangeOperator: OperatorType.rangeExclusive,
defaultFilterRangeOperator: OperatorType.rangeInclusive,
defaultColumnSortFieldId: 'id',
defaultComponentEventPrefix: '',
defaultSlickgridEventPrefix: '',
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/gridOption.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,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;

/** Default prefix for SlickGrid Event names (events created in the SlickGrid and/or DataView objects) */
Expand Down
14 changes: 7 additions & 7 deletions packages/graphql/src/services/__tests__/graphql.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,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 @@ -880,7 +880,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 @@ -1062,7 +1062,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 @@ -1078,7 +1078,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 @@ -1108,7 +1108,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 @@ -1123,7 +1123,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 @@ -1153,7 +1153,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
4 changes: 2 additions & 2 deletions packages/graphql/src/services/graphql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,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 @@ -439,7 +439,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 @@ -1418,7 +1418,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', () => {
const columns = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'duration', field: 'duration', type: FieldType.number }];
jest.spyOn(gridStub, 'getColumns').mockReturnValue(columns);
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 @@ -1435,7 +1435,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', () => {
const columns = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'duration', field: 'duration', type: FieldType.number }];
jest.spyOn(gridStub, 'getColumns').mockReturnValue(columns);
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 @@ -1469,7 +1469,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', () => {
const columns = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'finish', field: 'finish', type: FieldType.date }];
jest.spyOn(gridStub, 'getColumns').mockReturnValue(columns);
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 @@ -1541,7 +1541,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', () => {
const columns = [{ id: 'company', field: 'company' }, { id: 'gender', field: 'gender' }, { id: 'duration', field: 'duration', type: FieldType.number }];
jest.spyOn(gridStub, 'getColumns').mockReturnValue(columns);
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
2 changes: 1 addition & 1 deletion packages/odata/src/services/grid-odata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,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