@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.
Files changed (39) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/dist/action-modal-dispatcher.d.ts +1 -0
  3. package/dist/action-modal-dispatcher.d.ts.map +1 -1
  4. package/dist/action-modal-dispatcher.js +34 -5
  5. package/dist/business/document-editor-model.d.ts +27 -1
  6. package/dist/business/document-editor-model.d.ts.map +1 -1
  7. package/dist/business/document-editor-model.js +104 -7
  8. package/dist/business/document-editor-panels.d.ts +18 -0
  9. package/dist/business/document-editor-panels.d.ts.map +1 -1
  10. package/dist/business/document-editor-panels.js +9 -0
  11. package/dist/business/document-editor.d.ts +7 -1
  12. package/dist/business/document-editor.d.ts.map +1 -1
  13. package/dist/business/document-editor.js +106 -41
  14. package/dist/document-form-dialog.d.ts.map +1 -1
  15. package/dist/document-form-dialog.js +8 -3
  16. package/dist/dynamic-row-actions.d.ts +6 -0
  17. package/dist/dynamic-row-actions.d.ts.map +1 -1
  18. package/dist/dynamic-row-actions.js +9 -4
  19. package/dist/index.d.ts +1 -1
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/record-mutation-events.d.ts +12 -0
  23. package/dist/record-mutation-events.d.ts.map +1 -1
  24. package/dist/record-mutation-events.js +18 -0
  25. package/package.json +1 -1
  26. package/src/__tests__/document-editor-model.test.ts +27 -0
  27. package/src/__tests__/document-editor.test.tsx +60 -0
  28. package/src/__tests__/invoice-document-editor.test.tsx +267 -0
  29. package/src/__tests__/r5-self-label-settled.test.ts +57 -0
  30. package/src/__tests__/r6-editor-source-seeds.test.tsx +137 -0
  31. package/src/__tests__/row-action-link-navigation.test.ts +10 -6
  32. package/src/action-modal-dispatcher.tsx +34 -5
  33. package/src/business/document-editor-model.ts +118 -7
  34. package/src/business/document-editor-panels.tsx +49 -0
  35. package/src/business/document-editor.tsx +288 -177
  36. package/src/document-form-dialog.tsx +13 -4
  37. package/src/dynamic-row-actions.tsx +12 -4
  38. package/src/index.ts +2 -0
  39. 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(url: string): { to: string; search?: Record<string, string> } {
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
- if (i < 0) return { to: url }
50
- return { to: url.slice(0, i), search: Object.fromEntries(new URLSearchParams(url.slice(i + 1))) }
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) => encodeURIComponent(String(row[field] ?? '')))
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
  */