@asteby/metacore-runtime-react 29.2.6 → 29.2.8
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 +15 -0
- package/dist/dialogs/dynamic-record.js +4 -1
- package/dist/dynamic-columns.d.ts +5 -2
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +25 -5
- package/dist/dynamic-form.js +4 -1
- package/package.json +1 -1
- package/src/__tests__/resolve-row-actions.test.ts +15 -0
- package/src/dialogs/dynamic-record.tsx +3 -1
- package/src/dynamic-columns.tsx +25 -5
- package/src/dynamic-form.tsx +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @asteby/metacore-runtime-react
|
|
2
2
|
|
|
3
|
+
## 29.2.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b705996: Fix row-action `condition` evaluation for nested fields and `equals`/`notEquals` operators. Hosts declaring `{ field: "user.verified", operator: "equals", value: false }` no longer show every action at once.
|
|
8
|
+
|
|
9
|
+
## 29.2.7
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 89e79b0: fix(barcode-scanner): cerrar al escanear en formularios (modal crear/editar)
|
|
14
|
+
|
|
15
|
+
`continuous={false}` en dynamic-form y dynamic-record: al llenar SKU/código el
|
|
16
|
+
overlay se cierra. El POS sigue con continuous (default) para varios productos.
|
|
17
|
+
|
|
3
18
|
## 29.2.6
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1034,7 +1034,10 @@ function ScannableRecordInput({ field, value, onChange, inputType, }) {
|
|
|
1034
1034
|
const input = (_jsx(Input, { type: inputType, value: value ?? '', onChange: (e) => onChange(inputType === 'number' ? (e.target.value === '' ? '' : Number(e.target.value)) : e.target.value), placeholder: field.placeholder }));
|
|
1035
1035
|
if (!scanEnabled)
|
|
1036
1036
|
return input;
|
|
1037
|
-
return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-1.5", children: [_jsx("div", { className: "min-w-0 flex-1", children: input }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "size-9 shrink-0", onClick: () => setScanOpen(true), title: "Escanear con la c\u00E1mara", "aria-label": "Escanear c\u00F3digo de barras con la c\u00E1mara", children: _jsx(ScanLine, { className: "size-4" }) }), _jsx(BarcodeScanner, { open: scanOpen, onClose: () => setScanOpen(false), onDetected: (code) => onChange(code),
|
|
1037
|
+
return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-1.5", children: [_jsx("div", { className: "min-w-0 flex-1", children: input }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "size-9 shrink-0", onClick: () => setScanOpen(true), title: "Escanear con la c\u00E1mara", "aria-label": "Escanear c\u00F3digo de barras con la c\u00E1mara", children: _jsx(ScanLine, { className: "size-4" }) }), _jsx(BarcodeScanner, { open: scanOpen, onClose: () => setScanOpen(false), onDetected: (code) => onChange(code),
|
|
1038
|
+
// Un campo = un código: cerrar al detectar. El POS usa continuous
|
|
1039
|
+
// (default) porque suma varios productos seguidos.
|
|
1040
|
+
continuous: false, position: "fixed", title: `Escanear ${field.label ?? ''}`.trim() })] }));
|
|
1038
1041
|
}
|
|
1039
1042
|
function ImageUploadField({ field: _field, value, onChange }) {
|
|
1040
1043
|
const { t } = useTranslation();
|
|
@@ -53,8 +53,11 @@ export declare const formatAggregateTotal: (col: ColumnDefinition, value: unknow
|
|
|
53
53
|
export declare const isActionAllowedForRowState: (action: any, row: any) => boolean;
|
|
54
54
|
/**
|
|
55
55
|
* Declarative `condition` gate for a per-row action: shows the action only when
|
|
56
|
-
* the row's `field` satisfies the
|
|
57
|
-
*
|
|
56
|
+
* the row's `field` satisfies the operator. Supports both the SDK dialect
|
|
57
|
+
* (`eq` | `neq` | `in` | `not_in`) and the common host dialect
|
|
58
|
+
* (`equals` | `notEquals` | `not_in`). Nested paths (`user.verified`) are
|
|
59
|
+
* resolved via `getNestedValue`. No condition → always shown. Unknown
|
|
60
|
+
* operator → permissive.
|
|
58
61
|
*/
|
|
59
62
|
export declare const isActionConditionMet: (action: any, row: any) => boolean;
|
|
60
63
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-columns.d.ts","sourceRoot":"","sources":["../src/dynamic-columns.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,KAAK,MAAM,EAAE,MAAM,UAAU,CAAA;AAwC9C,OAAO,KAAK,EAAiB,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAE9D,OAAO,KAAK,EAER,iBAAiB,EACpB,MAAM,wBAAwB,CAAA;AAE/B,qEAAqE;AACrE,MAAM,WAAW,qBAAqB;IAClC;;;;OAIG;IACH,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;IACtC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB;AA0BD;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAAI,KAAK,gBAAgB,EAAE,cAAc,MAAM,KAAG,MACzB,CAAA;AAQrD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,KAAK,gBAAgB,KAAG,MAAM,GAAG,SAG5D,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAC7B,KAAK,gBAAgB,EACrB,OAAO,OAAO,EACd,WAAW,MAAM,EACjB,SAAS,MAAM,KAChB,MAyBF,CAAA;AAyCD;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,GAAI,QAAQ,GAAG,EAAE,KAAK,GAAG,KAAG,OAMlE,CAAA;AAED
|
|
1
|
+
{"version":3,"file":"dynamic-columns.d.ts","sourceRoot":"","sources":["../src/dynamic-columns.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,KAAK,MA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S,EAC5B,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,GAClB;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CA6C5C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,gBAAgB,EAAE,KAAK,GAAG,KAAG,MAWtE,CAAA;AAED;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,GAAI,KAAK,gBAAgB,EAAE,KAAK,GAAG,KAAG,MAOtE,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,gBAAgB,GACzB,KAAK,gBAAgB,EACrB,KAAK,GAAG,EACR,OAAO,GAAG,EACV,mBAAe,KAChB,MAAM,GAAG,SAcX,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,uBAAuB,GAAI,KAAK,gBAAgB,EAAE,KAAK,GAAG,KAAG,MAOzE,CAAA;AA+ID;;;;GAIG;AACH;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC;IAC7B,KAAK,EAAE,OAAO,CAAA;IACd,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;CACxC,CAqBA,CAAA;AAED,wBAAgB,4BAA4B,CACxC,OAAO,GAAE,qBAA0B,GACpC,iBAAiB,CA+mBnB;AAED;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,EAAE,iBACL,CAAA"}
|
package/dist/dynamic-columns.js
CHANGED
|
@@ -129,23 +129,43 @@ export const isActionAllowedForRowState = (action, row) => {
|
|
|
129
129
|
};
|
|
130
130
|
/**
|
|
131
131
|
* Declarative `condition` gate for a per-row action: shows the action only when
|
|
132
|
-
* the row's `field` satisfies the
|
|
133
|
-
*
|
|
132
|
+
* the row's `field` satisfies the operator. Supports both the SDK dialect
|
|
133
|
+
* (`eq` | `neq` | `in` | `not_in`) and the common host dialect
|
|
134
|
+
* (`equals` | `notEquals` | `not_in`). Nested paths (`user.verified`) are
|
|
135
|
+
* resolved via `getNestedValue`. No condition → always shown. Unknown
|
|
136
|
+
* operator → permissive.
|
|
134
137
|
*/
|
|
135
138
|
export const isActionConditionMet = (action, row) => {
|
|
136
139
|
if (!action?.condition)
|
|
137
140
|
return true;
|
|
138
141
|
const { field, operator, value } = action.condition;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
if (!field)
|
|
143
|
+
return true;
|
|
144
|
+
const coerce = (v) => {
|
|
145
|
+
if (v === null || v === undefined)
|
|
146
|
+
return '';
|
|
147
|
+
if (typeof v === 'boolean')
|
|
148
|
+
return v ? 'true' : 'false';
|
|
149
|
+
return String(v);
|
|
150
|
+
};
|
|
151
|
+
const raw = getNestedValue(row, field);
|
|
152
|
+
const rowValue = coerce(raw);
|
|
153
|
+
const values = (Array.isArray(value) ? value : [value]).map(coerce);
|
|
154
|
+
const op = String(operator ?? '').toLowerCase();
|
|
155
|
+
switch (op) {
|
|
142
156
|
case 'eq':
|
|
157
|
+
case 'equals':
|
|
158
|
+
case '==':
|
|
143
159
|
return rowValue === values[0];
|
|
144
160
|
case 'neq':
|
|
161
|
+
case 'notequals':
|
|
162
|
+
case 'not_equals':
|
|
163
|
+
case '!=':
|
|
145
164
|
return rowValue !== values[0];
|
|
146
165
|
case 'in':
|
|
147
166
|
return values.includes(rowValue);
|
|
148
167
|
case 'not_in':
|
|
168
|
+
case 'notin':
|
|
149
169
|
return !values.includes(rowValue);
|
|
150
170
|
default:
|
|
151
171
|
return true;
|
package/dist/dynamic-form.js
CHANGED
|
@@ -264,7 +264,10 @@ function ScannableInput({ field, value, onChange, type, }) {
|
|
|
264
264
|
const input = (_jsx(Input, { id: field.key, type: type, value: value ?? '', onChange: (e) => onChange(type === 'number' ? e.target.valueAsNumber || '' : e.target.value), placeholder: field.placeholder }));
|
|
265
265
|
if (!scanEnabled)
|
|
266
266
|
return input;
|
|
267
|
-
return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-1.5", children: [_jsx("div", { className: "min-w-0 flex-1", children: input }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "size-9 shrink-0", onClick: () => setScanOpen(true), title: "Escanear con la c\u00E1mara", "aria-label": "Escanear c\u00F3digo de barras con la c\u00E1mara", children: _jsx(ScanLine, { className: "size-4" }) }), _jsx(BarcodeScanner, { open: scanOpen, onClose: () => setScanOpen(false), onDetected: (code) => onChange(code),
|
|
267
|
+
return (_jsxs("div", { className: "flex w-full min-w-0 items-center gap-1.5", children: [_jsx("div", { className: "min-w-0 flex-1", children: input }), _jsx(Button, { type: "button", variant: "outline", size: "icon", className: "size-9 shrink-0", onClick: () => setScanOpen(true), title: "Escanear con la c\u00E1mara", "aria-label": "Escanear c\u00F3digo de barras con la c\u00E1mara", children: _jsx(ScanLine, { className: "size-4" }) }), _jsx(BarcodeScanner, { open: scanOpen, onClose: () => setScanOpen(false), onDetected: (code) => onChange(code),
|
|
268
|
+
// Un campo = un código: cerrar al detectar. El POS usa continuous
|
|
269
|
+
// (default) porque suma varios productos seguidos.
|
|
270
|
+
continuous: false, position: "fixed", title: `Escanear ${field.label ?? ''}`.trim() })] }));
|
|
268
271
|
}
|
|
269
272
|
function RefSelect({ field, value, onChange }) {
|
|
270
273
|
const { options, loading } = useOptionsResolver({
|
package/package.json
CHANGED
|
@@ -77,4 +77,19 @@ describe('isRowActionVisible', () => {
|
|
|
77
77
|
expect(isActionConditionMet({ condition: { field: 's', operator: 'not_in', value: ['a', 'b'] } }, { s: 'c' })).toBe(true)
|
|
78
78
|
expect(isActionConditionMet({ condition: { field: 's', operator: 'neq', value: 'a' } }, { s: 'a' })).toBe(false)
|
|
79
79
|
})
|
|
80
|
+
|
|
81
|
+
it('isActionConditionMet resolves nested paths and equals/notEquals aliases', () => {
|
|
82
|
+
const approve = {
|
|
83
|
+
condition: { field: 'user.verified', operator: 'equals', value: false },
|
|
84
|
+
}
|
|
85
|
+
const revoke = {
|
|
86
|
+
condition: { field: 'user.verified', operator: 'equals', value: true },
|
|
87
|
+
}
|
|
88
|
+
expect(isActionConditionMet(approve, { user: { verified: false } })).toBe(true)
|
|
89
|
+
expect(isActionConditionMet(approve, { user: { verified: true } })).toBe(false)
|
|
90
|
+
expect(isActionConditionMet(revoke, { user: { verified: true } })).toBe(true)
|
|
91
|
+
expect(isActionConditionMet(revoke, { user: { verified: false } })).toBe(false)
|
|
92
|
+
// Flat lookup must NOT match nested conditions (regression of row[field]).
|
|
93
|
+
expect(isActionConditionMet(approve, { 'user.verified': false } as any)).toBe(false)
|
|
94
|
+
})
|
|
80
95
|
})
|
|
@@ -1886,7 +1886,9 @@ function ScannableRecordInput({
|
|
|
1886
1886
|
open={scanOpen}
|
|
1887
1887
|
onClose={() => setScanOpen(false)}
|
|
1888
1888
|
onDetected={(code) => onChange(code)}
|
|
1889
|
-
continuous
|
|
1889
|
+
// Un campo = un código: cerrar al detectar. El POS usa continuous
|
|
1890
|
+
// (default) porque suma varios productos seguidos.
|
|
1891
|
+
continuous={false}
|
|
1890
1892
|
position="fixed"
|
|
1891
1893
|
title={`Escanear ${field.label ?? ''}`.trim()}
|
|
1892
1894
|
/>
|
package/src/dynamic-columns.tsx
CHANGED
|
@@ -226,22 +226,42 @@ export const isActionAllowedForRowState = (action: any, row: any): boolean => {
|
|
|
226
226
|
|
|
227
227
|
/**
|
|
228
228
|
* Declarative `condition` gate for a per-row action: shows the action only when
|
|
229
|
-
* the row's `field` satisfies the
|
|
230
|
-
*
|
|
229
|
+
* the row's `field` satisfies the operator. Supports both the SDK dialect
|
|
230
|
+
* (`eq` | `neq` | `in` | `not_in`) and the common host dialect
|
|
231
|
+
* (`equals` | `notEquals` | `not_in`). Nested paths (`user.verified`) are
|
|
232
|
+
* resolved via `getNestedValue`. No condition → always shown. Unknown
|
|
233
|
+
* operator → permissive.
|
|
231
234
|
*/
|
|
232
235
|
export const isActionConditionMet = (action: any, row: any): boolean => {
|
|
233
236
|
if (!action?.condition) return true
|
|
234
237
|
const { field, operator, value } = action.condition
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
+
if (!field) return true
|
|
239
|
+
|
|
240
|
+
const coerce = (v: unknown): string => {
|
|
241
|
+
if (v === null || v === undefined) return ''
|
|
242
|
+
if (typeof v === 'boolean') return v ? 'true' : 'false'
|
|
243
|
+
return String(v)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const raw = getNestedValue(row, field)
|
|
247
|
+
const rowValue = coerce(raw)
|
|
248
|
+
const values = (Array.isArray(value) ? value : [value]).map(coerce)
|
|
249
|
+
const op = String(operator ?? '').toLowerCase()
|
|
250
|
+
|
|
251
|
+
switch (op) {
|
|
238
252
|
case 'eq':
|
|
253
|
+
case 'equals':
|
|
254
|
+
case '==':
|
|
239
255
|
return rowValue === values[0]
|
|
240
256
|
case 'neq':
|
|
257
|
+
case 'notequals':
|
|
258
|
+
case 'not_equals':
|
|
259
|
+
case '!=':
|
|
241
260
|
return rowValue !== values[0]
|
|
242
261
|
case 'in':
|
|
243
262
|
return values.includes(rowValue)
|
|
244
263
|
case 'not_in':
|
|
264
|
+
case 'notin':
|
|
245
265
|
return !values.includes(rowValue)
|
|
246
266
|
default:
|
|
247
267
|
return true
|
package/src/dynamic-form.tsx
CHANGED
|
@@ -480,7 +480,9 @@ function ScannableInput({
|
|
|
480
480
|
open={scanOpen}
|
|
481
481
|
onClose={() => setScanOpen(false)}
|
|
482
482
|
onDetected={(code) => onChange(code)}
|
|
483
|
-
continuous
|
|
483
|
+
// Un campo = un código: cerrar al detectar. El POS usa continuous
|
|
484
|
+
// (default) porque suma varios productos seguidos.
|
|
485
|
+
continuous={false}
|
|
484
486
|
position="fixed"
|
|
485
487
|
title={`Escanear ${field.label ?? ''}`.trim()}
|
|
486
488
|
/>
|