@asteby/metacore-runtime-react 53.22.0 → 53.23.2
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 +33 -0
- package/dist/assist-interview.d.ts.map +1 -1
- package/dist/assist-interview.js +7 -10
- package/dist/custom-stages.d.ts.map +1 -1
- package/dist/custom-stages.js +2 -10
- package/dist/dialogs/dynamic-record.d.ts.map +1 -1
- package/dist/dialogs/dynamic-record.js +5 -3
- package/dist/dialogs/use-inline-relations.d.ts.map +1 -1
- package/dist/dialogs/use-inline-relations.js +4 -4
- package/dist/genui/settings-block.d.ts.map +1 -1
- package/dist/genui/settings-block.js +7 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/record-picker-dialog.d.ts.map +1 -1
- package/dist/record-picker-dialog.js +4 -3
- package/dist/setup/addon-config-surface.d.ts.map +1 -1
- package/dist/setup/addon-config-surface.js +14 -12
- package/dist/stage-automations.d.ts.map +1 -1
- package/dist/stage-automations.js +3 -12
- package/dist/stage-layout.d.ts.map +1 -1
- package/dist/stage-layout.js +2 -7
- package/dist/use-addon-installed-probe.d.ts +8 -0
- package/dist/use-addon-installed-probe.d.ts.map +1 -0
- package/dist/use-addon-installed-probe.js +36 -0
- package/dist/use-addon-settings.d.ts +24 -0
- package/dist/use-addon-settings.d.ts.map +1 -1
- package/dist/use-addon-settings.js +39 -13
- package/dist/use-org-document-templates.d.ts.map +1 -1
- package/dist/use-org-document-templates.js +5 -9
- package/dist/view-system/card-spec.d.ts +3 -2
- package/dist/view-system/card-spec.d.ts.map +1 -1
- package/dist/view-system/card-spec.js +7 -6
- package/dist/views/data-source.d.ts.map +1 -1
- package/dist/views/data-source.js +9 -14
- package/dist/views/panels.d.ts.map +1 -1
- package/dist/views/panels.js +2 -1
- package/package.json +7 -6
- package/src/__tests__/genui-settings-block.test.tsx +6 -3
- package/src/__tests__/use-addon-settings-hooks.test.tsx +73 -0
- package/src/__tests__/use-addon-settings.test.ts +19 -3
- package/src/assist-interview.tsx +7 -11
- package/src/custom-stages.tsx +2 -7
- package/src/dialogs/dynamic-record.tsx +7 -2
- package/src/dialogs/use-inline-relations.ts +4 -5
- package/src/genui/settings-block.tsx +7 -13
- package/src/index.ts +1 -0
- package/src/record-picker-dialog.tsx +4 -3
- package/src/setup/addon-config-surface.tsx +16 -15
- package/src/stage-automations.tsx +3 -9
- package/src/stage-layout.ts +2 -7
- package/src/use-addon-installed-probe.ts +39 -0
- package/src/use-addon-settings.ts +66 -12
- package/src/use-org-document-templates.ts +5 -10
- package/src/view-system/card-spec.tsx +7 -6
- package/src/views/data-source.ts +6 -16
- package/src/views/panels.tsx +2 -1
|
@@ -9,6 +9,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
9
9
|
// `available: false` and the lane simply omits the ⚡ affordance — the board
|
|
10
10
|
// keeps working. All UI text goes through t() with a Spanish defaultValue so a
|
|
11
11
|
// host that ships no `dynamic.automations.*` keys still renders in Spanish.
|
|
12
|
+
import { unwrapResponse } from '@asteby/metacore-lib/envelope';
|
|
12
13
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
13
14
|
import { useTranslation } from 'react-i18next';
|
|
14
15
|
import { Zap, Trash2, Plus } from 'lucide-react';
|
|
@@ -65,16 +66,6 @@ export function activeAutomationCount(rules) {
|
|
|
65
66
|
return 0;
|
|
66
67
|
return rules.filter((r) => r.enabled).length;
|
|
67
68
|
}
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
// Data hook
|
|
70
|
-
// ---------------------------------------------------------------------------
|
|
71
|
-
function unwrap(res) {
|
|
72
|
-
const body = res?.data;
|
|
73
|
-
// Envelope {success, data}; tolerate a bare array/object too.
|
|
74
|
-
if (body && typeof body === 'object' && 'data' in body)
|
|
75
|
-
return body.data;
|
|
76
|
-
return body;
|
|
77
|
-
}
|
|
78
69
|
/**
|
|
79
70
|
* Loads a model's stage automations and exposes CRUD. Swallows a missing
|
|
80
71
|
* endpoint (404 / network error) into `available: false` so the kanban never
|
|
@@ -91,7 +82,7 @@ export function useStageAutomations(model) {
|
|
|
91
82
|
setLoading(true);
|
|
92
83
|
try {
|
|
93
84
|
const res = await api.get(`/stage-automations?model=${encodeURIComponent(model)}`);
|
|
94
|
-
const data =
|
|
85
|
+
const data = unwrapResponse(res);
|
|
95
86
|
setRules(Array.isArray(data) ? data : []);
|
|
96
87
|
setAvailable(true);
|
|
97
88
|
}
|
|
@@ -110,7 +101,7 @@ export function useStageAutomations(model) {
|
|
|
110
101
|
const create = useCallback(async (draft) => {
|
|
111
102
|
try {
|
|
112
103
|
const res = await api.post('/stage-automations', draft);
|
|
113
|
-
const created =
|
|
104
|
+
const created = unwrapResponse(res);
|
|
114
105
|
await load();
|
|
115
106
|
if (!created)
|
|
116
107
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stage-layout.d.ts","sourceRoot":"","sources":["../src/stage-layout.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stage-layout.d.ts","sourceRoot":"","sources":["../src/stage-layout.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,4EAA4E;IAC5E,WAAW,EAAE,MAAM,EAAE,CAAA;CACxB;AAED,MAAM,WAAW,oBAAoB;IACjC,iFAAiF;IACjF,SAAS,EAAE,OAAO,CAAA;IAClB,oFAAoF;IACpF,eAAe,EAAE,OAAO,CAAA;IACxB,wFAAwF;IACxF,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxC,oEAAoE;IACpE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC7B;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,oBAAoB,CA6ClE"}
|
package/dist/stage-layout.js
CHANGED
|
@@ -13,14 +13,9 @@
|
|
|
13
13
|
// GET /stage-layout?model=<m> → { model, stage_order: string[] } | null
|
|
14
14
|
// PUT /stage-layout { model, stage_order: string[] } (full order)
|
|
15
15
|
// DELETE /stage-layout?model=<m> → reset to the declared order
|
|
16
|
+
import { unwrapResponse } from '@asteby/metacore-lib/envelope';
|
|
16
17
|
import { useCallback, useEffect, useState } from 'react';
|
|
17
18
|
import { useApi } from './api-context';
|
|
18
|
-
function unwrap(res) {
|
|
19
|
-
const body = res?.data;
|
|
20
|
-
if (body && typeof body === 'object' && 'data' in body)
|
|
21
|
-
return body.data;
|
|
22
|
-
return body;
|
|
23
|
-
}
|
|
24
19
|
/**
|
|
25
20
|
* Loads a model's saved lane order (only to learn availability + whether a
|
|
26
21
|
* custom order exists) and exposes save/reset. A missing endpoint degrades to
|
|
@@ -39,7 +34,7 @@ export function useStageLayout(model) {
|
|
|
39
34
|
if (cancelled)
|
|
40
35
|
return;
|
|
41
36
|
setAvailable(true);
|
|
42
|
-
const data =
|
|
37
|
+
const data = unwrapResponse(res);
|
|
43
38
|
const order = data?.stage_order;
|
|
44
39
|
setHasCustomLayout(Array.isArray(order) && order.length > 0);
|
|
45
40
|
})
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface UseAddonInstalledProbeResult {
|
|
2
|
+
installed: boolean | undefined;
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function useAddonInstalledProbe(addonKey: string, opts?: {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
}): UseAddonInstalledProbeResult;
|
|
8
|
+
//# sourceMappingURL=use-addon-installed-probe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-addon-installed-probe.d.ts","sourceRoot":"","sources":["../src/use-addon-installed-probe.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,4BAA4B;IACzC,SAAS,EAAE,OAAO,GAAG,SAAS,CAAA;IAC9B,SAAS,EAAE,OAAO,CAAA;CACrB;AAED,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,4BAA4B,CAqBvH"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// useAddonInstalledProbe — "is addon X installed here?" for hosts/addons that do
|
|
2
|
+
// NOT mount an <InstalledAddonsProvider>: asks the installation API
|
|
3
|
+
// (`GET /addons/:key/settings`, the same call everyone used to hand-roll).
|
|
4
|
+
// With a provider present it answers from it and never touches the network.
|
|
5
|
+
// installed: true → 2xx
|
|
6
|
+
// false → 404 (not installed) or the provider says no
|
|
7
|
+
// undefined → still loading, or unknown (403/network error: never "absent")
|
|
8
|
+
import { useQuery } from '@tanstack/react-query';
|
|
9
|
+
import { useApi } from './api-context';
|
|
10
|
+
import { addonSettingsUrl } from './use-addon-settings';
|
|
11
|
+
import { useInstalledAddons } from './installed-addons-context';
|
|
12
|
+
export function useAddonInstalledProbe(addonKey, opts = {}) {
|
|
13
|
+
const api = useApi();
|
|
14
|
+
const ctx = useInstalledAddons();
|
|
15
|
+
const query = useQuery({
|
|
16
|
+
queryKey: ['addon-installed', addonKey],
|
|
17
|
+
queryFn: async () => {
|
|
18
|
+
try {
|
|
19
|
+
await api.get(addonSettingsUrl(addonKey));
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
const status = e?.response?.status;
|
|
24
|
+
if (status === 404)
|
|
25
|
+
return false;
|
|
26
|
+
throw e;
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
retry: false,
|
|
30
|
+
staleTime: 60_000,
|
|
31
|
+
enabled: !ctx && (opts.enabled ?? true) && !!addonKey,
|
|
32
|
+
});
|
|
33
|
+
if (ctx)
|
|
34
|
+
return { installed: ctx.addons.has(addonKey), isLoading: false };
|
|
35
|
+
return { installed: query.data, isLoading: query.isLoading };
|
|
36
|
+
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
import type { SettingDefLike } from './genui/settings-block';
|
|
2
|
+
/** What `GET /addons/:key/settings` answers, normalised. */
|
|
3
|
+
export interface AddonSettingsPayload<T = Record<string, unknown>> {
|
|
4
|
+
/** Stored values (org, or the branch's resolution when `branchId` is given). */
|
|
5
|
+
values: Partial<T>;
|
|
6
|
+
/** The manifest's setting definitions the host serves alongside the values. */
|
|
7
|
+
definitions: SettingDefLike[];
|
|
8
|
+
/** Branch overrides (only meaningful with `branchId`). */
|
|
9
|
+
overrides: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Normalises the settings response. Envelope `{ success?, data, definitions?,
|
|
13
|
+
* overrides? }` (definitions/overrides are siblings of `data`); a bare
|
|
14
|
+
* `{ key: value }` map is accepted too. Pure + exported for tests.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseAddonSettingsBody<T = Record<string, unknown>>(body: unknown): AddonSettingsPayload<T>;
|
|
1
17
|
/** Stable react-query key for an addon's per-org settings (per branch when given). */
|
|
2
18
|
export declare function addonSettingsKey(addonKey: string, branchId?: string | null): readonly ["addon-settings", string, string] | readonly ["addon-settings", string];
|
|
3
19
|
/**
|
|
@@ -35,9 +51,17 @@ export interface UseAddonSettingsOptions<T> {
|
|
|
35
51
|
export interface UseAddonSettingsResult<T> {
|
|
36
52
|
/** Saved org values merged over `defaults`. Never null. */
|
|
37
53
|
settings: T;
|
|
54
|
+
/** Stored values only (no defaults merged); `{}` until loaded. */
|
|
55
|
+
stored: Partial<T>;
|
|
56
|
+
/** Setting definitions served with the values (`[]` when the host sends none). */
|
|
57
|
+
definitions: SettingDefLike[];
|
|
58
|
+
/** Branch overrides served with the values. */
|
|
59
|
+
overrides: Record<string, unknown>;
|
|
38
60
|
isLoading: boolean;
|
|
39
61
|
error: unknown;
|
|
40
62
|
refetch: () => void;
|
|
63
|
+
/** Forces a fresh GET (bypassing staleTime), updates the cache and resolves with the payload. Rejects on error. */
|
|
64
|
+
reload: () => Promise<AddonSettingsPayload<T>>;
|
|
41
65
|
}
|
|
42
66
|
/**
|
|
43
67
|
* Read an addon's per-organization settings.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-addon-settings.d.ts","sourceRoot":"","sources":["../src/use-addon-settings.ts"],"names":[],"mappings":"AA6BA,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,qFAE1E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"use-addon-settings.d.ts","sourceRoot":"","sources":["../src/use-addon-settings.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAE5D,4DAA4D;AAC5D,MAAM,WAAW,oBAAoB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC7D,gFAAgF;IAChF,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAClB,+EAA+E;IAC/E,WAAW,EAAE,cAAc,EAAE,CAAA;IAC7B,0DAA0D;IAC1D,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC;AAID;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAS1G;AAED,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,qFAE1E;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE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C,CAAC,CAAM,GACtC,sBAAsB,CAAC,CAAC,CAAC,CA4C3B;AAED;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9F,QAAQ,EAAE,MAAM;AAChB,mGAAmG;AACnG,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,6FAiB3B"}
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
//
|
|
5
5
|
// The host (ops) persists settings per org on `AddonInstallation.settings`
|
|
6
6
|
// (jsonb) and exposes:
|
|
7
|
-
// GET /
|
|
8
|
-
// PUT /
|
|
7
|
+
// GET /addons/:key/settings → { success, data: { <key>: <value> }, definitions?, overrides? }
|
|
8
|
+
// PUT /addons/:key/settings → body = object of values
|
|
9
|
+
// (paths are relative to the host api client's baseURL, like every other call.)
|
|
9
10
|
// A setting the org has never saved simply isn't present in `data`; the
|
|
10
11
|
// caller supplies the fallback via `opts.defaults` (which mirror the
|
|
11
12
|
// manifest's `settings[].default`). runtime-react has no access to the
|
|
@@ -19,9 +20,25 @@
|
|
|
19
20
|
// Server-side gating (wasm/Go backends) is out of scope here: a backend that
|
|
20
21
|
// must gate behaviour on org config reads the same `AddonInstallation.settings`
|
|
21
22
|
// jsonb directly — this hook is the client-read half of that contract.
|
|
22
|
-
import { useMemo } from 'react';
|
|
23
|
+
import { useCallback, useMemo } from 'react';
|
|
23
24
|
import { useMutation, useQuery, useQueryClient, } from '@tanstack/react-query';
|
|
24
25
|
import { useApi } from './api-context';
|
|
26
|
+
const isRecord = (v) => typeof v === 'object' && v !== null && !Array.isArray(v);
|
|
27
|
+
/**
|
|
28
|
+
* Normalises the settings response. Envelope `{ success?, data, definitions?,
|
|
29
|
+
* overrides? }` (definitions/overrides are siblings of `data`); a bare
|
|
30
|
+
* `{ key: value }` map is accepted too. Pure + exported for tests.
|
|
31
|
+
*/
|
|
32
|
+
export function parseAddonSettingsBody(body) {
|
|
33
|
+
if (isRecord(body) && ('data' in body || 'success' in body)) {
|
|
34
|
+
return {
|
|
35
|
+
values: (isRecord(body.data) ? body.data : {}),
|
|
36
|
+
definitions: Array.isArray(body.definitions) ? body.definitions : [],
|
|
37
|
+
overrides: isRecord(body.overrides) ? body.overrides : {},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return { values: (isRecord(body) ? body : {}), definitions: [], overrides: {} };
|
|
41
|
+
}
|
|
25
42
|
/** Stable react-query key for an addon's per-org settings (per branch when given). */
|
|
26
43
|
export function addonSettingsKey(addonKey, branchId) {
|
|
27
44
|
return branchId ? ['addon-settings', addonKey, branchId] : ['addon-settings', addonKey];
|
|
@@ -32,7 +49,9 @@ export function addonSettingsKey(addonKey, branchId) {
|
|
|
32
49
|
* override (POS-1). Without one, the org values (legacy behaviour).
|
|
33
50
|
*/
|
|
34
51
|
export function addonSettingsUrl(addonKey, branchId) {
|
|
35
|
-
|
|
52
|
+
// Relative to the host api client's baseURL (ops: `/api`); a literal `/api`
|
|
53
|
+
// here would double-prefix to `/api/api/addons/...`.
|
|
54
|
+
const base = `/addons/${addonKey}/settings`;
|
|
36
55
|
return branchId ? `${base}?branch_id=${encodeURIComponent(branchId)}` : base;
|
|
37
56
|
}
|
|
38
57
|
/**
|
|
@@ -69,21 +88,28 @@ export function mergeAddonSettings(defaults, stored) {
|
|
|
69
88
|
export function useAddonSettings(addonKey, opts = {}) {
|
|
70
89
|
const api = useApi();
|
|
71
90
|
const { defaults, staleTime, enabled, branchId } = opts;
|
|
91
|
+
const qc = useQueryClient();
|
|
92
|
+
const queryKey = addonSettingsKey(addonKey, branchId);
|
|
93
|
+
const fetchPayload = useCallback(async () => {
|
|
94
|
+
const res = await api.get(addonSettingsUrl(addonKey, branchId));
|
|
95
|
+
return parseAddonSettingsBody(res.data);
|
|
96
|
+
}, [api, addonKey, branchId]);
|
|
72
97
|
const query = useQuery({
|
|
73
|
-
queryKey
|
|
74
|
-
queryFn:
|
|
75
|
-
const res = await api.get(addonSettingsUrl(addonKey, branchId));
|
|
76
|
-
const body = res.data;
|
|
77
|
-
// Host envelope: { success, data: { <key>: <value> } }.
|
|
78
|
-
const values = body?.success ? body.data : body;
|
|
79
|
-
return (values ?? {});
|
|
80
|
-
},
|
|
98
|
+
queryKey,
|
|
99
|
+
queryFn: fetchPayload,
|
|
81
100
|
staleTime: staleTime ?? 30_000,
|
|
82
101
|
enabled: (enabled ?? true) && !!addonKey,
|
|
83
102
|
});
|
|
84
|
-
const settings = useMemo(() => mergeAddonSettings(defaults, query.data), [defaults, query.data]);
|
|
103
|
+
const settings = useMemo(() => mergeAddonSettings(defaults, query.data?.values), [defaults, query.data]);
|
|
104
|
+
const reload = useCallback(() => qc.fetchQuery({ queryKey, queryFn: fetchPayload, staleTime: 0 }),
|
|
105
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
106
|
+
[qc, fetchPayload, addonKey, branchId]);
|
|
85
107
|
return {
|
|
86
108
|
settings,
|
|
109
|
+
stored: query.data?.values ?? {},
|
|
110
|
+
definitions: query.data?.definitions ?? [],
|
|
111
|
+
overrides: query.data?.overrides ?? {},
|
|
112
|
+
reload,
|
|
87
113
|
isLoading: query.isLoading,
|
|
88
114
|
error: query.error,
|
|
89
115
|
refetch: () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-org-document-templates.d.ts","sourceRoot":"","sources":["../src/use-org-document-templates.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-org-document-templates.d.ts","sourceRoot":"","sources":["../src/use-org-document-templates.ts"],"names":[],"mappings":"AAwBA,MAAM,WAAW,sBAAsB;IACnC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;IAClB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,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13,6 +13,7 @@
|
|
|
13
13
|
// POST /api/settings/templates/preview → application/pdf
|
|
14
14
|
//
|
|
15
15
|
// ApiClient is a PEER via <ApiProvider> (same one usePrintDocument uses).
|
|
16
|
+
import { unwrapResponse } from '@asteby/metacore-lib/envelope';
|
|
16
17
|
import { useCallback, useMemo } from 'react';
|
|
17
18
|
import { useMutation, useQuery, useQueryClient, } from '@tanstack/react-query';
|
|
18
19
|
import { useApi } from './api-context';
|
|
@@ -22,18 +23,13 @@ export function orgDocumentCatalogKey() {
|
|
|
22
23
|
export function orgDocumentTemplateKey(addonKey, documentKey) {
|
|
23
24
|
return ['org-document-templates', addonKey, documentKey];
|
|
24
25
|
}
|
|
25
|
-
function unwrapData(res) {
|
|
26
|
-
const body = res.data;
|
|
27
|
-
const values = body?.success ? body.data : body;
|
|
28
|
-
return values;
|
|
29
|
-
}
|
|
30
26
|
export function useOrgDocumentCatalog(opts) {
|
|
31
27
|
const api = useApi();
|
|
32
28
|
const query = useQuery({
|
|
33
29
|
queryKey: orgDocumentCatalogKey(),
|
|
34
30
|
queryFn: async () => {
|
|
35
31
|
const res = await api.get('/settings/templates');
|
|
36
|
-
const data =
|
|
32
|
+
const data = unwrapResponse(res);
|
|
37
33
|
return Array.isArray(data) ? data : [];
|
|
38
34
|
},
|
|
39
35
|
staleTime: 30_000,
|
|
@@ -54,7 +50,7 @@ export function useOrgDocumentTemplate(addonKey, documentKey, opts) {
|
|
|
54
50
|
queryKey: orgDocumentTemplateKey(addonKey, documentKey),
|
|
55
51
|
queryFn: async () => {
|
|
56
52
|
const res = await api.get(`/settings/templates/${encodeURIComponent(addonKey)}/${encodeURIComponent(documentKey)}`);
|
|
57
|
-
return
|
|
53
|
+
return unwrapResponse(res);
|
|
58
54
|
},
|
|
59
55
|
enabled: (opts?.enabled ?? true) && !!addonKey && !!documentKey,
|
|
60
56
|
});
|
|
@@ -73,7 +69,7 @@ export function useSaveOrgDocumentTemplate() {
|
|
|
73
69
|
return useMutation({
|
|
74
70
|
mutationFn: async ({ addonKey, documentKey, html, paper }) => {
|
|
75
71
|
const res = await api.put(`/settings/templates/${encodeURIComponent(addonKey)}/${encodeURIComponent(documentKey)}`, { html, paper });
|
|
76
|
-
return
|
|
72
|
+
return unwrapResponse(res);
|
|
77
73
|
},
|
|
78
74
|
onSuccess: (_data, vars) => {
|
|
79
75
|
void qc.invalidateQueries({ queryKey: orgDocumentCatalogKey() });
|
|
@@ -89,7 +85,7 @@ export function useResetOrgDocumentTemplate() {
|
|
|
89
85
|
return useMutation({
|
|
90
86
|
mutationFn: async ({ addonKey, documentKey }) => {
|
|
91
87
|
const res = await api.delete(`/settings/templates/${encodeURIComponent(addonKey)}/${encodeURIComponent(documentKey)}`);
|
|
92
|
-
return
|
|
88
|
+
return unwrapResponse(res);
|
|
93
89
|
},
|
|
94
90
|
onSuccess: (_data, vars) => {
|
|
95
91
|
void qc.invalidateQueries({ queryKey: orgDocumentCatalogKey() });
|
|
@@ -14,11 +14,12 @@ export interface ResolvedCard {
|
|
|
14
14
|
}[];
|
|
15
15
|
}
|
|
16
16
|
/** Pure: row + manifest CardSpec -> display model. Missing fields are skipped, never throw. */
|
|
17
|
-
export declare function resolveCard(spec: CardSpec, row: Record<string, unknown>, locale?: string): ResolvedCard;
|
|
18
|
-
export declare function ConfigurableCard({ spec, row, onClick, locale }: {
|
|
17
|
+
export declare function resolveCard(spec: CardSpec, row: Record<string, unknown>, locale?: string, currency?: string): ResolvedCard;
|
|
18
|
+
export declare function ConfigurableCard({ spec, row, onClick, locale, currency }: {
|
|
19
19
|
spec: CardSpec;
|
|
20
20
|
row: Record<string, unknown>;
|
|
21
21
|
onClick?: () => void;
|
|
22
22
|
locale?: string;
|
|
23
|
+
currency?: string;
|
|
23
24
|
}): import("react").JSX.Element;
|
|
24
25
|
//# sourceMappingURL=card-spec.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card-spec.d.ts","sourceRoot":"","sources":["../../src/view-system/card-spec.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"card-spec.d.ts","sourceRoot":"","sources":["../../src/view-system/card-spec.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAG5E,OAAO,KAAK,EAAiB,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEtD,MAAM,WAAW,YAAY;IACzB,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,QAAQ,CAAA;KAAE,CAAA;IACxC,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,IAAI,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC5C;AAgBD,+FAA+F;AAC/F,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,YAAY,CAU1H;AAED,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,+BAsCpL"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { BADGE_TONE_CLASS } from '@asteby/metacore-ui/layout';
|
|
3
3
|
import { cn } from '@asteby/metacore-ui/lib';
|
|
4
|
-
|
|
4
|
+
import { formatAmount } from '@asteby/metacore-lib';
|
|
5
|
+
function fmt(v, f = 'text', locale, currency) {
|
|
5
6
|
if (v == null || v === '')
|
|
6
7
|
return '';
|
|
7
8
|
try {
|
|
@@ -10,7 +11,7 @@ function fmt(v, f = 'text', locale) {
|
|
|
10
11
|
if (f === 'percent')
|
|
11
12
|
return `${new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }).format(Number(v))}%`;
|
|
12
13
|
if (f === 'currency')
|
|
13
|
-
return
|
|
14
|
+
return formatAmount(v, { currency, locale });
|
|
14
15
|
if (f === 'date')
|
|
15
16
|
return new Date(String(v)).toLocaleDateString(locale);
|
|
16
17
|
if (f === 'datetime')
|
|
@@ -22,7 +23,7 @@ function fmt(v, f = 'text', locale) {
|
|
|
22
23
|
return String(v);
|
|
23
24
|
}
|
|
24
25
|
/** Pure: row + manifest CardSpec -> display model. Missing fields are skipped, never throw. */
|
|
25
|
-
export function resolveCard(spec, row, locale) {
|
|
26
|
+
export function resolveCard(spec, row, locale, currency) {
|
|
26
27
|
const bv = spec.badge ? row[spec.badge.field] : undefined;
|
|
27
28
|
const key = bv == null ? '' : String(bv);
|
|
28
29
|
return {
|
|
@@ -30,11 +31,11 @@ export function resolveCard(spec, row, locale) {
|
|
|
30
31
|
subtitle: spec.subtitle ? fmt(row[spec.subtitle]) || undefined : undefined,
|
|
31
32
|
badge: spec.badge && key ? { text: spec.badge.labels?.[key] ?? key, tone: spec.badge.tones?.[key] ?? 'info' } : undefined,
|
|
32
33
|
chips: (spec.chips ?? []).map((f) => fmt(row[f])).filter(Boolean),
|
|
33
|
-
meta: (spec.meta ?? []).map((m) => ({ label: m.label, value: fmt(row[m.field], m.format, locale) })).filter((m) => m.value),
|
|
34
|
+
meta: (spec.meta ?? []).map((m) => ({ label: m.label, value: fmt(row[m.field], m.format, locale, currency) })).filter((m) => m.value),
|
|
34
35
|
};
|
|
35
36
|
}
|
|
36
|
-
export function ConfigurableCard({ spec, row, onClick, locale }) {
|
|
37
|
-
const c = resolveCard(spec, row, locale);
|
|
37
|
+
export function ConfigurableCard({ spec, row, onClick, locale, currency }) {
|
|
38
|
+
const c = resolveCard(spec, row, locale, currency);
|
|
38
39
|
const Tag = onClick ? 'button' : 'div';
|
|
39
40
|
return (_jsxs(Tag, { ...(onClick ? { type: 'button', onClick } : {}), className: cn('flex w-full flex-col gap-2 rounded-xl border bg-card p-4 text-start', onClick && 'transition-colors hover:bg-accent/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring'), children: [_jsxs("div", { className: 'flex items-start justify-between gap-2', children: [_jsx("span", { className: 'line-clamp-2 font-medium', children: c.title }), c.badge && (_jsx("span", { "data-tone": c.badge.tone, className: cn('shrink-0 rounded-full px-2 text-xs font-semibold leading-5 ring-1 ring-inset', BADGE_TONE_CLASS[c.badge.tone].replace(/motion-safe:animate-pulse/, '')), children: c.badge.text }))] }), c.subtitle && _jsx("span", { className: 'line-clamp-2 text-sm text-muted-foreground', children: c.subtitle }), c.chips.length > 0 && (_jsx("div", { className: 'flex flex-wrap gap-1', children: c.chips.map((x, i) => (_jsx("span", { className: 'rounded-md bg-muted px-1.5 py-0.5 text-xs text-muted-foreground', children: x }, i))) })), c.meta.length > 0 && (_jsx("dl", { className: 'mt-auto grid grid-cols-2 gap-x-3 gap-y-1 text-xs text-muted-foreground', children: c.meta.map((m, i) => (_jsxs("div", { className: 'min-w-0', children: [m.label && _jsx("dt", { className: 'sr-only', children: m.label }), _jsx("dd", { className: 'truncate', children: m.value })] }, i))) }))] }));
|
|
40
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-source.d.ts","sourceRoot":"","sources":["../../src/views/data-source.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"data-source.d.ts","sourceRoot":"","sources":["../../src/views/data-source.ts"],"names":[],"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|
|
5
|
-
throw new Error(env.message || 'request failed');
|
|
6
|
-
return { data: env.data, total: env.meta?.total };
|
|
7
|
-
}
|
|
8
|
-
return { data: body };
|
|
9
|
-
}
|
|
1
|
+
// Default ViewDataSource over the runtime-react ApiClient, plus the pure
|
|
2
|
+
// helpers renderers share (capability input mapping, item extraction, date
|
|
3
|
+
// grouping). Light on purpose: this module is in the static graph.
|
|
4
|
+
import { unwrapEnvelope, unwrapList } from '@asteby/metacore-lib/envelope';
|
|
10
5
|
export function createApiViewDataSource(api, opts = {}) {
|
|
11
6
|
const chartPath = opts.chartPath ?? '/views/chart';
|
|
12
7
|
const capabilityPath = opts.capabilityPath ?? '/capabilities/query';
|
|
13
8
|
return {
|
|
14
9
|
async list(model, params) {
|
|
15
10
|
const res = await api.get(`/data/${encodeURIComponent(model)}`, params ? { params } : undefined);
|
|
16
|
-
const {
|
|
17
|
-
return { rows:
|
|
11
|
+
const { items, meta } = unwrapList(res.data);
|
|
12
|
+
return { rows: items, total: meta.total };
|
|
18
13
|
},
|
|
19
14
|
async record(model, id) {
|
|
20
15
|
const res = await api.get(`/data/${encodeURIComponent(model)}/${encodeURIComponent(id)}`);
|
|
21
|
-
return
|
|
16
|
+
return unwrapEnvelope(res.data) ?? null;
|
|
22
17
|
},
|
|
23
18
|
async chart(req) {
|
|
24
19
|
const res = await api.post(chartPath, {
|
|
@@ -28,11 +23,11 @@ export function createApiViewDataSource(api, opts = {}) {
|
|
|
28
23
|
record_id: req.recordId,
|
|
29
24
|
panel_key: req.panelKey,
|
|
30
25
|
});
|
|
31
|
-
return
|
|
26
|
+
return unwrapEnvelope(res.data) ?? {};
|
|
32
27
|
},
|
|
33
28
|
async capability(key, input) {
|
|
34
29
|
const res = await api.post(capabilityPath, { capability: key, input });
|
|
35
|
-
return
|
|
30
|
+
return unwrapEnvelope(res.data);
|
|
36
31
|
},
|
|
37
32
|
};
|
|
38
33
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panels.d.ts","sourceRoot":"","sources":["../../src/views/panels.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"panels.d.ts","sourceRoot":"","sources":["../../src/views/panels.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,MAAM,MAAM,UAAU,GAChB,QAAQ,GACR,UAAU,GACV,SAAS,GACT,SAAS,GACT,MAAM,GACN,UAAU,GACV,eAAe,CAAA;AAErB,8EAA8E;AAC9E,wBAAgB,UAAU,CACtB,KAAK,EAAE,OAAO,EACd,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,IAAI,CAAA;CAAO,GACjF,MAAM,CA4CR;AAED,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,kBAAkB,qBAiBzG;AAED,wBAAgB,iBAAiB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,kBAAkB,4BAuFpG"}
|
package/dist/views/panels.js
CHANGED
|
@@ -6,6 +6,7 @@ import * as React from 'react';
|
|
|
6
6
|
import { useTranslation } from 'react-i18next';
|
|
7
7
|
import { buildRelationFilterParams } from '../dynamic-relation-helpers';
|
|
8
8
|
import { displayValue, toDate } from './data-source';
|
|
9
|
+
import { formatAmount } from '@asteby/metacore-lib';
|
|
9
10
|
import { ViewSkeleton } from './skeleton';
|
|
10
11
|
/** Pure: format one stat value for display. `now` is injectable for tests. */
|
|
11
12
|
export function formatStat(value, format, opts = {}) {
|
|
@@ -18,7 +19,7 @@ export function formatStat(value, format, opts = {}) {
|
|
|
18
19
|
case 'currency':
|
|
19
20
|
if (Number.isNaN(num))
|
|
20
21
|
break;
|
|
21
|
-
return
|
|
22
|
+
return formatAmount(num, { currency, locale });
|
|
22
23
|
case 'percent':
|
|
23
24
|
if (Number.isNaN(num))
|
|
24
25
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asteby/metacore-runtime-react",
|
|
3
|
-
"version": "53.
|
|
3
|
+
"version": "53.23.2",
|
|
4
4
|
"description": "React runtime for metacore hosts — renders addon contributions dynamically",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -37,7 +37,8 @@
|
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@asteby/metacore-charts": "^0.1.
|
|
40
|
+
"@asteby/metacore-charts": "^0.1.1",
|
|
41
|
+
"@asteby/metacore-lib": "^0.11.0",
|
|
41
42
|
"@dnd-kit/core": "^6.3.0",
|
|
42
43
|
"@dnd-kit/sortable": "^10.0.0",
|
|
43
44
|
"@dnd-kit/utilities": "^3.2.2",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"zod": "^4.3.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
|
-
"@asteby/metacore-sdk": "^3.
|
|
50
|
+
"@asteby/metacore-sdk": "^3.20.0",
|
|
50
51
|
"@asteby/metacore-ui": "^2.34.0",
|
|
51
52
|
"@tanstack/react-query": ">=5",
|
|
52
53
|
"@tanstack/react-router": ">=1.100",
|
|
@@ -62,7 +63,7 @@
|
|
|
62
63
|
"zustand": ">=5",
|
|
63
64
|
"@module-federation/runtime": ">=2.5",
|
|
64
65
|
"@testing-library/react": ">=14",
|
|
65
|
-
"@asteby/metacore-genui": "^2.9.
|
|
66
|
+
"@asteby/metacore-genui": "^2.9.1"
|
|
66
67
|
},
|
|
67
68
|
"peerDependenciesMeta": {
|
|
68
69
|
"@tanstack/react-router": {
|
|
@@ -82,7 +83,7 @@
|
|
|
82
83
|
}
|
|
83
84
|
},
|
|
84
85
|
"devDependencies": {
|
|
85
|
-
"@asteby/metacore-sdk": "3.
|
|
86
|
+
"@asteby/metacore-sdk": "3.20.0",
|
|
86
87
|
"@asteby/metacore-ui": "2.34.0",
|
|
87
88
|
"@tanstack/react-query": "^5.95.0",
|
|
88
89
|
"@tanstack/react-router": "^1.168.0",
|
|
@@ -104,7 +105,7 @@
|
|
|
104
105
|
"vitest": "^4.0.0",
|
|
105
106
|
"zustand": "^5.0.0",
|
|
106
107
|
"@module-federation/runtime": "^2.5.0",
|
|
107
|
-
"@asteby/metacore-genui": "2.9.
|
|
108
|
+
"@asteby/metacore-genui": "2.9.1"
|
|
108
109
|
},
|
|
109
110
|
"scripts": {
|
|
110
111
|
"build": "tsc -p tsconfig.json",
|
|
@@ -7,6 +7,7 @@ vi.mock('react-i18next', () => {
|
|
|
7
7
|
return { useTranslation: () => ({ t, i18n: { language: 'es', exists: () => false } }) }
|
|
8
8
|
})
|
|
9
9
|
|
|
10
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
10
11
|
import { GenUI } from '@asteby/metacore-genui'
|
|
11
12
|
import { ApiProvider } from '../api-context'
|
|
12
13
|
import { coerceSettings, registerGenUISettingsBlock, settingsToFields } from '../genui'
|
|
@@ -50,9 +51,11 @@ describe('genui settings block (pilot)', () => {
|
|
|
50
51
|
delete: vi.fn(),
|
|
51
52
|
}
|
|
52
53
|
render(
|
|
53
|
-
<
|
|
54
|
-
<
|
|
55
|
-
|
|
54
|
+
<QueryClientProvider client={new QueryClient({ defaultOptions: { queries: { retry: false } } })}>
|
|
55
|
+
<ApiProvider client={client as never}>
|
|
56
|
+
<GenUI spec={{ version: 'genui/v2', blocks: [{ type: 'settings', addon: 'inventory', scope: 'org' }] }} />
|
|
57
|
+
</ApiProvider>
|
|
58
|
+
</QueryClientProvider>,
|
|
56
59
|
)
|
|
57
60
|
const lines = await screen.findByRole('spinbutton')
|
|
58
61
|
expect(screen.queryByText(/Token/)).toBeNull()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { cleanup, renderHook, waitFor } from '@testing-library/react'
|
|
4
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
5
|
+
import type { ReactNode } from 'react'
|
|
6
|
+
import { ApiProvider } from '../api-context'
|
|
7
|
+
import { InstalledAddonsProvider } from '../installed-addons-context'
|
|
8
|
+
import { useAddonSettings } from '../use-addon-settings'
|
|
9
|
+
import { useAddonInstalledProbe } from '../use-addon-installed-probe'
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup)
|
|
12
|
+
|
|
13
|
+
function wrap(get: (url: string) => Promise<unknown>, installed?: string[]) {
|
|
14
|
+
const client = { get: vi.fn(get), post: vi.fn(), put: vi.fn(), delete: vi.fn() }
|
|
15
|
+
const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
16
|
+
const W = ({ children }: { children: ReactNode }) => (
|
|
17
|
+
<QueryClientProvider client={qc}>
|
|
18
|
+
<ApiProvider client={client as never}>
|
|
19
|
+
{installed ? <InstalledAddonsProvider addons={installed}>{children}</InstalledAddonsProvider> : children}
|
|
20
|
+
</ApiProvider>
|
|
21
|
+
</QueryClientProvider>
|
|
22
|
+
)
|
|
23
|
+
return { W, client }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('useAddonSettings', () => {
|
|
27
|
+
it('merges defaults under stored values and exposes definitions/overrides', async () => {
|
|
28
|
+
const { W, client } = wrap(async () => ({ data: { success: true, data: { a: 5 }, definitions: [{ key: 'a' }], overrides: { a: 6 } } }))
|
|
29
|
+
const defaults = { a: 1, b: 2 }
|
|
30
|
+
const { result } = renderHook(() => useAddonSettings('pos', { defaults, branchId: 'b1' }), { wrapper: W })
|
|
31
|
+
await waitFor(() => expect(result.current.isLoading).toBe(false))
|
|
32
|
+
expect(client.get).toHaveBeenCalledWith('/addons/pos/settings?branch_id=b1')
|
|
33
|
+
expect(result.current.settings).toEqual({ a: 5, b: 2 })
|
|
34
|
+
expect(result.current.stored).toEqual({ a: 5 })
|
|
35
|
+
expect(result.current.definitions).toEqual([{ key: 'a' }])
|
|
36
|
+
expect(result.current.overrides).toEqual({ a: 6 })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('reload() fetches again and resolves with the payload', async () => {
|
|
40
|
+
const { W, client } = wrap(async () => ({ data: { data: { a: 1 } } }))
|
|
41
|
+
const { result } = renderHook(() => useAddonSettings('pos', { enabled: false }), { wrapper: W })
|
|
42
|
+
const payload = await result.current.reload()
|
|
43
|
+
expect(payload.values).toEqual({ a: 1 })
|
|
44
|
+
await result.current.reload()
|
|
45
|
+
expect(client.get).toHaveBeenCalledTimes(2)
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
describe('useAddonInstalledProbe', () => {
|
|
50
|
+
it('true on 2xx, false on 404, unknown on other errors', async () => {
|
|
51
|
+
const ok = wrap(async () => ({ data: {} }))
|
|
52
|
+
const r1 = renderHook(() => useAddonInstalledProbe('caja'), { wrapper: ok.W })
|
|
53
|
+
await waitFor(() => expect(r1.result.current.installed).toBe(true))
|
|
54
|
+
|
|
55
|
+
const nf = wrap(async () => Promise.reject({ response: { status: 404 } }))
|
|
56
|
+
const r2 = renderHook(() => useAddonInstalledProbe('caja'), { wrapper: nf.W })
|
|
57
|
+
await waitFor(() => expect(r2.result.current.installed).toBe(false))
|
|
58
|
+
|
|
59
|
+
const forbidden = wrap(async () => Promise.reject({ response: { status: 403 } }))
|
|
60
|
+
const r3 = renderHook(() => useAddonInstalledProbe('caja'), { wrapper: forbidden.W })
|
|
61
|
+
await waitFor(() => expect(r3.result.current.isLoading).toBe(false))
|
|
62
|
+
expect(r3.result.current.installed).toBeUndefined()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('answers from the provider without touching the network', () => {
|
|
66
|
+
const { W, client } = wrap(async () => ({ data: {} }), ['fiscal'])
|
|
67
|
+
const yes = renderHook(() => useAddonInstalledProbe('fiscal'), { wrapper: W })
|
|
68
|
+
const no = renderHook(() => useAddonInstalledProbe('caja'), { wrapper: W })
|
|
69
|
+
expect(yes.result.current.installed).toBe(true)
|
|
70
|
+
expect(no.result.current.installed).toBe(false)
|
|
71
|
+
expect(client.get).not.toHaveBeenCalled()
|
|
72
|
+
})
|
|
73
|
+
})
|