@genesislcap/grid-pro 14.151.1 → 14.152.0
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 +245 -9
- package/dist/dts/datasource/server-side.datasource.d.ts.map +1 -1
- package/dist/dts/grid-pro-genesis-datasource/grid-pro-genesis-datasource.d.ts.map +1 -1
- package/dist/dts/grid-pro.d.ts +22 -11
- package/dist/dts/grid-pro.d.ts.map +1 -1
- package/dist/dts/index.d.ts +1 -0
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/state-persistence/index.d.ts +4 -0
- package/dist/dts/state-persistence/index.d.ts.map +1 -0
- package/dist/dts/state-persistence/kv-state.d.ts +15 -0
- package/dist/dts/state-persistence/kv-state.d.ts.map +1 -0
- package/dist/dts/state-persistence/local-state.d.ts +13 -0
- package/dist/dts/state-persistence/local-state.d.ts.map +1 -0
- package/dist/dts/state-persistence/state-persistence.d.ts +24 -0
- package/dist/dts/state-persistence/state-persistence.d.ts.map +1 -0
- package/dist/esm/datasource/server-side.datasource.js +41 -39
- package/dist/esm/grid-pro-genesis-datasource/grid-pro-genesis-datasource.js +65 -61
- package/dist/esm/grid-pro.js +102 -90
- package/dist/esm/index.js +1 -0
- package/dist/esm/state-persistence/index.js +3 -0
- package/dist/esm/state-persistence/kv-state.js +58 -0
- package/dist/esm/state-persistence/local-state.js +30 -0
- package/dist/esm/state-persistence/state-persistence.js +7 -0
- package/dist/grid-pro.api.json +795 -158
- package/dist/grid-pro.d.ts +69 -11
- package/docs/api/grid-pro.gridpro.applytemplatedefinitions.md +2 -2
- package/docs/api/grid-pro.gridpro.getsavedcolumnstate.md +3 -3
- package/docs/api/grid-pro.gridpro.md +2 -1
- package/docs/api/grid-pro.gridpro.mergeallcolumndefsandstates.md +2 -2
- package/docs/api/grid-pro.gridpro.statepersistence.md +11 -0
- package/docs/api/grid-pro.kvstoragestatepersistence.getcolumnstate.md +22 -0
- package/docs/api/grid-pro.kvstoragestatepersistence.kvstorage.md +11 -0
- package/docs/api/grid-pro.kvstoragestatepersistence.md +29 -0
- package/docs/api/grid-pro.kvstoragestatepersistence.savecolumnstate.md +23 -0
- package/docs/api/grid-pro.kvstoragestatepersistence.session.md +11 -0
- package/docs/api/grid-pro.localstoragestatepersistence.getcolumnstate.md +22 -0
- package/docs/api/grid-pro.localstoragestatepersistence.md +28 -0
- package/docs/api/grid-pro.localstoragestatepersistence.savecolumnstate.md +23 -0
- package/docs/api/grid-pro.localstoragestatepersistence.session.md +11 -0
- package/docs/api/grid-pro.md +3 -0
- package/docs/api/grid-pro.statepersistence.getcolumnstate.md +24 -0
- package/docs/api/grid-pro.statepersistence.md +21 -0
- package/docs/api/grid-pro.statepersistence.savecolumnstate.md +25 -0
- package/docs/api-report.md +40 -3
- package/package.json +14 -13
|
@@ -197,16 +197,18 @@ let GridProGenesisDatasource = class GridProGenesisDatasource extends LifecycleM
|
|
|
197
197
|
*/
|
|
198
198
|
setRowData(rowData) {
|
|
199
199
|
var _a;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
const preSetColumnDefs = (_a = this.agGrid.gridApi) === null || _a === void 0 ? void 0 : _a.getColumnDefs();
|
|
202
|
+
if (!preSetColumnDefs || preSetColumnDefs.length === 0) {
|
|
203
|
+
const agColumnDefs = yield this.getAgColumnDefs(this.datasource.fieldMetadata);
|
|
204
|
+
if (agColumnDefs) {
|
|
205
|
+
this.agGrid.gridApi.setColumnDefs(agColumnDefs);
|
|
206
|
+
}
|
|
205
207
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
const data = this.rowDataMapper ? this.rowDataMapper(rowData) : rowData;
|
|
209
|
+
this.agGrid.gridApi.setRowData(data);
|
|
210
|
+
this.requiresFullRowDataAndColDefs = false;
|
|
211
|
+
});
|
|
210
212
|
}
|
|
211
213
|
/**
|
|
212
214
|
* Resets the grid data while keeping columnDefs and sends a DATA_LOGOFF message if it's a stream.
|
|
@@ -377,61 +379,63 @@ let GridProGenesisDatasource = class GridProGenesisDatasource extends LifecycleM
|
|
|
377
379
|
}
|
|
378
380
|
// FUTURE: Work with the field types vs ag grid column def types!
|
|
379
381
|
getAgColumnDefs(fieldsMetadata) {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
withTime: true,
|
|
409
|
-
};
|
|
410
|
-
break;
|
|
411
|
-
case FieldTypeEnum.ENUM:
|
|
412
|
-
if (field.enumOptions) {
|
|
413
|
-
colDefBase.cellEditor = GridProRendererTypes.selectEditor;
|
|
382
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
383
|
+
const colDefsFromGenesisData = fieldsMetadata === null || fieldsMetadata === void 0 ? void 0 : fieldsMetadata.flatMap((field) => {
|
|
384
|
+
var _a;
|
|
385
|
+
const colDefBase = {};
|
|
386
|
+
colDefBase.filterParams = getFilterParamsByFieldType(field.type);
|
|
387
|
+
switch (field.type) {
|
|
388
|
+
case FieldTypeEnum.STRING:
|
|
389
|
+
colDefBase.cellEditor = GridProRendererTypes.stringEditor;
|
|
390
|
+
break;
|
|
391
|
+
case FieldTypeEnum.NUMBER:
|
|
392
|
+
colDefBase.cellEditor = GridProRendererTypes.numberEditor;
|
|
393
|
+
colDefBase.filter = 'agNumberColumnFilter';
|
|
394
|
+
break;
|
|
395
|
+
case FieldTypeEnum.BOOLEAN:
|
|
396
|
+
if (this.agGrid.autoCellRendererByType) {
|
|
397
|
+
colDefBase.cellRenderer = GridProRendererTypes.boolean;
|
|
398
|
+
colDefBase.cellEditor = GridProRendererTypes.boolean;
|
|
399
|
+
}
|
|
400
|
+
break;
|
|
401
|
+
case FieldTypeEnum.DATE:
|
|
402
|
+
colDefBase.valueFormatter = dateValueFormatter;
|
|
403
|
+
colDefBase.cellEditor = GridProRendererTypes.dateEditor;
|
|
404
|
+
colDefBase.filter = 'agDateColumnFilter';
|
|
405
|
+
break;
|
|
406
|
+
case FieldTypeEnum.DATETIME:
|
|
407
|
+
colDefBase.valueFormatter = dateTimeValueFormatter;
|
|
408
|
+
colDefBase.filter = 'agDateColumnFilter';
|
|
409
|
+
colDefBase.cellEditor = GridProRendererTypes.dateEditor;
|
|
414
410
|
colDefBase.cellEditorParams = {
|
|
415
|
-
|
|
416
|
-
valueField: 'value',
|
|
417
|
-
labelField: 'label',
|
|
411
|
+
withTime: true,
|
|
418
412
|
};
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
413
|
+
break;
|
|
414
|
+
case FieldTypeEnum.ENUM:
|
|
415
|
+
if (field.enumOptions) {
|
|
416
|
+
colDefBase.cellEditor = GridProRendererTypes.selectEditor;
|
|
417
|
+
colDefBase.cellEditorParams = {
|
|
418
|
+
values: field.enumOptions.map((option) => ({ value: option, label: option })),
|
|
419
|
+
valueField: 'value',
|
|
420
|
+
labelField: 'label',
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
logger.warn(`No enumOptions found for field ${field.name}. Default cell editor applied.`);
|
|
425
|
+
}
|
|
426
|
+
break;
|
|
427
|
+
default:
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
const colDefExtras = (_a = this.agGrid.gridApi) === null || _a === void 0 ? void 0 : _a.getColumnDef(field.name);
|
|
431
|
+
if (this.fields && !this.fields.includes(field.name)) {
|
|
432
|
+
return [];
|
|
433
|
+
}
|
|
434
|
+
return Object.assign(Object.assign({ field: field.name }, colDefBase), colDefExtras);
|
|
435
|
+
});
|
|
436
|
+
const colDefsMergedWithTemplateDefs = yield this.agGrid.mergeAllColumnDefsAndStates(colDefsFromGenesisData, true);
|
|
437
|
+
return colDefsMergedWithTemplateDefs;
|
|
432
438
|
});
|
|
433
|
-
const colDefsMergedWithTemplateDefs = this.agGrid.mergeAllColumnDefsAndStates(colDefsFromGenesisData, true);
|
|
434
|
-
return colDefsMergedWithTemplateDefs;
|
|
435
439
|
}
|
|
436
440
|
buildCriteria() {
|
|
437
441
|
var _a;
|
package/dist/esm/grid-pro.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { __decorate, __rest } from "tslib";
|
|
1
|
+
import { __awaiter, __decorate, __rest } from "tslib";
|
|
2
2
|
import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
|
|
3
3
|
import { ComponentUtil, Grid, ModuleRegistry, } from '@ag-grid-community/core';
|
|
4
4
|
import { CsvExportModule } from '@ag-grid-community/csv-export';
|
|
5
|
-
import { Session } from '@genesislcap/foundation-comms';
|
|
6
5
|
import { insertDocumentCSSRule, LifecycleMixin, respondToVisibility, } from '@genesislcap/foundation-utils';
|
|
7
6
|
import { attr, DOM, observable } from '@microsoft/fast-element';
|
|
8
7
|
import { FoundationElement } from '@microsoft/fast-foundation';
|
|
9
8
|
import { classNames } from '@microsoft/fast-web-utilities';
|
|
10
9
|
import * as changeCase from 'change-case';
|
|
10
|
+
import debounce from 'lodash.debounce';
|
|
11
11
|
import { GridProCell } from './cell';
|
|
12
12
|
import { SelectEditor, NumberEditor, MultiselectEditor, DateEditor, StringEditor, } from './cell-editors';
|
|
13
13
|
import { ActionRenderer, ActionsMenuRenderer, BooleanRenderer, EditableRenderer, } from './cell-renderers';
|
|
@@ -19,6 +19,7 @@ import { DEBOUNCED_RESIZE_TIME } from './grid-pro.definitions';
|
|
|
19
19
|
import { foundationGridProStyles as styles } from './grid-pro.styles';
|
|
20
20
|
import { gridProTemplate as template } from './grid-pro.template';
|
|
21
21
|
import { AgGridTheme, GridProRendererTypes, agThemeFontsId, agThemeTokenMapClassname, GRID_READY_EVENT, ERROR_COLUMN_FIELD, EDITED_COLUMN_FIELD, GridOptionsConfig, } from './grid-pro.types';
|
|
22
|
+
import { StatePersistence } from './state-persistence';
|
|
22
23
|
import { ErrorTooltip } from './tooltips';
|
|
23
24
|
import { convertToKebabCase, logger, mergeAndDedupColDefWithColumnState } from './utils';
|
|
24
25
|
GridProGenesisDatasource;
|
|
@@ -27,6 +28,7 @@ GridProServerSideDatasource;
|
|
|
27
28
|
GridProCell;
|
|
28
29
|
GridProColumn;
|
|
29
30
|
ModuleRegistry.registerModules([CsvExportModule, ClientSideRowModelModule]);
|
|
31
|
+
const DEBOUNCE_TIME = 400;
|
|
30
32
|
/**
|
|
31
33
|
* The Grid Pro element.
|
|
32
34
|
* @remarks Grid Pro is a Web Component wrapper around the AG Grid Community library.
|
|
@@ -193,44 +195,45 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
|
|
|
193
195
|
return colState.map((col) => (Object.assign(Object.assign({}, col), { width: null })));
|
|
194
196
|
}
|
|
195
197
|
saveColumnState() {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
198
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
if (this.rehydrationAttempted && this.statePersistanceEnabled()) {
|
|
200
|
+
let colState = this.columnApi.getColumnState();
|
|
201
|
+
colState = this.gridAutosizingEnabled
|
|
202
|
+
? this.removeConfigWidthsToAutosize(colState)
|
|
203
|
+
: colState;
|
|
204
|
+
if (colState.length === 0 || JSON.stringify(colState) === JSON.stringify(this.columnState))
|
|
205
|
+
return;
|
|
206
|
+
yield this.statePersistence.saveColumnState(this.persistColumnStateKey, colState);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
207
209
|
}
|
|
208
210
|
/**
|
|
209
|
-
* Gets the saved grid ColumnState[] from
|
|
211
|
+
* Gets the saved grid ColumnState[] from storage
|
|
210
212
|
* @remarks This is used to restore the grid state when the grid is rehydrated
|
|
211
213
|
* @privateRemarks Not using `columnApi.get|setColumnState()` for these flows as it doesn't work setting new columnDefs vs different ordering.
|
|
212
214
|
* @public
|
|
213
215
|
*/
|
|
214
216
|
getSavedColumnState() {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return JSON.parse(allGridOptions[this.persistColumnStateKey]);
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
this.columnState = [];
|
|
219
|
+
if (this.statePersistanceEnabled()) {
|
|
220
|
+
this.columnState = yield this.statePersistence.getColumnState(this.persistColumnStateKey);
|
|
220
221
|
}
|
|
221
|
-
|
|
222
|
-
|
|
222
|
+
return this.columnState;
|
|
223
|
+
});
|
|
223
224
|
}
|
|
224
225
|
restoreColumnState() {
|
|
225
226
|
var _a;
|
|
226
|
-
this
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
227
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
228
|
+
this.rehydrationAttempted = true;
|
|
229
|
+
const colState = yield this.getSavedColumnState();
|
|
230
|
+
if (colState && colState.length > 0) {
|
|
231
|
+
(_a = this.columnApi) === null || _a === void 0 ? void 0 : _a.applyColumnState({
|
|
232
|
+
state: colState,
|
|
233
|
+
applyOrder: true,
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
});
|
|
234
237
|
}
|
|
235
238
|
cacheFilterConfig() {
|
|
236
239
|
var _a;
|
|
@@ -255,9 +258,10 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
|
|
|
255
258
|
this.querySelector('grid-pro-server-side-datasource'));
|
|
256
259
|
}
|
|
257
260
|
set gridOptions(options) {
|
|
261
|
+
const debounceSaveColumnState = debounce(this.saveColumnState.bind(this), DEBOUNCE_TIME);
|
|
258
262
|
const globalEventListener = this.globalEventListener.bind(this);
|
|
259
263
|
const gridOnChangeCallback = () => {
|
|
260
|
-
|
|
264
|
+
debounceSaveColumnState();
|
|
261
265
|
this.debouncedColumnAutosize.bind(this)();
|
|
262
266
|
};
|
|
263
267
|
Array.from(this.attributes).forEach((attribute) => {
|
|
@@ -293,10 +297,16 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
|
|
|
293
297
|
}, onColumnPinned: gridOnChangeCallback, onColumnResized: gridOnChangeCallback, onColumnMoved: gridOnChangeCallback, onDisplayedColumnsChanged: gridOnChangeCallback, onFilterChanged: gridOnChangeCallback, onGridSizeChanged: gridOnChangeCallback, onSortChanged: gridOnChangeCallback }), rest);
|
|
294
298
|
if (this.gridProDatasource) {
|
|
295
299
|
derivedOptions.columnDefs = columnDefs;
|
|
300
|
+
this.initGridOptions(derivedOptions, globalEventListener);
|
|
296
301
|
}
|
|
297
302
|
else {
|
|
298
|
-
|
|
303
|
+
this.mergeAllColumnDefsAndStates(columnDefs).then((value) => {
|
|
304
|
+
derivedOptions.columnDefs = value;
|
|
305
|
+
this.initGridOptions(derivedOptions, globalEventListener);
|
|
306
|
+
});
|
|
299
307
|
}
|
|
308
|
+
}
|
|
309
|
+
initGridOptions(derivedOptions, globalEventListener) {
|
|
300
310
|
this.agGridOptions = Object.assign(Object.assign({}, this.agGridOptions), ComponentUtil.copyAttributesToGridOptions(derivedOptions, this.agAttributes));
|
|
301
311
|
const gridParams = {
|
|
302
312
|
globalEventListener: globalEventListener,
|
|
@@ -335,70 +345,72 @@ export class GridPro extends LifecycleMixin(FoundationElement) {
|
|
|
335
345
|
*/
|
|
336
346
|
mergeAllColumnDefsAndStates(columnDefs, deferredColumnDefsOrState = false) {
|
|
337
347
|
var _a;
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
348
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
349
|
+
const columnDefinitionsFromMetadata = columnDefs || [];
|
|
350
|
+
columnDefinitionsFromMetadata.forEach((colDefFromMetadata) => {
|
|
351
|
+
if (this.headerCaseType && colDefFromMetadata.field && !colDefFromMetadata.headerName) {
|
|
352
|
+
const changeCaseByType = changeCase[this.headerCaseType];
|
|
353
|
+
if (changeCaseByType) {
|
|
354
|
+
colDefFromMetadata.headerName = changeCaseByType(colDefFromMetadata.field);
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
logger.warn(`Invalid header-case-type attribute value: ${this.headerCaseType}. Please use one of the following: camelCase, capitalCase, dotCase, headerCase, noCase, paramCase, pascalCase, pathCase, sentenceCase, snakeCase.`);
|
|
358
|
+
}
|
|
344
359
|
}
|
|
345
|
-
|
|
346
|
-
|
|
360
|
+
});
|
|
361
|
+
const templateColumnDefs = Array.from(this.querySelectorAll(this.columnComponentName))
|
|
362
|
+
.map((templateColumn) => templateColumn.definition)
|
|
363
|
+
.map((columnDef) => {
|
|
364
|
+
// enable cell flashing for each column if unspecified on column level but enabled on grid level
|
|
365
|
+
if (this.enableCellFlashing && columnDef.enableCellChangeFlash === undefined) {
|
|
366
|
+
columnDef.enableCellChangeFlash = true;
|
|
347
367
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
368
|
+
if (columnDef.editable) {
|
|
369
|
+
if (!columnDef.cellRenderer && !columnDef.cellRendererSelector) {
|
|
370
|
+
columnDef.cellRendererSelector = (params) => {
|
|
371
|
+
if (params.data[EDITED_COLUMN_FIELD] === columnDef.field) {
|
|
372
|
+
return {
|
|
373
|
+
component: GridProRendererTypes.editable,
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
if (!columnDef.tooltipComponent && !columnDef.tooltipValueGetter) {
|
|
379
|
+
columnDef.tooltipComponent = ErrorTooltip;
|
|
380
|
+
columnDef.tooltipValueGetter = (params) => {
|
|
381
|
+
const error = params.data[ERROR_COLUMN_FIELD];
|
|
382
|
+
if (error && error.column === columnDef.field) {
|
|
383
|
+
return error.message;
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
if (!columnDef.cellClassRules) {
|
|
388
|
+
columnDef.cellClassRules = {
|
|
389
|
+
error: (params) => { var _a; return ((_a = params.data[ERROR_COLUMN_FIELD]) === null || _a === void 0 ? void 0 : _a.column) === params.colDef.field; },
|
|
390
|
+
};
|
|
391
|
+
}
|
|
366
392
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
393
|
+
const metadataColumnDef = columnDefinitionsFromMetadata.find((colDef) => columnDef.field === colDef.field);
|
|
394
|
+
return Object.assign(Object.assign({}, metadataColumnDef), columnDef);
|
|
395
|
+
});
|
|
396
|
+
const templateColumnKeys = templateColumnDefs.map((x) => x.field);
|
|
397
|
+
const colDefsToReturn = [
|
|
398
|
+
...templateColumnDefs,
|
|
399
|
+
...(this.onlyTemplateColDefs
|
|
400
|
+
? []
|
|
401
|
+
: columnDefinitionsFromMetadata.filter((g) => !templateColumnKeys.includes(g.field))),
|
|
402
|
+
];
|
|
403
|
+
if (this.gridProDatasource && deferredColumnDefsOrState) {
|
|
404
|
+
const savedColumnState = yield this.getSavedColumnState();
|
|
405
|
+
if ((savedColumnState === null || savedColumnState === void 0 ? void 0 : savedColumnState.length) > 0) {
|
|
406
|
+
return mergeAndDedupColDefWithColumnState(colDefsToReturn, savedColumnState);
|
|
375
407
|
}
|
|
376
|
-
if (
|
|
377
|
-
|
|
378
|
-
error: (params) => { var _a; return ((_a = params.data[ERROR_COLUMN_FIELD]) === null || _a === void 0 ? void 0 : _a.column) === params.colDef.field; },
|
|
379
|
-
};
|
|
408
|
+
else if (((_a = this.gridProDatasource.deferredColumnStates) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
409
|
+
return mergeAndDedupColDefWithColumnState(colDefsToReturn, this.gridProDatasource.deferredColumnStates);
|
|
380
410
|
}
|
|
381
411
|
}
|
|
382
|
-
|
|
383
|
-
return Object.assign(Object.assign({}, metadataColumnDef), columnDef);
|
|
412
|
+
return colDefsToReturn;
|
|
384
413
|
});
|
|
385
|
-
const templateColumnKeys = templateColumnDefs.map((x) => x.field);
|
|
386
|
-
const colDefsToReturn = [
|
|
387
|
-
...templateColumnDefs,
|
|
388
|
-
...(this.onlyTemplateColDefs
|
|
389
|
-
? []
|
|
390
|
-
: columnDefinitionsFromMetadata.filter((g) => !templateColumnKeys.includes(g.field))),
|
|
391
|
-
];
|
|
392
|
-
if (this.gridProDatasource && deferredColumnDefsOrState) {
|
|
393
|
-
const savedColumnState = this.getSavedColumnState();
|
|
394
|
-
if ((savedColumnState === null || savedColumnState === void 0 ? void 0 : savedColumnState.length) > 0) {
|
|
395
|
-
return mergeAndDedupColDefWithColumnState(colDefsToReturn, savedColumnState);
|
|
396
|
-
}
|
|
397
|
-
else if (((_a = this.gridProDatasource.deferredColumnStates) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
398
|
-
return mergeAndDedupColDefWithColumnState(colDefsToReturn, this.gridProDatasource.deferredColumnStates);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
return colDefsToReturn;
|
|
402
414
|
}
|
|
403
415
|
get observedAttributes() {
|
|
404
416
|
// allow properties to be supplied either lowercased or kebab-cased
|
|
@@ -460,8 +472,8 @@ __decorate([
|
|
|
460
472
|
observable
|
|
461
473
|
], GridPro.prototype, "gridApi", void 0);
|
|
462
474
|
__decorate([
|
|
463
|
-
|
|
464
|
-
], GridPro.prototype, "
|
|
475
|
+
StatePersistence
|
|
476
|
+
], GridPro.prototype, "statePersistence", void 0);
|
|
465
477
|
__decorate([
|
|
466
478
|
attr({ attribute: 'auto-cell-renderer-by-type', mode: 'boolean' })
|
|
467
479
|
], GridPro.prototype, "autoCellRendererByType", void 0);
|
package/dist/esm/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export * from './grid-pro.template';
|
|
|
11
11
|
export * from './grid-pro.types';
|
|
12
12
|
export * from './grid-pro';
|
|
13
13
|
export * from './grid-pro-genesis-datasource';
|
|
14
|
+
export * from './state-persistence';
|
|
14
15
|
export * from './style';
|
|
15
16
|
export * from './tooltips';
|
|
16
17
|
export * from './utils';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { __awaiter, __decorate } from "tslib";
|
|
2
|
+
import { KVStorage, Session } from '@genesislcap/foundation-comms';
|
|
3
|
+
import { logger } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Implementation for the KV Storage State Persistence interface.
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class KVStorageStatePersistence {
|
|
9
|
+
getColumnState(persistColumnStateKey) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
yield this.migrateLocalStorageToKVStorage(persistColumnStateKey);
|
|
13
|
+
const kvColumnState = yield this.kvStorage.get(persistColumnStateKey);
|
|
14
|
+
const storageColumnState = kvColumnState ? (_b = (_a = kvColumnState[0]) === null || _a === void 0 ? void 0 : _a.kv) === null || _b === void 0 ? void 0 : _b.value : undefined;
|
|
15
|
+
if (storageColumnState) {
|
|
16
|
+
return JSON.parse(storageColumnState);
|
|
17
|
+
}
|
|
18
|
+
return [];
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
saveColumnState(persistColumnStateKey, columnState) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
this.kvStorage.put([
|
|
24
|
+
{
|
|
25
|
+
key: persistColumnStateKey,
|
|
26
|
+
value: JSON.stringify(columnState),
|
|
27
|
+
},
|
|
28
|
+
]);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
migrateLocalStorageToKVStorage(persistColumnStateKey) {
|
|
32
|
+
var _a, _b;
|
|
33
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
+
const kv = yield this.kvStorage.get(persistColumnStateKey);
|
|
35
|
+
if (kv && ((_b = (_a = kv[0]) === null || _a === void 0 ? void 0 : _a.kv) === null || _b === void 0 ? void 0 : _b.value))
|
|
36
|
+
return;
|
|
37
|
+
const localGridOptions = this.session.getLocalStorageItem('gridOptions');
|
|
38
|
+
const localState = localGridOptions
|
|
39
|
+
? JSON.parse(localGridOptions)[persistColumnStateKey]
|
|
40
|
+
: undefined;
|
|
41
|
+
if (localState) {
|
|
42
|
+
logger.debug(`Columns state migration for key: ${persistColumnStateKey} from LocalStorage to KV Storage`);
|
|
43
|
+
this.kvStorage.put([
|
|
44
|
+
{
|
|
45
|
+
key: persistColumnStateKey,
|
|
46
|
+
value: localState,
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
__decorate([
|
|
54
|
+
KVStorage
|
|
55
|
+
], KVStorageStatePersistence.prototype, "kvStorage", void 0);
|
|
56
|
+
__decorate([
|
|
57
|
+
Session
|
|
58
|
+
], KVStorageStatePersistence.prototype, "session", void 0);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { __awaiter, __decorate } from "tslib";
|
|
2
|
+
import { Session } from '@genesislcap/foundation-comms';
|
|
3
|
+
/**
|
|
4
|
+
* Implementation for the Local Storage State Persistence interface.
|
|
5
|
+
* @public
|
|
6
|
+
*/
|
|
7
|
+
export class LocalStorageStatePersistence {
|
|
8
|
+
getColumnState(persistColumnStateKey) {
|
|
9
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
const localStorageGridOptions = this.session.getLocalStorageItem('gridOptions');
|
|
11
|
+
if (localStorageGridOptions) {
|
|
12
|
+
const allGridOptions = JSON.parse(localStorageGridOptions);
|
|
13
|
+
if (persistColumnStateKey in allGridOptions) {
|
|
14
|
+
return JSON.parse(allGridOptions[persistColumnStateKey]);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return [];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
saveColumnState(persistColumnStateKey, columnState) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const existingOptions = JSON.parse(this.session.getLocalStorageItem('gridOptions') || '{}');
|
|
23
|
+
existingOptions[persistColumnStateKey] = JSON.stringify(columnState);
|
|
24
|
+
this.session.setLocalStorageItem('gridOptions', JSON.stringify(existingOptions));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
__decorate([
|
|
29
|
+
Session
|
|
30
|
+
], LocalStorageStatePersistence.prototype, "session", void 0);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DI } from '@microsoft/fast-foundation';
|
|
2
|
+
import { LocalStorageStatePersistence } from './local-state';
|
|
3
|
+
/**
|
|
4
|
+
* The DI token for the StatePersistence interface.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export const StatePersistence = DI.createInterface((x) => x.singleton(LocalStorageStatePersistence));
|