@asteby/metacore-runtime-react 53.23.2 → 53.25.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 +21 -0
- package/dist/addon-page-host.d.ts +6 -1
- package/dist/addon-page-host.d.ts.map +1 -1
- package/dist/addon-page-host.js +16 -2
- package/dist/dashboard-grid.d.ts +1 -1
- package/dist/dashboard-grid.d.ts.map +1 -1
- package/dist/dashboard-grid.js +19 -17
- package/dist/dashboard-types.d.ts +6 -0
- package/dist/dashboard-types.d.ts.map +1 -1
- package/dist/dynamic-columns.d.ts +16 -0
- package/dist/dynamic-columns.d.ts.map +1 -1
- package/dist/dynamic-columns.js +63 -8
- package/dist/dynamic-crud-page.d.ts.map +1 -1
- package/dist/dynamic-crud-page.js +10 -7
- package/dist/dynamic-table.d.ts +3 -1
- package/dist/dynamic-table.d.ts.map +1 -1
- package/dist/dynamic-table.js +24 -12
- package/dist/host-api-client.d.ts +55 -0
- package/dist/host-api-client.d.ts.map +1 -0
- package/dist/host-api-client.js +85 -0
- package/dist/host-api-context.d.ts +10 -0
- package/dist/host-api-context.d.ts.map +1 -0
- package/dist/host-api-context.js +10 -0
- package/dist/host-api.d.ts.map +1 -1
- package/dist/host-api.js +4 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/model-labels.d.ts +38 -0
- package/dist/model-labels.d.ts.map +1 -0
- package/dist/model-labels.js +35 -0
- package/dist/types.d.ts +23 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/use-host-api-client.d.ts +8 -0
- package/dist/use-host-api-client.d.ts.map +1 -0
- package/dist/use-host-api-client.js +12 -0
- package/package.json +9 -9
- package/src/__tests__/host-api-client.test.tsx +119 -0
- package/src/__tests__/initials-avatar-cell.test.tsx +54 -0
- package/src/__tests__/load-guard.test.tsx +94 -0
- package/src/__tests__/model-labels.test.tsx +31 -0
- package/src/__tests__/resolve-row-actions.test.ts +44 -0
- package/src/addon-page-host.tsx +18 -2
- package/src/dashboard-grid.tsx +49 -35
- package/src/dashboard-types.ts +6 -0
- package/src/dynamic-columns.tsx +68 -10
- package/src/dynamic-crud-page.tsx +10 -7
- package/src/dynamic-table.tsx +38 -12
- package/src/host-api-client.ts +137 -0
- package/src/host-api-context.tsx +18 -0
- package/src/host-api.ts +3 -0
- package/src/index.ts +11 -0
- package/src/model-labels.ts +80 -0
- package/src/types.ts +28 -3
- package/src/use-host-api-client.ts +13 -0
package/src/index.ts
CHANGED
|
@@ -305,6 +305,14 @@ export {
|
|
|
305
305
|
type PageChromeStore,
|
|
306
306
|
} from './addon-page-host'
|
|
307
307
|
export { createHostApi, toHostApiError, type CreateHostApiOptions } from './host-api'
|
|
308
|
+
export { HostApiProvider, type HostApiProviderProps } from './host-api-context'
|
|
309
|
+
export {
|
|
310
|
+
createHostApiClient,
|
|
311
|
+
type HostApiClient,
|
|
312
|
+
type HostRequestConfig,
|
|
313
|
+
type AxiosLikeClient,
|
|
314
|
+
} from './host-api-client'
|
|
315
|
+
export { useHostApiClient } from './use-host-api-client'
|
|
308
316
|
export {
|
|
309
317
|
FederatedErrorBoundary,
|
|
310
318
|
type FederatedErrorBoundaryProps,
|
|
@@ -902,3 +910,6 @@ export type { BulkImageTarget } from './bulk-image-target'
|
|
|
902
910
|
export type { BatchLog as BulkImageBatchLog } from './bulk-image-import'
|
|
903
911
|
export * from './attention'
|
|
904
912
|
export * from './view-system'
|
|
913
|
+
|
|
914
|
+
export { useModelLabels, resolveModelLabels, defaultSingular } from './model-labels'
|
|
915
|
+
export type { ModelLabels, ModelLabelInput, ModelLabelT } from './model-labels'
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { useTranslation } from 'react-i18next'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Model-driven labels. A backend often ships generic/English titles
|
|
6
|
+
* ("Clients", "New Client"); the SDK resolves them through i18n from the model
|
|
7
|
+
* key so the host can translate (or rebrand) per model without touching code:
|
|
8
|
+
*
|
|
9
|
+
* models.<model>.title -> list/page title ("Clientes")
|
|
10
|
+
* models.<model>.singular -> singular name ("Cliente")
|
|
11
|
+
* models.<model>.new -> create button label ("Nuevo cliente")
|
|
12
|
+
*
|
|
13
|
+
* Every key is looked up in the host's i18n resources (also addon namespaces
|
|
14
|
+
* merged by `I18nProvider`). Order: explicit override > `titleKey` from
|
|
15
|
+
* metadata > `models.<model>.*` > backend text > generic fallback. When no
|
|
16
|
+
* `models.<model>.new` exists the label is `common.new_model` interpolated
|
|
17
|
+
* with the singular name (`{{prefix}} {{name}}`), prefix overridable via
|
|
18
|
+
* `common.new`.
|
|
19
|
+
*/
|
|
20
|
+
export type ModelLabelT = (key: string, opts?: Record<string, unknown>) => string
|
|
21
|
+
|
|
22
|
+
export interface ModelLabelInput {
|
|
23
|
+
model: string
|
|
24
|
+
/** Backend title (already possibly localized). */
|
|
25
|
+
title?: string
|
|
26
|
+
/** Backend i18n key for the title (`titleKey`/`title_key`). */
|
|
27
|
+
titleKey?: string
|
|
28
|
+
/** Prefix fallback for the create label when nothing translates (default "New"). */
|
|
29
|
+
newPrefix?: string
|
|
30
|
+
titleOverride?: string
|
|
31
|
+
newLabelOverride?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface ModelLabels {
|
|
35
|
+
title: string
|
|
36
|
+
singular: string
|
|
37
|
+
newLabel: string
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const MISSING = '\u0000'
|
|
41
|
+
|
|
42
|
+
/** Returns the translation or undefined when the key has no value. */
|
|
43
|
+
function tryKey(t: ModelLabelT, key: string | undefined): string | undefined {
|
|
44
|
+
if (!key) return undefined
|
|
45
|
+
const v = t(key, { defaultValue: MISSING })
|
|
46
|
+
return v && v !== MISSING && v !== key ? v : undefined
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function defaultSingular(title: string): string {
|
|
50
|
+
const s = title.replace(/s$/i, '')
|
|
51
|
+
return s.charAt(0).toUpperCase() + s.slice(1)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function resolveModelLabels(t: ModelLabelT, input: ModelLabelInput): ModelLabels {
|
|
55
|
+
const { model } = input
|
|
56
|
+
const title =
|
|
57
|
+
input.titleOverride ??
|
|
58
|
+
tryKey(t, input.titleKey) ??
|
|
59
|
+
tryKey(t, `models.${model}.title`) ??
|
|
60
|
+
input.title ??
|
|
61
|
+
model
|
|
62
|
+
const singular =
|
|
63
|
+
tryKey(t, `models.${model}.singular`) ?? defaultSingular(title)
|
|
64
|
+
const newLabel =
|
|
65
|
+
input.newLabelOverride ??
|
|
66
|
+
tryKey(t, `models.${model}.new`) ??
|
|
67
|
+
`${tryKey(t, 'common.new') ?? input.newPrefix ?? 'New'} ${singular}`
|
|
68
|
+
return { title, singular, newLabel }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Hook form of {@link resolveModelLabels}, bound to the active i18n instance. */
|
|
72
|
+
export function useModelLabels(input: ModelLabelInput): ModelLabels {
|
|
73
|
+
const { t, i18n } = useTranslation()
|
|
74
|
+
const { model, title, titleKey, newPrefix, titleOverride, newLabelOverride } = input
|
|
75
|
+
return useMemo(
|
|
76
|
+
() => resolveModelLabels(t as unknown as ModelLabelT, { model, title, titleKey, newPrefix, titleOverride, newLabelOverride }),
|
|
77
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
78
|
+
[t, i18n?.language, model, title, titleKey, newPrefix, titleOverride, newLabelOverride],
|
|
79
|
+
)
|
|
80
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -198,6 +198,9 @@ export interface AuditMeta {
|
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
export interface TableMetadata {
|
|
201
|
+
/** i18n key for `title` (host resources win over the raw backend text). */
|
|
202
|
+
titleKey?: string
|
|
203
|
+
title_key?: string
|
|
201
204
|
title: string
|
|
202
205
|
endpoint: string
|
|
203
206
|
columns: ColumnDefinition[]
|
|
@@ -612,10 +615,32 @@ export interface ColumnItemField {
|
|
|
612
615
|
ref?: string
|
|
613
616
|
}
|
|
614
617
|
|
|
618
|
+
/**
|
|
619
|
+
* Canonical operator names (same vocabulary as the kernel's declarative
|
|
620
|
+
* conditions): `eq` `neq` `in` `not_in` `gt` `gte` `lt` `lte` `truthy` `falsy`,
|
|
621
|
+
* plus the `all` / `any` groups. Legacy aliases (`equals`, `notEquals`, `notin`,
|
|
622
|
+
* `==`, `!=`, `present`, `set`, `blank`, `empty`) are still evaluated but are not
|
|
623
|
+
* part of the typed contract.
|
|
624
|
+
*/
|
|
625
|
+
export type ActionConditionOperator =
|
|
626
|
+
| 'eq' | 'neq' | 'in' | 'not_in'
|
|
627
|
+
| 'gt' | 'gte' | 'lt' | 'lte'
|
|
628
|
+
| 'truthy' | 'falsy'
|
|
629
|
+
| 'all' | 'any'
|
|
630
|
+
|
|
615
631
|
export interface ActionCondition {
|
|
616
|
-
field
|
|
617
|
-
|
|
618
|
-
|
|
632
|
+
/** Row field (dotted paths allowed). Unused by `all`/`any` groups. */
|
|
633
|
+
field?: string
|
|
634
|
+
/**
|
|
635
|
+
* `gt|gte|lt|lte` compare numerically (a non-numeric side never matches);
|
|
636
|
+
* `truthy|falsy` test presence and take no `value`; `all|any` combine
|
|
637
|
+
* `conditions` (AND / OR, nestable; an empty list passes).
|
|
638
|
+
*/
|
|
639
|
+
operator: ActionConditionOperator
|
|
640
|
+
/** Comparison operand; a list for `in` / `not_in`. Omitted for `truthy|falsy` and groups. */
|
|
641
|
+
value?: string | number | boolean | Array<string | number | boolean>
|
|
642
|
+
/** Members of an `all` / `any` group. */
|
|
643
|
+
conditions?: ActionCondition[]
|
|
619
644
|
}
|
|
620
645
|
|
|
621
646
|
/**
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useMemo } from 'react'
|
|
2
|
+
import { useHostApi } from './addon-page-host'
|
|
3
|
+
import { createHostApiClient, type HostApiClient } from './host-api-client'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The addon's HTTP client, built over the host-injected HostApi. Works inside
|
|
7
|
+
* <AddonPageHost> (pages) and <HostApiProvider> (modals, pickers). Without a
|
|
8
|
+
* host it throws a clear error: there is no localStorage / fetch fallback.
|
|
9
|
+
*/
|
|
10
|
+
export function useHostApiClient(): HostApiClient {
|
|
11
|
+
const api = useHostApi()
|
|
12
|
+
return useMemo(() => createHostApiClient(api), [api])
|
|
13
|
+
}
|