@genesislcap/foundation-workspace 15.46.2-FUI-2628.2 → 15.46.3
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 +55 -405
- package/dist/dts/workspace/filter-registry.d.ts +0 -12
- package/dist/dts/workspace/filter-registry.d.ts.map +1 -1
- package/dist/dts/workspace/grid-register/grid-register.d.ts +10 -3
- package/dist/dts/workspace/grid-register/grid-register.d.ts.map +1 -1
- package/dist/dts/workspace/grid-registry.d.ts +4 -76
- package/dist/dts/workspace/grid-registry.d.ts.map +1 -1
- package/dist/dts/workspace/layout-registry.d.ts +0 -18
- package/dist/dts/workspace/layout-registry.d.ts.map +1 -1
- package/dist/dts/workspace/workspace.types.d.ts +0 -6
- package/dist/dts/workspace/workspace.types.d.ts.map +1 -1
- package/dist/dts/workspace-manager/workspace-manager.d.ts +0 -6
- package/dist/dts/workspace-manager/workspace-manager.d.ts.map +1 -1
- package/dist/esm/workspace/filter-registry.js +21 -32
- package/dist/esm/workspace/grid-register/grid-register.js +54 -7
- package/dist/esm/workspace/grid-registry.js +32 -329
- package/dist/esm/workspace/layout-registry.js +8 -60
- package/dist/esm/workspace-manager/workspace-manager.js +9 -10
- package/dist/foundation-workspace.api.json +39 -244
- package/dist/foundation-workspace.d.ts +13 -122
- package/package.json +14 -14
|
@@ -1,131 +1,20 @@
|
|
|
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;
|
|
7
3
|
/**
|
|
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.
|
|
36
4
|
* @alpha
|
|
37
5
|
*/
|
|
38
6
|
export class DefaultGridRegistry {
|
|
39
7
|
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;
|
|
46
8
|
this.grids = new Map();
|
|
47
|
-
this.
|
|
48
|
-
this.listeners = new Map();
|
|
49
|
-
this.guards = new Map();
|
|
9
|
+
this.cachedSettings = new Map();
|
|
50
10
|
}
|
|
51
11
|
// Note: StatePersistence is not wired here to avoid a hard dependency on grid-pro.
|
|
52
|
-
registerGrid(gridKey, gridApi, columnApi
|
|
53
|
-
|
|
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 = {
|
|
12
|
+
registerGrid(gridKey, gridApi, columnApi) {
|
|
13
|
+
this.grids.set(gridKey, {
|
|
69
14
|
gridKey,
|
|
70
15
|
gridApi: gridApi,
|
|
71
16
|
columnApi: columnApi,
|
|
72
|
-
|
|
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
|
-
}
|
|
17
|
+
});
|
|
129
18
|
}
|
|
130
19
|
getGrid(gridKey) {
|
|
131
20
|
return this.grids.get(gridKey) || null;
|
|
@@ -135,9 +24,8 @@ export class DefaultGridRegistry {
|
|
|
135
24
|
if (grid) {
|
|
136
25
|
const settings = this.getGridSettings(gridKey, grid);
|
|
137
26
|
if (settings) {
|
|
138
|
-
this.
|
|
27
|
+
this.cachedSettings.set(gridKey, settings);
|
|
139
28
|
}
|
|
140
|
-
this.detach(grid);
|
|
141
29
|
}
|
|
142
30
|
this.grids.delete(gridKey);
|
|
143
31
|
}
|
|
@@ -145,10 +33,10 @@ export class DefaultGridRegistry {
|
|
|
145
33
|
Array.from(this.grids).forEach(([key, grid]) => {
|
|
146
34
|
const settings = this.getGridSettings(key, grid);
|
|
147
35
|
if (settings) {
|
|
148
|
-
this.
|
|
36
|
+
this.cachedSettings.set(key, settings);
|
|
149
37
|
}
|
|
150
38
|
});
|
|
151
|
-
return Array.from(this.
|
|
39
|
+
return Array.from(this.cachedSettings.values()).filter((s) => !!s);
|
|
152
40
|
}
|
|
153
41
|
applyGridSettings(gridSetting, options) {
|
|
154
42
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -158,10 +46,10 @@ export class DefaultGridRegistry {
|
|
|
158
46
|
return false;
|
|
159
47
|
}
|
|
160
48
|
const hasColumnState = gridSetting.columnState && gridSetting.columnState.length > 0;
|
|
161
|
-
const
|
|
162
|
-
const
|
|
163
|
-
if (!shouldApplyColumns
|
|
164
|
-
//
|
|
49
|
+
const applyColumns = !options || options.applyColumns !== false;
|
|
50
|
+
const shouldApplyColumns = applyColumns && !!hasColumnState;
|
|
51
|
+
if (!shouldApplyColumns) {
|
|
52
|
+
// No column state to apply; treat as a no-op.
|
|
165
53
|
return false;
|
|
166
54
|
}
|
|
167
55
|
try {
|
|
@@ -175,15 +63,11 @@ export class DefaultGridRegistry {
|
|
|
175
63
|
applyOrder: true,
|
|
176
64
|
});
|
|
177
65
|
}
|
|
178
|
-
else
|
|
66
|
+
else {
|
|
179
67
|
console.warn(`GridRegistry: applyColumnState not found for ${gridSetting.gridKey} (gridApi/columnApi)`);
|
|
180
68
|
return false;
|
|
181
69
|
}
|
|
182
70
|
}
|
|
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
|
-
}
|
|
187
71
|
return true;
|
|
188
72
|
}
|
|
189
73
|
catch (error) {
|
|
@@ -192,224 +76,43 @@ export class DefaultGridRegistry {
|
|
|
192
76
|
}
|
|
193
77
|
});
|
|
194
78
|
}
|
|
195
|
-
applyAllGridsSettings(
|
|
196
|
-
return __awaiter(this,
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (gridSetting.filterModel !== undefined) {
|
|
205
|
-
this.armFilterGuard(registration);
|
|
79
|
+
applyAllGridsSettings(gridsSettings_1) {
|
|
80
|
+
return __awaiter(this, arguments, void 0, function* (gridsSettings, maxRetries = 3) {
|
|
81
|
+
for (let attempt = 0; attempt < maxRetries; attempt += 1) {
|
|
82
|
+
const remainingSettings = [];
|
|
83
|
+
/* oxlint-disable no-await-in-loop -- apply each grid settings snapshot in order */
|
|
84
|
+
for (const gridSetting of gridsSettings) {
|
|
85
|
+
const applied = yield this.applyGridSettings(gridSetting);
|
|
86
|
+
if (!applied) {
|
|
87
|
+
remainingSettings.push(gridSetting);
|
|
206
88
|
}
|
|
207
|
-
yield this.applyGridSettings(gridSetting);
|
|
208
89
|
}
|
|
90
|
+
/* oxlint-enable no-await-in-loop */
|
|
91
|
+
if (remainingSettings.length === 0 || attempt >= maxRetries - 1) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
gridsSettings = remainingSettings;
|
|
209
95
|
}
|
|
210
|
-
/* oxlint-enable no-await-in-loop */
|
|
211
96
|
});
|
|
212
97
|
}
|
|
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
|
-
}
|
|
375
98
|
getGridSettings(gridKey, grid) {
|
|
376
|
-
var _a, _b, _c, _d
|
|
99
|
+
var _a, _b, _c, _d;
|
|
377
100
|
if (grid) {
|
|
378
101
|
// Prefer Grid API if available, otherwise fall back to Column API.
|
|
379
102
|
// (AG Grid's Column state is typically on ColumnApi; this is defensive.)
|
|
380
103
|
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;
|
|
384
104
|
const columnCount = (columnState === null || columnState === void 0 ? void 0 : columnState.length) || 0;
|
|
385
105
|
console.log(`Saved grid settings for ${gridKey}: ${columnCount} columns`);
|
|
386
|
-
return
|
|
106
|
+
return {
|
|
107
|
+
gridKey: grid.gridKey,
|
|
108
|
+
columnState: columnState || [],
|
|
109
|
+
savedAt: new Date().toISOString(),
|
|
110
|
+
};
|
|
387
111
|
}
|
|
388
112
|
console.warn(`No grid found for ${gridKey}`);
|
|
389
113
|
return null;
|
|
390
114
|
}
|
|
391
115
|
}
|
|
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
|
-
}
|
|
413
116
|
/**
|
|
414
117
|
* DI token for grid registry.
|
|
415
118
|
* @alpha
|
|
@@ -1,66 +1,38 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
-
import { LayoutEmitEvents } from '@genesislcap/foundation-layout';
|
|
3
2
|
import { DI } from '@genesislcap/web-core';
|
|
4
3
|
const LAYOUT_DELAY = 300;
|
|
5
4
|
/**
|
|
6
5
|
* 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.
|
|
18
6
|
* @alpha
|
|
19
7
|
*/
|
|
20
8
|
export class DefaultLayoutRegistry {
|
|
21
9
|
constructor() {
|
|
22
10
|
this.layouts = new Map();
|
|
23
|
-
this.stored = new Map();
|
|
24
11
|
}
|
|
25
12
|
registerLayout(layoutKey, layout) {
|
|
26
13
|
if (!layoutKey) {
|
|
27
14
|
return;
|
|
28
15
|
}
|
|
29
16
|
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
|
-
}
|
|
39
17
|
}
|
|
40
18
|
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
|
-
}
|
|
46
19
|
this.layouts.delete(layoutKey);
|
|
47
20
|
}
|
|
48
21
|
getLayoutsConfigs() {
|
|
49
|
-
this.layouts.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
return Array.from(this.stored).map(([layoutKey, layout]) => ({ layoutKey, layout }));
|
|
22
|
+
return Array.from(this.layouts).map(([key, layout]) => ({
|
|
23
|
+
layoutKey: key,
|
|
24
|
+
layout: layout.getLayout(),
|
|
25
|
+
}));
|
|
56
26
|
}
|
|
57
27
|
applySavedLayouts(savedLayouts) {
|
|
58
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
this.stored = new Map(savedLayouts.map((s) => [s.layoutKey, s.layout]));
|
|
60
29
|
savedLayouts.forEach((s) => {
|
|
61
30
|
const layout = this.layouts.get(s.layoutKey);
|
|
62
31
|
if (layout) {
|
|
63
|
-
|
|
32
|
+
layout.loadLayout(s.layout, 'placeholder', true);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
console.warn(`layout for ${s.layoutKey} not found`);
|
|
64
36
|
}
|
|
65
37
|
});
|
|
66
38
|
yield new Promise((resolve) => {
|
|
@@ -68,30 +40,6 @@ export class DefaultLayoutRegistry {
|
|
|
68
40
|
});
|
|
69
41
|
});
|
|
70
42
|
}
|
|
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
|
-
}
|
|
95
43
|
}
|
|
96
44
|
/**
|
|
97
45
|
* DI token for layout registry.
|
|
@@ -137,18 +137,17 @@ 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
|
-
*/
|
|
146
140
|
applyWorkspace(workspace) {
|
|
147
141
|
return __awaiter(this, void 0, void 0, function* () {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
142
|
+
if (workspace.filters && workspace.filters.length > 0) {
|
|
143
|
+
this.filterRegistry.applyFiltersValues(workspace.filters);
|
|
144
|
+
}
|
|
145
|
+
if (workspace.layouts && workspace.layouts.length > 0) {
|
|
146
|
+
yield this.layoutRegistry.applySavedLayouts(workspace.layouts);
|
|
147
|
+
}
|
|
148
|
+
if (workspace.grids && workspace.grids.length > 0) {
|
|
149
|
+
yield this.gridRegistry.applyAllGridsSettings(workspace.grids);
|
|
150
|
+
}
|
|
152
151
|
});
|
|
153
152
|
}
|
|
154
153
|
loadWorkspace(workspaceName) {
|