@genesislcap/foundation-workspace 15.46.1 → 15.46.2-FUI-2628.2
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/dist/custom-elements.json +405 -55
- package/dist/dts/workspace/filter-registry.d.ts +12 -0
- package/dist/dts/workspace/filter-registry.d.ts.map +1 -1
- package/dist/dts/workspace/grid-register/grid-register.d.ts +3 -10
- package/dist/dts/workspace/grid-register/grid-register.d.ts.map +1 -1
- package/dist/dts/workspace/grid-registry.d.ts +76 -4
- package/dist/dts/workspace/grid-registry.d.ts.map +1 -1
- package/dist/dts/workspace/layout-registry.d.ts +18 -0
- package/dist/dts/workspace/layout-registry.d.ts.map +1 -1
- package/dist/dts/workspace/workspace.types.d.ts +6 -0
- package/dist/dts/workspace/workspace.types.d.ts.map +1 -1
- package/dist/dts/workspace-manager/workspace-manager.d.ts +6 -0
- package/dist/dts/workspace-manager/workspace-manager.d.ts.map +1 -1
- package/dist/esm/workspace/filter-registry.js +32 -21
- package/dist/esm/workspace/grid-register/grid-register.js +7 -54
- package/dist/esm/workspace/grid-registry.js +329 -32
- package/dist/esm/workspace/layout-registry.js +60 -8
- package/dist/esm/workspace-manager/workspace-manager.js +10 -9
- package/dist/foundation-workspace.api.json +244 -39
- package/dist/foundation-workspace.d.ts +122 -13
- package/package.json +14 -14
|
@@ -1,20 +1,131 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import { DI } from '@genesislcap/web-core';
|
|
3
|
+
/** Defaults for {@link DefaultGridRegistry}'s filter guard. */
|
|
4
|
+
const FILTER_SETTLE_MS = 1500;
|
|
5
|
+
const FILTER_GUARD_MAX_MS = 10000;
|
|
6
|
+
const MAX_FILTER_REAPPLIES = 3;
|
|
3
7
|
/**
|
|
8
|
+
* Default grid registry implementation.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* Keeps a store of every grid's last known column state and filter model by key, so a workspace
|
|
12
|
+
* covers grids that aren't currently mounted (e.g. on another route):
|
|
13
|
+
* - `unregisterGrid` stores the grid's last state; `registerGrid` applies any stored state.
|
|
14
|
+
* - `applyAllGridsSettings` (workspace load) replaces the store with the loaded settings and
|
|
15
|
+
* applies them to mounted grids; unmounted ones pick theirs up when they register.
|
|
16
|
+
* - `getAllGridsSettings` (workspace save) returns the store with mounted grids' live state on
|
|
17
|
+
* top, so a grid the user never visited keeps its loaded state rather than being dropped.
|
|
18
|
+
*
|
|
19
|
+
* Filters race with the grid's own start-up. grid-pro restores its persisted filter model
|
|
20
|
+
* (`persist-filter-model-key`) asynchronously, up to three times — at grid ready, once
|
|
21
|
+
* datasource-driven columns exist, and on the datasource's `filtersRestored` — and a restore with
|
|
22
|
+
* nothing stored applies `{}`, clearing every filter. A filter for a column that doesn't exist yet
|
|
23
|
+
* is dropped. So when the registry applies a filter model it:
|
|
24
|
+
* 1. writes it into the grid's own filter persistence first (`filterPersistence`), so grid-pro's
|
|
25
|
+
* later restores, including a datasource re-init long after start-up, return the workspace's
|
|
26
|
+
* model rather than an older one;
|
|
27
|
+
* 2. arms a guard that re-applies it if a programmatic filter change (e.g. a restore that read
|
|
28
|
+
* storage before step 1 landed, as KV storage can) replaces it, and when the grid's columns
|
|
29
|
+
* change (so filters on columns that arrive late apply). The guard ends as soon as the user
|
|
30
|
+
* changes a filter, once the grid has been quiet for `filterSettleMs` after its last start-up
|
|
31
|
+
* event, and in any case after `filterGuardMaxMs`, so it never fights app code for long. It
|
|
32
|
+
* re-applies at most `maxFilterReapplies` times per arming, so it cannot loop.
|
|
33
|
+
*
|
|
34
|
+
* A saved entry without `filterModel` (a workspace saved before filters were captured) leaves the
|
|
35
|
+
* grid's filters alone.
|
|
4
36
|
* @alpha
|
|
5
37
|
*/
|
|
6
38
|
export class DefaultGridRegistry {
|
|
7
39
|
constructor() {
|
|
40
|
+
/** Quiet period after the last start-up event before the filter guard ends. */
|
|
41
|
+
this.filterSettleMs = FILTER_SETTLE_MS;
|
|
42
|
+
/** Longest the filter guard runs after it is armed, however often it is re-armed. */
|
|
43
|
+
this.filterGuardMaxMs = FILTER_GUARD_MAX_MS;
|
|
44
|
+
/** Most re-applies the filter guard makes per arming. */
|
|
45
|
+
this.maxFilterReapplies = MAX_FILTER_REAPPLIES;
|
|
8
46
|
this.grids = new Map();
|
|
9
|
-
this.
|
|
47
|
+
this.stored = new Map();
|
|
48
|
+
this.listeners = new Map();
|
|
49
|
+
this.guards = new Map();
|
|
10
50
|
}
|
|
11
51
|
// Note: StatePersistence is not wired here to avoid a hard dependency on grid-pro.
|
|
12
|
-
registerGrid(gridKey, gridApi, columnApi) {
|
|
13
|
-
|
|
52
|
+
registerGrid(gridKey, gridApi, columnApi, filterPersistence) {
|
|
53
|
+
// Re-registering a key (e.g. the grid re-initialised with a new API) keeps what the user did on
|
|
54
|
+
// the outgoing instance, as unregistering would, rather than re-applying older stored state.
|
|
55
|
+
const previous = this.grids.get(gridKey);
|
|
56
|
+
if (previous) {
|
|
57
|
+
try {
|
|
58
|
+
const settings = this.getGridSettings(gridKey, previous);
|
|
59
|
+
if (settings) {
|
|
60
|
+
this.stored.set(gridKey, settings);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
catch (_a) {
|
|
64
|
+
// The outgoing API may already be destroyed; keep what was stored.
|
|
65
|
+
}
|
|
66
|
+
this.detach(previous);
|
|
67
|
+
}
|
|
68
|
+
const registration = {
|
|
14
69
|
gridKey,
|
|
15
70
|
gridApi: gridApi,
|
|
16
71
|
columnApi: columnApi,
|
|
17
|
-
|
|
72
|
+
filterPersistence,
|
|
73
|
+
};
|
|
74
|
+
this.grids.set(gridKey, registration);
|
|
75
|
+
const stored = this.stored.get(gridKey);
|
|
76
|
+
if ((stored === null || stored === void 0 ? void 0 : stored.filterModel) !== undefined) {
|
|
77
|
+
this.armFilterGuard(registration);
|
|
78
|
+
}
|
|
79
|
+
this.applyStoredSettings(registration);
|
|
80
|
+
// A datasource-driven grid creates its columns after grid ready (from the datasource schema),
|
|
81
|
+
// and grid-pro restores its own `persist-column-state-key` state asynchronously then too;
|
|
82
|
+
// either discards state applied now. Apply the stored state again once the first data renders,
|
|
83
|
+
// when both have happened.
|
|
84
|
+
const onFirstDataRendered = () => {
|
|
85
|
+
this.removeListener(registration, 'firstDataRendered', onFirstDataRendered);
|
|
86
|
+
this.touchFilterGuard(registration);
|
|
87
|
+
// Once the user has changed a filter (which ends the guard), keep their filters.
|
|
88
|
+
this.applyStoredSettings(registration, {
|
|
89
|
+
applyFilters: this.guardActive(registration),
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
// Columns that arrive late (datasource schema, new column defs) had their filters dropped.
|
|
93
|
+
const onGridColumnsChanged = () => {
|
|
94
|
+
if (this.guardActive(registration)) {
|
|
95
|
+
this.touchFilterGuard(registration);
|
|
96
|
+
this.reapplyStoredFilter(registration);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const onFilterChanged = (event) => {
|
|
100
|
+
var _a;
|
|
101
|
+
if ((_a = this.guards.get(registration)) === null || _a === void 0 ? void 0 : _a.applying) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (isUserFilterChange(event)) {
|
|
105
|
+
this.endFilterGuard(registration);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
if (this.guardActive(registration) && this.filterWasReplaced(registration)) {
|
|
109
|
+
this.reapplyStoredFilter(registration);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
// Only the filter UI fires `filterModified` (v29 and v36 alike): the user is editing a filter.
|
|
113
|
+
const onFilterModified = () => this.endFilterGuard(registration);
|
|
114
|
+
this.addListener(registration, 'firstDataRendered', onFirstDataRendered);
|
|
115
|
+
this.addListener(registration, 'gridColumnsChanged', onGridColumnsChanged);
|
|
116
|
+
this.addListener(registration, 'filterChanged', onFilterChanged);
|
|
117
|
+
this.addListener(registration, 'filterModified', onFilterModified);
|
|
118
|
+
}
|
|
119
|
+
/** Applies the stored settings for a grid, unless it already has exactly that state. */
|
|
120
|
+
applyStoredSettings(registration, options) {
|
|
121
|
+
const stored = this.stored.get(registration.gridKey);
|
|
122
|
+
if (!stored) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const settings = (options === null || options === void 0 ? void 0 : options.applyFilters) === false ? Object.assign(Object.assign({}, stored), { filterModel: undefined }) : stored;
|
|
126
|
+
if (!this.hasSettings(registration, settings)) {
|
|
127
|
+
void this.applyGridSettings(settings);
|
|
128
|
+
}
|
|
18
129
|
}
|
|
19
130
|
getGrid(gridKey) {
|
|
20
131
|
return this.grids.get(gridKey) || null;
|
|
@@ -24,8 +135,9 @@ export class DefaultGridRegistry {
|
|
|
24
135
|
if (grid) {
|
|
25
136
|
const settings = this.getGridSettings(gridKey, grid);
|
|
26
137
|
if (settings) {
|
|
27
|
-
this.
|
|
138
|
+
this.stored.set(gridKey, settings);
|
|
28
139
|
}
|
|
140
|
+
this.detach(grid);
|
|
29
141
|
}
|
|
30
142
|
this.grids.delete(gridKey);
|
|
31
143
|
}
|
|
@@ -33,10 +145,10 @@ export class DefaultGridRegistry {
|
|
|
33
145
|
Array.from(this.grids).forEach(([key, grid]) => {
|
|
34
146
|
const settings = this.getGridSettings(key, grid);
|
|
35
147
|
if (settings) {
|
|
36
|
-
this.
|
|
148
|
+
this.stored.set(key, settings);
|
|
37
149
|
}
|
|
38
150
|
});
|
|
39
|
-
return Array.from(this.
|
|
151
|
+
return Array.from(this.stored.values());
|
|
40
152
|
}
|
|
41
153
|
applyGridSettings(gridSetting, options) {
|
|
42
154
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -46,10 +158,10 @@ export class DefaultGridRegistry {
|
|
|
46
158
|
return false;
|
|
47
159
|
}
|
|
48
160
|
const hasColumnState = gridSetting.columnState && gridSetting.columnState.length > 0;
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
if (!shouldApplyColumns) {
|
|
52
|
-
//
|
|
161
|
+
const shouldApplyColumns = (options === null || options === void 0 ? void 0 : options.applyColumns) !== false && !!hasColumnState;
|
|
162
|
+
const shouldApplyFilters = (options === null || options === void 0 ? void 0 : options.applyFilters) !== false && gridSetting.filterModel !== undefined;
|
|
163
|
+
if (!shouldApplyColumns && !shouldApplyFilters) {
|
|
164
|
+
// Nothing to apply; treat as a no-op.
|
|
53
165
|
return false;
|
|
54
166
|
}
|
|
55
167
|
try {
|
|
@@ -63,11 +175,15 @@ export class DefaultGridRegistry {
|
|
|
63
175
|
applyOrder: true,
|
|
64
176
|
});
|
|
65
177
|
}
|
|
66
|
-
else {
|
|
178
|
+
else if (!shouldApplyFilters) {
|
|
67
179
|
console.warn(`GridRegistry: applyColumnState not found for ${gridSetting.gridKey} (gridApi/columnApi)`);
|
|
68
180
|
return false;
|
|
69
181
|
}
|
|
70
182
|
}
|
|
183
|
+
// Columns first: a filter on a column the state reveals or reorders still applies.
|
|
184
|
+
if (shouldApplyFilters) {
|
|
185
|
+
this.applyFilterModel(gridRegistration, gridSetting.filterModel);
|
|
186
|
+
}
|
|
71
187
|
return true;
|
|
72
188
|
}
|
|
73
189
|
catch (error) {
|
|
@@ -76,43 +192,224 @@ export class DefaultGridRegistry {
|
|
|
76
192
|
}
|
|
77
193
|
});
|
|
78
194
|
}
|
|
79
|
-
applyAllGridsSettings(
|
|
80
|
-
return __awaiter(this,
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
195
|
+
applyAllGridsSettings(gridsSettings) {
|
|
196
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
197
|
+
this.stored = new Map(gridsSettings.map((g) => [g.gridKey, g]));
|
|
198
|
+
/* oxlint-disable no-await-in-loop -- apply each grid settings snapshot in order */
|
|
199
|
+
for (const gridSetting of gridsSettings) {
|
|
200
|
+
const registration = this.grids.get(gridSetting.gridKey);
|
|
201
|
+
if (registration) {
|
|
202
|
+
// A grid mid start-up (or whose datasource re-initialises right after) can still restore
|
|
203
|
+
// an older filter over the loaded one, so a load re-arms the guard as a register does.
|
|
204
|
+
if (gridSetting.filterModel !== undefined) {
|
|
205
|
+
this.armFilterGuard(registration);
|
|
88
206
|
}
|
|
207
|
+
yield this.applyGridSettings(gridSetting);
|
|
89
208
|
}
|
|
90
|
-
/* oxlint-enable no-await-in-loop */
|
|
91
|
-
if (remainingSettings.length === 0 || attempt >= maxRetries - 1) {
|
|
92
|
-
break;
|
|
93
|
-
}
|
|
94
|
-
gridsSettings = remainingSettings;
|
|
95
209
|
}
|
|
210
|
+
/* oxlint-enable no-await-in-loop */
|
|
96
211
|
});
|
|
97
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* Writes a filter model into the grid's own persistence, then onto the grid, and records what
|
|
215
|
+
* the grid reports back so the guard can tell a later replacement from AG Grid's normalisation.
|
|
216
|
+
*/
|
|
217
|
+
applyFilterModel(registration, filterModel) {
|
|
218
|
+
var _a;
|
|
219
|
+
try {
|
|
220
|
+
// Fire-and-forget is fine: grid-pro's local-storage persistence writes synchronously, and the
|
|
221
|
+
// guard covers a KV write that a restore's read overtakes.
|
|
222
|
+
void ((_a = registration.filterPersistence) === null || _a === void 0 ? void 0 : _a.setFilterModel(filterModel));
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
console.warn(`GridRegistry: failed to persist filter model for ${registration.gridKey}`, error);
|
|
226
|
+
}
|
|
227
|
+
const api = registration.gridApi;
|
|
228
|
+
if (!(api === null || api === void 0 ? void 0 : api.setFilterModel)) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
const guard = this.guards.get(registration);
|
|
232
|
+
if (guard) {
|
|
233
|
+
guard.applying = true;
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
api.setFilterModel(filterModel);
|
|
237
|
+
}
|
|
238
|
+
finally {
|
|
239
|
+
if (guard) {
|
|
240
|
+
guard.applying = false;
|
|
241
|
+
guard.lastApplied = this.readFilterModel(registration);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
reapplyStoredFilter(registration) {
|
|
246
|
+
var _a;
|
|
247
|
+
const guard = this.guards.get(registration);
|
|
248
|
+
const filterModel = (_a = this.stored.get(registration.gridKey)) === null || _a === void 0 ? void 0 : _a.filterModel;
|
|
249
|
+
if (!guard ||
|
|
250
|
+
filterModel === undefined ||
|
|
251
|
+
this.grids.get(registration.gridKey) !== registration) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (this.readFilterModel(registration) === stableStringify(filterModel)) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (guard.reapplies >= this.maxFilterReapplies) {
|
|
258
|
+
this.endFilterGuard(registration);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
guard.reapplies += 1;
|
|
262
|
+
this.applyFilterModel(registration, filterModel);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Whether the grid's filter model moved away from what the registry last applied — a stale
|
|
266
|
+
* restore or other programmatic change, rather than AG Grid normalising the applied model (which
|
|
267
|
+
* reads back the same each time).
|
|
268
|
+
*/
|
|
269
|
+
filterWasReplaced(registration) {
|
|
270
|
+
var _a;
|
|
271
|
+
const guard = this.guards.get(registration);
|
|
272
|
+
const filterModel = (_a = this.stored.get(registration.gridKey)) === null || _a === void 0 ? void 0 : _a.filterModel;
|
|
273
|
+
if (!guard || filterModel === undefined) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
const current = this.readFilterModel(registration);
|
|
277
|
+
return current !== guard.lastApplied && current !== stableStringify(filterModel);
|
|
278
|
+
}
|
|
279
|
+
armFilterGuard(registration) {
|
|
280
|
+
const existing = this.guards.get(registration);
|
|
281
|
+
if (existing === null || existing === void 0 ? void 0 : existing.settleTimer) {
|
|
282
|
+
clearTimeout(existing.settleTimer);
|
|
283
|
+
}
|
|
284
|
+
const guard = {
|
|
285
|
+
hardStop: Date.now() + this.filterGuardMaxMs,
|
|
286
|
+
reapplies: 0,
|
|
287
|
+
active: true,
|
|
288
|
+
};
|
|
289
|
+
this.guards.set(registration, guard);
|
|
290
|
+
this.touchFilterGuard(registration);
|
|
291
|
+
}
|
|
292
|
+
/** Restarts the settle timer: the grid just did something that can precede a stale restore. */
|
|
293
|
+
touchFilterGuard(registration) {
|
|
294
|
+
const guard = this.guards.get(registration);
|
|
295
|
+
if (!(guard === null || guard === void 0 ? void 0 : guard.active)) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
if (guard.settleTimer) {
|
|
299
|
+
clearTimeout(guard.settleTimer);
|
|
300
|
+
}
|
|
301
|
+
const remaining = guard.hardStop - Date.now();
|
|
302
|
+
if (remaining <= 0) {
|
|
303
|
+
this.endFilterGuard(registration);
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
guard.settleTimer = setTimeout(() => this.endFilterGuard(registration), Math.min(this.filterSettleMs, remaining));
|
|
307
|
+
}
|
|
308
|
+
guardActive(registration) {
|
|
309
|
+
const guard = this.guards.get(registration);
|
|
310
|
+
if (!(guard === null || guard === void 0 ? void 0 : guard.active)) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
if (Date.now() >= guard.hardStop) {
|
|
314
|
+
this.endFilterGuard(registration);
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
return true;
|
|
318
|
+
}
|
|
319
|
+
endFilterGuard(registration) {
|
|
320
|
+
const guard = this.guards.get(registration);
|
|
321
|
+
if (!guard) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
guard.active = false;
|
|
325
|
+
if (guard.settleTimer) {
|
|
326
|
+
clearTimeout(guard.settleTimer);
|
|
327
|
+
guard.settleTimer = undefined;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
addListener(registration, type, listener) {
|
|
331
|
+
var _a;
|
|
332
|
+
const api = registration.gridApi;
|
|
333
|
+
if (!(api === null || api === void 0 ? void 0 : api.addEventListener)) {
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
api.addEventListener(type, listener);
|
|
337
|
+
const list = (_a = this.listeners.get(registration)) !== null && _a !== void 0 ? _a : [];
|
|
338
|
+
list.push([type, listener]);
|
|
339
|
+
this.listeners.set(registration, list);
|
|
340
|
+
}
|
|
341
|
+
removeListener(registration, type, listener) {
|
|
342
|
+
var _a, _b;
|
|
343
|
+
(_b = (_a = registration.gridApi) === null || _a === void 0 ? void 0 : _a.removeEventListener) === null || _b === void 0 ? void 0 : _b.call(_a, type, listener);
|
|
344
|
+
const list = this.listeners.get(registration);
|
|
345
|
+
if (list) {
|
|
346
|
+
this.listeners.set(registration, list.filter(([t, l]) => t !== type || l !== listener));
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/** Removes a registration's grid listeners and stops its filter guard. */
|
|
350
|
+
detach(registration) {
|
|
351
|
+
var _a;
|
|
352
|
+
const api = registration.gridApi;
|
|
353
|
+
((_a = this.listeners.get(registration)) !== null && _a !== void 0 ? _a : []).forEach(([type, listener]) => {
|
|
354
|
+
var _a;
|
|
355
|
+
(_a = api === null || api === void 0 ? void 0 : api.removeEventListener) === null || _a === void 0 ? void 0 : _a.call(api, type, listener);
|
|
356
|
+
});
|
|
357
|
+
this.listeners.delete(registration);
|
|
358
|
+
this.endFilterGuard(registration);
|
|
359
|
+
this.guards.delete(registration);
|
|
360
|
+
}
|
|
361
|
+
/** Whether the grid already has exactly these settings, so re-applying them is a no-op. */
|
|
362
|
+
hasSettings(grid, settings) {
|
|
363
|
+
var _a, _b, _c, _d, _e;
|
|
364
|
+
const current = (_c = (_b = (_a = grid.gridApi) === null || _a === void 0 ? void 0 : _a.getColumnState) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : (_d = grid.columnApi) === null || _d === void 0 ? void 0 : _d.getColumnState();
|
|
365
|
+
const columnsMatch = !((_e = settings.columnState) === null || _e === void 0 ? void 0 : _e.length) ||
|
|
366
|
+
JSON.stringify(current !== null && current !== void 0 ? current : []) === JSON.stringify(settings.columnState);
|
|
367
|
+
const filtersMatch = settings.filterModel === undefined ||
|
|
368
|
+
this.readFilterModel(grid) === stableStringify(settings.filterModel);
|
|
369
|
+
return columnsMatch && filtersMatch;
|
|
370
|
+
}
|
|
371
|
+
readFilterModel(grid) {
|
|
372
|
+
var _a, _b, _c;
|
|
373
|
+
return stableStringify((_c = (_b = (_a = grid.gridApi) === null || _a === void 0 ? void 0 : _a.getFilterModel) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : {});
|
|
374
|
+
}
|
|
98
375
|
getGridSettings(gridKey, grid) {
|
|
99
|
-
var _a, _b, _c, _d;
|
|
376
|
+
var _a, _b, _c, _d, _e;
|
|
100
377
|
if (grid) {
|
|
101
378
|
// Prefer Grid API if available, otherwise fall back to Column API.
|
|
102
379
|
// (AG Grid's Column state is typically on ColumnApi; this is defensive.)
|
|
103
380
|
const columnState = (_c = (_b = (_a = grid.gridApi) === null || _a === void 0 ? void 0 : _a.getColumnState) === null || _b === void 0 ? void 0 : _b.call(_a)) !== null && _c !== void 0 ? _c : (_d = grid.columnApi) === null || _d === void 0 ? void 0 : _d.getColumnState();
|
|
381
|
+
const api = grid.gridApi;
|
|
382
|
+
// `{}` (no filters) is saved too, so loading the workspace clears filters set since.
|
|
383
|
+
const filterModel = (api === null || api === void 0 ? void 0 : api.getFilterModel) ? ((_e = api.getFilterModel()) !== null && _e !== void 0 ? _e : {}) : undefined;
|
|
104
384
|
const columnCount = (columnState === null || columnState === void 0 ? void 0 : columnState.length) || 0;
|
|
105
385
|
console.log(`Saved grid settings for ${gridKey}: ${columnCount} columns`);
|
|
106
|
-
return {
|
|
107
|
-
gridKey: grid.gridKey,
|
|
108
|
-
columnState: columnState || [],
|
|
109
|
-
savedAt: new Date().toISOString(),
|
|
110
|
-
};
|
|
386
|
+
return Object.assign(Object.assign({ gridKey: grid.gridKey, columnState: columnState || [] }, (filterModel !== undefined && { filterModel })), { savedAt: new Date().toISOString() });
|
|
111
387
|
}
|
|
112
388
|
console.warn(`No grid found for ${gridKey}`);
|
|
113
389
|
return null;
|
|
114
390
|
}
|
|
115
391
|
}
|
|
392
|
+
/**
|
|
393
|
+
* Whether a `filterChanged` event came from the user: v36 tags its `source`; v29 has no `source`,
|
|
394
|
+
* but marks floating-filter changes (column-menu edits are caught by `filterModified`).
|
|
395
|
+
*/
|
|
396
|
+
function isUserFilterChange(event) {
|
|
397
|
+
if (!event) {
|
|
398
|
+
return false;
|
|
399
|
+
}
|
|
400
|
+
if (event.afterFloatingFilter) {
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
return event.source === 'columnFilter' || event.source === 'advancedFilter';
|
|
404
|
+
}
|
|
405
|
+
/** JSON with object keys sorted, so filter models compare equal regardless of key order. */
|
|
406
|
+
function stableStringify(value) {
|
|
407
|
+
return JSON.stringify(value, (_key, v) => v && typeof v === 'object' && !Array.isArray(v)
|
|
408
|
+
? Object.fromEntries(Object.keys(v)
|
|
409
|
+
.sort()
|
|
410
|
+
.map((k) => [k, v[k]]))
|
|
411
|
+
: v);
|
|
412
|
+
}
|
|
116
413
|
/**
|
|
117
414
|
* DI token for grid registry.
|
|
118
415
|
* @alpha
|
|
@@ -1,38 +1,66 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
+
import { LayoutEmitEvents } from '@genesislcap/foundation-layout';
|
|
2
3
|
import { DI } from '@genesislcap/web-core';
|
|
3
4
|
const LAYOUT_DELAY = 300;
|
|
4
5
|
/**
|
|
5
6
|
* Default layout registry implementation.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* Keeps a store of every layout's last known config by key, so a workspace covers layouts that
|
|
10
|
+
* aren't currently mounted (e.g. on another route):
|
|
11
|
+
* - `unregisterLayout` stores the layout's last config; `registerLayout` loads any stored config
|
|
12
|
+
* once the layout has finished its first load (so its declared or autosaved layout doesn't
|
|
13
|
+
* overwrite it).
|
|
14
|
+
* - `applySavedLayouts` (workspace load) replaces the store with the loaded configs and loads them
|
|
15
|
+
* into mounted layouts; unmounted ones pick theirs up when they register.
|
|
16
|
+
* - `getLayoutsConfigs` (workspace save) returns the store with mounted layouts' live configs on
|
|
17
|
+
* top, so a layout the user never visited keeps its loaded config rather than being dropped.
|
|
6
18
|
* @alpha
|
|
7
19
|
*/
|
|
8
20
|
export class DefaultLayoutRegistry {
|
|
9
21
|
constructor() {
|
|
10
22
|
this.layouts = new Map();
|
|
23
|
+
this.stored = new Map();
|
|
11
24
|
}
|
|
12
25
|
registerLayout(layoutKey, layout) {
|
|
13
26
|
if (!layoutKey) {
|
|
14
27
|
return;
|
|
15
28
|
}
|
|
16
29
|
this.layouts.set(layoutKey, layout);
|
|
30
|
+
if (this.stored.has(layoutKey)) {
|
|
31
|
+
this.whenFirstLoaded(layout, () => {
|
|
32
|
+
// Re-read at load time: a workspace load may have replaced the entry since registering.
|
|
33
|
+
const stored = this.stored.get(layoutKey);
|
|
34
|
+
if (stored && this.layouts.get(layoutKey) === layout) {
|
|
35
|
+
layout.loadLayout(stored, 'placeholder', true);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
17
39
|
}
|
|
18
40
|
unregisterLayout(layoutKey) {
|
|
41
|
+
const layout = this.layouts.get(layoutKey);
|
|
42
|
+
const config = layout && this.readLayout(layout);
|
|
43
|
+
if (config) {
|
|
44
|
+
this.stored.set(layoutKey, config);
|
|
45
|
+
}
|
|
19
46
|
this.layouts.delete(layoutKey);
|
|
20
47
|
}
|
|
21
48
|
getLayoutsConfigs() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
this.layouts.forEach((layout, key) => {
|
|
50
|
+
const config = this.readLayout(layout);
|
|
51
|
+
if (config) {
|
|
52
|
+
this.stored.set(key, config);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
return Array.from(this.stored).map(([layoutKey, layout]) => ({ layoutKey, layout }));
|
|
26
56
|
}
|
|
27
57
|
applySavedLayouts(savedLayouts) {
|
|
28
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
this.stored = new Map(savedLayouts.map((s) => [s.layoutKey, s.layout]));
|
|
29
60
|
savedLayouts.forEach((s) => {
|
|
30
61
|
const layout = this.layouts.get(s.layoutKey);
|
|
31
62
|
if (layout) {
|
|
32
|
-
layout.loadLayout(s.layout, 'placeholder', true);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
console.warn(`layout for ${s.layoutKey} not found`);
|
|
63
|
+
this.whenFirstLoaded(layout, () => layout.loadLayout(s.layout, 'placeholder', true));
|
|
36
64
|
}
|
|
37
65
|
});
|
|
38
66
|
yield new Promise((resolve) => {
|
|
@@ -40,6 +68,30 @@ export class DefaultLayoutRegistry {
|
|
|
40
68
|
});
|
|
41
69
|
});
|
|
42
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* A layout's config is only meaningful once it has finished its first load; before that it has
|
|
73
|
+
* no panes yet, and storing that would wipe the saved config.
|
|
74
|
+
*/
|
|
75
|
+
readLayout(layout) {
|
|
76
|
+
if (!layout.hasFirstLoaded) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
return layout.getLayout();
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.warn('LayoutRegistry: failed to read layout config', error);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
whenFirstLoaded(layout, callback) {
|
|
88
|
+
if (layout.hasFirstLoaded) {
|
|
89
|
+
callback();
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
layout.addEventListener(LayoutEmitEvents.firstLoaded, callback, { once: true });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
43
95
|
}
|
|
44
96
|
/**
|
|
45
97
|
* DI token for layout registry.
|
|
@@ -137,17 +137,18 @@ let WorkspaceManager = class WorkspaceManager extends FoundationElement {
|
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Seeds every registry's store with the workspace's entries (replacing whatever was stored,
|
|
142
|
+
* even when a list is empty) and applies them to what's mounted; unmounted grids, layouts and
|
|
143
|
+
* filters pick theirs up when they register. Grids and filters are seeded before layouts:
|
|
144
|
+
* loading a layout rebuilds its panes, and the grids/filters inside re-register straight away.
|
|
145
|
+
*/
|
|
140
146
|
applyWorkspace(workspace) {
|
|
141
147
|
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
yield this.layoutRegistry.applySavedLayouts(workspace.layouts);
|
|
147
|
-
}
|
|
148
|
-
if (workspace.grids && workspace.grids.length > 0) {
|
|
149
|
-
yield this.gridRegistry.applyAllGridsSettings(workspace.grids);
|
|
150
|
-
}
|
|
148
|
+
var _a, _b, _c;
|
|
149
|
+
this.filterRegistry.applyFiltersValues((_a = workspace.filters) !== null && _a !== void 0 ? _a : []);
|
|
150
|
+
yield this.gridRegistry.applyAllGridsSettings((_b = workspace.grids) !== null && _b !== void 0 ? _b : []);
|
|
151
|
+
yield this.layoutRegistry.applySavedLayouts((_c = workspace.layouts) !== null && _c !== void 0 ? _c : []);
|
|
151
152
|
});
|
|
152
153
|
}
|
|
153
154
|
loadWorkspace(workspaceName) {
|