Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 959fc38

Browse files
committed
2 parents 19982d0 + a176037 commit 959fc38

File tree

7 files changed

+55
-14
lines changed

7 files changed

+55
-14
lines changed

src/app/modules/angular-slickgrid/filter-conditions/__tests__/dateIsoFilterCondition.spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FieldType, FilterConditionOption } from '../../models/index';
1+
import { FieldType, FilterConditionOption, OperatorType, SearchTerm } from '../../models/index';
22
import { executeDateFilterCondition, getFilterParsedDates } from '../dateFilterCondition';
33
import { executeFilterConditionTest, getParsedSearchTermsByFieldType } from '../filterConditionProcesses';
44

@@ -98,6 +98,20 @@ describe('dateIsoFilterCondition method', () => {
9898
});
9999

100100
describe('date range', () => {
101+
it('should return True when input value is on the inclusive limit range of search terms using 2 dots (..) notation AND no operator provided except a defaultFilterRangeOperator is rangeInclusive', () => {
102+
const searchTerms = ['1993-12-01..1993-12-31'];
103+
const options = { dataKey: '', defaultFilterRangeOperator: OperatorType.rangeInclusive, cellValue: '1993-12-01', fieldType: FieldType.dateIso, searchTerms } as FilterConditionOption;
104+
const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateIso));
105+
expect(output).toBe(true);
106+
});
107+
108+
it('should return False when input value is on the inclusive limit range of search terms using 2 dots (..) notation AND no operator provided except a defaultFilterRangeOperator is rangeExclusive', () => {
109+
const searchTerms = ['1993-12-01..1993-12-31'];
110+
const options = { dataKey: '', defaultFilterRangeOperator: OperatorType.rangeExclusive, cellValue: '1993-12-01', fieldType: FieldType.dateIso, searchTerms } as FilterConditionOption;
111+
const output = executeFilterConditionTest(options, getFilterParsedDates(searchTerms, FieldType.dateIso));
112+
expect(output).toBe(false);
113+
});
114+
101115
it('should return True when input value is in the range of search terms', () => {
102116
const searchTerms = ['1993-12-01..1993-12-31'];
103117
const options = { dataKey: '', operator: 'EQ', cellValue: '1993-12-25', fieldType: FieldType.dateIso, searchTerms } as FilterConditionOption;
@@ -140,14 +154,14 @@ describe('dateIsoFilterCondition method', () => {
140154
it('should return False when no cell value is provided, neither search terms', () => {
141155
const searchTerms = [undefined];
142156
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateIso, cellValue: '' } as FilterConditionOption;
143-
const output = executeDateFilterCondition(options, getParsedSearchTermsByFieldType(searchTerms, FieldType.dateIso) as any[]);
157+
const output = executeDateFilterCondition(options, getParsedSearchTermsByFieldType(searchTerms as unknown as SearchTerm[], FieldType.dateIso) as any[]);
144158
expect(output).toBe(false);
145159
});
146160

147161
it('should return False when any cell value is provided without any search terms', () => {
148162
const searchTerms = [undefined];
149163
const options = { dataKey: '', operator: 'EQ', fieldType: FieldType.dateIso, cellValue: '2000-12-25' } as FilterConditionOption;
150-
const output = executeDateFilterCondition(options, getParsedSearchTermsByFieldType(searchTerms, FieldType.dateIso) as any[]);
164+
const output = executeDateFilterCondition(options, getParsedSearchTermsByFieldType(searchTerms as unknown as SearchTerm[], FieldType.dateIso) as any[]);
151165
expect(output).toBe(false);
152166
});
153167

src/app/modules/angular-slickgrid/filter-conditions/__tests__/numberFilterCondition.spec.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FieldType, FilterConditionOption } from '../../models/index';
1+
import { FieldType, FilterConditionOption, OperatorType, SearchTerm } from '../../models/index';
22
import { executeFilterConditionTest } from '../filterConditionProcesses';
33
import { executeNumberFilterCondition, getFilterParsedNumbers } from '../numberFilterCondition';
44

@@ -20,12 +20,12 @@ describe('executeNumberFilterCondition method', () => {
2020
it('should return True when first searchTerm is undefined provided neither an operator when executing "executeFilterConditionTest" method', () => {
2121
const searchTerms = [undefined];
2222
const options = { dataKey: '', cellValue: 0, fieldType: FieldType.number } as FilterConditionOption;
23-
const output = executeFilterConditionTest(options, searchTerms);
23+
const output = executeFilterConditionTest(options, searchTerms as unknown as SearchTerm[]);
2424
expect(output).toBe(true);
2525
});
2626

2727
it('should return False when any cell value is provided without any search terms', () => {
28-
const searchTerms = [];
28+
const searchTerms: SearchTerm[] = [];
2929
const options = { dataKey: '', operator: 'EQ', cellValue: 'foo', fieldType: FieldType.number } as FilterConditionOption;
3030
const output = executeNumberFilterCondition(options, getFilterParsedNumbers(searchTerms));
3131
expect(output).toBe(false);
@@ -115,6 +115,20 @@ describe('executeNumberFilterCondition method', () => {
115115
expect(output).toBe(true);
116116
});
117117

118+
it('should return True when input value is on the inclusive limit range of search terms using 2 dots (..) notation AND no operator provided except a defaultFilterRangeOperator is rangeInclusive', () => {
119+
const searchTerms = ['1..5'];
120+
const options = { dataKey: '', defaultFilterRangeOperator: OperatorType.rangeInclusive, cellValue: '1', fieldType: FieldType.number, searchTerms } as FilterConditionOption;
121+
const output = executeNumberFilterCondition(options, getFilterParsedNumbers(searchTerms));
122+
expect(output).toBe(true);
123+
});
124+
125+
it('should return False when input value is on the inclusive limit range of search terms using 2 dots (..) notation AND no operator provided except a defaultFilterRangeOperator is rangeExclusive', () => {
126+
const searchTerms = ['1..5'];
127+
const options = { dataKey: '', defaultFilterRangeOperator: OperatorType.rangeExclusive, cellValue: '1', fieldType: FieldType.number, searchTerms } as FilterConditionOption;
128+
const output = executeNumberFilterCondition(options, getFilterParsedNumbers(searchTerms));
129+
expect(output).toBe(false);
130+
});
131+
118132
it('should return False when input value is not in the range of search terms using 2 dots (..) notation', () => {
119133
const searchTerms = ['1..5'];
120134
const options = { dataKey: '', operator: 'EQ', cellValue: '15', fieldType: FieldType.number, searchTerms } as FilterConditionOption;

src/app/modules/angular-slickgrid/filter-conditions/dateFilterCondition.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export function executeDateFilterCondition(options: FilterConditionOption, parse
2727

2828
// having 2 search dates, we assume that it's a date range filtering and we'll compare against both dates
2929
if (searchDate1 && searchDate2) {
30-
const isInclusive = options.operator && options.operator === OperatorType.rangeInclusive;
30+
let operator = options && options.operator || options.defaultFilterRangeOperator;
31+
if (operator !== OperatorType.rangeInclusive && operator !== OperatorType.rangeExclusive) {
32+
operator = options.defaultFilterRangeOperator;
33+
}
34+
const isInclusive = operator === OperatorType.rangeInclusive;
3135
const resultCondition1 = testFilterCondition((isInclusive ? '>=' : '>'), dateCellTimestamp, searchDate1.valueOf());
3236
const resultCondition2 = testFilterCondition((isInclusive ? '<=' : '<'), dateCellTimestamp, searchDate2.valueOf());
3337
return (resultCondition1 && resultCondition2);

src/app/modules/angular-slickgrid/filter-conditions/numberFilterCondition.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ export const executeNumberFilterCondition: FilterCondition = ((options: FilterCo
1212
}
1313

1414
if (searchValue1 !== undefined && searchValue2 !== undefined) {
15-
const isInclusive = (options && options.operator) === OperatorType.rangeInclusive;
15+
let operator = options && options.operator || options.defaultFilterRangeOperator;
16+
if (operator !== OperatorType.rangeInclusive && operator !== OperatorType.rangeExclusive) {
17+
operator = options.defaultFilterRangeOperator;
18+
}
19+
const isInclusive = operator === OperatorType.rangeInclusive;
1620
const resultCondition1 = testFilterCondition((isInclusive ? '>=' : '>'), cellValue, +searchValue1);
1721
const resultCondition2 = testFilterCondition((isInclusive ? '<=' : '<'), cellValue, +searchValue2);
1822
return (resultCondition1 && resultCondition2);

src/app/modules/angular-slickgrid/models/filterConditionOption.interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { FieldType } from './fieldType.enum';
22
import { OperatorString } from './operatorString';
3+
import { OperatorType } from './operatorType.enum';
34
import { SearchTerm } from './searchTerm.type';
45

56
export interface FilterConditionOption {
67
/** optional object data key */
78
dataKey?: string;
89

10+
/** pull the grid option default filter in case the "operator" provided is not a range operator or is simply undefined */
11+
defaultFilterRangeOperator: OperatorType | OperatorString;
12+
913
/** filter operator */
1014
operator: OperatorString;
1115

src/app/modules/angular-slickgrid/services/filter.service.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ export class FilterService {
400400
searchTerms: searchValues || [],
401401
operator: operator as OperatorString,
402402
searchInputLastChar: inputLastChar,
403-
filterSearchType: columnDef.filterSearchType
403+
filterSearchType: columnDef.filterSearchType,
404+
defaultFilterRangeOperator: this._gridOptions.defaultFilterRangeOperator,
404405
} as FilterConditionOption;
405406
}
406407

@@ -489,6 +490,7 @@ export class FilterService {
489490
operator: operator as OperatorString,
490491
searchInputLastChar: columnFilter.searchInputLastChar,
491492
filterSearchType: columnDef.filterSearchType,
493+
defaultFilterRangeOperator: this._gridOptions.defaultFilterRangeOperator,
492494
} as FilterConditionOption;
493495
}
494496

test/cypress/integration/example12.spec.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ describe('Example 12: Localization (i18n)', () => {
9090
.find('.slick-custom-footer')
9191
.find('.right-footer')
9292
.should($span => {
93-
const now = new Date();
93+
const dateTime = moment().format('YYYY-MM-DD, hh:mm a');
9494
const text = removeExtraSpaces($span.text()); // remove all white spaces
95-
const dateFormatted = moment(now).format('YYYY-MM-DD, hh:mm a');
96-
expect(text).to.eq(`Dernière mise à jour ${dateFormatted} | 1500 de 1500 éléments`);
95+
expect(text).to.eq(`Dernière mise à jour ${dateTime} | 1500 de 1500 éléments`);
9796
});
9897
});
9998

@@ -270,14 +269,14 @@ describe('Example 12: Localization (i18n)', () => {
270269

271270
it('should have some metrics shown in the grid footer', () => {
272271
const now = new Date();
273-
const dateFormatted = moment(now).format('YYYY-MM-DD, hh:mm a');
274272

275273
cy.get('#slickGridContainer-grid12')
276274
.find('.slick-custom-footer')
277275
.find('.right-footer')
278276
.should($span => {
277+
const dateTime = moment().format('YYYY-MM-DD, hh:mm a');
279278
const text = removeExtraSpaces($span.text()); // remove all white spaces
280-
expect(text).to.eq(`Last Update ${dateFormatted} | 447 of 1500 items`);
279+
expect(text).to.eq(`Last Update ${dateTime} | 447 of 1500 items`);
281280
});
282281
});
283282

0 commit comments

Comments
 (0)