@asteby/metacore-runtime-react 52.1.0 → 53.0.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 +18 -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 +113 -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 +16 -4
- 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 +87 -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 +143 -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,23 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { CalendarView } from '@asteby/metacore-sdk';
|
|
3
|
+
import type { ViewRendererProps } from './types';
|
|
4
|
+
export interface CalendarEntry {
|
|
5
|
+
key: string;
|
|
6
|
+
title: string;
|
|
7
|
+
start: Date;
|
|
8
|
+
end: Date;
|
|
9
|
+
allDay: boolean;
|
|
10
|
+
color?: string;
|
|
11
|
+
row: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
/** First and last calendar day of the month containing `d` (`YYYY-MM-DD`). */
|
|
14
|
+
export declare function monthRange(d: Date): {
|
|
15
|
+
first: string;
|
|
16
|
+
last: string;
|
|
17
|
+
};
|
|
18
|
+
/** Pure: rows → entries with parsed dates (rows without a start are dropped). */
|
|
19
|
+
export declare function toCalendarEntries(rows: Record<string, unknown>[], view: CalendarView): CalendarEntry[];
|
|
20
|
+
/** Pure: entries bucketed by local day key, each multi-day entry on every day it spans. */
|
|
21
|
+
export declare function bucketByDay(entries: CalendarEntry[], maxSpanDays?: number): Map<string, CalendarEntry[]>;
|
|
22
|
+
export default function CalendarViewRenderer(props: ViewRendererProps<'calendar'>): React.JSX.Element;
|
|
23
|
+
//# sourceMappingURL=calendar-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-view.d.ts","sourceRoot":"","sources":["../../src/views/calendar-view.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAMhD,MAAM,WAAW,aAAa;IAC1B,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,IAAI,CAAA;IACX,GAAG,EAAE,IAAI,CAAA;IACT,MAAM,EAAE,OAAO,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED,8EAA8E;AAC9E,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAInE;AAED,iFAAiF;AACjF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,GAAG,aAAa,EAAE,CAuBtG;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,WAAW,SAAK,GAAG,GAAG,CAAC,MAAM,EAAE,aAAa,EAAE,CAAC,CAcpG;AAqBD,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAAC,KAAK,EAAE,iBAAiB,CAAC,UAAU,CAAC,qBA2IhF"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// `view_type: calendar`: a model's rows on a month grid. Lazy chunk, no
|
|
3
|
+
// calendar library: a 7-column CSS grid built from the UI kit, one request per
|
|
4
|
+
// visible month (`f_<start_field>=RANGE:<first>,<last>`, the list syntax the
|
|
5
|
+
// kernel already serves). Multi-day entries (end_field) show on each day.
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
9
|
+
import { Badge, Button } from '@asteby/metacore-ui/primitives';
|
|
10
|
+
import { dayKey, displayValue, toDate } from './data-source';
|
|
11
|
+
import { ViewSkeleton } from './skeleton';
|
|
12
|
+
const MAX_ROWS = 500;
|
|
13
|
+
/** First and last calendar day of the month containing `d` (`YYYY-MM-DD`). */
|
|
14
|
+
export function monthRange(d) {
|
|
15
|
+
const first = new Date(d.getFullYear(), d.getMonth(), 1, 12);
|
|
16
|
+
const last = new Date(d.getFullYear(), d.getMonth() + 1, 0, 12);
|
|
17
|
+
return { first: dayKey(first), last: dayKey(last) };
|
|
18
|
+
}
|
|
19
|
+
/** Pure: rows → entries with parsed dates (rows without a start are dropped). */
|
|
20
|
+
export function toCalendarEntries(rows, view) {
|
|
21
|
+
const out = [];
|
|
22
|
+
rows.forEach((row, i) => {
|
|
23
|
+
const start = toDate(row[view.start_field]);
|
|
24
|
+
if (!start)
|
|
25
|
+
return;
|
|
26
|
+
const endRaw = view.end_field ? toDate(row[view.end_field]) : null;
|
|
27
|
+
const end = endRaw && endRaw.getTime() >= start.getTime() ? endRaw : start;
|
|
28
|
+
const allDayRaw = view.all_day_field ? row[view.all_day_field] : undefined;
|
|
29
|
+
const allDay = allDayRaw !== undefined
|
|
30
|
+
? allDayRaw === true || allDayRaw === 'true'
|
|
31
|
+
: typeof row[view.start_field] === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(row[view.start_field]);
|
|
32
|
+
out.push({
|
|
33
|
+
key: String(row.id ?? i),
|
|
34
|
+
title: displayValue(view.title_field ? row[view.title_field] : row.name ?? row.title ?? row.id),
|
|
35
|
+
start,
|
|
36
|
+
end,
|
|
37
|
+
allDay,
|
|
38
|
+
color: view.color_by ? displayValue(row[view.color_by]) || undefined : undefined,
|
|
39
|
+
row,
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
return out;
|
|
43
|
+
}
|
|
44
|
+
/** Pure: entries bucketed by local day key, each multi-day entry on every day it spans. */
|
|
45
|
+
export function bucketByDay(entries, maxSpanDays = 62) {
|
|
46
|
+
const map = new Map();
|
|
47
|
+
for (const e of entries) {
|
|
48
|
+
const cur = new Date(e.start.getFullYear(), e.start.getMonth(), e.start.getDate(), 12);
|
|
49
|
+
const stop = new Date(e.end.getFullYear(), e.end.getMonth(), e.end.getDate(), 12);
|
|
50
|
+
for (let n = 0; cur.getTime() <= stop.getTime() && n < maxSpanDays; n++) {
|
|
51
|
+
const k = dayKey(cur);
|
|
52
|
+
const arr = map.get(k) ?? [];
|
|
53
|
+
arr.push(e);
|
|
54
|
+
map.set(k, arr);
|
|
55
|
+
cur.setDate(cur.getDate() + 1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return map;
|
|
59
|
+
}
|
|
60
|
+
function weeksOf(month) {
|
|
61
|
+
const first = new Date(month.getFullYear(), month.getMonth(), 1, 12);
|
|
62
|
+
// Monday-first grid (es-MX convention); pad with the previous month.
|
|
63
|
+
const offset = (first.getDay() + 6) % 7;
|
|
64
|
+
const start = new Date(first);
|
|
65
|
+
start.setDate(first.getDate() - offset);
|
|
66
|
+
const weeks = [];
|
|
67
|
+
const cur = new Date(start);
|
|
68
|
+
do {
|
|
69
|
+
const week = [];
|
|
70
|
+
for (let i = 0; i < 7; i++) {
|
|
71
|
+
week.push(new Date(cur));
|
|
72
|
+
cur.setDate(cur.getDate() + 1);
|
|
73
|
+
}
|
|
74
|
+
weeks.push(week);
|
|
75
|
+
} while (cur.getMonth() === month.getMonth());
|
|
76
|
+
return weeks;
|
|
77
|
+
}
|
|
78
|
+
export default function CalendarViewRenderer(props) {
|
|
79
|
+
const { model, view, data, locale, onOpenRecord, className } = props;
|
|
80
|
+
const { t } = useTranslation();
|
|
81
|
+
const [month, setMonth] = React.useState(() => {
|
|
82
|
+
const n = new Date();
|
|
83
|
+
return new Date(n.getFullYear(), n.getMonth(), 1, 12);
|
|
84
|
+
});
|
|
85
|
+
const [rows, setRows] = React.useState(null);
|
|
86
|
+
const [error, setError] = React.useState(false);
|
|
87
|
+
const { first, last } = monthRange(month);
|
|
88
|
+
React.useEffect(() => {
|
|
89
|
+
let cancelled = false;
|
|
90
|
+
setRows(null);
|
|
91
|
+
setError(false);
|
|
92
|
+
data
|
|
93
|
+
.list(model, {
|
|
94
|
+
[`f_${view.start_field}`]: `RANGE:${first},${last}`,
|
|
95
|
+
per_page: MAX_ROWS,
|
|
96
|
+
sortBy: view.start_field,
|
|
97
|
+
order: 'asc',
|
|
98
|
+
})
|
|
99
|
+
.then((res) => !cancelled && setRows(res.rows))
|
|
100
|
+
.catch(() => !cancelled && setError(true));
|
|
101
|
+
return () => {
|
|
102
|
+
cancelled = true;
|
|
103
|
+
};
|
|
104
|
+
}, [data, model, view.start_field, first, last]);
|
|
105
|
+
const monthLabel = React.useMemo(() => {
|
|
106
|
+
try {
|
|
107
|
+
return new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' }).format(month);
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return dayKey(month).slice(0, 7);
|
|
111
|
+
}
|
|
112
|
+
}, [locale, month]);
|
|
113
|
+
const weekdayLabels = React.useMemo(() => {
|
|
114
|
+
const monday = new Date(2024, 0, 1, 12); // a Monday
|
|
115
|
+
return Array.from({ length: 7 }, (_, i) => {
|
|
116
|
+
const d = new Date(monday);
|
|
117
|
+
d.setDate(monday.getDate() + i);
|
|
118
|
+
try {
|
|
119
|
+
return new Intl.DateTimeFormat(locale, { weekday: 'short' }).format(d);
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return String(i);
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}, [locale]);
|
|
126
|
+
const byDay = React.useMemo(() => bucketByDay(toCalendarEntries(rows ?? [], view)), [rows, view]);
|
|
127
|
+
const shift = (n) => setMonth((m) => new Date(m.getFullYear(), m.getMonth() + n, 1, 12));
|
|
128
|
+
const today = dayKey(new Date());
|
|
129
|
+
return (_jsxs("div", { className: className, "data-testid": "calendar-view", children: [_jsxs("div", { className: "mb-3 flex items-center justify-between gap-2", children: [_jsx("h2", { className: "text-base font-semibold capitalize text-foreground", "aria-live": "polite", children: monthLabel }), _jsxs("div", { className: "flex gap-1", children: [_jsx(Button, { variant: "outline", size: "icon", "aria-label": t('metacore.views.prev_month', 'Mes anterior'), onClick: () => shift(-1), children: _jsx(ChevronLeft, { "aria-hidden": true, className: "h-4 w-4" }) }), _jsx(Button, { variant: "outline", size: "icon", "aria-label": t('metacore.views.next_month', 'Mes siguiente'), onClick: () => shift(1), children: _jsx(ChevronRight, { "aria-hidden": true, className: "h-4 w-4" }) })] })] }), error ? (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: t('metacore.views.error', 'No se pudo cargar la información.') })) : !rows ? (_jsx(ViewSkeleton, { height: 480 })) : (_jsxs("div", { role: "grid", "aria-label": monthLabel, className: "overflow-hidden rounded-lg border", children: [_jsx("div", { role: "row", className: "grid grid-cols-7 border-b bg-muted/40", children: weekdayLabels.map((w) => (_jsx("div", { role: "columnheader", className: "px-2 py-1 text-xs font-medium text-muted-foreground", children: w }, w))) }), weeksOf(month).map((week) => (_jsx("div", { role: "row", className: "grid grid-cols-7", children: week.map((d) => {
|
|
130
|
+
const k = dayKey(d);
|
|
131
|
+
const items = byDay.get(k) ?? [];
|
|
132
|
+
const outside = d.getMonth() !== month.getMonth();
|
|
133
|
+
return (_jsxs("div", { role: "gridcell", "aria-label": k, "data-day": k, className: [
|
|
134
|
+
'min-h-[6rem] border-b border-r p-1 text-xs',
|
|
135
|
+
outside ? 'bg-muted/20 text-muted-foreground' : '',
|
|
136
|
+
].join(' '), children: [_jsx("div", { className: ['mb-1 text-right', k === today ? 'font-semibold text-primary' : ''].join(' '), children: d.getDate() }), _jsxs("ul", { className: "space-y-1", children: [items.slice(0, 3).map((e) => (_jsx("li", { children: _jsxs("button", { type: "button", className: "w-full truncate rounded px-1 py-0.5 text-left hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", onClick: () => onOpenRecord?.(e.row), title: e.title, children: [e.color ? (_jsx(Badge, { variant: "outline", className: "mr-1 px-1 py-0 text-[10px]", children: e.color })) : null, e.title] }) }, e.key))), items.length > 3 ? (_jsx("li", { className: "px-1 text-muted-foreground", children: t('metacore.views.more_count', '+{{count}} más', { count: items.length - 3 }) })) : null] })] }, k));
|
|
137
|
+
}) }, dayKey(week[0]))))] }))] }));
|
|
138
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { WidgetData } from '../dashboard-types';
|
|
3
|
+
import type { ChartRequest, PanelRendererProps, ViewDataSource, ViewRendererProps } from './types';
|
|
4
|
+
/** Load one declared chart; exposes loading/error so tests and hosts can assert. */
|
|
5
|
+
export declare function useChartData(data: ViewDataSource, req: ChartRequest | null): {
|
|
6
|
+
loading: boolean;
|
|
7
|
+
data?: WidgetData;
|
|
8
|
+
error?: Error;
|
|
9
|
+
};
|
|
10
|
+
/** `view_type: chart` on a nav entry. */
|
|
11
|
+
export default function ChartViewRenderer(props: ViewRendererProps<'chart'>): React.JSX.Element | null;
|
|
12
|
+
/** `kind: chart` detail panel (query scoped to the record's relation). */
|
|
13
|
+
export declare function ChartPanel({ panel, model, record, data, locale, currency }: PanelRendererProps): React.JSX.Element | null;
|
|
14
|
+
//# sourceMappingURL=chart-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart-view.d.ts","sourceRoot":"","sources":["../../src/views/chart-view.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAuB,UAAU,EAAgB,MAAM,oBAAoB,CAAA;AAGvF,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAWlG,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,IAAI,EAAE,cAAc,EAAE,GAAG,EAAE,YAAY,GAAG,IAAI;aACnB,OAAO;WAAS,UAAU;YAAU,KAAK;EAkBhG;AAgDD,yCAAyC;AACzC,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC,4BAgB1E;AAED,0EAA0E;AAC1E,wBAAgB,UAAU,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,kBAAkB,4BAY9F"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// `view_type: chart` and `kind: chart` detail panels. Reuses the dashboard
|
|
3
|
+
// widgets (same WidgetQuery, same aggregation engine on the host, same cards):
|
|
4
|
+
// no new chart code, no client-side math. This module is a lazy chunk; it is
|
|
5
|
+
// the only place views reach recharts (through ../widgets/charts).
|
|
6
|
+
import * as React from 'react';
|
|
7
|
+
import { useTranslation } from 'react-i18next';
|
|
8
|
+
import { AreaWidget, BarWidget, DonutWidget, LineWidget, PieWidget } from '../widgets/charts';
|
|
9
|
+
import { ViewSkeleton } from './skeleton';
|
|
10
|
+
const BY_KIND = {
|
|
11
|
+
bar: BarWidget,
|
|
12
|
+
line: LineWidget,
|
|
13
|
+
area: AreaWidget,
|
|
14
|
+
pie: PieWidget,
|
|
15
|
+
donut: DonutWidget,
|
|
16
|
+
};
|
|
17
|
+
/** Load one declared chart; exposes loading/error so tests and hosts can assert. */
|
|
18
|
+
export function useChartData(data, req) {
|
|
19
|
+
const [state, setState] = React.useState({
|
|
20
|
+
loading: true,
|
|
21
|
+
});
|
|
22
|
+
const sig = req ? JSON.stringify(req) : '';
|
|
23
|
+
React.useEffect(() => {
|
|
24
|
+
if (!req)
|
|
25
|
+
return;
|
|
26
|
+
let cancelled = false;
|
|
27
|
+
setState({ loading: true });
|
|
28
|
+
data.chart(req).then((d) => !cancelled && setState({ loading: false, data: d }), (e) => !cancelled && setState({ loading: false, error: e instanceof Error ? e : new Error(String(e)) }));
|
|
29
|
+
return () => {
|
|
30
|
+
cancelled = true;
|
|
31
|
+
};
|
|
32
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
33
|
+
}, [data, sig]);
|
|
34
|
+
return state;
|
|
35
|
+
}
|
|
36
|
+
function ChartBody({ chart, title, req, data, locale, currency, }) {
|
|
37
|
+
const { t } = useTranslation();
|
|
38
|
+
const state = useChartData(data, req);
|
|
39
|
+
const Widget = BY_KIND[chart.kind];
|
|
40
|
+
if (state.loading)
|
|
41
|
+
return _jsx(ViewSkeleton, { height: 260 });
|
|
42
|
+
if (state.error) {
|
|
43
|
+
return (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: t('metacore.views.error', 'No se pudo cargar la información.') }));
|
|
44
|
+
}
|
|
45
|
+
if (!Widget)
|
|
46
|
+
return null;
|
|
47
|
+
const spec = {
|
|
48
|
+
key: req.panelKey ?? `${req.model}.chart`,
|
|
49
|
+
title: t(title),
|
|
50
|
+
kind: chart.kind,
|
|
51
|
+
format: chart.format,
|
|
52
|
+
};
|
|
53
|
+
return (_jsx("div", { "data-testid": "chart-view", "data-kind": chart.kind, children: _jsx(Widget, { spec: spec, data: state.data, locale: locale, currency: currency, emptyText: t('metacore.views.empty', 'Sin datos todavía.') }) }));
|
|
54
|
+
}
|
|
55
|
+
/** `view_type: chart` on a nav entry. */
|
|
56
|
+
export default function ChartViewRenderer(props) {
|
|
57
|
+
const { view, model, data, metadata, locale, currency, className } = props;
|
|
58
|
+
if (!view.query)
|
|
59
|
+
return null;
|
|
60
|
+
const req = { model, query: view.query };
|
|
61
|
+
return (_jsx("div", { className: className, children: _jsx(ChartBody, { chart: view, title: metadata?.title ?? model, req: req, data: data, locale: locale, currency: currency }) }));
|
|
62
|
+
}
|
|
63
|
+
/** `kind: chart` detail panel (query scoped to the record's relation). */
|
|
64
|
+
export function ChartPanel({ panel, model, record, data, locale, currency }) {
|
|
65
|
+
const chart = panel.chart;
|
|
66
|
+
const id = record.id;
|
|
67
|
+
if (!chart?.query || id === undefined || id === null)
|
|
68
|
+
return null;
|
|
69
|
+
const req = {
|
|
70
|
+
model,
|
|
71
|
+
query: chart.query,
|
|
72
|
+
relation: chart.relation,
|
|
73
|
+
recordId: String(id),
|
|
74
|
+
panelKey: panel.key,
|
|
75
|
+
};
|
|
76
|
+
return _jsx(ChartBody, { chart: chart, title: panel.title, req: req, data: data, locale: locale, currency: currency });
|
|
77
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ApiClient } from '../api-context';
|
|
2
|
+
import type { ViewDataSource } from './types';
|
|
3
|
+
export interface ApiViewDataSourceOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Endpoint the host serves declared view/panel charts on (`POST`, body
|
|
6
|
+
* {@link ChartRequest} in snake_case, response `{ success, data: WidgetData }`).
|
|
7
|
+
* Default `/views/chart`.
|
|
8
|
+
*/
|
|
9
|
+
chartPath?: string;
|
|
10
|
+
/** Capability query endpoint (`POST { capability, input }`). Default `/capabilities/query`. */
|
|
11
|
+
capabilityPath?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function createApiViewDataSource(api: ApiClient, opts?: ApiViewDataSourceOptions): ViewDataSource;
|
|
14
|
+
/**
|
|
15
|
+
* Map a timeline source `input` (`record.<column>` | `const:<literal>`) onto
|
|
16
|
+
* the record. Unknown forms are rejected (the kernel validates them; a host
|
|
17
|
+
* serving something else is a bug, not something to guess at).
|
|
18
|
+
*/
|
|
19
|
+
export declare function resolveCapabilityInput(input: Record<string, string> | undefined, record: Record<string, unknown>): Record<string, unknown>;
|
|
20
|
+
/** Read the `items` array (dot path) out of a capability output. */
|
|
21
|
+
export declare function pickItems(output: unknown, path: string | undefined): Record<string, unknown>[];
|
|
22
|
+
/** Parse a date-ish value (ISO string, epoch ms, Date). */
|
|
23
|
+
export declare function toDate(v: unknown): Date | null;
|
|
24
|
+
/** `YYYY-MM-DD` of a date in local time. */
|
|
25
|
+
export declare function dayKey(d: Date): string;
|
|
26
|
+
/** Sort entries by a date field, newest first (stable for equal dates). */
|
|
27
|
+
export declare function sortByDate<T extends Record<string, unknown>>(rows: T[], field: string, dir?: 'asc' | 'desc'): T[];
|
|
28
|
+
/** Display string of a cell value (renderers show what the server sent). */
|
|
29
|
+
export declare function displayValue(v: unknown): string;
|
|
30
|
+
//# sourceMappingURL=data-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-source.d.ts","sourceRoot":"","sources":["../../src/views/data-source.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAE/C,OAAO,KAAK,EAAgB,cAAc,EAA4B,MAAM,SAAS,CAAA;AAErF,MAAM,WAAW,wBAAwB;IACrC;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,+FAA+F;IAC/F,cAAc,CAAC,EAAE,MAAM,CAAA;CAC1B;AAaD,wBAAgB,uBAAuB,CACnC,GAAG,EAAE,SAAS,EACd,IAAI,GAAE,wBAA6B,GACpC,cAAc,CA4BhB;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,EACzC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAQzB;AAED,oEAAoE;AACpE,wBAAgB,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAM9F;AAED,2DAA2D;AAC3D,wBAAgB,MAAM,CAAC,CAAC,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAU9C;AAED,4CAA4C;AAC5C,wBAAgB,MAAM,CAAC,CAAC,EAAE,IAAI,GAAG,MAAM,CAGtC;AAED,2EAA2E;AAC3E,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,KAAK,GAAG,MAAe,GAAG,CAAC,EAAE,CAMzH;AAED,4EAA4E;AAC5E,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAQ/C"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
function unwrap(body) {
|
|
2
|
+
const env = body;
|
|
3
|
+
if (env && typeof env === 'object' && 'success' in env) {
|
|
4
|
+
if (env.success === false)
|
|
5
|
+
throw new Error(env.message || 'request failed');
|
|
6
|
+
return { data: env.data, total: env.meta?.total };
|
|
7
|
+
}
|
|
8
|
+
return { data: body };
|
|
9
|
+
}
|
|
10
|
+
export function createApiViewDataSource(api, opts = {}) {
|
|
11
|
+
const chartPath = opts.chartPath ?? '/views/chart';
|
|
12
|
+
const capabilityPath = opts.capabilityPath ?? '/capabilities/query';
|
|
13
|
+
return {
|
|
14
|
+
async list(model, params) {
|
|
15
|
+
const res = await api.get(`/data/${encodeURIComponent(model)}`, params ? { params } : undefined);
|
|
16
|
+
const { data, total } = unwrap(res.data);
|
|
17
|
+
return { rows: Array.isArray(data) ? data : [], total };
|
|
18
|
+
},
|
|
19
|
+
async record(model, id) {
|
|
20
|
+
const res = await api.get(`/data/${encodeURIComponent(model)}/${encodeURIComponent(id)}`);
|
|
21
|
+
return unwrap(res.data).data ?? null;
|
|
22
|
+
},
|
|
23
|
+
async chart(req) {
|
|
24
|
+
const res = await api.post(chartPath, {
|
|
25
|
+
model: req.model,
|
|
26
|
+
query: req.query,
|
|
27
|
+
relation: req.relation,
|
|
28
|
+
record_id: req.recordId,
|
|
29
|
+
panel_key: req.panelKey,
|
|
30
|
+
});
|
|
31
|
+
return unwrap(res.data).data ?? {};
|
|
32
|
+
},
|
|
33
|
+
async capability(key, input) {
|
|
34
|
+
const res = await api.post(capabilityPath, { capability: key, input });
|
|
35
|
+
return unwrap(res.data).data;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Map a timeline source `input` (`record.<column>` | `const:<literal>`) onto
|
|
41
|
+
* the record. Unknown forms are rejected (the kernel validates them; a host
|
|
42
|
+
* serving something else is a bug, not something to guess at).
|
|
43
|
+
*/
|
|
44
|
+
export function resolveCapabilityInput(input, record) {
|
|
45
|
+
const out = {};
|
|
46
|
+
for (const [key, ref] of Object.entries(input ?? {})) {
|
|
47
|
+
if (ref.startsWith('record.'))
|
|
48
|
+
out[key] = record[ref.slice('record.'.length)];
|
|
49
|
+
else if (ref.startsWith('const:'))
|
|
50
|
+
out[key] = ref.slice('const:'.length);
|
|
51
|
+
else
|
|
52
|
+
throw new Error(`timeline source input "${key}": unsupported reference "${ref}"`);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
/** Read the `items` array (dot path) out of a capability output. */
|
|
57
|
+
export function pickItems(output, path) {
|
|
58
|
+
let cur = output;
|
|
59
|
+
for (const seg of (path ?? '').split('.').filter(Boolean)) {
|
|
60
|
+
cur = cur && typeof cur === 'object' ? cur[seg] : undefined;
|
|
61
|
+
}
|
|
62
|
+
return Array.isArray(cur) ? cur.filter((x) => x && typeof x === 'object') : [];
|
|
63
|
+
}
|
|
64
|
+
/** Parse a date-ish value (ISO string, epoch ms, Date). */
|
|
65
|
+
export function toDate(v) {
|
|
66
|
+
if (v instanceof Date)
|
|
67
|
+
return Number.isNaN(v.getTime()) ? null : v;
|
|
68
|
+
if (typeof v === 'number')
|
|
69
|
+
return new Date(v);
|
|
70
|
+
if (typeof v === 'string' && v) {
|
|
71
|
+
// Date-only values are calendar days: anchor at local noon so a time
|
|
72
|
+
// zone offset never moves them to the previous day.
|
|
73
|
+
const d = /^\d{4}-\d{2}-\d{2}$/.test(v) ? new Date(`${v}T12:00:00`) : new Date(v);
|
|
74
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
75
|
+
}
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
/** `YYYY-MM-DD` of a date in local time. */
|
|
79
|
+
export function dayKey(d) {
|
|
80
|
+
const p = (n) => String(n).padStart(2, '0');
|
|
81
|
+
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())}`;
|
|
82
|
+
}
|
|
83
|
+
/** Sort entries by a date field, newest first (stable for equal dates). */
|
|
84
|
+
export function sortByDate(rows, field, dir = 'desc') {
|
|
85
|
+
const k = dir === 'desc' ? -1 : 1;
|
|
86
|
+
return rows
|
|
87
|
+
.map((r, i) => ({ r, i, t: toDate(r[field])?.getTime() ?? Number.NEGATIVE_INFINITY }))
|
|
88
|
+
.sort((a, b) => (a.t === b.t ? a.i - b.i : (a.t - b.t) * k))
|
|
89
|
+
.map((x) => x.r);
|
|
90
|
+
}
|
|
91
|
+
/** Display string of a cell value (renderers show what the server sent). */
|
|
92
|
+
export function displayValue(v) {
|
|
93
|
+
if (v === null || v === undefined)
|
|
94
|
+
return '';
|
|
95
|
+
if (typeof v === 'object') {
|
|
96
|
+
const o = v;
|
|
97
|
+
for (const k of ['label', 'name', 'title', 'display'])
|
|
98
|
+
if (typeof o[k] === 'string')
|
|
99
|
+
return o[k];
|
|
100
|
+
return JSON.stringify(v);
|
|
101
|
+
}
|
|
102
|
+
return String(v);
|
|
103
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type { DeclarativeViewType, DeclarativeViewConfig, ViewDataSource, ViewRows, ViewListParams, ChartRequest, ViewRendererProps, PanelRendererProps, ViewRendererComponent, PanelRendererComponent, ViewRendererLoader, PanelRendererLoader, } from './types';
|
|
2
|
+
export { DECLARATIVE_VIEW_TYPES, isDeclarativeViewType, registerViewRenderer, registerPanelRenderer, hasViewRenderer, hasPanelRenderer, preloadViewRenderer, DeclarativeView, DetailPanels, ViewSkeleton, type DeclarativeViewProps, type DetailPanelsProps, } from './registry';
|
|
3
|
+
export { createApiViewDataSource, resolveCapabilityInput, pickItems, type ApiViewDataSourceOptions, } from './data-source';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/views/index.ts"],"names":[],"mappings":"AAGA,YAAY,EACR,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACd,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,GACtB,MAAM,SAAS,CAAA;AAChB,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,GACzB,MAAM,YAAY,CAAA;AACnB,OAAO,EACH,uBAAuB,EACvB,sBAAsB,EACtB,SAAS,EACT,KAAK,wBAAwB,GAChC,MAAM,eAAe,CAAA"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { DECLARATIVE_VIEW_TYPES, isDeclarativeViewType, registerViewRenderer, registerPanelRenderer, hasViewRenderer, hasPanelRenderer, preloadViewRenderer, DeclarativeView, DetailPanels, ViewSkeleton, } from './registry';
|
|
2
|
+
export { createApiViewDataSource, resolveCapabilityInput, pickItems, } from './data-source';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { MapPoint, MapView } from '@asteby/metacore-sdk';
|
|
3
|
+
import type { PanelRendererProps, ViewRendererProps } from './types';
|
|
4
|
+
export interface MapFeature {
|
|
5
|
+
key: string;
|
|
6
|
+
lat: number;
|
|
7
|
+
lng: number;
|
|
8
|
+
/** `color_by` value (option key); the renderer maps it to a token. */
|
|
9
|
+
color?: string;
|
|
10
|
+
/** Popup fields in `popup[]` order. */
|
|
11
|
+
popup: Array<{
|
|
12
|
+
field: string;
|
|
13
|
+
value: string;
|
|
14
|
+
}>;
|
|
15
|
+
row: Record<string, unknown>;
|
|
16
|
+
}
|
|
17
|
+
/** Coordinates of a row: `point {lat,lng}` columns or a GeoJSON Point column. */
|
|
18
|
+
export declare function rowCoordinates(row: Record<string, unknown>, point: MapPoint | undefined, geometry: string | undefined): {
|
|
19
|
+
lat: number;
|
|
20
|
+
lng: number;
|
|
21
|
+
} | null;
|
|
22
|
+
/** Pure: rows → map features (rows without valid coordinates are skipped). */
|
|
23
|
+
export declare function toMapFeatures(rows: Record<string, unknown>[], view: MapView): MapFeature[];
|
|
24
|
+
/** Pure: ordered route points of a record's children (`route.order_by` ascending). */
|
|
25
|
+
export declare function toRoutePoints(children: Record<string, unknown>[], route: NonNullable<MapView['route']>): Array<{
|
|
26
|
+
lat: number;
|
|
27
|
+
lng: number;
|
|
28
|
+
}>;
|
|
29
|
+
/** "Open in map" link (OpenStreetMap; no key, no tracking script). */
|
|
30
|
+
export declare function openInMapHref(lat: number, lng: number): string;
|
|
31
|
+
export declare function MapFeatureList({ features, onOpen, }: {
|
|
32
|
+
features: MapFeature[];
|
|
33
|
+
onOpen?: (row: Record<string, unknown>) => void;
|
|
34
|
+
}): React.JSX.Element;
|
|
35
|
+
/** `view_type: map` fallback renderer: the accessible list of features. */
|
|
36
|
+
export default function MapViewFallback(props: ViewRendererProps<'map'>): React.JSX.Element;
|
|
37
|
+
/** `kind: map` panel fallback: the record's point and its route stops. */
|
|
38
|
+
export declare function MapPanel({ panel, record, metadata, data }: PanelRendererProps): React.JSX.Element | null;
|
|
39
|
+
//# sourceMappingURL=map-view.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map-view.d.ts","sourceRoot":"","sources":["../../src/views/map-view.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAA;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAMpE,MAAM,WAAW,UAAU;IACvB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;IACX,sEAAsE;IACtE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,uCAAuC;IACvC,KAAK,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC9C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAOD,iFAAiF;AACjF,wBAAgB,cAAc,CAC1B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,KAAK,EAAE,QAAQ,GAAG,SAAS,EAC3B,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC7B;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAwBrC;AAED,8EAA8E;AAC9E,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,GAAG,UAAU,EAAE,CAc1F;AAED,sFAAsF;AACtF,wBAAgB,aAAa,CACzB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,EACnC,KAAK,EAAE,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GACrC,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAC,CAKrC;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,wBAAgB,cAAc,CAAC,EAC3B,QAAQ,EACR,MAAM,GACT,EAAE;IACC,QAAQ,EAAE,UAAU,EAAE,CAAA;IACtB,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;CAClD,qBAgDA;AAED,2EAA2E;AAC3E,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,KAAK,EAAE,iBAAiB,CAAC,KAAK,CAAC,qBA4BtE;AAED,0EAA0E;AAC1E,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,EAAE,kBAAkB,4BA6B7E"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
// `view_type: map` and `kind: map` detail panels — CONTRACT + ACCESSIBLE
|
|
3
|
+
// FALLBACK. The interactive renderer (MapLibre, clustering, layers, dark
|
|
4
|
+
// style) belongs to `@asteby/metacore-maps`, which registers itself with
|
|
5
|
+
// `registerViewRenderer('map', …)` / `registerPanelRenderer('map', …)`. Until a
|
|
6
|
+
// host does, this chunk renders what every map must offer anyway: the
|
|
7
|
+
// equivalent keyboard-navigable list of features, each with an "open in map"
|
|
8
|
+
// link. The pure helpers below (features, route) are the shared contract the
|
|
9
|
+
// maps package builds on, so both renderers read the manifest identically.
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
import { useTranslation } from 'react-i18next';
|
|
12
|
+
import { MapPin } from 'lucide-react';
|
|
13
|
+
import { buildRelationFilterParams } from '../dynamic-relation-helpers';
|
|
14
|
+
import { displayValue } from './data-source';
|
|
15
|
+
import { ViewSkeleton } from './skeleton';
|
|
16
|
+
const MAX_FEATURES = 500;
|
|
17
|
+
function num(v) {
|
|
18
|
+
const n = typeof v === 'number' ? v : typeof v === 'string' && v.trim() !== '' ? Number(v) : NaN;
|
|
19
|
+
return Number.isFinite(n) ? n : null;
|
|
20
|
+
}
|
|
21
|
+
/** Coordinates of a row: `point {lat,lng}` columns or a GeoJSON Point column. */
|
|
22
|
+
export function rowCoordinates(row, point, geometry) {
|
|
23
|
+
if (point) {
|
|
24
|
+
const lat = num(row[point.lat]);
|
|
25
|
+
const lng = num(row[point.lng]);
|
|
26
|
+
if (lat === null || lng === null || Math.abs(lat) > 90 || Math.abs(lng) > 180)
|
|
27
|
+
return null;
|
|
28
|
+
return { lat, lng };
|
|
29
|
+
}
|
|
30
|
+
if (geometry) {
|
|
31
|
+
let g = row[geometry];
|
|
32
|
+
if (typeof g === 'string') {
|
|
33
|
+
try {
|
|
34
|
+
g = JSON.parse(g);
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const geo = g;
|
|
41
|
+
if (geo?.type === 'Point' && Array.isArray(geo.coordinates)) {
|
|
42
|
+
const lng = num(geo.coordinates[0]);
|
|
43
|
+
const lat = num(geo.coordinates[1]);
|
|
44
|
+
if (lat !== null && lng !== null)
|
|
45
|
+
return { lat, lng };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/** Pure: rows → map features (rows without valid coordinates are skipped). */
|
|
51
|
+
export function toMapFeatures(rows, view) {
|
|
52
|
+
const out = [];
|
|
53
|
+
rows.forEach((row, i) => {
|
|
54
|
+
const c = rowCoordinates(row, view.point, view.geometry);
|
|
55
|
+
if (!c)
|
|
56
|
+
return;
|
|
57
|
+
out.push({
|
|
58
|
+
key: String(row.id ?? i),
|
|
59
|
+
...c,
|
|
60
|
+
color: view.color_by ? displayValue(row[view.color_by]) || undefined : undefined,
|
|
61
|
+
popup: (view.popup ?? []).map((field) => ({ field, value: displayValue(row[field]) })),
|
|
62
|
+
row,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
/** Pure: ordered route points of a record's children (`route.order_by` ascending). */
|
|
68
|
+
export function toRoutePoints(children, route) {
|
|
69
|
+
return [...children]
|
|
70
|
+
.sort((a, b) => String(a[route.order_by] ?? '').localeCompare(String(b[route.order_by] ?? '')))
|
|
71
|
+
.map((r) => rowCoordinates(r, route.point, undefined))
|
|
72
|
+
.filter((p) => p !== null);
|
|
73
|
+
}
|
|
74
|
+
/** "Open in map" link (OpenStreetMap; no key, no tracking script). */
|
|
75
|
+
export function openInMapHref(lat, lng) {
|
|
76
|
+
return `https://www.openstreetmap.org/?mlat=${lat}&mlon=${lng}#map=16/${lat}/${lng}`;
|
|
77
|
+
}
|
|
78
|
+
export function MapFeatureList({ features, onOpen, }) {
|
|
79
|
+
const { t } = useTranslation();
|
|
80
|
+
if (features.length === 0) {
|
|
81
|
+
return (_jsx("p", { className: "py-8 text-center text-sm text-muted-foreground", "data-testid": "map-empty", children: t('metacore.views.map_empty', 'No hay ubicaciones para mostrar.') }));
|
|
82
|
+
}
|
|
83
|
+
return (_jsx("ul", { className: "divide-y rounded-lg border", "data-testid": "map-feature-list", children: features.map((f) => {
|
|
84
|
+
const label = f.popup[0]?.value || f.key;
|
|
85
|
+
return (_jsxs("li", { className: "flex items-start gap-3 p-3", children: [_jsx(MapPin, { "aria-hidden": true, className: "mt-0.5 h-4 w-4 shrink-0 text-primary" }), _jsxs("div", { className: "min-w-0 flex-1", children: [onOpen ? (_jsx("button", { type: "button", className: "truncate text-left text-sm font-medium text-foreground hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring", onClick: () => onOpen(f.row), children: label })) : (_jsx("span", { className: "truncate text-sm font-medium text-foreground", children: label })), f.popup.length > 1 || f.color ? (_jsx("p", { className: "truncate text-xs text-muted-foreground", children: [f.color, ...f.popup.slice(1).map((p) => p.value)].filter(Boolean).join(' · ') })) : null] }), _jsx("a", { href: openInMapHref(f.lat, f.lng), target: "_blank", rel: "noopener noreferrer", className: "shrink-0 text-xs text-primary underline-offset-2 hover:underline", "aria-label": t('metacore.views.open_in_map_of', 'Abrir en mapa: {{label}}', { label }), children: t('metacore.views.open_in_map', 'Abrir en mapa') })] }, f.key));
|
|
86
|
+
}) }));
|
|
87
|
+
}
|
|
88
|
+
/** `view_type: map` fallback renderer: the accessible list of features. */
|
|
89
|
+
export default function MapViewFallback(props) {
|
|
90
|
+
const { model, view, data, onOpenRecord, className } = props;
|
|
91
|
+
const { t } = useTranslation();
|
|
92
|
+
const [rows, setRows] = React.useState(null);
|
|
93
|
+
const [error, setError] = React.useState(false);
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
let cancelled = false;
|
|
96
|
+
data
|
|
97
|
+
.list(model, { per_page: MAX_FEATURES })
|
|
98
|
+
.then((res) => !cancelled && setRows(res.rows))
|
|
99
|
+
.catch(() => !cancelled && setError(true));
|
|
100
|
+
return () => {
|
|
101
|
+
cancelled = true;
|
|
102
|
+
};
|
|
103
|
+
}, [data, model]);
|
|
104
|
+
if (error) {
|
|
105
|
+
return (_jsx("p", { role: "alert", className: "text-sm text-destructive", children: t('metacore.views.error', 'No se pudo cargar la información.') }));
|
|
106
|
+
}
|
|
107
|
+
if (!rows)
|
|
108
|
+
return _jsx(ViewSkeleton, {});
|
|
109
|
+
return (_jsx("div", { className: className, "data-testid": "map-view-fallback", children: _jsx(MapFeatureList, { features: toMapFeatures(rows, view), onOpen: onOpenRecord }) }));
|
|
110
|
+
}
|
|
111
|
+
/** `kind: map` panel fallback: the record's point and its route stops. */
|
|
112
|
+
export function MapPanel({ panel, record, metadata, data }) {
|
|
113
|
+
const view = panel.map;
|
|
114
|
+
const route = view?.route;
|
|
115
|
+
const rel = route ? metadata?.relations?.find((r) => r.name === route.relation) : undefined;
|
|
116
|
+
const [stops, setStops] = React.useState([]);
|
|
117
|
+
const recordId = record.id;
|
|
118
|
+
React.useEffect(() => {
|
|
119
|
+
if (!route || !rel || recordId === undefined || recordId === null)
|
|
120
|
+
return;
|
|
121
|
+
let cancelled = false;
|
|
122
|
+
data
|
|
123
|
+
.list(rel.through, {
|
|
124
|
+
...buildRelationFilterParams(rel.foreign_key, String(recordId), rel.scope),
|
|
125
|
+
per_page: MAX_FEATURES,
|
|
126
|
+
sortBy: route.order_by,
|
|
127
|
+
order: 'asc',
|
|
128
|
+
})
|
|
129
|
+
.then((res) => !cancelled && setStops(toRoutePoints(res.rows, route)))
|
|
130
|
+
.catch(() => undefined);
|
|
131
|
+
return () => {
|
|
132
|
+
cancelled = true;
|
|
133
|
+
};
|
|
134
|
+
}, [data, route, rel, recordId]);
|
|
135
|
+
if (!view)
|
|
136
|
+
return null;
|
|
137
|
+
const own = toMapFeatures([record], { ...view, popup: view.popup ?? [] });
|
|
138
|
+
const features = [
|
|
139
|
+
...stops.map((s, i) => ({ key: `stop-${i}`, ...s, popup: [{ field: '#', value: `#${i + 1}` }], row: {} })),
|
|
140
|
+
...own,
|
|
141
|
+
];
|
|
142
|
+
return _jsx(MapFeatureList, { features: features });
|
|
143
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { PanelRendererProps } from './types';
|
|
3
|
+
export type StatFormat = 'number' | 'currency' | 'percent' | 'compact' | 'date' | 'datetime' | 'relative_date';
|
|
4
|
+
/** Pure: format one stat value for display. `now` is injectable for tests. */
|
|
5
|
+
export declare function formatStat(value: unknown, format: string | undefined, opts?: {
|
|
6
|
+
locale?: string;
|
|
7
|
+
currency?: string;
|
|
8
|
+
timeZone?: string;
|
|
9
|
+
now?: Date;
|
|
10
|
+
}): string;
|
|
11
|
+
export declare function StatsPanelView({ panel, record, metadata, locale, currency, timeZone }: PanelRendererProps): React.JSX.Element;
|
|
12
|
+
export declare function RelationPanelView({ panel, record, metadata, data, onOpenRecord }: PanelRendererProps): React.JSX.Element | null;
|
|
13
|
+
//# sourceMappingURL=panels.d.ts.map
|
|
@@ -0,0 +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;AAIjD,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"}
|