mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
+22
-3
@@ -3,15 +3,34 @@ import * as XLSX from "xlsx";
|
||||
|
||||
const SKIP_IDS = new Set(["select", "actions"]);
|
||||
|
||||
// ─── Flatten a value into something a spreadsheet cell can display ────────────
|
||||
// Array-of-object columns (e.g. `groups`: [{group_id, name, group_code}]) would
|
||||
// otherwise hit Array.prototype.toString → "[object Object]" per item.
|
||||
function flattenForExport(value) {
|
||||
if (Array.isArray(value)) {
|
||||
return value
|
||||
.map((item) => (item && typeof item === "object")
|
||||
? (item.name ?? item.label ?? item.group_code ?? JSON.stringify(item))
|
||||
: item)
|
||||
.join(", ");
|
||||
}
|
||||
if (value && typeof value === "object") {
|
||||
return value.name ?? value.label ?? JSON.stringify(value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
// ─── Resolve dot-notation or direct key from a row ────────────────────────────
|
||||
function resolveValue(row, key) {
|
||||
if (!key) return "";
|
||||
|
||||
// ─── Try direct key first e.g. "email", "acc_type" ────────────────────────
|
||||
if (key in row) return row[key] ?? "";
|
||||
const raw = key in row
|
||||
? row[key]
|
||||
// ─── Dot-notation fallback e.g. "personal_info.name.full_name" ──────────
|
||||
: key.split(".").reduce((acc, part) => acc?.[part] ?? "", row);
|
||||
|
||||
// ─── Dot-notation fallback e.g. "personal_info.name.full_name" ────────────
|
||||
return key.split(".").reduce((acc, part) => acc?.[part] ?? "", row) ?? "";
|
||||
return flattenForExport(raw) ?? "";
|
||||
}
|
||||
|
||||
// ─── Flatten a nested row based on attributes ─────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user