@masterteam/components 0.0.294 → 0.0.295
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/fesm2022/masterteam-components-business-fields.mjs +161 -36
- package/fesm2022/masterteam-components-business-fields.mjs.map +1 -1
- package/fesm2022/masterteam-components.mjs.map +1 -1
- package/package.json +1 -1
- package/types/masterteam-components-business-fields.d.ts +56 -7
- package/types/masterteam-components-entities.d.ts +1 -1
- package/types/masterteam-components.d.ts +7 -0
|
@@ -888,6 +888,14 @@ class EntityListField {
|
|
|
888
888
|
const metadata = this.metadata();
|
|
889
889
|
return metadata?.sourceType === 'Module' && Number(metadata.moduleId) > 0;
|
|
890
890
|
}, ...(ngDevMode ? [{ debugName: "moduleBacked" }] : /* istanbul ignore next */ []));
|
|
891
|
+
/**
|
|
892
|
+
* Rows live in this property's own value rather than in target records: the
|
|
893
|
+
* module supplies the columns and the editors, nothing else. The whole row
|
|
894
|
+
* array is submitted on every save and no target record is ever written.
|
|
895
|
+
*/
|
|
896
|
+
embedded = computed(() => this.moduleBacked() && this.metadata()?.storageMode === 'Embedded', ...(ngDevMode ? [{ debugName: "embedded" }] : /* istanbul ignore next */ []));
|
|
897
|
+
/** The module record that owns an embedded value — the rows `instanceId`. */
|
|
898
|
+
ownerRecordId = computed(() => Number(this.runtimeContext()?.moduleDataId ?? 0), ...(ngDevMode ? [{ debugName: "ownerRecordId" }] : /* istanbul ignore next */ []));
|
|
891
899
|
canRead = computed(() => {
|
|
892
900
|
const access = this.accessMode();
|
|
893
901
|
return access === 'Auto' || access === 'Read' || access === 'ReadWrite';
|
|
@@ -936,6 +944,11 @@ class EntityListField {
|
|
|
936
944
|
}, ...(ngDevMode ? [{ debugName: "deletedIds" }] : /* istanbul ignore next */ []));
|
|
937
945
|
/** rowId → original form values / option labels (view state only). */
|
|
938
946
|
rowDrafts = signal({}, ...(ngDevMode ? [{ debugName: "rowDrafts" }] : /* istanbul ignore next */ []));
|
|
947
|
+
/**
|
|
948
|
+
* rowId → the backend's rendered cells for a saved embedded row, from the
|
|
949
|
+
* rows endpoint. View state only: the submitted values stay `pendingRows`.
|
|
950
|
+
*/
|
|
951
|
+
renderedRows = signal({}, ...(ngDevMode ? [{ debugName: "renderedRows" }] : /* istanbul ignore next */ []));
|
|
939
952
|
localRowSeq = 0;
|
|
940
953
|
/** Serialized copy of the last value we emitted, to ignore CVA echoes. */
|
|
941
954
|
lastEmittedJson = null;
|
|
@@ -949,14 +962,23 @@ class EntityListField {
|
|
|
949
962
|
}
|
|
950
963
|
return map;
|
|
951
964
|
}, ...(ngDevMode ? [{ debugName: "rowsByEntityId" }] : /* istanbul ignore next */ []));
|
|
952
|
-
/**
|
|
965
|
+
/**
|
|
966
|
+
* Rows with no target record: locally created ones in a linked list, and
|
|
967
|
+
* *every* row of an embedded list.
|
|
968
|
+
*
|
|
969
|
+
* Three sources, in order: what the user last entered (`rowDrafts`), what the
|
|
970
|
+
* rows endpoint rendered for a saved embedded row, and the stored value's own
|
|
971
|
+
* cells. The middle one is what turns a saved `rawValue` of `"3fa85f64…"`
|
|
972
|
+
* back into an assignee's name after a reload.
|
|
973
|
+
*/
|
|
953
974
|
createdRows = computed(() => {
|
|
954
975
|
const drafts = this.rowDrafts();
|
|
976
|
+
const rendered = this.renderedRows();
|
|
955
977
|
return this.pendingRows()
|
|
956
978
|
.filter((row) => !(row.entityId > 0))
|
|
957
979
|
.map((row) => {
|
|
958
|
-
const
|
|
959
|
-
return this.buildRow(row.rowId, row.rowId, 0,
|
|
980
|
+
const source = drafts[row.rowId] ?? rendered[row.rowId];
|
|
981
|
+
return this.buildRow(row.rowId, row.rowId, 0, source?.values ?? this.toValueMap(row.values), source?.display ?? this.toDisplayMap(row.values), source?.prefill);
|
|
960
982
|
});
|
|
961
983
|
}, ...(ngDevMode ? [{ debugName: "createdRows" }] : /* istanbul ignore next */ []));
|
|
962
984
|
/** Pending edits of existing rows, keyed by entity id. */
|
|
@@ -1010,7 +1032,10 @@ class EntityListField {
|
|
|
1010
1032
|
*/
|
|
1011
1033
|
showsPendingOperations = computed(() => this.canWrite() ||
|
|
1012
1034
|
this.accessMode() === 'Write' ||
|
|
1013
|
-
this.pendingSubmission()
|
|
1035
|
+
this.pendingSubmission() ||
|
|
1036
|
+
// An embedded list has nothing else to show: its rows *are* the value,
|
|
1037
|
+
// so they render even when the field is read-only.
|
|
1038
|
+
this.embedded(), ...(ngDevMode ? [{ debugName: "showsPendingOperations" }] : /* istanbul ignore next */ []));
|
|
1014
1039
|
/**
|
|
1015
1040
|
* Rows rendered in the table: existing rows merged with pending edits,
|
|
1016
1041
|
* removed rows hidden, and created rows appended.
|
|
@@ -1190,6 +1215,7 @@ class EntityListField {
|
|
|
1190
1215
|
levelDataId: this.levelDataId(),
|
|
1191
1216
|
writeFields: this.writeFields(),
|
|
1192
1217
|
lookups: this.lookups(),
|
|
1218
|
+
useRootModuleSchema: this.embedded(),
|
|
1193
1219
|
},
|
|
1194
1220
|
});
|
|
1195
1221
|
ref.onClose.pipe(take(1)).subscribe((result) => {
|
|
@@ -1235,6 +1261,7 @@ class EntityListField {
|
|
|
1235
1261
|
levelDataId: this.levelDataId(),
|
|
1236
1262
|
writeFields: this.writeFields(),
|
|
1237
1263
|
lookups: this.lookups(),
|
|
1264
|
+
useRootModuleSchema: this.embedded(),
|
|
1238
1265
|
initialValues: prefillValues,
|
|
1239
1266
|
isEdit: true,
|
|
1240
1267
|
},
|
|
@@ -1350,15 +1377,16 @@ class EntityListField {
|
|
|
1350
1377
|
delete next[rowId];
|
|
1351
1378
|
this.rowDrafts.set(next);
|
|
1352
1379
|
}
|
|
1353
|
-
buildRow(id, rowId, entityId, values, display = {}) {
|
|
1380
|
+
buildRow(id, rowId, entityId, values, display = {}, prefill) {
|
|
1354
1381
|
const row = {
|
|
1355
1382
|
Id: id,
|
|
1356
1383
|
[ROW_ID_KEY]: rowId,
|
|
1357
1384
|
[ROW_ENTITY_ID_KEY]: entityId,
|
|
1358
1385
|
[ROW_VALUES_KEY]: values,
|
|
1359
1386
|
// A drafted row is built from control values already, so there is
|
|
1360
|
-
// nothing to resolve — the two maps are the same.
|
|
1361
|
-
|
|
1387
|
+
// nothing to resolve — the two maps are the same. A saved embedded row
|
|
1388
|
+
// is not: it holds stored scalars and carries its own prefill.
|
|
1389
|
+
[ROW_PREFILL_KEY]: prefill ?? values,
|
|
1362
1390
|
};
|
|
1363
1391
|
for (const column of this.columns()) {
|
|
1364
1392
|
// Form values are keyed by catalog property key (e.g. "task_name"),
|
|
@@ -1471,27 +1499,31 @@ class EntityListField {
|
|
|
1471
1499
|
// ============================================================================
|
|
1472
1500
|
emitValue() {
|
|
1473
1501
|
const current = this.storedValue();
|
|
1474
|
-
// `
|
|
1475
|
-
//
|
|
1476
|
-
//
|
|
1477
|
-
const
|
|
1478
|
-
...
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
rows: this.pendingRows().map((row) => ({
|
|
1483
|
-
...row,
|
|
1484
|
-
values: (row.values ?? []).map(({ propertyKey, rawValue }) => ({
|
|
1485
|
-
propertyKey,
|
|
1486
|
-
rawValue,
|
|
1487
|
-
})),
|
|
1502
|
+
// `values[].value` is the backend's rendered label, carried only so the
|
|
1503
|
+
// table can print it. Submitting it back would echo a user object where
|
|
1504
|
+
// the stored scalar belongs.
|
|
1505
|
+
const rows = this.pendingRows().map((row) => ({
|
|
1506
|
+
...row,
|
|
1507
|
+
values: (row.values ?? []).map(({ propertyKey, rawValue }) => ({
|
|
1508
|
+
propertyKey,
|
|
1509
|
+
rawValue,
|
|
1488
1510
|
})),
|
|
1489
|
-
|
|
1490
|
-
|
|
1511
|
+
}));
|
|
1512
|
+
// An embedded value *is* its rows: the array is submitted whole, a removed
|
|
1513
|
+
// row is simply absent from it, and linked bookkeeping has no meaning —
|
|
1514
|
+
// the backend strips `entityIds` / `deletedIds` / `snapshot` for it anyway.
|
|
1515
|
+
// A linked value instead carries pending intent over backend-owned fields,
|
|
1516
|
+
// which are passed through untouched.
|
|
1517
|
+
const next = this.embedded()
|
|
1518
|
+
? { rows }
|
|
1519
|
+
: { ...(current ?? {}), rows, deletedIds: this.deletedIds() };
|
|
1491
1520
|
this.storedValue.set(next);
|
|
1521
|
+
// Normalized the same way `isEchoOfLastEmit` reads the incoming value —
|
|
1522
|
+
// an embedded payload has no `deletedIds`, and an absent key would make
|
|
1523
|
+
// every echo look like a new value and reset the user's edits.
|
|
1492
1524
|
this.lastEmittedJson = JSON.stringify({
|
|
1493
|
-
rows: next.rows,
|
|
1494
|
-
deletedIds: next.deletedIds,
|
|
1525
|
+
rows: next.rows ?? [],
|
|
1526
|
+
deletedIds: next.deletedIds ?? [],
|
|
1495
1527
|
});
|
|
1496
1528
|
this.onModelChange(next);
|
|
1497
1529
|
this.onTouched();
|
|
@@ -1617,6 +1649,7 @@ class EntityListField {
|
|
|
1617
1649
|
this.metadataFailure.set(null);
|
|
1618
1650
|
this.columns.set([]);
|
|
1619
1651
|
this.rows.set([]);
|
|
1652
|
+
this.renderedRows.set({});
|
|
1620
1653
|
this.errorMessage.set(null);
|
|
1621
1654
|
this.loading.set(false);
|
|
1622
1655
|
if (!(propertyId > 0) || levelId == null || !(Number(levelId) > 0))
|
|
@@ -1656,15 +1689,101 @@ class EntityListField {
|
|
|
1656
1689
|
applyMetadata(metadata, levelDataId) {
|
|
1657
1690
|
this.metadata.set(metadata);
|
|
1658
1691
|
this.columns.set(this.buildColumns(metadata));
|
|
1659
|
-
if (!this.moduleBacked() ||
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1692
|
+
if (!this.moduleBacked() || !this.canRead()) {
|
|
1693
|
+
this.loading.set(false);
|
|
1694
|
+
return;
|
|
1695
|
+
}
|
|
1696
|
+
// An embedded list reads its own saved rows, keyed by the record that owns
|
|
1697
|
+
// them — never the schema module's records. Before that record exists the
|
|
1698
|
+
// rows are purely local, exactly like a draft parent's.
|
|
1699
|
+
if (this.embedded()) {
|
|
1700
|
+
const ownerRecordId = this.ownerRecordId();
|
|
1701
|
+
if (ownerRecordId > 0) {
|
|
1702
|
+
this.fetchEmbeddedRows(metadata.propertyId, ownerRecordId);
|
|
1703
|
+
}
|
|
1704
|
+
else {
|
|
1705
|
+
this.loading.set(false);
|
|
1706
|
+
}
|
|
1707
|
+
return;
|
|
1708
|
+
}
|
|
1709
|
+
if (levelDataId == null || Number(levelDataId) <= 0) {
|
|
1663
1710
|
this.loading.set(false);
|
|
1664
1711
|
return;
|
|
1665
1712
|
}
|
|
1666
1713
|
this.fetchRows(metadata.levelId, levelDataId, metadata.moduleId, this.projectedKeys());
|
|
1667
1714
|
}
|
|
1715
|
+
/**
|
|
1716
|
+
* Saved rows of an embedded list, rendered by the backend.
|
|
1717
|
+
*
|
|
1718
|
+
* They are not merged into `rows` — that signal is target module records,
|
|
1719
|
+
* which an embedded list has none of. They land in `renderedRows`, which
|
|
1720
|
+
* `createdRows` consults to render the value's own rows with resolved labels
|
|
1721
|
+
* instead of stored scalars.
|
|
1722
|
+
*
|
|
1723
|
+
* The stored value stays authoritative for *which* rows exist, so a value
|
|
1724
|
+
* that already carries them is left alone; the response only seeds the array
|
|
1725
|
+
* when the control arrived without one.
|
|
1726
|
+
*/
|
|
1727
|
+
fetchEmbeddedRows(propertyId, ownerRecordId) {
|
|
1728
|
+
this.loading.set(true);
|
|
1729
|
+
this.errorMessage.set(null);
|
|
1730
|
+
const ctx = this.context();
|
|
1731
|
+
this.fetchSubscription = this.http
|
|
1732
|
+
.get(`Properties/${propertyId}/entitylist/rows`, {
|
|
1733
|
+
params: { instanceId: String(ownerRecordId) },
|
|
1734
|
+
headers: { noMessage: 'true' },
|
|
1735
|
+
...(ctx ? { context: ctx } : {}),
|
|
1736
|
+
})
|
|
1737
|
+
.pipe(takeUntilDestroyed(this.destroyRef), finalize(() => this.loading.set(false)), catchError((error) => {
|
|
1738
|
+
// `404` is "no saved rows for this owner" as much as it is a
|
|
1739
|
+
// misconfiguration, and the value's own rows still render.
|
|
1740
|
+
if (error.status !== 404 && error.status !== 403) {
|
|
1741
|
+
this.errorMessage.set(this.transloco.translate('components.entityListField.loadFailed'));
|
|
1742
|
+
}
|
|
1743
|
+
return of({ data: [] });
|
|
1744
|
+
}))
|
|
1745
|
+
.subscribe((response) => this.applyEmbeddedRows(response.data ?? []));
|
|
1746
|
+
}
|
|
1747
|
+
applyEmbeddedRows(rows) {
|
|
1748
|
+
const rendered = {};
|
|
1749
|
+
const stored = [];
|
|
1750
|
+
const properties = this.propertyByKey();
|
|
1751
|
+
for (const row of rows) {
|
|
1752
|
+
const rowId = row.rowId?.trim();
|
|
1753
|
+
if (!rowId)
|
|
1754
|
+
continue;
|
|
1755
|
+
const values = {};
|
|
1756
|
+
const display = {};
|
|
1757
|
+
const prefill = {};
|
|
1758
|
+
const submitted = [];
|
|
1759
|
+
for (const cell of row.values ?? []) {
|
|
1760
|
+
if (!cell?.propertyKey)
|
|
1761
|
+
continue;
|
|
1762
|
+
values[cell.propertyKey] = cell.rawValue;
|
|
1763
|
+
if (cell.value !== undefined)
|
|
1764
|
+
display[cell.propertyKey] = cell.value;
|
|
1765
|
+
// A user picker binds the resolved object, not the stored id, so the
|
|
1766
|
+
// edit dialog is pre-filled from the rendered value for those view
|
|
1767
|
+
// types — the same exception the loaded linked rows make. The rendered
|
|
1768
|
+
// counterpart is only usable when the backend resolved one.
|
|
1769
|
+
const resolved = cell.value !== null &&
|
|
1770
|
+
typeof cell.value === 'object' &&
|
|
1771
|
+
OBJECT_VALUED_VIEW_TYPES.has(properties.get(cell.propertyKey)?.viewType ?? '');
|
|
1772
|
+
prefill[cell.propertyKey] = resolved ? cell.value : cell.rawValue;
|
|
1773
|
+
submitted.push({
|
|
1774
|
+
propertyKey: cell.propertyKey,
|
|
1775
|
+
rawValue: cell.rawValue,
|
|
1776
|
+
});
|
|
1777
|
+
}
|
|
1778
|
+
rendered[rowId] = { values, display, prefill };
|
|
1779
|
+
// `entityId` is always 0 here: an embedded row has no target record.
|
|
1780
|
+
stored.push({ rowId, entityId: 0, values: submitted });
|
|
1781
|
+
}
|
|
1782
|
+
this.renderedRows.set(rendered);
|
|
1783
|
+
if (this.pendingRows().length === 0 && stored.length > 0) {
|
|
1784
|
+
this.pendingRows.set(stored);
|
|
1785
|
+
}
|
|
1786
|
+
}
|
|
1668
1787
|
/**
|
|
1669
1788
|
* Table columns, in the order the backend returned them.
|
|
1670
1789
|
*
|
|
@@ -1673,12 +1792,16 @@ class EntityListField {
|
|
|
1673
1792
|
* value directly. The lookup still falls back to `normalizedKey` so a column
|
|
1674
1793
|
* fed from any other projection keeps resolving.
|
|
1675
1794
|
*
|
|
1676
|
-
* The columns are the *union* of readable and writable fields, so a
|
|
1677
|
-
* write-only key arrives as a column too — a `Planned
|
|
1678
|
-
* set in the dialog but may not read. It is not
|
|
1679
|
-
* would render as an empty column, so only
|
|
1680
|
-
*
|
|
1681
|
-
*
|
|
1795
|
+
* The columns are the *union* of readable and writable fields, so in a
|
|
1796
|
+
* **linked** list a write-only key arrives as a column too — a `Planned
|
|
1797
|
+
* Finish` the user may set in the dialog but may not read. It is not
|
|
1798
|
+
* projected into the rows and would render as an empty column, so only
|
|
1799
|
+
* readable keys become columns there. Two exceptions keep the union:
|
|
1800
|
+
*
|
|
1801
|
+
* - **Write-only access**, whose readable set is empty by definition and
|
|
1802
|
+
* whose stored rows have nothing else to render through.
|
|
1803
|
+
* - **Embedded storage**, where the rows endpoint returns cells for the whole
|
|
1804
|
+
* union by design, "so saved editor values can be rendered after reload".
|
|
1682
1805
|
*/
|
|
1683
1806
|
buildColumns(metadata) {
|
|
1684
1807
|
const propertyByKey = new Map();
|
|
@@ -1687,7 +1810,9 @@ class EntityListField {
|
|
|
1687
1810
|
propertyByKey.set(property.key, property);
|
|
1688
1811
|
propertyByNormalizedKey.set(property.normalizedKey, property);
|
|
1689
1812
|
}
|
|
1690
|
-
const readable =
|
|
1813
|
+
const readable = metadata.storageMode === 'Embedded'
|
|
1814
|
+
? new Set()
|
|
1815
|
+
: new Set(metadata.readFields);
|
|
1691
1816
|
return (metadata.projectionMeta?.columns ?? [])
|
|
1692
1817
|
.filter((column) => column.visible)
|
|
1693
1818
|
.filter((column) => readable.size === 0 || readable.has(column.key))
|