@asteby/metacore-runtime-react 53.27.0 → 53.29.0
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 +26 -0
- package/dist/business/customer-picker.d.ts +10 -1
- package/dist/business/customer-picker.d.ts.map +1 -1
- package/dist/business/customer-picker.js +7 -2
- package/dist/dialogs/create-record-dialog.d.ts +1 -1
- package/dist/dialogs/create-record-dialog.d.ts.map +1 -1
- package/dist/dialogs/create-record-dialog.js +2 -2
- package/dist/dialogs/dynamic-record.d.ts +19 -2
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +83 -25
- package/dist/dialogs/types.d.ts +6 -0
- package/dist/dialogs/types.d.ts.map +1 -1
- package/dist/dynamic-crud-page.d.ts.map +1 -1
- package/dist/dynamic-crud-page.js +3 -0
- package/dist/dynamic-form.d.ts.map +1 -1
- package/dist/dynamic-form.js +6 -5
- package/dist/field-widget-registry.d.ts +6 -0
- package/dist/field-widget-registry.d.ts.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/loom/index.d.ts +9 -0
- package/dist/loom/index.d.ts.map +1 -0
- package/dist/loom/index.js +9 -0
- package/dist/loom/overlay.d.ts +74 -0
- package/dist/loom/overlay.d.ts.map +1 -0
- package/dist/loom/overlay.js +142 -0
- package/dist/loom/proposals.d.ts +26 -0
- package/dist/loom/proposals.d.ts.map +1 -0
- package/dist/loom/proposals.js +74 -0
- package/dist/loom/provider.d.ts +28 -0
- package/dist/loom/provider.d.ts.map +1 -0
- package/dist/loom/provider.js +31 -0
- package/dist/loom/resolve.d.ts +23 -0
- package/dist/loom/resolve.d.ts.map +1 -0
- package/dist/loom/resolve.js +138 -0
- package/dist/loom/seam.d.ts +28 -0
- package/dist/loom/seam.d.ts.map +1 -0
- package/dist/loom/seam.js +127 -0
- package/dist/loom/seams.d.ts +31 -0
- package/dist/loom/seams.d.ts.map +1 -0
- package/dist/loom/seams.js +21 -0
- package/dist/loom/store.d.ts +16 -0
- package/dist/loom/store.d.ts.map +1 -0
- package/dist/loom/store.js +72 -0
- package/dist/loom/types.d.ts +153 -0
- package/dist/loom/types.d.ts.map +1 -0
- package/dist/loom/types.js +1 -0
- package/dist/model-labels.d.ts +26 -0
- package/dist/model-labels.d.ts.map +1 -1
- package/dist/model-labels.js +22 -5
- package/dist/record-picker-dialog.d.ts +10 -1
- package/dist/record-picker-dialog.d.ts.map +1 -1
- package/dist/record-picker-dialog.js +18 -3
- package/dist/record-picker.d.ts +6 -0
- package/dist/record-picker.d.ts.map +1 -1
- package/dist/record-picker.js +4 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/dynamic-record-seam.test.tsx +194 -0
- package/src/__tests__/dynamic-record-texts.test.tsx +22 -0
- package/src/__tests__/field-widget-set-values.test.tsx +65 -0
- package/src/__tests__/loom-overlay.test.ts +94 -0
- package/src/__tests__/loom-resolve.test.ts +108 -0
- package/src/__tests__/model-labels.test.tsx +41 -1
- package/src/__tests__/record-picker-open-on-focus.test.tsx +49 -0
- package/src/business/customer-picker.tsx +17 -0
- package/src/dialogs/create-record-dialog.tsx +6 -0
- package/src/dialogs/dynamic-record.tsx +131 -26
- package/src/dialogs/types.ts +6 -0
- package/src/dynamic-crud-page.tsx +3 -0
- package/src/dynamic-form.tsx +9 -2
- package/src/field-widget-registry.tsx +6 -0
- package/src/index.ts +4 -1
- package/src/loom/index.ts +36 -0
- package/src/loom/overlay.ts +196 -0
- package/src/loom/proposals.tsx +156 -0
- package/src/loom/provider.tsx +69 -0
- package/src/loom/resolve.ts +136 -0
- package/src/loom/seam.tsx +235 -0
- package/src/loom/seams.ts +42 -0
- package/src/loom/store.ts +81 -0
- package/src/loom/types.ts +167 -0
- package/src/model-labels.ts +45 -5
- package/src/record-picker-dialog.tsx +42 -1
- package/src/record-picker.tsx +10 -0
- package/src/types.ts +10 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Overlays sobre el grafo de bloques del tablero: base de OPS + capas del preset
|
|
2
|
+
// (7 Leguas), organización y rol.
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import { applyOverlays, mergeConfig, type BlockGraph, type OverlayLayer } from '../loom'
|
|
5
|
+
|
|
6
|
+
const base: BlockGraph = {
|
|
7
|
+
id: 'ops.dashboard',
|
|
8
|
+
version: '1.3.0',
|
|
9
|
+
blocks: [
|
|
10
|
+
{ id: 'kpi.sales', type: 'kpi', config: { metric: 'sales', range: '7d', style: { tone: 'primary' } } },
|
|
11
|
+
{ id: 'chart.sales', type: 'chart', config: { kind: 'line' } },
|
|
12
|
+
{ id: 'list.recent', type: 'table', config: { model: 'SalesOrder' } },
|
|
13
|
+
],
|
|
14
|
+
}
|
|
15
|
+
const ids = (g: BlockGraph) => g.blocks.map((b) => b.id)
|
|
16
|
+
|
|
17
|
+
describe('applyOverlays', () => {
|
|
18
|
+
it('aplica capas por alcance (preset < org < role) sin importar el orden de entrada', () => {
|
|
19
|
+
const layers: OverlayLayer[] = [
|
|
20
|
+
{ id: 'role.cajero', scope: 'role', ops: [{ op: 'remove', id: 'leguas.vehicles' }] },
|
|
21
|
+
{
|
|
22
|
+
id: 'preset.7leguas',
|
|
23
|
+
scope: 'preset',
|
|
24
|
+
targets: '^1.2',
|
|
25
|
+
ops: [
|
|
26
|
+
{ op: 'add', block: { id: 'leguas.vehicles', type: 'kpi', config: { metric: 'vehicles' } }, after: 'kpi.sales' },
|
|
27
|
+
{ op: 'configure', id: 'kpi.sales', set: { range: '30d', style: { tone: null } } },
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
{ id: 'org.matriz', scope: 'org', ops: [{ op: 'move', id: 'list.recent', before: 'kpi.sales' }] },
|
|
31
|
+
]
|
|
32
|
+
const r = applyOverlays(base, layers)
|
|
33
|
+
expect(r.applied).toEqual(['preset.7leguas', 'org.matriz', 'role.cajero'])
|
|
34
|
+
expect(ids(r.graph)).toEqual(['list.recent', 'kpi.sales', 'chart.sales'])
|
|
35
|
+
expect(r.graph.blocks[1].config).toEqual({ metric: 'sales', range: '30d', style: {} })
|
|
36
|
+
expect(r.removed).toEqual({ 'leguas.vehicles': 'role.cajero' })
|
|
37
|
+
expect(r.provenance['kpi.sales']).toEqual({ origin: 'base', touchedBy: ['preset.7leguas'] })
|
|
38
|
+
expect(r.conflicts).toEqual([])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('una capa es atómica: si una operación no aplica, no aplica ninguna', () => {
|
|
42
|
+
const r = applyOverlays(base, [
|
|
43
|
+
{
|
|
44
|
+
id: 'org.x',
|
|
45
|
+
scope: 'org',
|
|
46
|
+
ops: [
|
|
47
|
+
{ op: 'remove', id: 'chart.sales' },
|
|
48
|
+
{ op: 'configure', id: 'kpi.inexistente', set: { a: 1 } },
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
])
|
|
52
|
+
expect(ids(r.graph)).toEqual(ids(base))
|
|
53
|
+
expect(r.conflicts).toEqual([{ layer: 'org.x', index: 1, reason: 'missing_target', detail: 'kpi.inexistente' }])
|
|
54
|
+
expect(r.applied).toEqual([])
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('si la base cambió de mayor, la capa cae al comportamiento base y avisa', () => {
|
|
58
|
+
const r = applyOverlays({ ...base, version: '2.0.0' }, [
|
|
59
|
+
{ id: 'preset.7leguas', scope: 'preset', targets: '^1.2', ops: [{ op: 'remove', id: 'chart.sales' }] },
|
|
60
|
+
])
|
|
61
|
+
expect(ids(r.graph)).toEqual(ids(base))
|
|
62
|
+
expect(r.conflicts[0]).toMatchObject({ reason: 'base_incompatible', index: -1 })
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('replace guarda el original como fallback y conserva el id', () => {
|
|
66
|
+
const r = applyOverlays(base, [
|
|
67
|
+
{ id: 'preset.p', scope: 'preset', ops: [{ op: 'replace', id: 'chart.sales', with: { id: 'x', type: 'leguas.sales-chart' } }] },
|
|
68
|
+
])
|
|
69
|
+
const b = r.graph.blocks[1]
|
|
70
|
+
expect(b).toMatchObject({ id: 'chart.sales', type: 'leguas.sales-chart' })
|
|
71
|
+
expect(b.fallback).toMatchObject({ type: 'chart' })
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('add con id repetido o ancla inexistente es conflicto', () => {
|
|
75
|
+
const r = applyOverlays(base, [
|
|
76
|
+
{ id: 'a', scope: 'org', ops: [{ op: 'add', block: { id: 'kpi.sales', type: 'kpi' } }] },
|
|
77
|
+
{ id: 'b', scope: 'org', ops: [{ op: 'add', block: { id: 'n', type: 'kpi' }, before: 'nope' }] },
|
|
78
|
+
])
|
|
79
|
+
expect(r.conflicts.map((c) => c.reason)).toEqual(['duplicate_id', 'missing_anchor'])
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('no muta la base y es determinista', () => {
|
|
83
|
+
const snap = JSON.stringify(base)
|
|
84
|
+
const layers: OverlayLayer[] = [{ id: 'o', scope: 'org', ops: [{ op: 'configure', id: 'kpi.sales', set: { range: '1d' } }] }]
|
|
85
|
+
const a = applyOverlays(base, layers)
|
|
86
|
+
const b = applyOverlays(base, layers)
|
|
87
|
+
expect(JSON.stringify(base)).toBe(snap)
|
|
88
|
+
expect(a).toEqual(b)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('mergeConfig: arrays se sustituyen, null borra', () => {
|
|
92
|
+
expect(mergeConfig({ a: [1, 2], b: { c: 1, d: 2 } }, { a: [3], b: { d: null } })).toEqual({ a: [3], b: { c: 1 } })
|
|
93
|
+
})
|
|
94
|
+
})
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
attenuatePatch,
|
|
4
|
+
clearLoom,
|
|
5
|
+
projectLenses,
|
|
6
|
+
redactMessage,
|
|
7
|
+
registerPart,
|
|
8
|
+
resolveSeam,
|
|
9
|
+
sensitiveClasses,
|
|
10
|
+
type GraftDef,
|
|
11
|
+
type LoomEnv,
|
|
12
|
+
type SeamContract,
|
|
13
|
+
} from '../loom'
|
|
14
|
+
|
|
15
|
+
const C = () => null
|
|
16
|
+
const contract: SeamContract = {
|
|
17
|
+
id: 'record.dialog.header',
|
|
18
|
+
version: '1.2.0',
|
|
19
|
+
lenses: { values: 'pii', model: 'public', fiscal: 'pii.fiscal' },
|
|
20
|
+
writable: new Set(['tax_id', 'postal_code', 'fiscal_data.regime']),
|
|
21
|
+
}
|
|
22
|
+
const env = (over: Partial<LoomEnv> = {}): LoomEnv => ({ can: () => true, model: 'customers.Customer', mode: 'create', ...over })
|
|
23
|
+
const g = (over: Partial<GraftDef>): GraftDef => ({ id: 'a.x', seam: 'record.dialog.header', component: C, ...over })
|
|
24
|
+
|
|
25
|
+
afterEach(clearLoom)
|
|
26
|
+
|
|
27
|
+
describe('resolveSeam', () => {
|
|
28
|
+
it('ordena por order y conserva el orden de entrada en empates', () => {
|
|
29
|
+
const r = resolveSeam(contract, [g({ id: 'a.b', order: 5 }), g({ id: 'a.c' }), g({ id: 'a.d' })], env())
|
|
30
|
+
expect(r.mounted.map((x) => x.id)).toEqual(['a.c', 'a.d', 'a.b'])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('explica cada descarte', () => {
|
|
34
|
+
const r = resolveSeam(
|
|
35
|
+
contract,
|
|
36
|
+
[
|
|
37
|
+
g({ id: 'a.perm', when: { permission: 'customers.csf' } }),
|
|
38
|
+
g({ id: 'a.flag', when: { flag: 'csf' } }),
|
|
39
|
+
g({ id: 'a.set', when: { setting: { key: 'csf.enabled' } } }),
|
|
40
|
+
g({ id: 'a.model', when: { model: ['Supplier'] } }),
|
|
41
|
+
g({ id: 'a.mode', when: { mode: ['edit'] } }),
|
|
42
|
+
g({ id: 'a.ver', requires: '^2' }),
|
|
43
|
+
g({ id: 'a.part', component: undefined, part: 'a.missing' }),
|
|
44
|
+
g({ id: 'a.ok', when: { model: ['Customer'], mode: ['create'] }, requires: '^1.1' }),
|
|
45
|
+
],
|
|
46
|
+
env({ can: (p) => p !== 'customers.csf' }),
|
|
47
|
+
)
|
|
48
|
+
expect(r.mounted.map((x) => x.id)).toEqual(['a.ok'])
|
|
49
|
+
expect(Object.fromEntries(r.skipped.map((s) => [s.graft.id, s.reason]))).toEqual({
|
|
50
|
+
'a.perm': 'permission',
|
|
51
|
+
'a.flag': 'flag',
|
|
52
|
+
'a.set': 'setting',
|
|
53
|
+
'a.model': 'model',
|
|
54
|
+
'a.mode': 'mode',
|
|
55
|
+
'a.ver': 'version',
|
|
56
|
+
'a.part': 'no_component',
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('con lista del servidor, lo no autorizado no se monta', () => {
|
|
61
|
+
const r = resolveSeam(contract, [g({ id: 'a.x' }), g({ id: 'a.y' })], env({ granted: new Set(['a.y']) }))
|
|
62
|
+
expect(r.mounted.map((x) => x.id)).toEqual(['a.y'])
|
|
63
|
+
expect(r.skipped[0]).toMatchObject({ reason: 'not_granted' })
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('resuelve el componente por Part registrado', () => {
|
|
67
|
+
registerPart({ id: 'fiscal.csf', component: C })
|
|
68
|
+
const r = resolveSeam(contract, [g({ id: 'a.p', component: undefined, part: 'fiscal.csf' })], env())
|
|
69
|
+
expect(r.mounted).toHaveLength(1)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('ignora injertos de otros seams', () => {
|
|
73
|
+
expect(resolveSeam(contract, [g({ seam: 'otro' })], env()).mounted).toEqual([])
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('capacidades', () => {
|
|
78
|
+
it('writes ∩ writable: lo demás se descarta', () => {
|
|
79
|
+
const r = attenuatePatch(
|
|
80
|
+
{ tax_id: 'X', organization_id: 'hack', postal_code: '1', 'fiscal_data.regime': '601' },
|
|
81
|
+
['tax_id', 'fiscal_data.*', 'organization_id'],
|
|
82
|
+
contract.writable,
|
|
83
|
+
)
|
|
84
|
+
expect(r.allowed).toEqual({ tax_id: 'X', 'fiscal_data.regime': '601' })
|
|
85
|
+
expect(r.dropped.sort()).toEqual(['organization_id', 'postal_code'])
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('sin writes no escribe nada', () => {
|
|
89
|
+
expect(attenuatePatch({ tax_id: 'X' }, undefined, contract.writable).allowed).toEqual({})
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('lentes: sólo las declaradas, congeladas y sin tocar el original', () => {
|
|
93
|
+
const values = { name: 'A', nested: { x: 1 } }
|
|
94
|
+
const view = projectLenses({ values, model: 'Customer', fiscal: {} }, ['values'])
|
|
95
|
+
expect(Object.keys(view)).toEqual(['values'])
|
|
96
|
+
expect(Object.isFrozen((view.values as typeof values).nested)).toBe(true)
|
|
97
|
+
expect(Object.isFrozen(values)).toBe(false)
|
|
98
|
+
expect(Object.isFrozen(values.nested)).toBe(false)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('redacta errores de injertos que leen datos sensibles', () => {
|
|
102
|
+
expect(sensitiveClasses(contract, ['model'])).toEqual([])
|
|
103
|
+
const cls = sensitiveClasses(contract, ['values', 'fiscal'])
|
|
104
|
+
expect(cls).toEqual(['pii', 'pii.fiscal'])
|
|
105
|
+
expect(redactMessage('RFC XAXX010101000 inválido', cls)).not.toContain('XAXX')
|
|
106
|
+
expect(redactMessage('boom', [])).toBe('boom')
|
|
107
|
+
})
|
|
108
|
+
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { resolveModelLabels, defaultSingular } from '../model-labels'
|
|
2
|
+
import { resolveModelLabels, defaultSingular, resolveModelNoun, modelVerbTitle } from '../model-labels'
|
|
3
3
|
|
|
4
4
|
const makeT = (dict: Record<string, string>) => (key: string, opts?: Record<string, unknown>) =>
|
|
5
5
|
dict[key] ?? (opts?.defaultValue as string | undefined) ?? key
|
|
@@ -29,3 +29,43 @@ describe('resolveModelLabels', () => {
|
|
|
29
29
|
})
|
|
30
30
|
it('singular helper', () => expect(defaultSingular('orders')).toBe('Order'))
|
|
31
31
|
})
|
|
32
|
+
|
|
33
|
+
describe('backend-declared names (singular_label / new_label / gender)', () => {
|
|
34
|
+
it('singular_label replaces the naive title-minus-s derivation', () => {
|
|
35
|
+
const l = resolveModelLabels(makeT({ 'common.new': 'Nuevo' }), {
|
|
36
|
+
model: 'addresses', title: 'Direcciones', singularLabel: 'dirección',
|
|
37
|
+
})
|
|
38
|
+
expect(l.singular).toBe('dirección')
|
|
39
|
+
expect(l.newLabel).toBe('Nuevo dirección')
|
|
40
|
+
})
|
|
41
|
+
it('gender picks common.new_<gender> before common.new', () => {
|
|
42
|
+
const t = makeT({ 'common.new': 'Nuevo', 'common.new_f': 'Nueva', 'common.new_m': 'Nuevo' })
|
|
43
|
+
expect(resolveModelLabels(t, { model: 'addresses', title: 'Direcciones', singularLabel: 'dirección', gender: 'f' }).newLabel)
|
|
44
|
+
.toBe('Nueva dirección')
|
|
45
|
+
expect(resolveModelLabels(t, { model: 'x', title: 'X', singularLabel: 'cliente', gender: 'm' }).newLabel).toBe('Nuevo cliente')
|
|
46
|
+
})
|
|
47
|
+
it('backend new_label is used as is; host models.<model>.new still wins', () => {
|
|
48
|
+
expect(resolveModelLabels(makeT({}), { model: 'x', title: 'X', newLabelMeta: 'Nueva figura' }).newLabel).toBe('Nueva figura')
|
|
49
|
+
expect(resolveModelLabels(makeT({ 'models.x.new': 'Alta' }), { model: 'x', title: 'X', newLabelMeta: 'Nueva figura' }).newLabel).toBe('Alta')
|
|
50
|
+
})
|
|
51
|
+
it('host models.<model>.singular overrides the backend singular_label', () => {
|
|
52
|
+
const l = resolveModelLabels(makeT({ 'models.x.singular': 'Socio' }), { model: 'x', title: 'X', singularLabel: 'cliente' })
|
|
53
|
+
expect(l.singular).toBe('Socio')
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
describe('resolveModelNoun / modelVerbTitle', () => {
|
|
58
|
+
it('order: host singular > singular_label > titleKey > title', () => {
|
|
59
|
+
expect(resolveModelNoun(makeT({ 'models.c.singular': 'Cliente' }), { model: 'c', singularLabel: 'cliente', title: 'Client' })).toBe('Cliente')
|
|
60
|
+
expect(resolveModelNoun(makeT({}), { model: 'c', singularLabel: 'cliente', title: 'Client' })).toBe('cliente')
|
|
61
|
+
expect(resolveModelNoun(makeT({ 'k.t': 'Socio' }), { model: 'c', titleKey: 'k.t', title: 'Client' })).toBe('Socio')
|
|
62
|
+
expect(resolveModelNoun(makeT({}), { model: 'c', title: 'Client' })).toBe('Client')
|
|
63
|
+
expect(resolveModelNoun(makeT({}), { model: 'c' })).toBe('')
|
|
64
|
+
})
|
|
65
|
+
it('verb titles are i18n-able with a Spanish default', () => {
|
|
66
|
+
const t = (k: string, o?: Record<string, unknown>) =>
|
|
67
|
+
k === 'dynamic.edit_title' ? `Edit ${o?.name}` : (o?.defaultValue as string)
|
|
68
|
+
expect(modelVerbTitle(t, 'edit', 'customer', 'Editar customer')).toBe('Edit customer')
|
|
69
|
+
expect(modelVerbTitle(t, 'create', 'cliente', 'Crear cliente')).toBe('Crear cliente')
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
//
|
|
3
|
+
// RecordPicker trigger="input" + openOnFocus: la lista se abre al enfocar el cuadro
|
|
4
|
+
// (sin teclear ni hacer clic aparte); sin la opcion queda cerrada como antes.
|
|
5
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
6
|
+
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
7
|
+
|
|
8
|
+
vi.mock('react-i18next', () => {
|
|
9
|
+
const t = (k: string, o?: Record<string, any>) => o?.defaultValue ?? k
|
|
10
|
+
const value = { t, i18n: { language: 'es' } }
|
|
11
|
+
return { useTranslation: () => value }
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
import { RecordPicker } from '../record-picker'
|
|
15
|
+
|
|
16
|
+
afterEach(cleanup)
|
|
17
|
+
const rows = [
|
|
18
|
+
{ id: 'a', name: 'Alfa' },
|
|
19
|
+
{ id: 'b', name: 'Beta' },
|
|
20
|
+
]
|
|
21
|
+
function Picker({ openOnFocus }: { openOnFocus?: boolean }) {
|
|
22
|
+
return (
|
|
23
|
+
<RecordPicker<(typeof rows)[number]>
|
|
24
|
+
trigger="input"
|
|
25
|
+
items={rows}
|
|
26
|
+
minChars={0}
|
|
27
|
+
getKey={(r) => r.id}
|
|
28
|
+
getLabel={(r) => r.name}
|
|
29
|
+
value={null}
|
|
30
|
+
selected={null}
|
|
31
|
+
onSelect={() => {}}
|
|
32
|
+
openOnFocus={openOnFocus}
|
|
33
|
+
entityLabel="Elemento"
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
describe('RecordPicker openOnFocus', () => {
|
|
39
|
+
it('abre la lista al enfocar', async () => {
|
|
40
|
+
render(<Picker openOnFocus />)
|
|
41
|
+
fireEvent.focus(screen.getByRole('combobox'))
|
|
42
|
+
expect(await screen.findByText('Alfa')).toBeTruthy()
|
|
43
|
+
})
|
|
44
|
+
it('sin openOnFocus no abre al enfocar', () => {
|
|
45
|
+
render(<Picker />)
|
|
46
|
+
fireEvent.focus(screen.getByRole('combobox'))
|
|
47
|
+
expect(screen.queryByText('Alfa')).toBeNull()
|
|
48
|
+
})
|
|
49
|
+
})
|
|
@@ -7,6 +7,7 @@ import { useTranslation } from 'react-i18next'
|
|
|
7
7
|
import { Badge } from '@asteby/metacore-ui'
|
|
8
8
|
import { RecordPicker, useLatestSearch } from '../record-picker'
|
|
9
9
|
import { useRecordPickerDialog } from '../record-picker-dialog'
|
|
10
|
+
import type { FieldDef } from '../dialogs/dynamic-record'
|
|
10
11
|
import { useCan } from '../permissions-context'
|
|
11
12
|
import { useFormatter } from './format'
|
|
12
13
|
|
|
@@ -46,6 +47,14 @@ export interface CustomerPickerProps {
|
|
|
46
47
|
canEdit?: boolean
|
|
47
48
|
/** Valores iniciales del alta rápida (p. ej. el texto buscado como nombre). */
|
|
48
49
|
createDefaults?: Record<string, unknown>
|
|
50
|
+
/**
|
|
51
|
+
* Campos extra del modal de alta/edicion (se fusionan al esquema servido). Con
|
|
52
|
+
* `widget: '<nombre>'` registrado via `registerFieldWidget`, el widget puede llenar
|
|
53
|
+
* el resto del formulario con `setValues` (p. ej. precarga desde un documento).
|
|
54
|
+
*/
|
|
55
|
+
ensureFields?: FieldDef[]
|
|
56
|
+
/** Abre la lista al enfocar el cuadro de busqueda (ver `RecordPicker.openOnFocus`). */
|
|
57
|
+
openOnFocus?: boolean
|
|
49
58
|
currency?: string
|
|
50
59
|
disabled?: boolean
|
|
51
60
|
placeholder?: string
|
|
@@ -72,6 +81,8 @@ export function CustomerPicker({
|
|
|
72
81
|
canCreate,
|
|
73
82
|
canEdit,
|
|
74
83
|
createDefaults,
|
|
84
|
+
ensureFields,
|
|
85
|
+
openOnFocus,
|
|
75
86
|
currency,
|
|
76
87
|
disabled,
|
|
77
88
|
placeholder,
|
|
@@ -103,6 +114,11 @@ export function CustomerPicker({
|
|
|
103
114
|
endpoint,
|
|
104
115
|
prefillField: 'name',
|
|
105
116
|
createDefaults,
|
|
117
|
+
ensureFields,
|
|
118
|
+
onSelectExisting: (rec) => {
|
|
119
|
+
onChange(toResult(rec))
|
|
120
|
+
setText('')
|
|
121
|
+
},
|
|
106
122
|
onSaved: (rec, kind) => {
|
|
107
123
|
const next = toResult(rec)
|
|
108
124
|
// Al editar se conservan saldo/crédito/alertas que el registro no trae.
|
|
@@ -139,6 +155,7 @@ export function CustomerPicker({
|
|
|
139
155
|
<>
|
|
140
156
|
<RecordPicker<CustomerResult>
|
|
141
157
|
trigger="input"
|
|
158
|
+
openOnFocus={openOnFocus}
|
|
142
159
|
slot="customer-picker"
|
|
143
160
|
search={searchFn}
|
|
144
161
|
minChars={2}
|
|
@@ -24,9 +24,12 @@ export function CreateRecordDialog({
|
|
|
24
24
|
schema,
|
|
25
25
|
defaults,
|
|
26
26
|
lockedFields,
|
|
27
|
+
ensureFields,
|
|
27
28
|
onCreate,
|
|
28
29
|
onUpdate,
|
|
29
30
|
onSaved,
|
|
31
|
+
onIntent,
|
|
32
|
+
initialProposal,
|
|
30
33
|
}: CreateRecordDialogProps) {
|
|
31
34
|
const mode = recordId ? 'edit' : 'create'
|
|
32
35
|
return (
|
|
@@ -40,9 +43,12 @@ export function CreateRecordDialog({
|
|
|
40
43
|
schema={schema}
|
|
41
44
|
defaults={defaults}
|
|
42
45
|
lockedFields={lockedFields}
|
|
46
|
+
ensureFields={ensureFields}
|
|
43
47
|
onCreate={onCreate}
|
|
44
48
|
onUpdate={onUpdate}
|
|
45
49
|
onSaved={onSaved}
|
|
50
|
+
onIntent={onIntent}
|
|
51
|
+
initialProposal={initialProposal}
|
|
46
52
|
/>
|
|
47
53
|
)
|
|
48
54
|
}
|