@asteby/metacore-runtime-react 37.1.0 → 37.1.1
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/CHANGELOG.md +6 -0
- package/dist/dynamic-form-schema.d.ts.map +1 -1
- package/dist/dynamic-form-schema.js +8 -2
- package/dist/dynamic-line-items.d.ts.map +1 -1
- package/dist/dynamic-line-items.js +7 -1
- package/package.json +3 -3
- package/src/__tests__/line-item-formulas.test.ts +12 -0
- package/src/dynamic-form-schema.ts +9 -2
- package/src/dynamic-line-items.tsx +8 -1
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-form-schema.d.ts","sourceRoot":"","sources":["../src/dynamic-form-schema.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAmB,MAAM,KAAK,CAAA;AACxC,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAkBzF;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,SAAS,GAAG,IAAI,CAEzF;AAcD,wBAAgB,cAAc,CAAC,MAAM,EAAE,cAAc,EAAE;;kBAMtD;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,cAAc,EAAE,CAGrE;AAED,8EAA8E;AAC9E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAE/D;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC1B,KAAK,EAAE,cAAc,GACtB;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS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B,gBAAgB,CAAC,KAAK,EAAE,cAAc,GAAG,kBAAkB,GAAG,SAAS,CAGtF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,cAAc,GAAG;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACnB,CAQA;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,cAAc,GAAG;IACpD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;CACvB,CAaA"}
|
|
@@ -152,9 +152,15 @@ export function applyLineItemRowFormulas(itemFields, row) {
|
|
|
152
152
|
const price = toNumber(row[priceKey]);
|
|
153
153
|
const discount = discountKey ? toNumber(row[discountKey]) : 0;
|
|
154
154
|
const next = Math.round((qty * price - discount) * 100) / 100;
|
|
155
|
-
|
|
155
|
+
// Coerce blank optional discount to 0 so submit never POSTs `discount: ""`
|
|
156
|
+
// (servers that see a present key then reject it as "discount is required").
|
|
157
|
+
const discountBlank = !!discountKey && (row[discountKey] === '' || row[discountKey] == null);
|
|
158
|
+
if (toNumber(row[amountKey]) === next && !discountBlank)
|
|
156
159
|
return row;
|
|
157
|
-
|
|
160
|
+
const out = { ...row, [amountKey]: next };
|
|
161
|
+
if (discountBlank)
|
|
162
|
+
out[discountKey] = 0;
|
|
163
|
+
return out;
|
|
158
164
|
}
|
|
159
165
|
/**
|
|
160
166
|
* Evaluates a line-items field's balance rule against its rows. Returns
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-line-items.d.ts","sourceRoot":"","sources":["../src/dynamic-line-items.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAiB7C,MAAM,WAAW,qBAAqB;IAClC,KAAK,EAAE,cAAc,CAAA;IACrB,KAAK,EAAE,GAAG,EAAE,GAAG,SAAS,CAAA;IACxB,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC;
|
|
1
|
+
{"version":3,"file":"dynamic-line-items.d.ts","sourceRoot":"","sources":["../src/dynamic-line-items.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAiB7C,MAAM,WAAW,qBAAqB;IAClC,KAAK,EAAE,cAAc,CAAA;IACrB,KAAK,EAAE,GAAG,EAAE,GAAG,SAAS,CAAA;IACxB,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;IAC/B,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC;AAyBD,wBAAgB,gBAAgB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAgB,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,qBAAqB,+BAwQvH"}
|
|
@@ -22,7 +22,13 @@ function isNumericCol(col) {
|
|
|
22
22
|
function emptyRow(itemFields) {
|
|
23
23
|
const row = {};
|
|
24
24
|
for (const f of itemFields) {
|
|
25
|
-
|
|
25
|
+
// Kernel serves `default` on action fields; the SDK type uses
|
|
26
|
+
// `defaultValue` (host carryActionFieldDefaults). Accept both so a
|
|
27
|
+
// manifest `"default": 0` on optional money cells (discount) seeds 0
|
|
28
|
+
// instead of "" — blank strings trip server parsers that treat a
|
|
29
|
+
// present key as required.
|
|
30
|
+
const seeded = f.defaultValue ?? f.default;
|
|
31
|
+
row[f.key] = seeded ?? (f.type === 'boolean' ? false : '');
|
|
26
32
|
}
|
|
27
33
|
return row;
|
|
28
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asteby/metacore-runtime-react",
|
|
3
|
-
"version": "37.1.
|
|
3
|
+
"version": "37.1.1",
|
|
4
4
|
"description": "React runtime for metacore hosts — renders addon contributions dynamically",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"typescript": "^6.0.0",
|
|
68
68
|
"vitest": "^4.0.0",
|
|
69
69
|
"zustand": "^5.0.0",
|
|
70
|
-
"@asteby/metacore-
|
|
71
|
-
"@asteby/metacore-
|
|
70
|
+
"@asteby/metacore-sdk": "3.7.0",
|
|
71
|
+
"@asteby/metacore-ui": "2.17.3"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"build": "tsc -p tsconfig.json",
|
|
@@ -30,6 +30,18 @@ describe('applyLineItemRowFormulas', () => {
|
|
|
30
30
|
subtotal: '',
|
|
31
31
|
})
|
|
32
32
|
expect(row.subtotal).toBe(25)
|
|
33
|
+
expect(row.discount).toBe(0)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('coerces blank discount to 0 even when subtotal already matches', () => {
|
|
37
|
+
const row = applyLineItemRowFormulas(fields, {
|
|
38
|
+
qty: 1,
|
|
39
|
+
unit_price: 10,
|
|
40
|
+
discount: '',
|
|
41
|
+
subtotal: 10,
|
|
42
|
+
})
|
|
43
|
+
expect(row.subtotal).toBe(10)
|
|
44
|
+
expect(row.discount).toBe(0)
|
|
33
45
|
})
|
|
34
46
|
|
|
35
47
|
it('is a no-op without an amount column', () => {
|
|
@@ -166,8 +166,15 @@ export function applyLineItemRowFormulas(
|
|
|
166
166
|
const price = toNumber(row[priceKey])
|
|
167
167
|
const discount = discountKey ? toNumber(row[discountKey]) : 0
|
|
168
168
|
const next = Math.round((qty * price - discount) * 100) / 100
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
|
|
170
|
+
// Coerce blank optional discount to 0 so submit never POSTs `discount: ""`
|
|
171
|
+
// (servers that see a present key then reject it as "discount is required").
|
|
172
|
+
const discountBlank =
|
|
173
|
+
!!discountKey && (row[discountKey] === '' || row[discountKey] == null)
|
|
174
|
+
if (toNumber(row[amountKey]) === next && !discountBlank) return row
|
|
175
|
+
const out: Record<string, any> = { ...row, [amountKey]: next }
|
|
176
|
+
if (discountBlank) out[discountKey!] = 0
|
|
177
|
+
return out
|
|
171
178
|
}
|
|
172
179
|
|
|
173
180
|
export interface BalanceState {
|
|
@@ -66,7 +66,14 @@ function isNumericCol(col: ActionFieldDef): boolean {
|
|
|
66
66
|
function emptyRow(itemFields: ActionFieldDef[]): Record<string, any> {
|
|
67
67
|
const row: Record<string, any> = {}
|
|
68
68
|
for (const f of itemFields) {
|
|
69
|
-
|
|
69
|
+
// Kernel serves `default` on action fields; the SDK type uses
|
|
70
|
+
// `defaultValue` (host carryActionFieldDefaults). Accept both so a
|
|
71
|
+
// manifest `"default": 0` on optional money cells (discount) seeds 0
|
|
72
|
+
// instead of "" — blank strings trip server parsers that treat a
|
|
73
|
+
// present key as required.
|
|
74
|
+
const seeded =
|
|
75
|
+
f.defaultValue ?? (f as { default?: unknown }).default
|
|
76
|
+
row[f.key] = seeded ?? (f.type === 'boolean' ? false : '')
|
|
70
77
|
}
|
|
71
78
|
return row
|
|
72
79
|
}
|