@asteby/metacore-runtime-react 49.1.0 → 49.2.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 +37 -0
- package/dist/action-modal-dispatcher.d.ts +1 -0
- package/dist/action-modal-dispatcher.d.ts.map +1 -1
- package/dist/action-modal-dispatcher.js +34 -5
- package/dist/business/document-editor-model.d.ts +27 -1
- package/dist/business/document-editor-model.d.ts.map +1 -1
- package/dist/business/document-editor-model.js +104 -7
- package/dist/business/document-editor-panels.d.ts +18 -0
- package/dist/business/document-editor-panels.d.ts.map +1 -1
- package/dist/business/document-editor-panels.js +9 -0
- package/dist/business/document-editor.d.ts +7 -1
- package/dist/business/document-editor.d.ts.map +1 -1
- package/dist/business/document-editor.js +106 -41
- package/dist/document-form-dialog.d.ts.map +1 -1
- package/dist/document-form-dialog.js +8 -3
- package/dist/dynamic-row-actions.d.ts +6 -0
- package/dist/dynamic-row-actions.d.ts.map +1 -1
- package/dist/dynamic-row-actions.js +9 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/record-mutation-events.d.ts +12 -0
- package/dist/record-mutation-events.d.ts.map +1 -1
- package/dist/record-mutation-events.js +18 -0
- package/package.json +1 -1
- package/src/__tests__/document-editor-model.test.ts +27 -0
- package/src/__tests__/document-editor.test.tsx +60 -0
- package/src/__tests__/invoice-document-editor.test.tsx +267 -0
- package/src/__tests__/r5-self-label-settled.test.ts +57 -0
- package/src/__tests__/r6-editor-source-seeds.test.tsx +137 -0
- package/src/__tests__/row-action-link-navigation.test.ts +10 -6
- package/src/action-modal-dispatcher.tsx +34 -5
- package/src/business/document-editor-model.ts +118 -7
- package/src/business/document-editor-panels.tsx +49 -0
- package/src/business/document-editor.tsx +288 -177
- package/src/document-form-dialog.tsx +13 -4
- package/src/dynamic-row-actions.tsx +12 -4
- package/src/index.ts +2 -0
- package/src/record-mutation-events.ts +23 -0
|
@@ -44,12 +44,20 @@ import type { TableMetadata, ActionMetadata, RequiresAddon } from './types'
|
|
|
44
44
|
* Destino de una acción link. La query (`?create=…&from_id=…`) va como `search`:
|
|
45
45
|
* metida en `to` el router la tomaba como parte del path y la ruta no casaba.
|
|
46
46
|
*/
|
|
47
|
-
export function linkNavigation(
|
|
47
|
+
export function linkNavigation(
|
|
48
|
+
url: string,
|
|
49
|
+
): { to: '/m/$model'; params: { model: string }; search?: Record<string, string> } | { to: string; search?: Record<string, string> } {
|
|
48
50
|
const i = url.indexOf('?')
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
const path = i < 0 ? url : url.slice(0, i)
|
|
52
|
+
const search = i < 0 ? undefined : Object.fromEntries(new URLSearchParams(url.slice(i + 1)))
|
|
53
|
+
// /m/<tabla>?create=&from=&from_id= → ruta parametrizada (retest r6b: el menú
|
|
54
|
+
// «Nota de crédito» de la factura aterrizaba en la lista sin abrir el editor).
|
|
55
|
+
const m = path.match(/^\/m\/([^/?#]+)\/?$/)
|
|
56
|
+
if (m) return { to: '/m/$model', params: { model: m[1] }, search }
|
|
57
|
+
return search ? { to: path, search } : { to: path }
|
|
51
58
|
}
|
|
52
59
|
|
|
60
|
+
|
|
53
61
|
export interface UseDynamicRowActionsParams {
|
|
54
62
|
/** Model key as registered on the backend (e.g. "issue"). */
|
|
55
63
|
model: string
|
|
@@ -138,7 +146,7 @@ export function useDynamicRowActions({
|
|
|
138
146
|
}
|
|
139
147
|
const linkDef = metadata?.actions?.find((a) => a.key === action && a.type === 'link')
|
|
140
148
|
if (linkDef?.linkUrl) {
|
|
141
|
-
const url = linkDef.linkUrl.replace(/\{(\w+)\}/g, (_: string, field: string) =>
|
|
149
|
+
const url = linkDef.linkUrl.replace(/\{(\w+)\}/g, (_: string, field: string) => String(row[field] ?? ''))
|
|
142
150
|
navigate(linkNavigation(url) as any)
|
|
143
151
|
return
|
|
144
152
|
}
|
package/src/index.ts
CHANGED
|
@@ -201,8 +201,10 @@ export {
|
|
|
201
201
|
} from './list-primary-action'
|
|
202
202
|
export {
|
|
203
203
|
emitRecordMutation,
|
|
204
|
+
emitRecordMutationSettled,
|
|
204
205
|
subscribeRecordMutations,
|
|
205
206
|
RECORD_MUTATION_EVENT,
|
|
207
|
+
RECORD_MUTATION_SETTLE_DELAYS,
|
|
206
208
|
type RecordMutationKind,
|
|
207
209
|
type RecordMutationDetail,
|
|
208
210
|
} from './record-mutation-events'
|
|
@@ -31,6 +31,29 @@ export function emitRecordMutation(model: string | undefined | null, kind: Recor
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Delays (ms) at which a mutation is announced again. The backend's event
|
|
36
|
+
* subscribers write AFTER the action answered (stamping → the invoice's state,
|
|
37
|
+
* a payment → its auto-stamped REP), so a list or tab that reloaded at once kept
|
|
38
|
+
* showing the previous state until a manual reload (retest Pitsline r5).
|
|
39
|
+
*/
|
|
40
|
+
export const RECORD_MUTATION_SETTLE_DELAYS: readonly number[] = [1500, 5000]
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Announce a mutation now and again after `delays`, so what the server derives
|
|
44
|
+
* asynchronously from it reaches mounted lists too. Returns a cancel function.
|
|
45
|
+
*/
|
|
46
|
+
export function emitRecordMutationSettled(
|
|
47
|
+
model: string | undefined | null,
|
|
48
|
+
kind: RecordMutationKind,
|
|
49
|
+
delays: readonly number[] = RECORD_MUTATION_SETTLE_DELAYS,
|
|
50
|
+
): () => void {
|
|
51
|
+
emitRecordMutation(model, kind)
|
|
52
|
+
if (!model || typeof window === 'undefined') return () => {}
|
|
53
|
+
const timers = delays.map((ms) => window.setTimeout(() => emitRecordMutation(model, kind), ms))
|
|
54
|
+
return () => timers.forEach((t) => window.clearTimeout(t))
|
|
55
|
+
}
|
|
56
|
+
|
|
34
57
|
/**
|
|
35
58
|
* Listen for mutations of `model` (case-insensitive). Returns an unsubscribe.
|
|
36
59
|
*/
|