@airoom/nextmin-react 1.2.0 → 1.4.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.
|
@@ -259,6 +259,43 @@ function formatShowValue(val) {
|
|
|
259
259
|
}
|
|
260
260
|
return null;
|
|
261
261
|
}
|
|
262
|
+
/** ---------- Date formatting for createdAt/updatedAt ---------- */
|
|
263
|
+
function isDateField(key) {
|
|
264
|
+
const k = key.toLowerCase().replace(/[^a-z]/g, '');
|
|
265
|
+
return k === 'createdat' || k === 'updatedat' || k === 'deletedat';
|
|
266
|
+
}
|
|
267
|
+
function tryParseDate(val) {
|
|
268
|
+
if (val == null)
|
|
269
|
+
return null;
|
|
270
|
+
if (val instanceof Date)
|
|
271
|
+
return isNaN(val.getTime()) ? null : val;
|
|
272
|
+
// ONLY parse ISO-like strings, NOT numbers (to avoid phone numbers, experience years, etc.)
|
|
273
|
+
if (typeof val === 'string') {
|
|
274
|
+
const s = val.trim();
|
|
275
|
+
// Must look like an ISO date: YYYY-MM-DD or contain 'T' or end with 'Z'
|
|
276
|
+
const looksIso = /^\d{4}-\d{2}-\d{2}/.test(s) || s.includes('T') || s.endsWith('Z');
|
|
277
|
+
if (!looksIso)
|
|
278
|
+
return null;
|
|
279
|
+
const d = new Date(s);
|
|
280
|
+
return isNaN(d.getTime()) ? null : d;
|
|
281
|
+
}
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
function formatDateLocal(d) {
|
|
285
|
+
try {
|
|
286
|
+
return d.toLocaleString(undefined, {
|
|
287
|
+
year: 'numeric',
|
|
288
|
+
month: 'short',
|
|
289
|
+
day: '2-digit',
|
|
290
|
+
hour: '2-digit',
|
|
291
|
+
minute: '2-digit',
|
|
292
|
+
hour12: true,
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
catch {
|
|
296
|
+
return d.toString();
|
|
297
|
+
}
|
|
298
|
+
}
|
|
262
299
|
/** ---------- component ---------- */
|
|
263
300
|
export function DataTableHero({ modelName, columns, rows, total, page, pageSize, onPageChange, onPageSizeChange, baseHref, loading, error, onDeleted, topContent, schema, onRequestView, }) {
|
|
264
301
|
const pageCount = Math.max(1, Math.ceil(total / Math.max(1, pageSize)));
|
|
@@ -329,6 +366,13 @@ export function DataTableHero({ modelName, columns, rows, total, page, pageSize,
|
|
|
329
366
|
// Prepare raw value (parse JSON-like strings first)
|
|
330
367
|
const rawRawVal = item[key];
|
|
331
368
|
const rawVal = maybeParseJson(rawRawVal);
|
|
369
|
+
// 0) Date fields (createdAt, updatedAt, deletedAt)
|
|
370
|
+
if (isDateField(key)) {
|
|
371
|
+
const d = tryParseDate(rawVal);
|
|
372
|
+
if (d) {
|
|
373
|
+
return (_jsx(TableCell, { children: formatDateLocal(d) }, `${item.id ?? item._id}-${key}`));
|
|
374
|
+
}
|
|
375
|
+
}
|
|
332
376
|
// 1) Time-only ranges like "15:00..00:00 17:00..23:00"
|
|
333
377
|
const timeRangePretty = formatTimeOnlyRanges(rawVal);
|
|
334
378
|
if (timeRangePretty) {
|
|
@@ -1,26 +1,3 @@
|
|
|
1
|
-
function isCreatedOrUpdated(key) {
|
|
2
|
-
const k = (key || '').toLowerCase().replace(/[^a-z]/g, '');
|
|
3
|
-
return k === 'createdat' || k === 'updatedat';
|
|
4
|
-
}
|
|
5
|
-
function tryParseDate(val) {
|
|
6
|
-
if (val == null)
|
|
7
|
-
return null;
|
|
8
|
-
// Handle numeric timestamps (ms or s)
|
|
9
|
-
if (typeof val === 'number') {
|
|
10
|
-
const ms = val < 1e11 ? val * 1000 : val; // heuristic: 10/13-digit
|
|
11
|
-
const d = new Date(ms);
|
|
12
|
-
return isNaN(d.getTime()) ? null : d;
|
|
13
|
-
}
|
|
14
|
-
// ISO string / Date
|
|
15
|
-
const d = new Date(val);
|
|
16
|
-
return isNaN(d.getTime()) ? null : d;
|
|
17
|
-
}
|
|
18
|
-
function formatLongDate(d) {
|
|
19
|
-
const day = d.getDate(); // no leading zero: "1 August, 2025"
|
|
20
|
-
const month = d.toLocaleString('en', { month: 'long' });
|
|
21
|
-
const year = d.getFullYear();
|
|
22
|
-
return `${day} ${month}, ${year}`; // "13 August, 2025"
|
|
23
|
-
}
|
|
24
1
|
export function formatAtom(v) {
|
|
25
2
|
if (v == null)
|
|
26
3
|
return '';
|
|
@@ -48,12 +25,6 @@ export function formatAtom(v) {
|
|
|
48
25
|
export function formatCell(val, key) {
|
|
49
26
|
if (val == null)
|
|
50
27
|
return '';
|
|
51
|
-
// Only format dates for createdAt / updatedAt columns
|
|
52
|
-
if (isCreatedOrUpdated(key)) {
|
|
53
|
-
const d = tryParseDate(val);
|
|
54
|
-
if (d)
|
|
55
|
-
return formatLongDate(d);
|
|
56
|
-
}
|
|
57
28
|
if (Array.isArray(val))
|
|
58
29
|
return val.map(formatAtom).join(', ');
|
|
59
30
|
if (typeof val === 'object')
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Generic JSON value summarizer for table cells and viewer
|
|
2
|
-
const HIDDEN_KEYS = new Set(['id', '_id', 'v', '__v', 'baseId', 'exId', '__childId']);
|
|
2
|
+
const HIDDEN_KEYS = new Set(['id', '_id', 'v', '__v', 'baseId', 'exId', '__childId', 'createdAt', 'updatedAt', 'deletedAt']);
|
|
3
3
|
function normKey(k) {
|
|
4
4
|
return k.toLowerCase();
|
|
5
5
|
}
|