@asteby/metacore-runtime-react 52.1.0 → 53.1.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 +24 -0
- package/dist/addon-loader.d.ts +22 -1
- package/dist/addon-loader.d.ts.map +1 -1
- package/dist/addon-loader.js +23 -5
- package/dist/addon-page-host.d.ts +80 -0
- package/dist/addon-page-host.d.ts.map +1 -0
- package/dist/addon-page-host.js +216 -0
- package/dist/addon-page-loader.d.ts +40 -0
- package/dist/addon-page-loader.d.ts.map +1 -0
- package/dist/addon-page-loader.js +87 -0
- package/dist/dynamic-view.d.ts +20 -1
- package/dist/dynamic-view.d.ts.map +1 -1
- package/dist/dynamic-view.js +26 -3
- package/dist/federated-error-boundary.d.ts +46 -0
- package/dist/federated-error-boundary.d.ts.map +1 -0
- package/dist/federated-error-boundary.js +55 -0
- package/dist/host-api.d.ts +22 -0
- package/dist/host-api.d.ts.map +1 -0
- package/dist/host-api.js +140 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/testing.d.ts +42 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +53 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/views/calendar-view.d.ts +23 -0
- package/dist/views/calendar-view.d.ts.map +1 -0
- package/dist/views/calendar-view.js +138 -0
- package/dist/views/chart-view.d.ts +14 -0
- package/dist/views/chart-view.d.ts.map +1 -0
- package/dist/views/chart-view.js +77 -0
- package/dist/views/data-source.d.ts +30 -0
- package/dist/views/data-source.d.ts.map +1 -0
- package/dist/views/data-source.js +103 -0
- package/dist/views/index.d.ts +4 -0
- package/dist/views/index.d.ts.map +1 -0
- package/dist/views/index.js +2 -0
- package/dist/views/map-view.d.ts +39 -0
- package/dist/views/map-view.d.ts.map +1 -0
- package/dist/views/map-view.js +143 -0
- package/dist/views/panels.d.ts +13 -0
- package/dist/views/panels.d.ts.map +1 -0
- package/dist/views/panels.js +119 -0
- package/dist/views/registry.d.ts +46 -0
- package/dist/views/registry.d.ts.map +1 -0
- package/dist/views/registry.js +139 -0
- package/dist/views/skeleton.d.ts +5 -0
- package/dist/views/skeleton.d.ts.map +1 -0
- package/dist/views/skeleton.js +6 -0
- package/dist/views/split-view.d.ts +6 -0
- package/dist/views/split-view.d.ts.map +1 -0
- package/dist/views/split-view.js +52 -0
- package/dist/views/timeline-view.d.ts +25 -0
- package/dist/views/timeline-view.d.ts.map +1 -0
- package/dist/views/timeline-view.js +130 -0
- package/dist/views/types.d.ts +87 -0
- package/dist/views/types.d.ts.map +1 -0
- package/dist/views/types.js +1 -0
- package/package.json +18 -6
- package/src/__tests__/addon-page-host.test.tsx +122 -0
- package/src/__tests__/addon-page-loader.test.tsx +201 -0
- package/src/__tests__/declarative-views.test.tsx +351 -0
- package/src/__tests__/host-api.test.ts +153 -0
- package/src/__tests__/index-static-graph.test.ts +18 -0
- package/src/addon-loader.tsx +51 -8
- package/src/addon-page-host.tsx +319 -0
- package/src/addon-page-loader.tsx +203 -0
- package/src/dynamic-view.tsx +61 -3
- package/src/federated-error-boundary.tsx +121 -0
- package/src/host-api.ts +166 -0
- package/src/index.ts +38 -0
- package/src/testing.tsx +108 -0
- package/src/types.ts +13 -0
- package/src/views/calendar-view.tsx +234 -0
- package/src/views/chart-view.tsx +122 -0
- package/src/views/data-source.ts +127 -0
- package/src/views/index.ts +37 -0
- package/src/views/map-view.tsx +217 -0
- package/src/views/panels.tsx +177 -0
- package/src/views/registry.tsx +202 -0
- package/src/views/skeleton.tsx +13 -0
- package/src/views/split-view.tsx +115 -0
- package/src/views/timeline-view.tsx +229 -0
- package/src/views/types.ts +105 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
// `view_type: timeline` (a model's rows over time) and `kind: timeline` detail
|
|
3
|
+
// panels (a record's child rows, or the items of a capability query such as
|
|
4
|
+
// `commerce.shipping.track`). Lazy chunk. Dates are formatted, never computed:
|
|
5
|
+
// ETAs and statuses are whatever the server returned.
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { Badge, Button } from '@asteby/metacore-ui/primitives';
|
|
9
|
+
import { buildRelationFilterParams } from '../dynamic-relation-helpers';
|
|
10
|
+
import { displayValue, pickItems, resolveCapabilityInput, sortByDate, toDate, } from './data-source';
|
|
11
|
+
import { ViewSkeleton } from './skeleton';
|
|
12
|
+
const PAGE = 50;
|
|
13
|
+
/** Pure: rows → ordered entries (newest first), grouped when `group_by` is set. */
|
|
14
|
+
export function toTimelineEntries(rows, view) {
|
|
15
|
+
return sortByDate(rows, view.date_field).map((row, i) => ({
|
|
16
|
+
key: String(row.id ?? `${i}`),
|
|
17
|
+
at: toDate(row[view.date_field]),
|
|
18
|
+
title: displayValue(row[view.title_field]),
|
|
19
|
+
status: view.status_field ? displayValue(row[view.status_field]) || undefined : undefined,
|
|
20
|
+
description: view.description_field ? displayValue(row[view.description_field]) || undefined : undefined,
|
|
21
|
+
group: view.group_by ? displayValue(row[view.group_by]) || undefined : undefined,
|
|
22
|
+
row,
|
|
23
|
+
}));
|
|
24
|
+
}
|
|
25
|
+
function useFormatter(locale, timeZone) {
|
|
26
|
+
return React.useMemo(() => {
|
|
27
|
+
try {
|
|
28
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: 'medium', timeStyle: 'short', timeZone });
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' });
|
|
32
|
+
}
|
|
33
|
+
}, [locale, timeZone]);
|
|
34
|
+
}
|
|
35
|
+
export function TimelineList({ entries, locale, timeZone, onOpen, }) {
|
|
36
|
+
const { t } = useTranslation();
|
|
37
|
+
const fmt = useFormatter(locale, timeZone);
|
|
38
|
+
if (entries.length === 0) {
|
|
39
|
+
return (_jsx("p", { className: "py-8 text-center text-sm text-muted-foreground", "data-testid": "timeline-empty", children: t('metacore.views.empty', 'Sin datos todavía.') }));
|
|
40
|
+
}
|
|
41
|
+
let lastGroup;
|
|
42
|
+
return (_jsx("ol", { className: "relative space-y-4 border-l border-border pl-5", "data-testid": "timeline", children: entries.map((e) => {
|
|
43
|
+
const header = e.group !== undefined && e.group !== lastGroup ? e.group : undefined;
|
|
44
|
+
lastGroup = e.group;
|
|
45
|
+
const body = (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": true, className: "absolute -left-[5px] mt-1.5 h-2.5 w-2.5 rounded-full border-2 border-background bg-primary" }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [_jsx("span", { className: "text-sm font-medium text-foreground", children: e.title }), e.status ? _jsx(Badge, { variant: "outline", children: e.status }) : null] }), e.at ? (_jsx("time", { dateTime: e.at.toISOString(), className: "block text-xs text-muted-foreground", children: fmt.format(e.at) })) : null, e.description ? _jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: e.description }) : null] }));
|
|
46
|
+
return (_jsxs(React.Fragment, { children: [header ? (_jsx("li", { className: "-ml-5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground", children: header })) : null, _jsx("li", { className: "relative", children: onOpen ? (_jsx("button", { type: "button", className: "w-full rounded-md text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", onClick: () => onOpen(e.row), children: body })) : (body) })] }, e.key));
|
|
47
|
+
}) }));
|
|
48
|
+
}
|
|
49
|
+
/** `view_type: timeline` on a nav entry: the model's rows, newest first, paged. */
|
|
50
|
+
export default function TimelineViewRenderer(props) {
|
|
51
|
+
const { model, view, data, locale, timeZone, onOpenRecord, className } = props;
|
|
52
|
+
const { t } = useTranslation();
|
|
53
|
+
const [rows, setRows] = React.useState(null);
|
|
54
|
+
const [total, setTotal] = React.useState();
|
|
55
|
+
const [page, setPage] = React.useState(1);
|
|
56
|
+
const [error, setError] = React.useState(false);
|
|
57
|
+
React.useEffect(() => {
|
|
58
|
+
let cancelled = false;
|
|
59
|
+
setError(false);
|
|
60
|
+
data
|
|
61
|
+
.list(model, { page, per_page: PAGE, sortBy: view.date_field, order: 'desc' })
|
|
62
|
+
.then((res) => {
|
|
63
|
+
if (cancelled)
|
|
64
|
+
return;
|
|
65
|
+
setRows((prev) => (page === 1 || !prev ? res.rows : [...prev, ...res.rows]));
|
|
66
|
+
setTotal(res.total);
|
|
67
|
+
})
|
|
68
|
+
.catch(() => !cancelled && setError(true));
|
|
69
|
+
return () => {
|
|
70
|
+
cancelled = true;
|
|
71
|
+
};
|
|
72
|
+
}, [data, model, view.date_field, page]);
|
|
73
|
+
if (error && !rows) {
|
|
74
|
+
return (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: t('metacore.views.error', 'No se pudo cargar la información.') }));
|
|
75
|
+
}
|
|
76
|
+
if (!rows)
|
|
77
|
+
return _jsx(ViewSkeleton, {});
|
|
78
|
+
const entries = toTimelineEntries(rows, view);
|
|
79
|
+
const more = total !== undefined ? rows.length < total : false;
|
|
80
|
+
return (_jsxs("div", { className: className, children: [_jsx(TimelineList, { entries: entries, locale: locale, timeZone: timeZone, onOpen: onOpenRecord }), more ? (_jsx("div", { className: "mt-4 flex justify-center", children: _jsx(Button, { variant: "outline", size: "sm", onClick: () => setPage((p) => p + 1), children: t('metacore.views.load_more', 'Cargar más') }) })) : null] }));
|
|
81
|
+
}
|
|
82
|
+
/** `kind: timeline` panel: child rows of a relation or a capability's items. */
|
|
83
|
+
export function TimelinePanel({ panel, record, metadata, data, locale, timeZone }) {
|
|
84
|
+
const { t } = useTranslation();
|
|
85
|
+
const view = panel.timeline;
|
|
86
|
+
const source = view?.source;
|
|
87
|
+
const [rows, setRows] = React.useState(null);
|
|
88
|
+
const [error, setError] = React.useState(false);
|
|
89
|
+
const recordId = record.id;
|
|
90
|
+
const sig = JSON.stringify([source, recordId]);
|
|
91
|
+
React.useEffect(() => {
|
|
92
|
+
if (!view || !source)
|
|
93
|
+
return;
|
|
94
|
+
let cancelled = false;
|
|
95
|
+
setRows(null);
|
|
96
|
+
setError(false);
|
|
97
|
+
const run = async () => {
|
|
98
|
+
if (source.capability) {
|
|
99
|
+
const out = await data.capability(source.capability, resolveCapabilityInput(source.input, record));
|
|
100
|
+
return pickItems(out, source.items);
|
|
101
|
+
}
|
|
102
|
+
if (source.relation) {
|
|
103
|
+
const rel = metadata?.relations?.find((r) => r.name === source.relation);
|
|
104
|
+
if (!rel || recordId === undefined || recordId === null)
|
|
105
|
+
return [];
|
|
106
|
+
const res = await data.list(rel.through, {
|
|
107
|
+
...buildRelationFilterParams(rel.foreign_key, String(recordId), rel.scope),
|
|
108
|
+
per_page: PAGE,
|
|
109
|
+
sortBy: view.date_field,
|
|
110
|
+
order: 'desc',
|
|
111
|
+
});
|
|
112
|
+
return res.rows;
|
|
113
|
+
}
|
|
114
|
+
return [];
|
|
115
|
+
};
|
|
116
|
+
run().then((r) => !cancelled && setRows(r), () => !cancelled && setError(true));
|
|
117
|
+
return () => {
|
|
118
|
+
cancelled = true;
|
|
119
|
+
};
|
|
120
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
121
|
+
}, [data, sig, metadata]);
|
|
122
|
+
if (!view)
|
|
123
|
+
return null;
|
|
124
|
+
if (error) {
|
|
125
|
+
return (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: t('metacore.views.error', 'No se pudo cargar la información.') }));
|
|
126
|
+
}
|
|
127
|
+
if (!rows)
|
|
128
|
+
return _jsx(ViewSkeleton, { height: 200 });
|
|
129
|
+
return _jsx(TimelineList, { entries: toTimelineEntries(rows, view), locale: locale, timeZone: timeZone });
|
|
130
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { ComponentType } from 'react';
|
|
2
|
+
import type { CalendarView, ChartView, DetailPanel, MapView, SplitView, TimelineView, WidgetQuery } from '@asteby/metacore-sdk';
|
|
3
|
+
import type { TableMetadata } from '../types';
|
|
4
|
+
import type { WidgetData } from '../dashboard-types';
|
|
5
|
+
/** `view_type` values rendered by a declarative renderer (table/kanban excluded). */
|
|
6
|
+
export type DeclarativeViewType = 'map' | 'timeline' | 'calendar' | 'chart' | 'split';
|
|
7
|
+
/** Block of `NavView` each type reads. */
|
|
8
|
+
export interface DeclarativeViewConfig {
|
|
9
|
+
map: MapView;
|
|
10
|
+
timeline: TimelineView;
|
|
11
|
+
calendar: CalendarView;
|
|
12
|
+
chart: ChartView;
|
|
13
|
+
split: SplitView;
|
|
14
|
+
}
|
|
15
|
+
/** A page of rows. */
|
|
16
|
+
export interface ViewRows<Row = Record<string, unknown>> {
|
|
17
|
+
rows: Row[];
|
|
18
|
+
total?: number;
|
|
19
|
+
}
|
|
20
|
+
/** List params in the kernel's list syntax (`f_<col>`, `sortBy`, `order`…). */
|
|
21
|
+
export type ViewListParams = Record<string, string | number | boolean | undefined>;
|
|
22
|
+
/**
|
|
23
|
+
* Where declarative renderers read data. The host provides it (default:
|
|
24
|
+
* {@link createApiViewDataSource} over the runtime-react ApiClient). Every
|
|
25
|
+
* call runs with the viewer's permissions server-side; renderers never
|
|
26
|
+
* compute business values (totals, ETAs) — they display what comes back.
|
|
27
|
+
*/
|
|
28
|
+
export interface ViewDataSource {
|
|
29
|
+
/** Rows of a model (`GET /data/<model>`). */
|
|
30
|
+
list(model: string, params?: ViewListParams): Promise<ViewRows>;
|
|
31
|
+
/** One record (`GET /data/<model>/<id>`). */
|
|
32
|
+
record(model: string, id: string): Promise<Record<string, unknown> | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Aggregate for a chart view or panel. The host must only answer queries
|
|
35
|
+
* the installed manifests declare (same rule as dashboard widgets): the
|
|
36
|
+
* request names the model and the declared query, never free SQL.
|
|
37
|
+
*/
|
|
38
|
+
chart(req: ChartRequest): Promise<WidgetData>;
|
|
39
|
+
/** Capability query (timeline panels with `source.capability`). */
|
|
40
|
+
capability(key: string, input: Record<string, unknown>): Promise<unknown>;
|
|
41
|
+
}
|
|
42
|
+
export interface ChartRequest {
|
|
43
|
+
/** Model whose nav entry / detail declares the chart. */
|
|
44
|
+
model: string;
|
|
45
|
+
query: WidgetQuery;
|
|
46
|
+
/** Detail panels: the relation the query is scoped to, and the record. */
|
|
47
|
+
relation?: string;
|
|
48
|
+
recordId?: string;
|
|
49
|
+
/** Detail panels: the panel key; nav views: undefined. */
|
|
50
|
+
panelKey?: string;
|
|
51
|
+
}
|
|
52
|
+
/** Props every declarative view renderer receives. */
|
|
53
|
+
export interface ViewRendererProps<T extends DeclarativeViewType = DeclarativeViewType> {
|
|
54
|
+
model: string;
|
|
55
|
+
view: DeclarativeViewConfig[T];
|
|
56
|
+
/** Served table metadata (columns, relations, options…), when loaded. */
|
|
57
|
+
metadata?: TableMetadata | null;
|
|
58
|
+
data: ViewDataSource;
|
|
59
|
+
/** Open a record (host route to its detail page or drawer). */
|
|
60
|
+
onOpenRecord?: (row: Record<string, unknown>) => void;
|
|
61
|
+
locale?: string;
|
|
62
|
+
currency?: string;
|
|
63
|
+
timeZone?: string;
|
|
64
|
+
className?: string;
|
|
65
|
+
}
|
|
66
|
+
/** Props every detail panel renderer receives. */
|
|
67
|
+
export interface PanelRendererProps {
|
|
68
|
+
model: string;
|
|
69
|
+
panel: DetailPanel;
|
|
70
|
+
record: Record<string, unknown>;
|
|
71
|
+
metadata?: TableMetadata | null;
|
|
72
|
+
data: ViewDataSource;
|
|
73
|
+
locale?: string;
|
|
74
|
+
currency?: string;
|
|
75
|
+
timeZone?: string;
|
|
76
|
+
onOpenRecord?: (model: string, row: Record<string, unknown>) => void;
|
|
77
|
+
}
|
|
78
|
+
export type ViewRendererComponent = ComponentType<ViewRendererProps<any>>;
|
|
79
|
+
export type PanelRendererComponent = ComponentType<PanelRendererProps>;
|
|
80
|
+
/** Lazy module of a renderer (default export = the component). */
|
|
81
|
+
export type ViewRendererLoader = () => Promise<{
|
|
82
|
+
default: ViewRendererComponent;
|
|
83
|
+
}>;
|
|
84
|
+
export type PanelRendererLoader = () => Promise<{
|
|
85
|
+
default: PanelRendererComponent;
|
|
86
|
+
}>;
|
|
87
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/views/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@asteby/metacore-runtime-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "53.1.0",
|
|
4
4
|
"description": "React runtime for metacore hosts — renders addon contributions dynamically",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,6 +18,14 @@
|
|
|
18
18
|
"./charts": {
|
|
19
19
|
"types": "./dist/widgets/charts.d.ts",
|
|
20
20
|
"import": "./dist/widgets/charts.js"
|
|
21
|
+
},
|
|
22
|
+
"./testing": {
|
|
23
|
+
"types": "./dist/testing.d.ts",
|
|
24
|
+
"import": "./dist/testing.js"
|
|
25
|
+
},
|
|
26
|
+
"./views/map": {
|
|
27
|
+
"types": "./dist/views/map-view.d.ts",
|
|
28
|
+
"import": "./dist/views/map-view.js"
|
|
21
29
|
}
|
|
22
30
|
},
|
|
23
31
|
"dependencies": {
|
|
@@ -29,8 +37,8 @@
|
|
|
29
37
|
"zod": "^4.3.0"
|
|
30
38
|
},
|
|
31
39
|
"peerDependencies": {
|
|
32
|
-
"@asteby/metacore-sdk": "^3.
|
|
33
|
-
"@asteby/metacore-ui": "^2.
|
|
40
|
+
"@asteby/metacore-sdk": "^3.16.0",
|
|
41
|
+
"@asteby/metacore-ui": "^2.29.0",
|
|
34
42
|
"@tanstack/react-query": ">=5",
|
|
35
43
|
"@tanstack/react-router": ">=1.100",
|
|
36
44
|
"@tanstack/react-table": ">=8",
|
|
@@ -43,7 +51,8 @@
|
|
|
43
51
|
"react-i18next": ">=13",
|
|
44
52
|
"sonner": ">=1.7",
|
|
45
53
|
"zustand": ">=5",
|
|
46
|
-
"@module-federation/runtime": ">=2.5"
|
|
54
|
+
"@module-federation/runtime": ">=2.5",
|
|
55
|
+
"@testing-library/react": ">=14"
|
|
47
56
|
},
|
|
48
57
|
"peerDependenciesMeta": {
|
|
49
58
|
"@tanstack/react-router": {
|
|
@@ -54,11 +63,14 @@
|
|
|
54
63
|
},
|
|
55
64
|
"@module-federation/runtime": {
|
|
56
65
|
"optional": true
|
|
66
|
+
},
|
|
67
|
+
"@testing-library/react": {
|
|
68
|
+
"optional": true
|
|
57
69
|
}
|
|
58
70
|
},
|
|
59
71
|
"devDependencies": {
|
|
60
|
-
"@asteby/metacore-sdk": "3.
|
|
61
|
-
"@asteby/metacore-ui": "2.
|
|
72
|
+
"@asteby/metacore-sdk": "3.16.0",
|
|
73
|
+
"@asteby/metacore-ui": "2.29.0",
|
|
62
74
|
"@tanstack/react-query": "^5.95.0",
|
|
63
75
|
"@tanstack/react-router": "^1.168.0",
|
|
64
76
|
"@tanstack/react-table": "^8.20.0",
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
3
|
+
import { act, cleanup, fireEvent, render, screen } from '@testing-library/react'
|
|
4
|
+
import {
|
|
5
|
+
addonSubpath,
|
|
6
|
+
createPageChromeStore,
|
|
7
|
+
resolveAddonPath,
|
|
8
|
+
useAddonLocation,
|
|
9
|
+
useAddonNavigate,
|
|
10
|
+
useAddonSearchParams,
|
|
11
|
+
useBreadcrumbs,
|
|
12
|
+
useHostApi,
|
|
13
|
+
useHostContext,
|
|
14
|
+
usePageChrome,
|
|
15
|
+
} from '../addon-page-host'
|
|
16
|
+
import { createMockHostApi, renderWithHost } from '../testing'
|
|
17
|
+
|
|
18
|
+
afterEach(cleanup)
|
|
19
|
+
|
|
20
|
+
describe('resolveAddonPath', () => {
|
|
21
|
+
const base = '/a/shipping/control-tower'
|
|
22
|
+
it('plain paths are base-relative and cannot escape the base', () => {
|
|
23
|
+
expect(resolveAddonPath(base, 'shipments/1', 'shipments/42')).toBe(`${base}/shipments/42`)
|
|
24
|
+
expect(resolveAddonPath(base, 'x', '/shipments/42')).toBe(`${base}/shipments/42`)
|
|
25
|
+
expect(resolveAddonPath(base, 'x', '../../../admin')).toBe(`${base}/admin`)
|
|
26
|
+
})
|
|
27
|
+
it('./ and ../ resolve against the current sub-path', () => {
|
|
28
|
+
expect(resolveAddonPath(base, 'shipments/1', './2')).toBe(`${base}/shipments/2`)
|
|
29
|
+
expect(resolveAddonPath(base, 'shipments/1/events', '../edit')).toBe(`${base}/shipments/edit`)
|
|
30
|
+
})
|
|
31
|
+
it('keeps query/hash and the current path for "?…"', () => {
|
|
32
|
+
expect(resolveAddonPath(base, 'shipments', '?carrier=dhl')).toBe(`${base}/shipments?carrier=dhl`)
|
|
33
|
+
expect(resolveAddonPath(base, '', '')).toBe(base)
|
|
34
|
+
expect(resolveAddonPath('/', '', 'x')).toBe('/x')
|
|
35
|
+
})
|
|
36
|
+
it('addonSubpath strips the base', () => {
|
|
37
|
+
expect(addonSubpath(base, `${base}/shipments/42`)).toBe('shipments/42')
|
|
38
|
+
expect(addonSubpath(base, base)).toBe('')
|
|
39
|
+
expect(addonSubpath(base, '/other')).toBe('')
|
|
40
|
+
})
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
function Probe() {
|
|
44
|
+
const api = useHostApi()
|
|
45
|
+
const ctx = useHostContext()
|
|
46
|
+
const navigate = useAddonNavigate()
|
|
47
|
+
const loc = useAddonLocation()
|
|
48
|
+
const [params, setParams] = useAddonSearchParams()
|
|
49
|
+
useBreadcrumbs([{ title: 'Envíos', url: '/m/Shipment' }])
|
|
50
|
+
usePageChrome({
|
|
51
|
+
title: 'Torre de envíos',
|
|
52
|
+
focus: true,
|
|
53
|
+
actions: [{ key: 'refresh', label: 'Actualizar', onSelect: () => navigate('?refreshed=1') }],
|
|
54
|
+
})
|
|
55
|
+
return (
|
|
56
|
+
<div>
|
|
57
|
+
<span data-testid="org">{ctx.org?.name}</span>
|
|
58
|
+
<span data-testid="path">{loc.path}</span>
|
|
59
|
+
<span data-testid="carrier">{params.get('carrier')}</span>
|
|
60
|
+
<span data-testid="has-get">{typeof api.get}</span>
|
|
61
|
+
<button onClick={() => navigate('shipments/42')}>go</button>
|
|
62
|
+
<button onClick={() => setParams({ carrier: 'fedex' })}>filter</button>
|
|
63
|
+
</div>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe('AddonPageHost hooks', () => {
|
|
68
|
+
it('expose host context, location and navigation through the host router', () => {
|
|
69
|
+
const r = renderWithHost(<Probe />, {
|
|
70
|
+
basePath: '/a/shipping/control-tower',
|
|
71
|
+
pathname: '/a/shipping/control-tower/shipments',
|
|
72
|
+
search: '?carrier=dhl',
|
|
73
|
+
})
|
|
74
|
+
expect(screen.getByTestId('org').textContent).toBe('Org de prueba')
|
|
75
|
+
expect(screen.getByTestId('path').textContent).toBe('shipments')
|
|
76
|
+
expect(screen.getByTestId('carrier').textContent).toBe('dhl')
|
|
77
|
+
expect(screen.getByTestId('has-get').textContent).toBe('function')
|
|
78
|
+
fireEvent.click(screen.getByText('go'))
|
|
79
|
+
fireEvent.click(screen.getByText('filter'))
|
|
80
|
+
expect(r.navigate.calls).toEqual([
|
|
81
|
+
['/a/shipping/control-tower/shipments/42', undefined],
|
|
82
|
+
['/a/shipping/control-tower/shipments?carrier=fedex', { replace: true }],
|
|
83
|
+
])
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('publishes chrome and breadcrumbs, with stable action handlers, and clears them on unmount', () => {
|
|
87
|
+
const r = renderWithHost(<Probe />)
|
|
88
|
+
const state = r.chrome.get()
|
|
89
|
+
expect(state.title).toBe('Torre de envíos')
|
|
90
|
+
expect(state.focus).toBe(true)
|
|
91
|
+
expect(state.breadcrumbs).toEqual([{ title: 'Envíos', url: '/m/Shipment' }])
|
|
92
|
+
act(() => state.actions![0].onSelect())
|
|
93
|
+
expect(r.navigate.calls.at(-1)?.[0]).toBe('/a/test/page?refreshed=1')
|
|
94
|
+
r.unmount()
|
|
95
|
+
expect(r.chrome.get().title).toBeUndefined()
|
|
96
|
+
expect(r.chrome.get().breadcrumbs).toEqual([])
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('hooks fail loudly outside a host', () => {
|
|
100
|
+
const spy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
101
|
+
expect(() => render(<Probe />)).toThrow(/inside <AddonPageHost>/)
|
|
102
|
+
spy.mockRestore()
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('mock host api records calls and 404s unknown routes', async () => {
|
|
106
|
+
const api = createMockHostApi({ get: { '/data/Shipment': { success: true, data: [] } } })
|
|
107
|
+
await expect(api.get('/data/Shipment?f_x=1')).resolves.toEqual({ success: true, data: [] })
|
|
108
|
+
await expect(api.get('/nope')).rejects.toMatchObject({ status: 404 })
|
|
109
|
+
expect(api.calls[0]).toEqual(['get', '/data/Shipment?f_x=1', undefined])
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('chrome store notifies subscribers', () => {
|
|
113
|
+
const store = createPageChromeStore()
|
|
114
|
+
let n = 0
|
|
115
|
+
const off = store.subscribe(() => n++)
|
|
116
|
+
store.set({ title: 'x' })
|
|
117
|
+
off()
|
|
118
|
+
store.set({ title: 'y' })
|
|
119
|
+
expect(n).toBe(1)
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
//
|
|
3
|
+
// AddonPageLoader + FederatedErrorBoundary: the page's expose is loaded through
|
|
4
|
+
// the MF runtime (mocked), SRI mismatches fail without retries, render crashes
|
|
5
|
+
// stay inside the boundary and the shell around them keeps rendering.
|
|
6
|
+
import { createHash } from 'node:crypto'
|
|
7
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
8
|
+
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
9
|
+
import { __resetRemoteIntegrityCache, definePage, type FrontendPage } from '@asteby/metacore-sdk'
|
|
10
|
+
|
|
11
|
+
const mf = vi.hoisted(() => ({
|
|
12
|
+
registerRemotes: vi.fn(),
|
|
13
|
+
loadRemote: vi.fn(),
|
|
14
|
+
}))
|
|
15
|
+
vi.mock('@module-federation/runtime', () => mf)
|
|
16
|
+
|
|
17
|
+
import { AddonPageLoader } from '../addon-page-loader'
|
|
18
|
+
import { FederatedErrorBoundary } from '../federated-error-boundary'
|
|
19
|
+
import { useHostApi, usePageChrome } from '../addon-page-host'
|
|
20
|
+
import { createMockHostApi } from '../testing'
|
|
21
|
+
|
|
22
|
+
const page: FrontendPage = {
|
|
23
|
+
key: 'control_tower',
|
|
24
|
+
path: 'control-tower',
|
|
25
|
+
expose: './pages/control-tower',
|
|
26
|
+
title: 'shipping.pages.control_tower',
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let quiet: ReturnType<typeof vi.spyOn>
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
mf.registerRemotes.mockReset()
|
|
32
|
+
mf.loadRemote.mockReset()
|
|
33
|
+
__resetRemoteIntegrityCache()
|
|
34
|
+
quiet = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
35
|
+
})
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
cleanup()
|
|
38
|
+
quiet.mockRestore()
|
|
39
|
+
vi.unstubAllGlobals()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
let n = 0
|
|
43
|
+
function mount(extra: Partial<React.ComponentProps<typeof AddonPageLoader>> = {}) {
|
|
44
|
+
n += 1
|
|
45
|
+
const onError = vi.fn()
|
|
46
|
+
const utils = render(
|
|
47
|
+
<div>
|
|
48
|
+
<nav data-testid="shell-sidebar">sidebar</nav>
|
|
49
|
+
<AddonPageLoader
|
|
50
|
+
scope={`metacore_shipping_${n}`}
|
|
51
|
+
url={`/api/metacore/addons/shipping/frontend/remoteEntry.js?v=${n}`}
|
|
52
|
+
addonKey="shipping"
|
|
53
|
+
page={page}
|
|
54
|
+
basePath="/a/shipping/control-tower"
|
|
55
|
+
host={{ locale: 'es-MX' }}
|
|
56
|
+
api={createMockHostApi()}
|
|
57
|
+
location={{ pathname: '/a/shipping/control-tower/shipments/42', search: '' }}
|
|
58
|
+
navigate={() => {}}
|
|
59
|
+
onError={onError}
|
|
60
|
+
{...extra}
|
|
61
|
+
/>
|
|
62
|
+
</div>,
|
|
63
|
+
)
|
|
64
|
+
return { ...utils, onError }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
describe('AddonPageLoader', () => {
|
|
68
|
+
it('loads the page expose and renders it with AddonPageProps + host hooks', async () => {
|
|
69
|
+
const Tower = definePage(({ basePath, params, page: p }) => {
|
|
70
|
+
const api = useHostApi()
|
|
71
|
+
usePageChrome({ title: 'Torre' })
|
|
72
|
+
return (
|
|
73
|
+
<p data-testid="page">
|
|
74
|
+
{basePath}|{params['*']}|{p.key}|{typeof api.capability}
|
|
75
|
+
</p>
|
|
76
|
+
)
|
|
77
|
+
})
|
|
78
|
+
mf.loadRemote.mockResolvedValue({ default: Tower })
|
|
79
|
+
mount()
|
|
80
|
+
expect(screen.getByTestId('addon-page-skeleton')).toBeTruthy()
|
|
81
|
+
await waitFor(() => expect(screen.getByTestId('page')).toBeTruthy())
|
|
82
|
+
expect(screen.getByTestId('page').textContent).toBe(
|
|
83
|
+
'/a/shipping/control-tower|shipments/42|control_tower|function',
|
|
84
|
+
)
|
|
85
|
+
expect(mf.registerRemotes).toHaveBeenCalledTimes(1)
|
|
86
|
+
expect(mf.loadRemote.mock.calls[0][0]).toMatch(/^metacore_shipping_\d+\/pages\/control-tower$/)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('contains a crashing page: the shell stays, the incident is reported, retry re-renders', async () => {
|
|
90
|
+
let crash = true
|
|
91
|
+
const Boom = definePage(() => {
|
|
92
|
+
if (crash) throw new Error('kaboom')
|
|
93
|
+
return <p data-testid="recovered">ok</p>
|
|
94
|
+
})
|
|
95
|
+
mf.loadRemote.mockResolvedValue({ default: Boom })
|
|
96
|
+
const { onError } = mount()
|
|
97
|
+
await waitFor(() => expect(screen.getByTestId('federated-error')).toBeTruthy())
|
|
98
|
+
expect(screen.getByTestId('shell-sidebar')).toBeTruthy()
|
|
99
|
+
expect(onError).toHaveBeenCalledWith(
|
|
100
|
+
expect.objectContaining({ message: 'kaboom' }),
|
|
101
|
+
expect.objectContaining({ addonKey: 'shipping', expose: './pages/control-tower', phase: 'render' }),
|
|
102
|
+
)
|
|
103
|
+
crash = false
|
|
104
|
+
fireEvent.click(screen.getByText('Reintentar'))
|
|
105
|
+
await waitFor(() => expect(screen.getByTestId('recovered')).toBeTruthy())
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('a module without a default page shows the load error and retry reloads', async () => {
|
|
109
|
+
mf.loadRemote.mockResolvedValueOnce({ notAPage: 1 })
|
|
110
|
+
const { onError } = mount()
|
|
111
|
+
await waitFor(() => expect(screen.getByTestId('federated-error')).toBeTruthy())
|
|
112
|
+
expect(onError.mock.calls[0][1]).toMatchObject({ phase: 'load' })
|
|
113
|
+
mf.loadRemote.mockResolvedValueOnce({ default: definePage(() => <p data-testid="page">ok</p>) })
|
|
114
|
+
fireEvent.click(screen.getByText('Reintentar'))
|
|
115
|
+
await waitFor(() => expect(screen.getByTestId('page')).toBeTruthy())
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('refuses a remote whose bytes do not match frontend.integrity (no MF import, no retries)', async () => {
|
|
119
|
+
const genuine = 'export const init = () => {}'
|
|
120
|
+
const integrity = `sha384-${createHash('sha384').update(genuine).digest('base64')}`
|
|
121
|
+
const fetchMock = vi.fn(async () => new Response('alert("tampered")'))
|
|
122
|
+
vi.stubGlobal('fetch', fetchMock)
|
|
123
|
+
// The browser would reject the modulepreload on the hash mismatch.
|
|
124
|
+
const append = document.head.appendChild.bind(document.head)
|
|
125
|
+
const spy = vi.spyOn(document.head, 'appendChild').mockImplementation((node: Node) => {
|
|
126
|
+
const out = append(node)
|
|
127
|
+
if (node instanceof HTMLLinkElement && node.rel === 'modulepreload') {
|
|
128
|
+
expect(node.integrity).toBe(integrity)
|
|
129
|
+
setTimeout(() => node.onerror?.(new Event('error')), 0)
|
|
130
|
+
}
|
|
131
|
+
return out
|
|
132
|
+
})
|
|
133
|
+
mf.loadRemote.mockResolvedValue({ default: definePage(() => <p>never</p>) })
|
|
134
|
+
const { onError } = mount({ integrity })
|
|
135
|
+
await waitFor(() => expect(onError).toHaveBeenCalled())
|
|
136
|
+
expect(onError.mock.calls[0][0].name).toBe('RemoteIntegrityError')
|
|
137
|
+
expect(mf.registerRemotes).not.toHaveBeenCalled()
|
|
138
|
+
expect(mf.loadRemote).not.toHaveBeenCalled()
|
|
139
|
+
// modulepreload is attempted first; on its failure one diagnostic fetch.
|
|
140
|
+
expect(fetchMock).toHaveBeenCalledTimes(1)
|
|
141
|
+
spy.mockRestore()
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
it('mounts a remote whose modulepreload passed the integrity check', async () => {
|
|
145
|
+
const fetchMock = vi.fn()
|
|
146
|
+
vi.stubGlobal('fetch', fetchMock)
|
|
147
|
+
const append = document.head.appendChild.bind(document.head)
|
|
148
|
+
const spy = vi.spyOn(document.head, 'appendChild').mockImplementation((node: Node) => {
|
|
149
|
+
const out = append(node)
|
|
150
|
+
if (node instanceof HTMLLinkElement && node.rel === 'modulepreload') {
|
|
151
|
+
setTimeout(() => node.onload?.(new Event('load')), 0)
|
|
152
|
+
}
|
|
153
|
+
return out
|
|
154
|
+
})
|
|
155
|
+
mf.loadRemote.mockResolvedValue({ default: definePage(() => <p data-testid="page">ok</p>) })
|
|
156
|
+
mount({ integrity: 'sha384-AAAA' })
|
|
157
|
+
await waitFor(() => expect(screen.getByTestId('page')).toBeTruthy())
|
|
158
|
+
expect(fetchMock).not.toHaveBeenCalled()
|
|
159
|
+
spy.mockRestore()
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
it('times out a hung remote', async () => {
|
|
163
|
+
mf.loadRemote.mockReturnValue(new Promise(() => {}))
|
|
164
|
+
const { onError } = mount({ timeoutMs: 30 })
|
|
165
|
+
await waitFor(() => expect(onError).toHaveBeenCalled())
|
|
166
|
+
expect(onError.mock.calls[0][0].message).toMatch(/did not load within 30 ms/)
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
describe('FederatedErrorBoundary', () => {
|
|
171
|
+
it('resets when resetKeys change and survives a throwing reporter', () => {
|
|
172
|
+
const Boom = ({ fail }: { fail: boolean }) => {
|
|
173
|
+
if (fail) throw new Error('x')
|
|
174
|
+
return <p data-testid="fine">fine</p>
|
|
175
|
+
}
|
|
176
|
+
const { rerender } = render(
|
|
177
|
+
<FederatedErrorBoundary resetKeys={['v1']} onError={() => { throw new Error('reporter down') }}>
|
|
178
|
+
<Boom fail />
|
|
179
|
+
</FederatedErrorBoundary>,
|
|
180
|
+
)
|
|
181
|
+
expect(screen.getByRole('alert')).toBeTruthy()
|
|
182
|
+
rerender(
|
|
183
|
+
<FederatedErrorBoundary resetKeys={['v2']}>
|
|
184
|
+
<Boom fail={false} />
|
|
185
|
+
</FederatedErrorBoundary>,
|
|
186
|
+
)
|
|
187
|
+
expect(screen.getByTestId('fine')).toBeTruthy()
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('accepts a custom fallback', () => {
|
|
191
|
+
const Boom = () => {
|
|
192
|
+
throw new Error('bad')
|
|
193
|
+
}
|
|
194
|
+
render(
|
|
195
|
+
<FederatedErrorBoundary fallback={({ error }) => <span data-testid="custom">{error.message}</span>}>
|
|
196
|
+
<Boom />
|
|
197
|
+
</FederatedErrorBoundary>,
|
|
198
|
+
)
|
|
199
|
+
expect(screen.getByTestId('custom').textContent).toBe('bad')
|
|
200
|
+
})
|
|
201
|
+
})
|