@masterteam/components 0.0.297 → 0.0.299
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/assets/i18n/ar.json +5 -1
- package/assets/i18n/en.json +5 -1
- package/fesm2022/masterteam-components-business-fields.mjs +151 -8
- package/fesm2022/masterteam-components-business-fields.mjs.map +1 -1
- package/fesm2022/masterteam-components-entities.mjs +166 -30
- package/fesm2022/masterteam-components-entities.mjs.map +1 -1
- package/package.json +1 -1
- package/types/masterteam-components-business-fields.d.ts +58 -2
- package/types/masterteam-components-entities.d.ts +44 -10
|
@@ -1637,11 +1637,11 @@ function coerceValue(data) {
|
|
|
1637
1637
|
}
|
|
1638
1638
|
}
|
|
1639
1639
|
/**
|
|
1640
|
-
*
|
|
1641
|
-
* entry; `configuration` is read as well because the table
|
|
1642
|
-
* display flags into that object when it builds a cell.
|
|
1640
|
+
* Read an array off the property configuration. `propertyConfiguration` is the
|
|
1641
|
+
* untouched catalog entry; `configuration` is read as well because the table
|
|
1642
|
+
* merges its own display flags into that object when it builds a cell.
|
|
1643
1643
|
*/
|
|
1644
|
-
function
|
|
1644
|
+
function readConfigArray(data, key) {
|
|
1645
1645
|
const sources = [
|
|
1646
1646
|
data.propertyConfiguration ?? null,
|
|
1647
1647
|
(data.configuration ?? null),
|
|
@@ -1649,13 +1649,27 @@ function readInlineFields(data) {
|
|
|
1649
1649
|
for (const source of sources) {
|
|
1650
1650
|
if (!source || Array.isArray(source))
|
|
1651
1651
|
continue;
|
|
1652
|
-
const
|
|
1653
|
-
if (Array.isArray(
|
|
1654
|
-
return
|
|
1655
|
-
}
|
|
1652
|
+
const value = source[key];
|
|
1653
|
+
if (Array.isArray(value) && value.length > 0)
|
|
1654
|
+
return value;
|
|
1656
1655
|
}
|
|
1657
1656
|
return [];
|
|
1658
1657
|
}
|
|
1658
|
+
/** The inline field catalog — present only on an inline list. */
|
|
1659
|
+
function readInlineFields(data) {
|
|
1660
|
+
return readConfigArray(data, 'inlineFields');
|
|
1661
|
+
}
|
|
1662
|
+
/**
|
|
1663
|
+
* Readable target property keys of a module-backed list, in configured order.
|
|
1664
|
+
*
|
|
1665
|
+
* Unlike `inlineFields` these are bare keys: a module list's configuration
|
|
1666
|
+
* names *what* to read from the target module, never how to render it — the
|
|
1667
|
+
* labels and view types live in that module's own catalog, which this
|
|
1668
|
+
* read-only renderer never fetches.
|
|
1669
|
+
*/
|
|
1670
|
+
function readModuleFieldKeys(data) {
|
|
1671
|
+
return readConfigArray(data, 'readFields').filter((key) => typeof key === 'string' && key.length > 0);
|
|
1672
|
+
}
|
|
1659
1673
|
/**
|
|
1660
1674
|
* The field this one is a machine companion of, when that field is present in
|
|
1661
1675
|
* the same list. `status_color` returns `status`; a standalone `color` field
|
|
@@ -1672,10 +1686,10 @@ function companionTargetOf(field, present) {
|
|
|
1672
1686
|
return null;
|
|
1673
1687
|
}
|
|
1674
1688
|
/** Field definitions in render order, machine companions already removed. */
|
|
1675
|
-
function
|
|
1676
|
-
const
|
|
1677
|
-
const present = new Set(
|
|
1678
|
-
const visible =
|
|
1689
|
+
function refineFields(declared, allowed) {
|
|
1690
|
+
const sorted = [...declared].sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
1691
|
+
const present = new Set(sorted.map((field) => field.key));
|
|
1692
|
+
const visible = sorted.filter((field) => !isIdentifierField(field) && !companionTargetOf(field, present));
|
|
1679
1693
|
if (allowed.length === 0)
|
|
1680
1694
|
return visible;
|
|
1681
1695
|
const byKey = new Map(visible.map((field) => [field.key, field]));
|
|
@@ -1683,7 +1697,115 @@ function visibleFields(data, allowed) {
|
|
|
1683
1697
|
.map((key) => byKey.get(key))
|
|
1684
1698
|
.filter((field) => !!field);
|
|
1685
1699
|
}
|
|
1700
|
+
/** `values` merged by property key, with `next` winning. */
|
|
1701
|
+
function mergeRowValues(base, next) {
|
|
1702
|
+
const byKey = new Map();
|
|
1703
|
+
for (const item of [...(base.values ?? []), ...(next.values ?? [])]) {
|
|
1704
|
+
if (item?.propertyKey)
|
|
1705
|
+
byKey.set(item.propertyKey, item);
|
|
1706
|
+
}
|
|
1707
|
+
return { ...base, ...next, values: [...byKey.values()] };
|
|
1708
|
+
}
|
|
1709
|
+
/**
|
|
1710
|
+
* Identity that recognises the same record in both halves of the value, or
|
|
1711
|
+
* null when the row carries nothing stable to match on.
|
|
1712
|
+
*/
|
|
1713
|
+
function rowKeyOf(row) {
|
|
1714
|
+
const entityId = Number(row.entityId);
|
|
1715
|
+
if (entityId > 0)
|
|
1716
|
+
return `entity:${entityId}`;
|
|
1717
|
+
return row.rowId ? `row:${row.rowId}` : null;
|
|
1718
|
+
}
|
|
1719
|
+
/**
|
|
1720
|
+
* The rows a reader should see, drawn from both halves of the value.
|
|
1721
|
+
*
|
|
1722
|
+
* An inline list carries everything in `rows`, so this is a pass-through for
|
|
1723
|
+
* it. A **module-backed** list keeps its linked records in `snapshot.entities`
|
|
1724
|
+
* and uses `rows` only for creates/updates the backend has not applied yet —
|
|
1725
|
+
* so reading `rows` alone showed an empty placeholder for every module list
|
|
1726
|
+
* that had been saved, and a count of the pending writes for one that had not.
|
|
1727
|
+
* Neither number was the number of related records.
|
|
1728
|
+
*
|
|
1729
|
+
* Snapshot first, so the linked records keep their order, with a pending row
|
|
1730
|
+
* for the same record merged over it — a pending update carries only the keys
|
|
1731
|
+
* the user changed, so replacing outright would blank the rest.
|
|
1732
|
+
*/
|
|
1733
|
+
function displayRowsOf(value) {
|
|
1734
|
+
const byKey = new Map();
|
|
1735
|
+
const loose = [];
|
|
1736
|
+
const absorb = (rows) => {
|
|
1737
|
+
for (const row of rows ?? []) {
|
|
1738
|
+
if (!row)
|
|
1739
|
+
continue;
|
|
1740
|
+
const key = rowKeyOf(row);
|
|
1741
|
+
if (!key) {
|
|
1742
|
+
loose.push(row);
|
|
1743
|
+
continue;
|
|
1744
|
+
}
|
|
1745
|
+
const base = byKey.get(key);
|
|
1746
|
+
byKey.set(key, base ? mergeRowValues(base, row) : row);
|
|
1747
|
+
}
|
|
1748
|
+
};
|
|
1749
|
+
absorb(value.snapshot?.entities);
|
|
1750
|
+
absorb(value.rows);
|
|
1751
|
+
return [...byKey.values(), ...loose];
|
|
1752
|
+
}
|
|
1753
|
+
/**
|
|
1754
|
+
* Field definitions for a list whose configuration declares none — every
|
|
1755
|
+
* module-backed list, whose rows carry bare target property keys.
|
|
1756
|
+
*
|
|
1757
|
+
* Order and membership come from the configured `readFields` when there is
|
|
1758
|
+
* one: a key the configuration does not read is not shown, the same rule the
|
|
1759
|
+
* runtime table applies to its columns. With no `readFields`, every key
|
|
1760
|
+
* present renders in first-seen order.
|
|
1761
|
+
*/
|
|
1762
|
+
function derivedFields(data, rows) {
|
|
1763
|
+
const present = [];
|
|
1764
|
+
const seen = new Set();
|
|
1765
|
+
for (const row of rows) {
|
|
1766
|
+
for (const item of row.values ?? []) {
|
|
1767
|
+
if (!item?.propertyKey || seen.has(item.propertyKey))
|
|
1768
|
+
continue;
|
|
1769
|
+
seen.add(item.propertyKey);
|
|
1770
|
+
present.push(item.propertyKey);
|
|
1771
|
+
}
|
|
1772
|
+
}
|
|
1773
|
+
const configured = readModuleFieldKeys(data);
|
|
1774
|
+
const keys = configured.length
|
|
1775
|
+
? configured.filter((key) => seen.has(key))
|
|
1776
|
+
: present;
|
|
1777
|
+
// `catalog.nestedProperties` carries the target module's own label and view
|
|
1778
|
+
// type per nested key. The backend populates it for LookupModuleCheckList
|
|
1779
|
+
// and not (yet) for EntityList, so this is usually empty and the key is
|
|
1780
|
+
// humanized instead — but when it arrives, the columns improve on their own.
|
|
1781
|
+
const meta = new Map((data.nestedProperties ?? []).map((property) => [property.key, property]));
|
|
1782
|
+
return keys.map((key, order) => {
|
|
1783
|
+
const nested = meta.get(key);
|
|
1784
|
+
return {
|
|
1785
|
+
key,
|
|
1786
|
+
order,
|
|
1787
|
+
label: nested?.label,
|
|
1788
|
+
viewType: nested?.viewType,
|
|
1789
|
+
configuration: nested?.configuration,
|
|
1790
|
+
};
|
|
1791
|
+
});
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* Row values by key. The resolved `value` is preferred over `rawValue` when
|
|
1795
|
+
* the backend sent one — a user object renders as a name, where the stored id
|
|
1796
|
+
* renders as a GUID.
|
|
1797
|
+
*/
|
|
1686
1798
|
function valuesByKey(row) {
|
|
1799
|
+
const map = new Map();
|
|
1800
|
+
for (const item of row.values ?? []) {
|
|
1801
|
+
if (!item?.propertyKey)
|
|
1802
|
+
continue;
|
|
1803
|
+
map.set(item.propertyKey, item.value ?? item.rawValue ?? null);
|
|
1804
|
+
}
|
|
1805
|
+
return map;
|
|
1806
|
+
}
|
|
1807
|
+
/** The same values, as the raw strings the status companions are read from. */
|
|
1808
|
+
function rawValuesByKey(row) {
|
|
1687
1809
|
const map = new Map();
|
|
1688
1810
|
for (const item of row.values ?? []) {
|
|
1689
1811
|
if (item?.propertyKey)
|
|
@@ -1696,13 +1818,16 @@ function valuesByKey(row) {
|
|
|
1696
1818
|
* companion becomes a `Status`, so the trio renders as one coloured badge
|
|
1697
1819
|
* instead of three separate cells.
|
|
1698
1820
|
*/
|
|
1699
|
-
function toNestedEntity(field, values) {
|
|
1700
|
-
const raw =
|
|
1701
|
-
const
|
|
1702
|
-
const
|
|
1821
|
+
function toNestedEntity(field, values, rawValues) {
|
|
1822
|
+
const raw = rawValues.get(field.key) ?? null;
|
|
1823
|
+
const resolved = values.get(field.key) ?? null;
|
|
1824
|
+
const color = rawValues.get(`${field.key}_color`);
|
|
1825
|
+
const statusKey = rawValues.get(`${field.key}_key`);
|
|
1703
1826
|
const base = {
|
|
1704
1827
|
key: field.key,
|
|
1705
|
-
|
|
1828
|
+
// A derived column carries the target module's label when the backend sent
|
|
1829
|
+
// one; inline configuration never has one, hence the humanized fallback.
|
|
1830
|
+
name: field.label || humanizeEntityListKey(field.key),
|
|
1706
1831
|
propertyConfiguration: field.configuration,
|
|
1707
1832
|
configuration: NESTED_FIELD_CONFIG,
|
|
1708
1833
|
order: field.order,
|
|
@@ -1723,32 +1848,43 @@ function toNestedEntity(field, values) {
|
|
|
1723
1848
|
...base,
|
|
1724
1849
|
rawValue: raw ?? undefined,
|
|
1725
1850
|
viewType: normalizeViewType(field.viewType),
|
|
1726
|
-
|
|
1851
|
+
// The resolved shape is what the rich renderers bind; a scalar falls back
|
|
1852
|
+
// to the stored string, which is all a snapshot carries today.
|
|
1853
|
+
value: (resolved ?? ''),
|
|
1727
1854
|
};
|
|
1728
1855
|
}
|
|
1729
1856
|
/**
|
|
1730
1857
|
* Turns an `EntityList` entity into rendered rows.
|
|
1731
1858
|
*
|
|
1732
|
-
* Nothing is fetched
|
|
1733
|
-
*
|
|
1734
|
-
*
|
|
1735
|
-
*
|
|
1736
|
-
*
|
|
1859
|
+
* Nothing is fetched. The value carries the rows — in `rows` for an inline
|
|
1860
|
+
* list, in `snapshot.entities` for a module-backed one, see `displayRowsOf` —
|
|
1861
|
+
* and the columns are described by the property configuration's
|
|
1862
|
+
* `inlineFields`, since the rows themselves carry bare keys. A module list has
|
|
1863
|
+
* no `inlineFields`, so its columns are derived from the keys present and
|
|
1864
|
+
* ordered by `readFields`; that yields humanized labels and plain text rather
|
|
1865
|
+
* than the target module's own labels and view types, which only that module's
|
|
1866
|
+
* catalog knows and this renderer never loads.
|
|
1867
|
+
*
|
|
1868
|
+
* Shared by the trigger (`mt-entity-list-preview`, which needs the count and
|
|
1869
|
+
* the titles) and the drawer that renders them in full.
|
|
1737
1870
|
*
|
|
1738
1871
|
* `allowed` narrows to those keys, in that order; empty renders every field
|
|
1739
1872
|
* that survives the companion and identifier rules.
|
|
1740
1873
|
*/
|
|
1741
1874
|
function buildEntityListRows(data, allowed = []) {
|
|
1742
|
-
const
|
|
1743
|
-
|
|
1744
|
-
|
|
1875
|
+
const value = coerceValue(data);
|
|
1876
|
+
if (!value)
|
|
1877
|
+
return [];
|
|
1878
|
+
const rows = displayRowsOf(value);
|
|
1879
|
+
if (rows.length === 0)
|
|
1745
1880
|
return [];
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1881
|
+
const declared = readInlineFields(data);
|
|
1882
|
+
const fields = refineFields(declared.length > 0 ? declared : derivedFields(data, rows), allowed);
|
|
1883
|
+
return rows.map((row, index) => {
|
|
1749
1884
|
const values = valuesByKey(row);
|
|
1885
|
+
const rawValues = rawValuesByKey(row);
|
|
1750
1886
|
const rendered = fields
|
|
1751
|
-
.map((field) => toNestedEntity(field, values))
|
|
1887
|
+
.map((field) => toNestedEntity(field, values, rawValues))
|
|
1752
1888
|
.filter((entity) => !!entity);
|
|
1753
1889
|
// The title is the first field that actually rendered, not the first
|
|
1754
1890
|
// that was declared: a leading field can drop out (an empty status
|