@trudb/tru-common-lib 0.2.552 → 0.2.554
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.
|
@@ -8796,8 +8796,24 @@ class TruDataGrid {
|
|
|
8796
8796
|
rowCount = 'Rows: 0';
|
|
8797
8797
|
selectedRowCount = 'Selected: 0';
|
|
8798
8798
|
api;
|
|
8799
|
+
invalidRowIds = new WeakMap();
|
|
8800
|
+
invalidRowIdSequence = 0;
|
|
8799
8801
|
gridOptions = {
|
|
8800
|
-
getRowId: (params) => {
|
|
8802
|
+
getRowId: (params) => {
|
|
8803
|
+
const ref = params.data?.$entity?.Ref;
|
|
8804
|
+
if (ref !== null && ref !== undefined)
|
|
8805
|
+
return ref.toString();
|
|
8806
|
+
const rowData = params.data;
|
|
8807
|
+
if (rowData && typeof rowData === 'object') {
|
|
8808
|
+
let fallbackId = this.invalidRowIds.get(rowData);
|
|
8809
|
+
if (!fallbackId) {
|
|
8810
|
+
fallbackId = 'invalid-row-' + (++this.invalidRowIdSequence).toString();
|
|
8811
|
+
this.invalidRowIds.set(rowData, fallbackId);
|
|
8812
|
+
}
|
|
8813
|
+
return fallbackId;
|
|
8814
|
+
}
|
|
8815
|
+
return 'invalid-row';
|
|
8816
|
+
},
|
|
8801
8817
|
context: {
|
|
8802
8818
|
grid: this
|
|
8803
8819
|
},
|
|
@@ -8937,6 +8953,23 @@ class TruDataGrid {
|
|
|
8937
8953
|
this.api.refreshCells({ force: true });
|
|
8938
8954
|
}
|
|
8939
8955
|
};
|
|
8956
|
+
refsEqual = (left, right) => {
|
|
8957
|
+
return left !== null && left !== undefined &&
|
|
8958
|
+
right !== null && right !== undefined &&
|
|
8959
|
+
left.toString() === right.toString();
|
|
8960
|
+
};
|
|
8961
|
+
confirmRowMembershipBeforeRemoval = (rowNode) => {
|
|
8962
|
+
const ref = rowNode.data?.$entity?.Ref;
|
|
8963
|
+
if (ref === null || ref === undefined)
|
|
8964
|
+
return;
|
|
8965
|
+
this.dataContext.entityAccess().searchByRefWithQuery(this.config.resultConfig.entityType, this.latestSetupQuery, ref).subscribe((results) => {
|
|
8966
|
+
if (results?.length)
|
|
8967
|
+
return;
|
|
8968
|
+
const currentRowNode = rowNode.id === undefined ? null : this.api?.getRowNode(rowNode.id);
|
|
8969
|
+
if (currentRowNode)
|
|
8970
|
+
this.api.applyTransaction({ remove: [currentRowNode.data] });
|
|
8971
|
+
});
|
|
8972
|
+
};
|
|
8940
8973
|
subscribeTo = () => {
|
|
8941
8974
|
this.subs.push(this.appEnvironment.onSaveComplete$.pipe(skip(1)).subscribe(event => {
|
|
8942
8975
|
if (event?.successful)
|
|
@@ -9005,17 +9038,16 @@ class TruDataGrid {
|
|
|
9005
9038
|
dataChange.dataChanges.forEach((change) => {
|
|
9006
9039
|
if (change.changeOperation === 'D') {
|
|
9007
9040
|
this.api.forEachNode((rowNode) => {
|
|
9008
|
-
if (rowNode.data.$entity.Ref
|
|
9009
|
-
rowNodesToRemove.push(
|
|
9010
|
-
}
|
|
9041
|
+
if (this.refsEqual(rowNode.data.$entity.Ref, change.tableRef))
|
|
9042
|
+
rowNodesToRemove.push(rowNode.data);
|
|
9011
9043
|
});
|
|
9012
9044
|
}
|
|
9013
9045
|
if (change.changeOperation === 'U' || change.changeOperation === 'I') {
|
|
9014
9046
|
this.api.forEachNode((rowNode) => {
|
|
9015
|
-
if (rowNode.data.$entity.Ref
|
|
9047
|
+
if (this.refsEqual(rowNode.data.$entity.Ref, change.tableRef)) {
|
|
9016
9048
|
let results = this.dataContext.entityAccess().searchByRefArrayCacheOnly(this.config.resultConfig.entityType, this.latestSetupQuery, [rowNode.data.$entity.Ref]);
|
|
9017
9049
|
if (!results)
|
|
9018
|
-
|
|
9050
|
+
this.confirmRowMembershipBeforeRemoval(rowNode);
|
|
9019
9051
|
}
|
|
9020
9052
|
});
|
|
9021
9053
|
}
|
|
@@ -9051,8 +9083,14 @@ class TruDataGrid {
|
|
|
9051
9083
|
return data;
|
|
9052
9084
|
};
|
|
9053
9085
|
loadGridData = (entities) => {
|
|
9054
|
-
|
|
9055
|
-
|
|
9086
|
+
const validEntities = (entities ?? []).filter(entity => entity?.Ref !== null && entity?.Ref !== undefined);
|
|
9087
|
+
const invalidEntityCount = (entities?.length ?? 0) - validEntities.length;
|
|
9088
|
+
if (invalidEntityCount > 0) {
|
|
9089
|
+
const tableName = this.config.tablePluralLabel ?? this.config.tablePluralName ?? this.config.tableName ?? 'records';
|
|
9090
|
+
this.uiNotification.error('Some ' + tableName + ' could not be displayed because the server returned them without an identity.', [invalidEntityCount.toString() + ' invalid record(s) were rejected.']);
|
|
9091
|
+
}
|
|
9092
|
+
this.rowData = validEntities.map(this.enhanceRowDataForEntity, validEntities);
|
|
9093
|
+
this.rowCount = 'Rows: ' + validEntities.length;
|
|
9056
9094
|
this.cdr.markForCheck();
|
|
9057
9095
|
};
|
|
9058
9096
|
loadManyToManyGridData = (associatedEntities, associatableEntities, initalLoad) => {
|