Skip to content

Commit 75a4401

Browse files
committed
refactor(columns): sorting & filtering properties for case sensitivity
1 parent 481712e commit 75a4401

9 files changed

Lines changed: 39 additions & 51 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4747
```
4848

4949
- **BREAKING:** Column `sort` and `filter` properties have been replaced with separate boolean and configuration properties:
50-
- `sort``sortable` (boolean) + `sortConfiguration` (object with `caseSensitive` and `comparer` options)
51-
- `filter``filterable` (boolean) + `filterConfiguration` (object with `caseSensitive` option)
50+
- `sort``sortable` (boolean) + `sortingCaseSensitive` (boolean) + `sortConfiguration` (object with `comparer` option)
51+
- `filter``filterable` (boolean) + `filteringCaseSensitive` (boolean)
52+
53+
- **BREAKING:** Removed `ColumnFilterConfiguration` type. Use `filteringCaseSensitive` boolean property directly on the column.
5254
- **BREAKING:** Renamed `GridSortConfiguration` type to `GridLiteSortingOptions`.
5355
- **BREAKING:** Renamed `IgcGridLite.sortConfiguration` property to `sortingOptions`.
5456
- **BREAKING:** Renamed `IgcGridLite.sortExpressions` property to `sortingExpressions`.

src/components/column.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { registerComponent } from '../internal/register.js';
66
import { GRID_COLUMN_TAG } from '../internal/tags.js';
77
import type {
88
BaseColumnConfiguration,
9-
ColumnFilterConfiguration,
109
ColumnSortConfiguration,
1110
IgcCellContext,
1211
IgcHeaderContext,
@@ -66,17 +65,21 @@ export class IgcGridLiteColumn<T extends object>
6665
@property({ type: Boolean })
6766
public sortable = false;
6867

69-
/** Sort configuration for the column. */
68+
/** Whether sort operations will be case sensitive. */
69+
@property({ type: Boolean, attribute: 'sorting-case-sensitive' })
70+
public sortingCaseSensitive = false;
71+
72+
/** Sort configuration for the column (e.g., custom comparer). */
7073
@property({ attribute: false })
7174
public sortConfiguration?: ColumnSortConfiguration<T>;
7275

7376
/** Indicates whether the column is filterable. */
7477
@property({ type: Boolean })
7578
public filterable = false;
7679

77-
/** Filter configuration for the column. */
78-
@property({ attribute: false })
79-
public filterConfiguration?: ColumnFilterConfiguration;
80+
/** Whether filter operations will be case sensitive. */
81+
@property({ type: Boolean, attribute: 'filtering-case-sensitive' })
82+
public filteringCaseSensitive = false;
8083

8184
/** Custom header template for the column. */
8285
@property({ attribute: false })

src/controllers/filter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export class FilterController<T extends object> implements ReactiveController {
7979
}
8080

8181
public getDefaultExpression(column: ColumnConfiguration<T>) {
82-
const caseSensitive = Boolean(column.filterConfiguration?.caseSensitive);
82+
const caseSensitive = Boolean(column.filteringCaseSensitive);
8383
const operands = getFilterOperandsFor(column);
8484
const keys = Object.keys(operands) as Keys<typeof operands>[];
8585

src/controllers/sort.ts

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import type { ReactiveController } from 'lit';
22
import { PIPELINE } from '../internal/constants.js';
3-
import type {
4-
ColumnConfiguration,
5-
ColumnSortConfiguration,
6-
GridHost,
7-
Keys,
8-
} from '../internal/types.js';
3+
import type { ColumnConfiguration, GridHost, Keys } from '../internal/types.js';
94
import { asArray } from '../internal/utils.js';
105
import type { SortingDirection, SortingExpression, SortState } from '../operations/sort/types.js';
116

@@ -24,29 +19,29 @@ export class SortController<T extends object> implements ReactiveController {
2419
return true;
2520
}
2621

27-
#resolveSortOptions(options?: ColumnSortConfiguration<T>) {
22+
#resolveSortOptions(column?: ColumnConfiguration<T>) {
2823
const expr: Pick<SortingExpression<T>, 'caseSensitive' | 'comparer'> = {
2924
caseSensitive: false,
3025
comparer: undefined,
3126
};
3227

33-
if (!options) {
28+
if (!column) {
3429
return expr as Partial<SortingExpression<T>>;
3530
}
3631

3732
return Object.assign(expr, {
38-
caseSensitive: options.caseSensitive,
39-
comparer: options.comparer,
33+
caseSensitive: column.sortingCaseSensitive,
34+
comparer: column.sortConfiguration?.comparer,
4035
}) as Partial<SortingExpression<T>>;
4136
}
4237

4338
#createDefaultExpression(key: Keys<T>) {
44-
const options = this.host.getColumn(key)?.sortConfiguration;
39+
const column = this.host.getColumn(key);
4540

4641
return {
4742
key,
4843
direction: 'ascending',
49-
...this.#resolveSortOptions(options),
44+
...this.#resolveSortOptions(column),
5045
} as SortingExpression<T>;
5146
}
5247

@@ -93,21 +88,18 @@ export class SortController<T extends object> implements ReactiveController {
9388
this.#emitSortedEvent(expression);
9489
}
9590

96-
public prepareExpression({
97-
key,
98-
sortConfiguration,
99-
}: ColumnConfiguration<T>): SortingExpression<T> {
100-
if (this.state.has(key)) {
101-
const expr = this.state.get(key)!;
91+
public prepareExpression(column: ColumnConfiguration<T>): SortingExpression<T> {
92+
if (this.state.has(column.key)) {
93+
const expr = this.state.get(column.key)!;
10294

10395
return Object.assign(expr, {
10496
direction: this.#orderBy(expr.direction),
105-
...this.#resolveSortOptions(sortConfiguration),
97+
...this.#resolveSortOptions(column),
10698
});
10799
}
108100

109101
// Initial state
110-
return this.#createDefaultExpression(key);
102+
return this.#createDefaultExpression(column.key);
111103
}
112104

113105
public reset(key?: Keys<T>) {

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ export type {
1111
BaseIgcCellContext,
1212
BasePropertyType,
1313
ColumnConfiguration,
14-
ColumnFilterConfiguration,
1514
ColumnSortConfiguration,
1615
DataPipelineConfiguration,
1716
DataPipelineHook,

src/internal/types.ts

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ export interface GridLiteSortingOptions {
4242
* Extended sort configuration for a column.
4343
*/
4444
export interface BaseColumnSortConfiguration<T, K extends Keys<T> = Keys<T>> {
45-
/**
46-
* Whether the sort operations will be case sensitive.
47-
*/
48-
caseSensitive?: boolean;
4945
/**
5046
* Custom comparer function for sort operations for this column.
5147
*/
@@ -59,16 +55,6 @@ export type ColumnSortConfiguration<T, K extends Keys<T> = Keys<T>> = K extends
5955
? BaseColumnSortConfiguration<T, K>
6056
: never;
6157

62-
/**
63-
* Extended filter configuration for a column.
64-
*/
65-
export interface ColumnFilterConfiguration {
66-
/**
67-
* Whether the filter operations will be case sensitive.
68-
*/
69-
caseSensitive?: boolean;
70-
}
71-
7258
/** Configuration object for grid columns. */
7359
export interface BaseColumnConfiguration<T extends object, K extends Keys<T> = Keys<T>> {
7460
/**
@@ -114,17 +100,21 @@ export interface BaseColumnConfiguration<T extends object, K extends Keys<T> = K
114100
*/
115101
sortable?: boolean;
116102
/**
117-
* Sort configuration options for the column.
103+
* Whether the sort operations will be case sensitive.
104+
*/
105+
sortingCaseSensitive?: boolean;
106+
/**
107+
* Sort configuration options for the column (e.g., custom comparer).
118108
*/
119109
sortConfiguration?: ColumnSortConfiguration<T, K>;
120110
/**
121111
* Whether the column can be filtered.
122112
*/
123113
filterable?: boolean;
124114
/**
125-
* Filter configuration options for the column.
115+
* Whether the filter operations will be case sensitive.
126116
*/
127-
filterConfiguration?: ColumnFilterConfiguration;
117+
filteringCaseSensitive?: boolean;
128118
/**
129119
* Header template callback.
130120
*/

src/internal/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,10 @@ export function createColumnConfiguration<T extends object>(
7474
hidden: config.hidden ?? false,
7575
resizable: config.resizable ?? false,
7676
sortable: config.sortable ?? false,
77+
sortingCaseSensitive: config.sortingCaseSensitive ?? false,
7778
sortConfiguration: config.sortConfiguration,
7879
filterable: config.filterable ?? false,
79-
filterConfiguration: config.filterConfiguration,
80+
filteringCaseSensitive: config.filteringCaseSensitive ?? false,
8081
headerTemplate: config.headerTemplate,
8182
cellTemplate: config.cellTemplate,
8283
} as ColumnConfiguration<T>;

test/data-operation/filter-ui.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ describe('Grid UI filter', () => {
269269
await TDD.updateColumns({
270270
key: 'name',
271271
filterable: true,
272-
filterConfiguration: { caseSensitive: true },
272+
filteringCaseSensitive: true,
273273
});
274274
await TDD.activateFilterRow('name');
275275
await TDD.filterByInput('a');
@@ -377,7 +377,7 @@ describe('Grid UI filter', () => {
377377
await TDD.updateColumns({
378378
key: 'name',
379379
filterable: true,
380-
filterConfiguration: { caseSensitive: true },
380+
filteringCaseSensitive: true,
381381
});
382382
await TDD.filter({ key: 'name', condition: 'contains', searchTerm: 'D' });
383383

@@ -388,7 +388,7 @@ describe('Grid UI filter', () => {
388388
await TDD.updateColumns({
389389
key: 'name',
390390
filterable: true,
391-
filterConfiguration: { caseSensitive: true },
391+
filteringCaseSensitive: true,
392392
});
393393
await TDD.filter({
394394
key: 'name',

test/utils/grid-fixture.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ export default class GridTestFixture<T extends object> {
6262
html`<igc-grid-lite-column
6363
.key=${col.key}
6464
?filterable=${col.filterable}
65-
.filterConfiguration=${col.filterConfiguration}
65+
?filtering-case-sensitive=${col.filteringCaseSensitive}
6666
?sortable=${col.sortable}
67+
?sorting-case-sensitive=${col.sortingCaseSensitive}
6768
.sortConfiguration=${col.sortConfiguration}
6869
.width=${col.width}
6970
.headerText=${col.headerText}

0 commit comments

Comments
 (0)