@asteby/metacore-runtime-react 18.10.2 → 18.11.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 +22 -0
- package/dist/activity-diff.d.ts +70 -0
- package/dist/activity-diff.d.ts.map +1 -0
- package/dist/activity-diff.js +133 -0
- package/dist/activity-timeline.d.ts +56 -0
- package/dist/activity-timeline.d.ts.map +1 -0
- package/dist/activity-timeline.js +215 -0
- package/dist/activity-value-renderer.d.ts +33 -0
- package/dist/activity-value-renderer.d.ts.map +1 -0
- package/dist/activity-value-renderer.js +213 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/record-history.d.ts +41 -0
- package/dist/record-history.d.ts.map +1 -0
- package/dist/record-history.js +99 -0
- package/package.json +1 -1
- package/src/activity-diff.tsx +298 -0
- package/src/activity-timeline.tsx +574 -0
- package/src/activity-value-renderer.tsx +371 -0
- package/src/index.ts +17 -0
- package/src/record-history.tsx +243 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* activity-value-renderer.tsx
|
|
4
|
+
*
|
|
5
|
+
* Pure, transport-agnostic value renderer for Activity / Time Machine diffs.
|
|
6
|
+
* Reuses the same display-type logic as dynamic-columns.tsx (currency, status,
|
|
7
|
+
* date, boolean, badge, relation, url, tags, color, number, percent) so the
|
|
8
|
+
* diff cells and the table cells are always consistent.
|
|
9
|
+
*
|
|
10
|
+
* Kept in its own module so it has no dependency on tanstack-table or the
|
|
11
|
+
* column-factory machinery — only React + metacore-ui primitives.
|
|
12
|
+
*/
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import * as icons from 'lucide-react';
|
|
15
|
+
import { es, enUS } from 'date-fns/locale';
|
|
16
|
+
import { Badge, Avatar, AvatarImage, AvatarFallback, } from '@asteby/metacore-ui/primitives';
|
|
17
|
+
import { generateBadgeStyles, getInitials, optionColor, relationChipStyles } from '@asteby/metacore-ui/lib';
|
|
18
|
+
import { formatDateCell } from './dynamic-columns';
|
|
19
|
+
import { humanizeToken } from './dynamic-columns-helpers';
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// Internal helpers (mirror dynamic-columns.tsx private helpers)
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
const styleCfg = (col, ...keys) => {
|
|
24
|
+
const cfg = col.styleConfig;
|
|
25
|
+
if (!cfg)
|
|
26
|
+
return undefined;
|
|
27
|
+
for (const k of keys) {
|
|
28
|
+
if (cfg[k] !== undefined && cfg[k] !== null)
|
|
29
|
+
return cfg[k];
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
};
|
|
33
|
+
const formatNumber = (value, opts, locale) => new Intl.NumberFormat(locale || undefined, opts).format(value);
|
|
34
|
+
const statusColorFor = (value) => {
|
|
35
|
+
const v = value.toLowerCase();
|
|
36
|
+
if (['active', 'enabled', 'paid', 'completed', 'done', 'success', 'approved', 'open'].includes(v))
|
|
37
|
+
return '#22c55e';
|
|
38
|
+
if (['pending', 'draft', 'processing', 'in_progress', 'review', 'waiting'].includes(v))
|
|
39
|
+
return '#eab308';
|
|
40
|
+
if (['inactive', 'disabled', 'cancelled', 'canceled', 'failed', 'rejected', 'error', 'closed'].includes(v))
|
|
41
|
+
return '#ef4444';
|
|
42
|
+
return '#6b7280';
|
|
43
|
+
};
|
|
44
|
+
const useIsDarkTheme = () => {
|
|
45
|
+
const [isDark, setIsDark] = React.useState(() => typeof document !== 'undefined' && document.documentElement.classList.contains('dark'));
|
|
46
|
+
React.useEffect(() => {
|
|
47
|
+
if (typeof document === 'undefined')
|
|
48
|
+
return;
|
|
49
|
+
const sync = () => setIsDark(document.documentElement.classList.contains('dark'));
|
|
50
|
+
const observer = new MutationObserver(sync);
|
|
51
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class'] });
|
|
52
|
+
return () => observer.disconnect();
|
|
53
|
+
}, []);
|
|
54
|
+
return isDark;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Renders a single field value from an activity event using the same display
|
|
58
|
+
* type logic as `defaultGetDynamicColumns`. Pass a `ColumnDefinition` to get
|
|
59
|
+
* rich formatting (currency, status badge, date, boolean, etc.); without it
|
|
60
|
+
* the component falls back to a plain string representation.
|
|
61
|
+
*/
|
|
62
|
+
export const ActivityValueRenderer = ({ value, col, timeZone, currency, locale = 'es', }) => {
|
|
63
|
+
const isDark = useIsDarkTheme();
|
|
64
|
+
const dateLocale = locale === 'en' ? enUS : es;
|
|
65
|
+
// null / undefined → dash
|
|
66
|
+
if (value === null || value === undefined || value === '') {
|
|
67
|
+
return _jsx("span", { className: "text-muted-foreground", children: "\u2014" });
|
|
68
|
+
}
|
|
69
|
+
// No column metadata → plain string
|
|
70
|
+
if (!col) {
|
|
71
|
+
if (typeof value === 'object') {
|
|
72
|
+
return (_jsx("span", { className: "text-muted-foreground text-xs font-mono", children: JSON.stringify(value) }));
|
|
73
|
+
}
|
|
74
|
+
return _jsx("span", { className: "font-medium text-sm", children: String(value) });
|
|
75
|
+
}
|
|
76
|
+
const renderAs = col.cellStyle ?? col.type;
|
|
77
|
+
// -----------------------------------------------------------------------
|
|
78
|
+
// Badge / Status / Select / Option
|
|
79
|
+
// -----------------------------------------------------------------------
|
|
80
|
+
if (renderAs === 'badge' || renderAs === 'status' || renderAs === 'select' || renderAs === 'option') {
|
|
81
|
+
const sv = String(value);
|
|
82
|
+
const option = col.options?.find((o) => o.value === sv);
|
|
83
|
+
if (option) {
|
|
84
|
+
const colorSource = option.color || optionColor(option.value || option.label);
|
|
85
|
+
const styles = generateBadgeStyles(colorSource, { isDark });
|
|
86
|
+
return (_jsx(Badge, { variant: "outline", className: "border-0", style: styles, children: option.label }));
|
|
87
|
+
}
|
|
88
|
+
if (renderAs === 'status') {
|
|
89
|
+
const styles = generateBadgeStyles(statusColorFor(sv), { isDark });
|
|
90
|
+
return (_jsx(Badge, { variant: "outline", className: "border-0", style: styles, children: humanizeToken(sv) }));
|
|
91
|
+
}
|
|
92
|
+
return _jsx(Badge, { variant: "outline", children: humanizeToken(sv) });
|
|
93
|
+
}
|
|
94
|
+
// -----------------------------------------------------------------------
|
|
95
|
+
// Date / Datetime / Timestamp
|
|
96
|
+
// -----------------------------------------------------------------------
|
|
97
|
+
if (['date', 'datetime', 'timestamp', 'timestamptz'].includes(renderAs ?? '')) {
|
|
98
|
+
const formatted = formatDateCell(value, renderAs, dateLocale, timeZone);
|
|
99
|
+
if (!formatted)
|
|
100
|
+
return _jsx("span", { className: "text-muted-foreground", children: "\u2014" });
|
|
101
|
+
return (_jsxs("span", { className: "inline-flex items-center gap-1 text-sm text-muted-foreground", title: formatted.title, children: [_jsx(icons.Calendar, { className: "h-3 w-3 opacity-60" }), formatted.display] }));
|
|
102
|
+
}
|
|
103
|
+
// -----------------------------------------------------------------------
|
|
104
|
+
// Boolean
|
|
105
|
+
// -----------------------------------------------------------------------
|
|
106
|
+
if (renderAs === 'boolean') {
|
|
107
|
+
return (_jsxs("span", { className: "inline-flex items-center gap-1", children: [value ? (_jsx(icons.Check, { className: "h-3.5 w-3.5 text-green-500" })) : (_jsx(icons.Minus, { className: "h-3.5 w-3.5 text-muted-foreground" })), _jsx("span", { className: "text-sm text-muted-foreground", children: value ? 'Sí' : 'No' })] }));
|
|
108
|
+
}
|
|
109
|
+
// -----------------------------------------------------------------------
|
|
110
|
+
// Currency
|
|
111
|
+
// -----------------------------------------------------------------------
|
|
112
|
+
if (renderAs === 'currency') {
|
|
113
|
+
const num = typeof value === 'number' ? value : Number(value);
|
|
114
|
+
if (isNaN(num))
|
|
115
|
+
return _jsx("span", { className: "text-muted-foreground", children: "\u2014" });
|
|
116
|
+
const decimals = styleCfg(col, 'decimals') ?? 2;
|
|
117
|
+
const curr = styleCfg(col, 'currency') || currency || 'USD';
|
|
118
|
+
return (_jsx("span", { className: "font-medium tabular-nums text-sm", children: formatNumber(num, { style: 'currency', currency: curr, minimumFractionDigits: decimals, maximumFractionDigits: decimals }, locale) }));
|
|
119
|
+
}
|
|
120
|
+
// -----------------------------------------------------------------------
|
|
121
|
+
// Number / Percent / Progress
|
|
122
|
+
// -----------------------------------------------------------------------
|
|
123
|
+
if (renderAs === 'number') {
|
|
124
|
+
const num = typeof value === 'number' ? value : Number(value);
|
|
125
|
+
if (isNaN(num))
|
|
126
|
+
return _jsx("span", { className: "text-muted-foreground", children: "\u2014" });
|
|
127
|
+
const decimals = styleCfg(col, 'decimals');
|
|
128
|
+
return (_jsx("span", { className: "font-medium tabular-nums text-sm", children: formatNumber(num, decimals !== undefined ? { minimumFractionDigits: decimals, maximumFractionDigits: decimals } : {}, locale) }));
|
|
129
|
+
}
|
|
130
|
+
if (renderAs === 'percent' || renderAs === 'progress') {
|
|
131
|
+
const num = typeof value === 'number' ? value : Number(value);
|
|
132
|
+
if (isNaN(num))
|
|
133
|
+
return _jsx("span", { className: "text-muted-foreground", children: "\u2014" });
|
|
134
|
+
return (_jsxs("span", { className: "font-medium tabular-nums text-sm text-muted-foreground", children: [Math.round(Math.max(0, Math.min(100, num))), "%"] }));
|
|
135
|
+
}
|
|
136
|
+
// -----------------------------------------------------------------------
|
|
137
|
+
// Tags
|
|
138
|
+
// -----------------------------------------------------------------------
|
|
139
|
+
if (renderAs === 'tags') {
|
|
140
|
+
const list = Array.isArray(value)
|
|
141
|
+
? value.map(String)
|
|
142
|
+
: String(value).split(',').map((s) => s.trim()).filter(Boolean);
|
|
143
|
+
if (list.length === 0)
|
|
144
|
+
return _jsx("span", { className: "text-muted-foreground", children: "\u2014" });
|
|
145
|
+
return (_jsx("span", { className: "inline-flex flex-wrap gap-1", children: list.map((tag, i) => (_jsx(Badge, { variant: "secondary", className: "px-1.5 py-0 text-[10px]", children: tag }, i))) }));
|
|
146
|
+
}
|
|
147
|
+
// -----------------------------------------------------------------------
|
|
148
|
+
// Color
|
|
149
|
+
// -----------------------------------------------------------------------
|
|
150
|
+
if (renderAs === 'color') {
|
|
151
|
+
const hex = String(value);
|
|
152
|
+
return (_jsxs("span", { className: "inline-flex items-center gap-1.5", children: [_jsx("span", { className: "h-3.5 w-3.5 rounded border border-border/60 shrink-0", style: { background: hex } }), _jsx("code", { className: "font-mono text-xs text-muted-foreground", children: hex })] }));
|
|
153
|
+
}
|
|
154
|
+
// -----------------------------------------------------------------------
|
|
155
|
+
// URL / Link
|
|
156
|
+
// -----------------------------------------------------------------------
|
|
157
|
+
if (renderAs === 'url' || renderAs === 'link') {
|
|
158
|
+
const urlStr = String(value);
|
|
159
|
+
const href = /^https?:\/\//i.test(urlStr) ? urlStr : `https://${urlStr}`;
|
|
160
|
+
let label;
|
|
161
|
+
try {
|
|
162
|
+
label = new URL(href).hostname;
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
label = urlStr;
|
|
166
|
+
}
|
|
167
|
+
return (_jsxs("a", { href: href, target: "_blank", rel: "noopener noreferrer", className: "inline-flex items-center gap-1 text-sm text-primary hover:underline", onClick: (e) => e.stopPropagation(), children: [_jsx(icons.ExternalLink, { className: "h-3 w-3 shrink-0" }), _jsx("span", { className: "truncate", style: { maxWidth: 200 }, children: label })] }));
|
|
168
|
+
}
|
|
169
|
+
// -----------------------------------------------------------------------
|
|
170
|
+
// Email
|
|
171
|
+
// -----------------------------------------------------------------------
|
|
172
|
+
if (renderAs === 'email') {
|
|
173
|
+
const email = String(value);
|
|
174
|
+
return (_jsxs("a", { href: `mailto:${email}`, className: "inline-flex items-center gap-1 text-sm text-primary hover:underline", onClick: (e) => e.stopPropagation(), children: [_jsx(icons.Mail, { className: "h-3 w-3 shrink-0" }), _jsx("span", { className: "truncate", style: { maxWidth: 200 }, children: email })] }));
|
|
175
|
+
}
|
|
176
|
+
// -----------------------------------------------------------------------
|
|
177
|
+
// Relation chip (FK / reference)
|
|
178
|
+
// -----------------------------------------------------------------------
|
|
179
|
+
if (renderAs === 'relation' || renderAs === 'reference' || col.ref) {
|
|
180
|
+
const sv = String(value);
|
|
181
|
+
const chipStyles = relationChipStyles(sv, { isDark });
|
|
182
|
+
return (_jsx("span", { className: "inline-flex items-center rounded-md px-2 py-0.5 text-sm font-medium", style: { ...chipStyles, maxWidth: 180 }, title: sv, children: _jsx("span", { className: "truncate", children: sv }) }));
|
|
183
|
+
}
|
|
184
|
+
// -----------------------------------------------------------------------
|
|
185
|
+
// Creator / User / Avatar — these carry an object (resolved by the backend);
|
|
186
|
+
// in a diff snapshot the value is likely a string (name/email) or the object.
|
|
187
|
+
// -----------------------------------------------------------------------
|
|
188
|
+
if (renderAs === 'creator' || renderAs === 'user' || renderAs === 'avatar' || renderAs === 'search') {
|
|
189
|
+
const name = typeof value === 'object' && value !== null
|
|
190
|
+
? String(value.name ?? value.label ?? JSON.stringify(value))
|
|
191
|
+
: String(value);
|
|
192
|
+
return (_jsxs("span", { className: "inline-flex items-center gap-1.5", children: [_jsxs(Avatar, { className: "h-5 w-5 rounded-full", children: [_jsx(AvatarImage, { src: "", alt: name }), _jsx(AvatarFallback, { className: "text-[8px] font-bold bg-primary/10 text-primary", children: getInitials(name) })] }), _jsx("span", { className: "text-sm font-medium truncate", style: { maxWidth: 180 }, children: name })] }));
|
|
193
|
+
}
|
|
194
|
+
// -----------------------------------------------------------------------
|
|
195
|
+
// Code / truncate-text / phone
|
|
196
|
+
// -----------------------------------------------------------------------
|
|
197
|
+
if (renderAs === 'code' || renderAs === 'truncate-text') {
|
|
198
|
+
const sv = String(value);
|
|
199
|
+
const maxLength = styleCfg(col, 'max_length', 'maxLength');
|
|
200
|
+
const display = maxLength && sv.length > maxLength ? `${sv.slice(0, maxLength)}…` : sv;
|
|
201
|
+
return _jsx("code", { className: "rounded bg-muted px-1.5 py-0.5 font-mono text-xs", children: display });
|
|
202
|
+
}
|
|
203
|
+
// -----------------------------------------------------------------------
|
|
204
|
+
// Generic object fallback
|
|
205
|
+
// -----------------------------------------------------------------------
|
|
206
|
+
if (typeof value === 'object') {
|
|
207
|
+
return (_jsx("span", { className: "text-muted-foreground text-xs font-mono", children: JSON.stringify(value) }));
|
|
208
|
+
}
|
|
209
|
+
// -----------------------------------------------------------------------
|
|
210
|
+
// Plain text fallback
|
|
211
|
+
// -----------------------------------------------------------------------
|
|
212
|
+
return _jsx("span", { className: "font-medium text-sm", children: String(value) });
|
|
213
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -36,4 +36,8 @@ export { isColumnVisibleInTable, getSearchableColumnKeys, } from './column-visib
|
|
|
36
36
|
export { useOptionsResolver, projectOption, type ResolvedOption, type OptionsMeta, type UseOptionsResolverArgs, type UseOptionsResolverResult, } from './use-options-resolver';
|
|
37
37
|
export { setOrgConfigBridge, getOrgConfigBridge, resolveValidatorToken, type OrgConfigBridge, } from './use-org-config-bridge';
|
|
38
38
|
export { registerValidator } from './dynamic-form-schema';
|
|
39
|
+
export { ActivityValueRenderer, type ActivityValueRendererProps, } from './activity-value-renderer';
|
|
40
|
+
export { ActivityDiff, type ActivityEvent, type ActivityDiffProps, } from './activity-diff';
|
|
41
|
+
export { RecordHistory, type RecordHistoryProps, } from './record-history';
|
|
42
|
+
export { ActivityTimeline, type ActivityTimelineProps, } from './activity-timeline';
|
|
39
43
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,cAAc,SAAS,CAAA;AACvB,cAAc,mBAAmB,CAAA;AACjC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EACH,qBAAqB,EACrB,KAAK,gBAAgB,GACxB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACH,kBAAkB,EAClB,eAAe,EACf,KAAK,uBAAuB,EAC5B,KAAK,eAAe,GACvB,MAAM,wBAAwB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,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5B,OAAO,EACH,kBAAkB,EAClB,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,GAChC,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACH,kBAAkB,EAClB,kBAAkB,EAClB,qBAAqB,EACrB,KAAK,eAAe,GACvB,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EACH,qBAAqB,EACrB,KAAK,0BAA0B,GAClC,MAAM,2BAA2B,CAAA;AAClC,OAAO,EACH,YAAY,EACZ,KAAK,aAAa,EAClB,KAAK,iBAAiB,GACzB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACH,aAAa,EACb,KAAK,kBAAkB,GAC1B,MAAM,kBAAkB,CAAA;AACzB,OAAO,EACH,gBAAgB,EAChB,KAAK,qBAAqB,GAC7B,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -38,3 +38,7 @@ export { isColumnVisibleInTable, getSearchableColumnKeys, } from './column-visib
|
|
|
38
38
|
export { useOptionsResolver, projectOption, } from './use-options-resolver';
|
|
39
39
|
export { setOrgConfigBridge, getOrgConfigBridge, resolveValidatorToken, } from './use-org-config-bridge';
|
|
40
40
|
export { registerValidator } from './dynamic-form-schema';
|
|
41
|
+
export { ActivityValueRenderer, } from './activity-value-renderer';
|
|
42
|
+
export { ActivityDiff, } from './activity-diff';
|
|
43
|
+
export { RecordHistory, } from './record-history';
|
|
44
|
+
export { ActivityTimeline, } from './activity-timeline';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* record-history.tsx
|
|
3
|
+
*
|
|
4
|
+
* <RecordHistory> — chronological timeline of all ActivityEvents for a single
|
|
5
|
+
* record. Most recent event first. Each event is shown as a collapsible card
|
|
6
|
+
* with actor, relative date, and the <ActivityDiff> inline.
|
|
7
|
+
*
|
|
8
|
+
* Intended to be embedded in a record dialog tab ("Historial").
|
|
9
|
+
*
|
|
10
|
+
* Transport-agnostic: events and column metadata arrive via props. No fetching.
|
|
11
|
+
*/
|
|
12
|
+
import * as React from 'react';
|
|
13
|
+
import type { ColumnDefinition } from './types';
|
|
14
|
+
import type { ActivityEvent } from './activity-diff';
|
|
15
|
+
export interface RecordHistoryProps {
|
|
16
|
+
/**
|
|
17
|
+
* All activity events for the record, in any order. The component sorts
|
|
18
|
+
* them chronologically (most recent first).
|
|
19
|
+
*/
|
|
20
|
+
events: ActivityEvent[];
|
|
21
|
+
/**
|
|
22
|
+
* Column metadata for the record's model. Forwarded to <ActivityDiff> so
|
|
23
|
+
* field labels and display types are resolved correctly.
|
|
24
|
+
*/
|
|
25
|
+
columns?: ColumnDefinition[];
|
|
26
|
+
/** IANA timezone for datetime cells. */
|
|
27
|
+
timeZone?: string;
|
|
28
|
+
/** ISO 4217 currency for money cells. */
|
|
29
|
+
currency?: string;
|
|
30
|
+
/** BCP-47 locale. Defaults to 'es'. */
|
|
31
|
+
locale?: string;
|
|
32
|
+
/** Class applied to the root element. */
|
|
33
|
+
className?: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Shows the full activity history of a single record as a vertical timeline.
|
|
37
|
+
* Each event is collapsible — the header shows actor + time; expanding reveals
|
|
38
|
+
* the <ActivityDiff> with field-level changes.
|
|
39
|
+
*/
|
|
40
|
+
export declare const RecordHistory: React.FC<RecordHistoryProps>;
|
|
41
|
+
//# sourceMappingURL=record-history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record-history.d.ts","sourceRoot":"","sources":["../src/record-history.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAc9B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAOpD,MAAM,WAAW,kBAAkB;IAC/B;;;OAGG;IACH,MAAM,EAAE,aAAa,EAAE,CAAA;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;IAC5B,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,uCAAuC;IACvC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAoCD;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAoJtD,CAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* record-history.tsx
|
|
4
|
+
*
|
|
5
|
+
* <RecordHistory> — chronological timeline of all ActivityEvents for a single
|
|
6
|
+
* record. Most recent event first. Each event is shown as a collapsible card
|
|
7
|
+
* with actor, relative date, and the <ActivityDiff> inline.
|
|
8
|
+
*
|
|
9
|
+
* Intended to be embedded in a record dialog tab ("Historial").
|
|
10
|
+
*
|
|
11
|
+
* Transport-agnostic: events and column metadata arrive via props. No fetching.
|
|
12
|
+
*/
|
|
13
|
+
import * as React from 'react';
|
|
14
|
+
import { formatDistanceToNow } from 'date-fns';
|
|
15
|
+
import { es, enUS } from 'date-fns/locale';
|
|
16
|
+
import { ChevronDown, ChevronRight, Clock } from 'lucide-react';
|
|
17
|
+
import { cn } from '@asteby/metacore-ui/lib';
|
|
18
|
+
import { Avatar, AvatarFallback, Badge, Collapsible, CollapsibleContent, CollapsibleTrigger, } from '@asteby/metacore-ui/primitives';
|
|
19
|
+
import { getInitials } from '@asteby/metacore-ui/lib';
|
|
20
|
+
import { ActivityDiff } from './activity-diff';
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
// Helpers
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
const ACTION_LABELS = {
|
|
25
|
+
created: 'Creó el registro',
|
|
26
|
+
create: 'Creó el registro',
|
|
27
|
+
updated: 'Actualizó el registro',
|
|
28
|
+
update: 'Actualizó el registro',
|
|
29
|
+
deleted: 'Eliminó el registro',
|
|
30
|
+
delete: 'Eliminó el registro',
|
|
31
|
+
};
|
|
32
|
+
function actionLabel(action) {
|
|
33
|
+
return ACTION_LABELS[action.toLowerCase()] ?? action;
|
|
34
|
+
}
|
|
35
|
+
const ACTION_DOT_COLOR = {
|
|
36
|
+
created: '#22c55e',
|
|
37
|
+
create: '#22c55e',
|
|
38
|
+
updated: '#eab308',
|
|
39
|
+
update: '#eab308',
|
|
40
|
+
deleted: '#ef4444',
|
|
41
|
+
delete: '#ef4444',
|
|
42
|
+
};
|
|
43
|
+
function actionDotColor(action) {
|
|
44
|
+
return ACTION_DOT_COLOR[action.toLowerCase()] ?? '#6b7280';
|
|
45
|
+
}
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Component
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
/**
|
|
50
|
+
* Shows the full activity history of a single record as a vertical timeline.
|
|
51
|
+
* Each event is collapsible — the header shows actor + time; expanding reveals
|
|
52
|
+
* the <ActivityDiff> with field-level changes.
|
|
53
|
+
*/
|
|
54
|
+
export const RecordHistory = ({ events, columns, timeZone, currency, locale = 'es', className, }) => {
|
|
55
|
+
const dateLocale = locale === 'en' ? enUS : es;
|
|
56
|
+
// Sort: most recent first
|
|
57
|
+
const sorted = React.useMemo(() => [...events].sort((a, b) => new Date(b.occurred_at).getTime() - new Date(a.occurred_at).getTime()), [events]);
|
|
58
|
+
// Expand the most-recent event by default
|
|
59
|
+
const [openIds, setOpenIds] = React.useState(() => sorted.length > 0 ? new Set([sorted[0].id]) : new Set());
|
|
60
|
+
const toggle = (id) => {
|
|
61
|
+
setOpenIds((prev) => {
|
|
62
|
+
const next = new Set(prev);
|
|
63
|
+
if (next.has(id))
|
|
64
|
+
next.delete(id);
|
|
65
|
+
else
|
|
66
|
+
next.add(id);
|
|
67
|
+
return next;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
if (sorted.length === 0) {
|
|
71
|
+
return (_jsxs("div", { className: cn('flex flex-col items-center justify-center py-12 gap-2 text-muted-foreground', className), children: [_jsx(Clock, { className: "h-8 w-8 opacity-40" }), _jsx("p", { className: "text-sm", children: "Sin historial de cambios." })] }));
|
|
72
|
+
}
|
|
73
|
+
return (_jsxs("div", { className: cn('relative pl-5', className), children: [_jsx("span", { className: "absolute left-2 top-2 bottom-2 w-px bg-border", "aria-hidden": "true" }), _jsx("div", { className: "space-y-3", children: sorted.map((event) => {
|
|
74
|
+
const isOpen = openIds.has(event.id);
|
|
75
|
+
const dotColor = actionDotColor(event.action);
|
|
76
|
+
const actor = event.actor_label || event.actor_id || 'Sistema';
|
|
77
|
+
const timeAgo = (() => {
|
|
78
|
+
try {
|
|
79
|
+
return formatDistanceToNow(new Date(event.occurred_at), { addSuffix: true, locale: dateLocale });
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return event.occurred_at;
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
const fullDate = (() => {
|
|
86
|
+
try {
|
|
87
|
+
return new Date(event.occurred_at).toLocaleString(locale === 'en' ? 'en-US' : 'es-MX', {
|
|
88
|
+
...(timeZone ? { timeZone } : {}),
|
|
89
|
+
dateStyle: 'medium',
|
|
90
|
+
timeStyle: 'short',
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
return event.occurred_at;
|
|
95
|
+
}
|
|
96
|
+
})();
|
|
97
|
+
return (_jsx(Collapsible, { open: isOpen, onOpenChange: () => toggle(event.id), children: _jsxs("div", { className: "relative", children: [_jsx("span", { className: "absolute -left-5 top-3.5 h-2.5 w-2.5 rounded-full border-2 border-background -translate-x-[4px]", style: { background: dotColor }, "aria-hidden": "true" }), _jsxs("div", { className: "rounded-lg border border-border/60 bg-card overflow-hidden", children: [_jsx(CollapsibleTrigger, { asChild: true, children: _jsxs("button", { type: "button", className: "w-full flex items-center gap-3 px-4 py-3 text-left hover:bg-muted/30 transition-colors", children: [_jsx(Avatar, { className: "h-7 w-7 rounded-full shrink-0", children: _jsx(AvatarFallback, { className: "text-[9px] font-bold bg-primary/10 text-primary", children: getInitials(actor) }) }), _jsxs("div", { className: "flex-1 min-w-0", children: [_jsxs("div", { className: "flex items-center gap-2 flex-wrap", children: [_jsx("span", { className: "text-sm font-semibold text-foreground truncate", children: actor }), _jsx("span", { className: "text-sm text-muted-foreground", children: actionLabel(event.action) })] }), _jsxs("div", { className: "flex items-center gap-1.5 mt-0.5", children: [_jsx(Clock, { className: "h-3 w-3 text-muted-foreground/60 shrink-0" }), _jsx("span", { className: "text-xs text-muted-foreground", title: fullDate, children: timeAgo }), event.addon_key && (_jsx(Badge, { variant: "outline", className: "text-[10px] px-1.5 py-0 h-4 ml-1", children: event.addon_key }))] })] }), _jsx("span", { className: "shrink-0 text-muted-foreground", children: isOpen ? (_jsx(ChevronDown, { className: "h-4 w-4" })) : (_jsx(ChevronRight, { className: "h-4 w-4" })) })] }) }), _jsx(CollapsibleContent, { children: _jsx("div", { className: "border-t border-border/40 px-4 py-3", children: _jsx(ActivityDiff, { event: event, columns: columns, timeZone: timeZone, currency: currency, locale: locale }) }) })] })] }) }, event.id));
|
|
98
|
+
}) })] }));
|
|
99
|
+
};
|