ag-grid-url-sync 0.3.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -1
- package/dist/core/ag-grid-url-sync.js +1 -53
- package/dist/core/ag-grid-url-sync.js.map +1 -1
- package/dist/core/grid-integration.js +5 -67
- package/dist/core/grid-integration.js.map +1 -1
- package/dist/core/index.js +0 -5
- package/dist/core/index.js.map +1 -1
- package/dist/core/serialization/formats.js +2 -21
- package/dist/core/serialization/formats.js.map +1 -1
- package/dist/core/serialization/grouped.js +0 -47
- package/dist/core/serialization/grouped.js.map +1 -1
- package/dist/core/serialization/index.js +0 -4
- package/dist/core/serialization/index.js.map +1 -1
- package/dist/core/types.d.ts +4 -4
- package/dist/core/types.js +0 -118
- package/dist/core/types.js.map +1 -1
- package/dist/core/url-generator.js +2 -48
- package/dist/core/url-generator.js.map +1 -1
- package/dist/core/url-parser.js +1 -57
- package/dist/core/url-parser.js.map +1 -1
- package/dist/core/validation.d.ts +4 -4
- package/dist/core/validation.js +1 -78
- package/dist/core/validation.js.map +1 -1
- package/dist/core/view-storage.d.ts +63 -0
- package/dist/core/view-storage.js +112 -0
- package/dist/core/view-storage.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +0 -6
- package/dist/index.js.map +1 -1
- package/dist/react/index.d.ts +1 -0
- package/dist/react/types.d.ts +96 -0
- package/dist/react/use-ag-grid-url-sync.js +408 -41
- package/dist/react/use-ag-grid-url-sync.js.map +1 -1
- package/package.json +85 -30
package/README.md
CHANGED
|
@@ -450,6 +450,7 @@ The package supports granular subpath exports for advanced usage and optimal bun
|
|
|
450
450
|
- `ag-grid-url-sync/url-parser` – URL parsing utilities
|
|
451
451
|
- `ag-grid-url-sync/url-generator` – URL generation utilities
|
|
452
452
|
- `ag-grid-url-sync/grid-integration` – AG Grid integration helpers
|
|
453
|
+
- `ag-grid-url-sync/view-storage` – localStorage-backed saved views
|
|
453
454
|
- `ag-grid-url-sync/types` – TypeScript types
|
|
454
455
|
|
|
455
456
|
Refer to the [package.json](./package.json) for the full export map.
|
|
@@ -577,6 +578,9 @@ interface UseAGGridUrlSyncOptions {
|
|
|
577
578
|
autoApplyOnMount?: boolean // Default: false
|
|
578
579
|
enabledWhenReady?: boolean // Default: true
|
|
579
580
|
onError?: (error: Error, context: string) => void // Advanced error handling
|
|
581
|
+
|
|
582
|
+
// Saved views: setting a key enables the feature and namespaces its storage
|
|
583
|
+
storageKey?: string // Default: undefined (saved views disabled)
|
|
580
584
|
}
|
|
581
585
|
```
|
|
582
586
|
|
|
@@ -596,16 +600,104 @@ interface UseAGGridUrlSyncOptions {
|
|
|
596
600
|
| `getFiltersAsFormat` | `(format: 'querystring' | 'json' | 'base64') => string` | Serialize filters to any supported format (for sharing/export) |
|
|
597
601
|
| `getCurrentFormat` | `() => 'individual' | 'grouped'` | Get the current serialization mode (individual or grouped) |
|
|
598
602
|
|
|
603
|
+
Saved views (inert unless `storageKey` is set):
|
|
604
|
+
|
|
605
|
+
| Property | Type | Description |
|
|
606
|
+
| -------------- | ------------------------------------ | ----------------------------------------------------------------------- |
|
|
607
|
+
| `views` | `GridView[]` | Saved views for this grid, in save order. Empty when views are disabled |
|
|
608
|
+
| `activeViewId` | `string \| null` | Id of the view currently applied to the grid, or `null` when none is |
|
|
609
|
+
| `saveView` | `(name: string) => GridView \| null` | Save current filters under a name; overwrites an existing name in place |
|
|
610
|
+
| `loadView` | `(id: string \| null) => void` | Apply a saved view, or pass `null` to reset to unfiltered |
|
|
611
|
+
| `deleteView` | `(id: string) => void` | Delete a saved view |
|
|
612
|
+
|
|
599
613
|
> **Note:** `getFiltersAsFormat` and `getCurrentFormat` are especially useful for grouped serialization, format conversion, and advanced sharing scenarios.
|
|
600
614
|
|
|
615
|
+
### Saved Views
|
|
616
|
+
|
|
617
|
+
Pass a `storageKey` to let users name and revisit filter sets. The key both enables
|
|
618
|
+
the feature and namespaces its storage, so two grids on the same origin must use
|
|
619
|
+
different keys:
|
|
620
|
+
|
|
621
|
+
```tsx
|
|
622
|
+
const { views, activeViewId, saveView, loadView, deleteView } =
|
|
623
|
+
useAGGridUrlSync(gridApi, { storageKey: 'employee-grid' })
|
|
624
|
+
|
|
625
|
+
// One handler each, as a user drives them: save whatever is currently filtered,
|
|
626
|
+
// then apply or remove a view by id in a later interaction.
|
|
627
|
+
const handleSave = () => saveView('Engineering, high salary')
|
|
628
|
+
const handleLoad = (id: string) => loadView(id)
|
|
629
|
+
const handleDelete = (id: string) => deleteView(id)
|
|
630
|
+
const handleReset = () => loadView(null) // back to an unfiltered grid
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
Render the list from `views` and drive the buttons from it. `views[i].id` is only
|
|
634
|
+
stale immediately after a mutation, not during render. If you do need the new
|
|
635
|
+
view's id in the same handler that saved it, use `saveView`'s return value rather
|
|
636
|
+
than reading it back out of `views`: that array is React state, so it does not
|
|
637
|
+
update until the next render.
|
|
638
|
+
|
|
639
|
+
Only the filter model is stored, using AG Grid's native format so set filters and
|
|
640
|
+
combined conditions survive a round trip. Column order, row selection and expanded
|
|
641
|
+
groups are not stored.
|
|
642
|
+
|
|
643
|
+
Behaviour worth knowing:
|
|
644
|
+
|
|
645
|
+
- **Names are unique.** Saving over an existing name updates that view in place,
|
|
646
|
+
keeping its id and list position, so "load, adjust, save under the same name" is
|
|
647
|
+
how you update one. Names are trimmed and must not be empty.
|
|
648
|
+
- **`activeViewId` describes the live grid**, not what is persisted. A stored view
|
|
649
|
+
is only applied on mount when `autoApplyOnMount` is set, so with it off this
|
|
650
|
+
stays `null` until you call `loadView` or `saveView`.
|
|
651
|
+
- **Filtering away from a view unloads it.** `activeViewId` returns to `null` as
|
|
652
|
+
soon as the grid stops showing that view, including through routes that never
|
|
653
|
+
mention views: `clearFilters`, `applyFilters`, `applyUrlFilters`, or the user
|
|
654
|
+
editing a filter in the grid's own UI. The stored pointer is cleared with it,
|
|
655
|
+
so `autoApplyOnMount` will not bring the view back on the next load. The grid
|
|
656
|
+
is compared against what it reported once the view was applied, so a view AG
|
|
657
|
+
Grid normalises (one naming a column the grid no longer has, say) stays loaded
|
|
658
|
+
and keeps its stored pointer. A write AG Grid defers, such as a restore made
|
|
659
|
+
before column data types are inferred, is recognised when it lands by the
|
|
660
|
+
event's `source: 'api'`; on AG Grid versions that do not report a source, a
|
|
661
|
+
deferred view the grid also normalises unloads when it lands. An API change
|
|
662
|
+
that filters a column the view does not, such as your own `setFilterModel`
|
|
663
|
+
over a view the grid ignored, is not taken for the view and unloads it. One
|
|
664
|
+
that filters only the view's columns cannot be told from the view landing.
|
|
665
|
+
Render the
|
|
666
|
+
active state from `activeViewId` and it follows the grid on its own. Replacing
|
|
667
|
+
`gridApi` also clears `activeViewId`, but keeps the stored pointer, so with
|
|
668
|
+
`autoApplyOnMount` the view is restored against the new grid.
|
|
669
|
+
- **URL filters win on mount.** With `autoApplyOnMount` set, an incoming URL that
|
|
670
|
+
carries filters takes precedence over the stored view, so a shared link shows the
|
|
671
|
+
sender's filters rather than the recipient's saved default. It wins once per
|
|
672
|
+
grid: switching `storageKey` later restores the new namespace's stored view
|
|
673
|
+
instead of applying the link again.
|
|
674
|
+
- **Deleting is conservative.** `deleteView` clears the grid only if it still shows
|
|
675
|
+
exactly that view's filters, so hand-edited filters survive.
|
|
676
|
+
- **Failures are reported, not silent.** A save that cannot be persisted (quota
|
|
677
|
+
exhausted, storage blocked by policy) returns `null` and reports through
|
|
678
|
+
`onError` with context `'save-view'`. Reads degrade to an empty list instead of
|
|
679
|
+
throwing, so server rendering is safe.
|
|
680
|
+
|
|
681
|
+
For non-React consumers the same store is available directly:
|
|
682
|
+
|
|
683
|
+
```ts
|
|
684
|
+
import { createViewStore } from 'ag-grid-url-sync/view-storage'
|
|
685
|
+
|
|
686
|
+
const store = createViewStore('employee-grid')
|
|
687
|
+
store.saveView('Engineering', gridApi.getFilterModel())
|
|
688
|
+
```
|
|
689
|
+
|
|
601
690
|
### React Features
|
|
602
691
|
|
|
603
692
|
- **🔄 Automatic State Management**: Tracks grid state and filter changes automatically
|
|
604
693
|
- **⚡ Ready State**: `isReady` indicates when the grid API is available
|
|
605
|
-
- **🎯 Auto-Apply**: `autoApplyOnMount` applies URL filters when component mounts
|
|
694
|
+
- **🎯 Auto-Apply**: `autoApplyOnMount` applies URL filters when component mounts.
|
|
695
|
+
It is attempted once per grid: a failure is reported through `onError` and
|
|
696
|
+
`onParseError` and is not retried on later renders
|
|
606
697
|
- **🧹 Cleanup**: Automatically cleans up resources when component unmounts
|
|
607
698
|
- **🛡️ Error Boundaries**: Graceful error handling with configurable callbacks
|
|
608
699
|
- **📊 Filter Status**: `hasFilters` tracks whether any filters are active
|
|
700
|
+
- **💾 Saved Views**: `storageKey` enables naming and revisiting filter sets
|
|
609
701
|
|
|
610
702
|
### React with Grouped Serialization
|
|
611
703
|
|
|
@@ -3,16 +3,8 @@ import { parseUrlFilters } from './url-parser.js';
|
|
|
3
3
|
import { generateUrl } from './url-generator.js';
|
|
4
4
|
import { getFilterModel, applyFilterModel } from './grid-integration.js';
|
|
5
5
|
import { serializeGrouped } from './serialization/grouped.js';
|
|
6
|
-
/**
|
|
7
|
-
* AGGridUrlSync class for synchronizing AG Grid text filters with URL parameters
|
|
8
|
-
*/
|
|
9
6
|
export class AGGridUrlSync {
|
|
10
7
|
config;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new instance of AGGridUrlSync
|
|
13
|
-
* @param gridApi - AG Grid API instance
|
|
14
|
-
* @param config - Optional configuration options
|
|
15
|
-
*/
|
|
16
8
|
constructor(gridApi, config = {}) {
|
|
17
9
|
this.config = {
|
|
18
10
|
gridApi,
|
|
@@ -20,90 +12,46 @@ export class AGGridUrlSync {
|
|
|
20
12
|
...config
|
|
21
13
|
};
|
|
22
14
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Generates a URL with the current filter state
|
|
25
|
-
* @param baseUrl - Optional base URL (defaults to current URL)
|
|
26
|
-
* @returns URL string with filter parameters
|
|
27
|
-
*/
|
|
28
15
|
generateUrl(baseUrl) {
|
|
29
16
|
const filterState = getFilterModel(this.config);
|
|
30
17
|
const url = baseUrl ?? window.location.href;
|
|
31
18
|
return generateUrl(url, filterState, this.config);
|
|
32
19
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Gets the current filter state as URL query parameters
|
|
35
|
-
* @returns Query parameter string
|
|
36
|
-
*/
|
|
37
20
|
getQueryParams() {
|
|
38
21
|
const url = this.generateUrl();
|
|
39
22
|
const urlObj = new URL(url);
|
|
40
23
|
return urlObj.search;
|
|
41
24
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Applies filters from a URL to the grid
|
|
44
|
-
* @param url - Optional URL to parse (defaults to current URL)
|
|
45
|
-
*/
|
|
46
25
|
applyFromUrl(url) {
|
|
47
26
|
const urlToParse = url ?? window.location.href;
|
|
48
27
|
const filterState = parseUrlFilters(urlToParse, this.config);
|
|
49
28
|
this.applyFilters(filterState);
|
|
50
29
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Applies a filter state object to the grid
|
|
53
|
-
* @param filterState - Filter state to apply
|
|
54
|
-
*/
|
|
55
30
|
applyFilters(filterState) {
|
|
56
31
|
applyFilterModel(filterState, this.config);
|
|
57
32
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Clears all text filters from the grid
|
|
60
|
-
*/
|
|
61
33
|
clearFilters() {
|
|
62
34
|
this.applyFilters({});
|
|
63
35
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Cleans up any resources or event listeners
|
|
66
|
-
*/
|
|
67
36
|
destroy() {
|
|
68
|
-
// Currently no cleanup needed, but included for future use
|
|
69
37
|
}
|
|
70
|
-
/**
|
|
71
|
-
* Gets the current serialization mode
|
|
72
|
-
* @returns The current serialization mode
|
|
73
|
-
*/
|
|
74
38
|
getSerializationMode() {
|
|
75
39
|
return this.config.serialization;
|
|
76
40
|
}
|
|
77
|
-
/**
|
|
78
|
-
* Gets the current format (for grouped mode)
|
|
79
|
-
* @returns The current format
|
|
80
|
-
*/
|
|
81
41
|
getCurrentFormat() {
|
|
82
42
|
return this.config.format;
|
|
83
|
-
}
|
|
84
|
-
* Gets filters in a specific format (useful for sharing/export)
|
|
85
|
-
* @param format - The format to serialize to
|
|
86
|
-
* @returns Serialized filter string
|
|
87
|
-
*/
|
|
43
|
+
}
|
|
88
44
|
getFiltersAsFormat(format) {
|
|
89
45
|
const filterState = getFilterModel(this.config);
|
|
90
|
-
// Create temporary config for the requested format
|
|
91
46
|
const tempConfig = {
|
|
92
47
|
...this.config,
|
|
93
48
|
format,
|
|
94
49
|
serialization: 'grouped'
|
|
95
50
|
};
|
|
96
|
-
// Use the serialization module
|
|
97
51
|
const result = serializeGrouped(filterState, tempConfig);
|
|
98
52
|
return result.value;
|
|
99
53
|
}
|
|
100
54
|
}
|
|
101
|
-
/**
|
|
102
|
-
* Factory function to create a new AGGridUrlSync instance
|
|
103
|
-
* @param gridApi - AG Grid API instance
|
|
104
|
-
* @param config - Optional configuration options
|
|
105
|
-
* @returns AGGridUrlSync instance
|
|
106
|
-
*/
|
|
107
55
|
export function createUrlSync(gridApi, config) {
|
|
108
56
|
return new AGGridUrlSync(gridApi, config);
|
|
109
57
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ag-grid-url-sync.js","sourceRoot":"","sources":["../../src/core/ag-grid-url-sync.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"ag-grid-url-sync.js","sourceRoot":"","sources":["../../src/core/ag-grid-url-sync.ts"],"names":[],"mappings":"AAQA,OAAO,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Y;QACV,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC,CAAA;IACvB,CAAC;IAKD,OAAO;IAEP,CAAC;IAMD,oBAAoB;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAA;IAClC,CAAC;IAMD,gBAAgB;QACd,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAA;IAC3B,CAAC;IAKD,kBAAkB,CAAC,MAA2B;QAC5C,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;QAG/C,MAAM,UAAU,GAAG;YACjB,GAAG,IAAI,CAAC,MAAM;YACd,MAAM;YACN,aAAa,EAAE,SAAkB;SAClC,CAAA;QAGD,MAAM,MAAM,GAAG,gBAAgB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;QAExD,OAAO,MAAM,CAAC,KAAK,CAAA;IACrB,CAAC;CACF;AAQD,MAAM,UAAU,aAAa,CAC3B,OAAgB,EAChB,MAA4B;IAE5B,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;AAC3C,CAAC"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { AG_GRID_OPERATION_NAMES, REVERSE_AG_GRID_OPERATION_NAMES, TEXT_FILTER_OPERATIONS, NUMBER_FILTER_OPERATIONS, DATE_FILTER_OPERATIONS } from './types.js';
|
|
2
|
-
// Map AG Grid number operations to our internal number operations
|
|
3
|
-
// Since AG Grid uses generic names, we need to be explicit about number operations
|
|
4
2
|
const AG_GRID_TO_NUMBER_OPERATION_MAP = {
|
|
5
3
|
lessThan: 'lessThan',
|
|
6
4
|
lessThanOrEqual: 'lessThanOrEqual',
|
|
@@ -12,74 +10,48 @@ const AG_GRID_TO_NUMBER_OPERATION_MAP = {
|
|
|
12
10
|
blank: 'blank',
|
|
13
11
|
notBlank: 'notBlank'
|
|
14
12
|
};
|
|
15
|
-
/**
|
|
16
|
-
* Type guard to check if a value is a valid number operation key
|
|
17
|
-
*/
|
|
18
13
|
function isValidNumberOperation(operation) {
|
|
19
14
|
return Boolean(operation && operation in AG_GRID_TO_NUMBER_OPERATION_MAP);
|
|
20
15
|
}
|
|
21
|
-
/**
|
|
22
|
-
* Converts a date string to ISO format (YYYY-MM-DD)
|
|
23
|
-
* Handles both date strings and undefined values
|
|
24
|
-
* Returns an empty string if the input is undefined or invalid
|
|
25
|
-
*/
|
|
26
16
|
function toIsoDateString(val) {
|
|
27
17
|
if (!val)
|
|
28
18
|
return '';
|
|
29
19
|
const match = val.match(/^(\d{4}-\d{2}-\d{2})/);
|
|
30
20
|
return match?.[1] ? match[1] : val || '';
|
|
31
21
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Type predicate to check if an operation is a valid text filter operation
|
|
34
|
-
*/
|
|
35
22
|
function isTextFilterOperation(operation) {
|
|
36
23
|
return TEXT_FILTER_OPERATIONS.includes(operation);
|
|
37
24
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Type predicate to check if an operation is a valid number filter operation
|
|
40
|
-
*/
|
|
41
25
|
function isNumberFilterOperation(operation) {
|
|
42
26
|
return NUMBER_FILTER_OPERATIONS.includes(operation);
|
|
43
27
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Type predicate to check if an operation is a valid date filter operation
|
|
46
|
-
*/
|
|
47
28
|
function isDateFilterOperation(operation) {
|
|
48
29
|
return DATE_FILTER_OPERATIONS.includes(operation);
|
|
49
30
|
}
|
|
50
|
-
/**
|
|
51
|
-
* Detects the expected filter type for a column based on AG Grid configuration
|
|
52
|
-
*/
|
|
53
31
|
export function detectColumnFilterType(gridApi, columnId) {
|
|
54
32
|
try {
|
|
55
33
|
const column = gridApi.getColumn(columnId);
|
|
56
34
|
if (!column)
|
|
57
|
-
return 'text';
|
|
35
|
+
return 'text';
|
|
58
36
|
const colDef = column.getColDef();
|
|
59
|
-
// 1. Explicit filter configuration takes priority
|
|
60
37
|
if (colDef.filter === 'agDateColumnFilter')
|
|
61
38
|
return 'date';
|
|
62
39
|
if (colDef.filter === 'agNumberColumnFilter')
|
|
63
40
|
return 'number';
|
|
64
41
|
if (colDef.filter === 'agTextColumnFilter')
|
|
65
42
|
return 'text';
|
|
66
|
-
// 2. Cell data type configuration
|
|
67
43
|
if (colDef.cellDataType === 'date')
|
|
68
44
|
return 'date';
|
|
69
45
|
if (colDef.cellDataType === 'number')
|
|
70
46
|
return 'number';
|
|
71
47
|
if (colDef.cellDataType === 'text')
|
|
72
48
|
return 'text';
|
|
73
|
-
// 3. Default to text for backward compatibility
|
|
74
49
|
return 'text';
|
|
75
50
|
}
|
|
76
51
|
catch {
|
|
77
|
-
return 'text';
|
|
52
|
+
return 'text';
|
|
78
53
|
}
|
|
79
54
|
}
|
|
80
|
-
/**
|
|
81
|
-
* Gets the current filter model from AG Grid
|
|
82
|
-
*/
|
|
83
55
|
export function getFilterModel(config) {
|
|
84
56
|
try {
|
|
85
57
|
const model = config.gridApi.getFilterModel();
|
|
@@ -91,28 +63,20 @@ export function getFilterModel(config) {
|
|
|
91
63
|
if (!filter || typeof filter !== 'object')
|
|
92
64
|
continue;
|
|
93
65
|
const { filterType, type, filter: value, filterTo, dateFrom, dateTo } = filter;
|
|
94
|
-
// Handle text filters
|
|
95
66
|
if (filterType === 'text') {
|
|
96
|
-
// Map AG Grid operations back to our internal operations using centralized mapping
|
|
97
67
|
const internalOperation = REVERSE_AG_GRID_OPERATION_NAMES[type];
|
|
98
|
-
// Use type predicate to validate and narrow the type
|
|
99
68
|
if (internalOperation && isTextFilterOperation(internalOperation)) {
|
|
100
69
|
filterState[column] = {
|
|
101
70
|
filterType: 'text',
|
|
102
|
-
type: internalOperation,
|
|
71
|
+
type: internalOperation,
|
|
103
72
|
filter: String(value || '')
|
|
104
73
|
};
|
|
105
74
|
}
|
|
106
75
|
}
|
|
107
|
-
// Handle number filters
|
|
108
76
|
else if (filterType === 'number') {
|
|
109
|
-
// For number filters, we need to handle the mapping carefully since
|
|
110
|
-
// AG Grid uses the same operation names for numbers and dates
|
|
111
|
-
// Use the explicit number mapping instead of the reverse AG Grid mapping
|
|
112
77
|
const internalOperation = isValidNumberOperation(type)
|
|
113
78
|
? AG_GRID_TO_NUMBER_OPERATION_MAP[type]
|
|
114
79
|
: null;
|
|
115
|
-
// If the operation type is not recognized, report the error
|
|
116
80
|
if (!internalOperation) {
|
|
117
81
|
if (config.onParseError) {
|
|
118
82
|
config.onParseError(new Error(`Unknown number filter operation '${type}' for column '${column}'. ` +
|
|
@@ -120,20 +84,16 @@ export function getFilterModel(config) {
|
|
|
120
84
|
}
|
|
121
85
|
continue;
|
|
122
86
|
}
|
|
123
|
-
// Use type predicate to validate and narrow the type
|
|
124
87
|
if (internalOperation && isNumberFilterOperation(internalOperation)) {
|
|
125
|
-
// Validate that the filter value is actually a number
|
|
126
88
|
const numericValue = typeof value === 'number' ? value : Number(value);
|
|
127
|
-
// Skip invalid number filters
|
|
128
89
|
if (isNaN(numericValue)) {
|
|
129
90
|
continue;
|
|
130
91
|
}
|
|
131
92
|
const numberFilter = {
|
|
132
93
|
filterType: 'number',
|
|
133
|
-
type: internalOperation,
|
|
94
|
+
type: internalOperation,
|
|
134
95
|
filter: numericValue
|
|
135
96
|
};
|
|
136
|
-
// Handle range operations
|
|
137
97
|
if (internalOperation === 'inRange' && typeof filterTo === 'number') {
|
|
138
98
|
;
|
|
139
99
|
numberFilter.filterTo = filterTo;
|
|
@@ -141,14 +101,9 @@ export function getFilterModel(config) {
|
|
|
141
101
|
filterState[column] = numberFilter;
|
|
142
102
|
}
|
|
143
103
|
}
|
|
144
|
-
// Handle date filters
|
|
145
104
|
else if (filterType === 'date') {
|
|
146
|
-
// Map AG Grid date operations back to our internal operations
|
|
147
105
|
const internalOperation = REVERSE_AG_GRID_OPERATION_NAMES[type];
|
|
148
|
-
// For date operations, we need to handle the special case where AG Grid uses
|
|
149
|
-
// generic operation names but we have date-specific internal names
|
|
150
106
|
let mappedOperation = internalOperation;
|
|
151
|
-
// Map AG Grid generic date operations to our date-specific operations
|
|
152
107
|
const AG_GRID_TO_DATE_OPERATION_MAP = {
|
|
153
108
|
lessThan: 'dateBefore',
|
|
154
109
|
lessThanOrEqual: 'dateBeforeOrEqual',
|
|
@@ -159,14 +114,12 @@ export function getFilterModel(config) {
|
|
|
159
114
|
mappedOperation = type
|
|
160
115
|
? AG_GRID_TO_DATE_OPERATION_MAP[type] || internalOperation
|
|
161
116
|
: internalOperation;
|
|
162
|
-
// Use type predicate to validate and narrow the type
|
|
163
117
|
if (mappedOperation && isDateFilterOperation(mappedOperation)) {
|
|
164
118
|
const dateFilter = {
|
|
165
119
|
filterType: 'date',
|
|
166
120
|
type: mappedOperation,
|
|
167
121
|
filter: toIsoDateString(dateFrom || String(value || ''))
|
|
168
122
|
};
|
|
169
|
-
// Handle date range operations (AG Grid uses dateFrom/dateTo)
|
|
170
123
|
if (mappedOperation === 'dateRange' && dateTo) {
|
|
171
124
|
;
|
|
172
125
|
dateFilter.filterTo = toIsoDateString(dateTo);
|
|
@@ -184,21 +137,16 @@ export function getFilterModel(config) {
|
|
|
184
137
|
return {};
|
|
185
138
|
}
|
|
186
139
|
}
|
|
187
|
-
/**
|
|
188
|
-
* Converts internal filter to AG Grid filter format
|
|
189
|
-
*/
|
|
190
140
|
function convertToAGGridFilter(filter) {
|
|
191
141
|
if (filter.filterType === 'date') {
|
|
192
|
-
// Handle date range operations
|
|
193
142
|
if (filter.type === 'dateRange') {
|
|
194
143
|
return {
|
|
195
144
|
filterType: 'date',
|
|
196
|
-
type: 'inRange',
|
|
145
|
+
type: 'inRange',
|
|
197
146
|
dateFrom: filter.filter,
|
|
198
147
|
dateTo: filter.filterTo || null
|
|
199
148
|
};
|
|
200
149
|
}
|
|
201
|
-
// Handle blank operations for dates
|
|
202
150
|
if (filter.type === 'blank' || filter.type === 'notBlank') {
|
|
203
151
|
return {
|
|
204
152
|
filterType: 'date',
|
|
@@ -207,7 +155,6 @@ function convertToAGGridFilter(filter) {
|
|
|
207
155
|
dateTo: null
|
|
208
156
|
};
|
|
209
157
|
}
|
|
210
|
-
// Map date-specific operations to AG Grid generic operations
|
|
211
158
|
const dateOperationMapping = {
|
|
212
159
|
dateBefore: 'lessThan',
|
|
213
160
|
dateBeforeOrEqual: 'lessThanOrEqual',
|
|
@@ -231,7 +178,6 @@ function convertToAGGridFilter(filter) {
|
|
|
231
178
|
type: agGridOperation,
|
|
232
179
|
filter: filter.filter
|
|
233
180
|
};
|
|
234
|
-
// Only include filterTo if it's defined
|
|
235
181
|
return filter.filterTo !== undefined
|
|
236
182
|
? { ...baseFilter, filterTo: filter.filterTo }
|
|
237
183
|
: baseFilter;
|
|
@@ -242,7 +188,6 @@ function convertToAGGridFilter(filter) {
|
|
|
242
188
|
filter: filter.filter
|
|
243
189
|
};
|
|
244
190
|
}
|
|
245
|
-
// Text filter handling
|
|
246
191
|
const agGridOperation = AG_GRID_OPERATION_NAMES[filter.type];
|
|
247
192
|
return {
|
|
248
193
|
filterType: 'text',
|
|
@@ -250,18 +195,13 @@ function convertToAGGridFilter(filter) {
|
|
|
250
195
|
filter: filter.filter
|
|
251
196
|
};
|
|
252
197
|
}
|
|
253
|
-
/**
|
|
254
|
-
* Applies a filter state to AG Grid
|
|
255
|
-
*/
|
|
256
198
|
export function applyFilterModel(filterState, config) {
|
|
257
199
|
try {
|
|
258
200
|
const model = {};
|
|
259
201
|
for (const [column, filter] of Object.entries(filterState)) {
|
|
260
202
|
if (!filter || typeof filter !== 'object')
|
|
261
203
|
continue;
|
|
262
|
-
// Detect expected filter type for this column
|
|
263
204
|
const expectedType = detectColumnFilterType(config.gridApi, column);
|
|
264
|
-
// Validate filter type compatibility
|
|
265
205
|
if (filter.filterType === 'date' && expectedType !== 'date') {
|
|
266
206
|
console.warn(`Column '${column}' expects a ${expectedType} filter but received a date filter. This may indicate a configuration mismatch in the column definition or filter application.`);
|
|
267
207
|
continue;
|
|
@@ -270,13 +210,11 @@ export function applyFilterModel(filterState, config) {
|
|
|
270
210
|
console.warn(`Column '${column}' expects a ${expectedType} filter but received a number filter. This may indicate a configuration mismatch in the column definition or filter application.`);
|
|
271
211
|
continue;
|
|
272
212
|
}
|
|
273
|
-
// Convert to AG Grid filter model
|
|
274
213
|
const agGridFilter = convertToAGGridFilter(filter);
|
|
275
214
|
if (agGridFilter) {
|
|
276
215
|
model[column] = agGridFilter;
|
|
277
216
|
}
|
|
278
217
|
}
|
|
279
|
-
// Apply the filter model to AG Grid
|
|
280
218
|
config.gridApi.setFilterModel(model);
|
|
281
219
|
}
|
|
282
220
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grid-integration.js","sourceRoot":"","sources":["../../src/core/grid-integration.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"grid-integration.js","sourceRoot":"","sources":["../../src/core/grid-integration.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,uBAAuB,EACvB,+BAA+B,EAC/B,sBAAsB,EACtB,wBAAwB,EACxB,sBAAsB,EACvB,MAAM,YAAY,CAAA;AAKnB,MAAM,+BAA+B,GAAG;IACtC,QAAQ,EAAE,UAAU;IACpB,eAAe,EAAE,iBAAiB;IAClC,WAAW,EAAE,aAAa;IAC1B,kBAAkB,EAAE,oBAAoB;IACxC,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,IAAI;IACZ,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;IACd,QAAQ,EAAE,UAAU;CAC8B,CAAA;AAKpD,SAAS,sBAAsB,CAC7B,SAA6B;IAE7B,OAAO,OAAO,CAAC,SAAS,IAAI,SAAS,IAAI,+BAA+B,CAAC,CAAA;AAC3E,CAAC;AAOD,SAAS,eAAe,CAAC,GAAuB;IAC9C,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAA;IACnB,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAA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3
|
export { validateFilterValue, DEFAULT_CONFIG } from './validation.js';
|
|
5
|
-
// URL parsing utilities
|
|
6
4
|
export { parseUrlFilters, parseFilterParam } from './url-parser.js';
|
|
7
|
-
// URL generation utilities
|
|
8
5
|
export { serializeFilters, generateUrl } from './url-generator.js';
|
|
9
|
-
// AG Grid integration utilities
|
|
10
6
|
export { getFilterModel, applyFilterModel } from './grid-integration.js';
|
|
11
|
-
// Grouped serialization utilities
|
|
12
7
|
export * from './serialization/index.js';
|
|
13
8
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAEpE,cAAc,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAEpE,cAAc,YAAY,CAAA;AAG1B,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAGrE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGnE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAGlE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxE,cAAc,0BAA0B,CAAA"}
|
|
@@ -2,39 +2,26 @@ import { DEFAULT_CONFIG } from '../index.js';
|
|
|
2
2
|
import { generateUrl } from '../url-generator.js';
|
|
3
3
|
import { parseUrlFilters } from '../url-parser.js';
|
|
4
4
|
import { isValidColumnFilter } from '../validation.js';
|
|
5
|
-
/**
|
|
6
|
-
* QueryString format serializer
|
|
7
|
-
* Reuses existing URL generation logic but groups into single parameter
|
|
8
|
-
*/
|
|
9
5
|
export class QueryStringSerializer {
|
|
10
6
|
format = 'querystring';
|
|
11
7
|
serialize(filterState) {
|
|
12
|
-
// Create a temporary config for individual parameter generation
|
|
13
8
|
const tempConfig = {
|
|
14
|
-
gridApi: null,
|
|
9
|
+
gridApi: null,
|
|
15
10
|
...DEFAULT_CONFIG
|
|
16
11
|
};
|
|
17
|
-
// Generate URL with individual parameters
|
|
18
12
|
const tempUrl = generateUrl('http://example.com', filterState, tempConfig);
|
|
19
13
|
const urlObj = new URL(tempUrl);
|
|
20
|
-
// Extract just the search params (without the ?)
|
|
21
14
|
return urlObj.search.slice(1);
|
|
22
15
|
}
|
|
23
16
|
deserialize(value) {
|
|
24
|
-
// Create a temporary URL with the query string
|
|
25
17
|
const tempUrl = `http://example.com?${value}`;
|
|
26
|
-
// Create a temporary config for parsing
|
|
27
18
|
const tempConfig = {
|
|
28
|
-
gridApi: null,
|
|
19
|
+
gridApi: null,
|
|
29
20
|
...DEFAULT_CONFIG
|
|
30
21
|
};
|
|
31
22
|
return parseUrlFilters(tempUrl, tempConfig);
|
|
32
23
|
}
|
|
33
24
|
}
|
|
34
|
-
/**
|
|
35
|
-
* JSON format serializer
|
|
36
|
-
* Serializes FilterState directly as JSON
|
|
37
|
-
*/
|
|
38
25
|
export class JsonSerializer {
|
|
39
26
|
format = 'json';
|
|
40
27
|
serialize(filterState) {
|
|
@@ -43,11 +30,9 @@ export class JsonSerializer {
|
|
|
43
30
|
deserialize(value) {
|
|
44
31
|
try {
|
|
45
32
|
const parsed = JSON.parse(value);
|
|
46
|
-
// Validate that it's a proper FilterState object
|
|
47
33
|
if (typeof parsed !== 'object' || parsed === null) {
|
|
48
34
|
throw new Error('Invalid JSON: must be an object');
|
|
49
35
|
}
|
|
50
|
-
// Basic validation of the structure
|
|
51
36
|
for (const [columnId, filter] of Object.entries(parsed)) {
|
|
52
37
|
if (typeof columnId !== 'string') {
|
|
53
38
|
throw new Error('Invalid JSON: column IDs must be strings');
|
|
@@ -63,10 +48,6 @@ export class JsonSerializer {
|
|
|
63
48
|
}
|
|
64
49
|
}
|
|
65
50
|
}
|
|
66
|
-
/**
|
|
67
|
-
* Base64 format serializer
|
|
68
|
-
* JSON encoded then base64 encoded for maximum compactness
|
|
69
|
-
*/
|
|
70
51
|
export class Base64Serializer {
|
|
71
52
|
format = 'base64';
|
|
72
53
|
jsonSerializer = new JsonSerializer();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formats.js","sourceRoot":"","sources":["../../../src/core/serialization/formats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAO5C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"formats.js","sourceRoot":"","sources":["../../../src/core/serialization/formats.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAO5C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAA;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AAMtD,MAAM,OAAO,qBAAqB;IACvB,MAAM,GAAwB,aAAa,CAAA;IAEpD,SAAS,CAAC,WAAwB;QAEhC,MAAM,UAAU,GAAmB;YACjC,OAAO,EAAE,IAAW;YACpB,GAAG,cAAc;SAClB,CAAA;QAGD,MAAM,OAAO,GAAG,WAAW,CAAC,oBAAoB,EAAE,WAAW,EAAE,UAAU,CAAC,CAAA;QAC1E,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAA;QAG/B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;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