@appcorp/stellar-solutions-modules 0.1.41 → 0.1.42
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.
|
@@ -3,7 +3,17 @@ export interface TableColumn {
|
|
|
3
3
|
key?: string;
|
|
4
4
|
label: string;
|
|
5
5
|
width?: string;
|
|
6
|
-
componentType?:
|
|
6
|
+
componentType?: COMPONENT_TYPE | string;
|
|
7
|
+
}
|
|
8
|
+
export declare enum COMPONENT_TYPE {
|
|
9
|
+
ID = "ID",
|
|
10
|
+
BOLD_TEXT = "BOLD_TEXT",
|
|
11
|
+
TEXT = "TEXT",
|
|
12
|
+
OBJECT = "OBJECT",
|
|
13
|
+
MULTIPLE_TEXT_LINES = "MULTIPLE_TEXT_LINES",
|
|
14
|
+
CREATED_UPDATED_AT = "CREATED_UPDATED_AT",
|
|
15
|
+
ACTIONS = "ACTIONS",
|
|
16
|
+
BOOLEAN = "BOOLEAN"
|
|
7
17
|
}
|
|
8
18
|
export interface TableRow extends Record<string, unknown> {
|
|
9
19
|
id?: string;
|
|
@@ -37,8 +47,8 @@ export interface EnhancedTableProps {
|
|
|
37
47
|
tableHeadItems: TableColumn[];
|
|
38
48
|
tableBodyRows: TableRow[];
|
|
39
49
|
tableBodyCols: Array<{
|
|
40
|
-
key
|
|
41
|
-
componentType: string;
|
|
50
|
+
key?: string | string[];
|
|
51
|
+
componentType: COMPONENT_TYPE | string;
|
|
42
52
|
}>;
|
|
43
53
|
tableHeading: string;
|
|
44
54
|
tableDescription?: string;
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
exports.EnhancedTable = void 0;
|
|
7
|
+
exports.EnhancedTable = exports.COMPONENT_TYPE = void 0;
|
|
8
8
|
var react_1 = __importDefault(require("react"));
|
|
9
9
|
var lucide_react_1 = require("lucide-react");
|
|
10
10
|
var table_1 = require("./table");
|
|
@@ -18,10 +18,75 @@ var popover_1 = require("./popover");
|
|
|
18
18
|
var enhanced_table_header_action_1 = require("./enhanced-table-header-action");
|
|
19
19
|
var enhanced_table_header_search_1 = require("./enhanced-table-header-search");
|
|
20
20
|
var badge_1 = require("./badge");
|
|
21
|
+
// Centralized component type values for table cell rendering
|
|
22
|
+
var COMPONENT_TYPE;
|
|
23
|
+
(function (COMPONENT_TYPE) {
|
|
24
|
+
COMPONENT_TYPE["ID"] = "ID";
|
|
25
|
+
COMPONENT_TYPE["BOLD_TEXT"] = "BOLD_TEXT";
|
|
26
|
+
COMPONENT_TYPE["TEXT"] = "TEXT";
|
|
27
|
+
COMPONENT_TYPE["OBJECT"] = "OBJECT";
|
|
28
|
+
COMPONENT_TYPE["MULTIPLE_TEXT_LINES"] = "MULTIPLE_TEXT_LINES";
|
|
29
|
+
COMPONENT_TYPE["CREATED_UPDATED_AT"] = "CREATED_UPDATED_AT";
|
|
30
|
+
COMPONENT_TYPE["ACTIONS"] = "ACTIONS";
|
|
31
|
+
COMPONENT_TYPE["BOOLEAN"] = "BOOLEAN";
|
|
32
|
+
})(COMPONENT_TYPE || (exports.COMPONENT_TYPE = COMPONENT_TYPE = {}));
|
|
21
33
|
var EnhancedTable = function (_a) {
|
|
22
34
|
var currentPage = _a.currentPage, handleNextOnClick = _a.handleNextOnClick, handleOnSelect = _a.handleOnSelect, handlePreviousOnClick = _a.handlePreviousOnClick, handleSearchInput = _a.handleSearchInput, headerActions = _a.headerActions, isNextDisabled = _a.isNextDisabled, isPreviousDisabled = _a.isPreviousDisabled, listOptions = _a.listOptions, loading = _a.loading, _b = _a.nodeSelectKey, nodeSelectKey = _b === void 0 ? "pageLimit" : _b, pageLimit = _a.pageLimit, rowActions = _a.rowActions, _c = _a.searchDisabled, searchDisabled = _c === void 0 ? false : _c, _d = _a.searchEnabled, searchEnabled = _d === void 0 ? true : _d, _e = _a.searchId, searchId = _e === void 0 ? "table-search" : _e, _f = _a.searchPlaceholder, searchPlaceholder = _f === void 0 ? "Search..." : _f, searchValue = _a.searchValue, tableBodyCols = _a.tableBodyCols, tableBodyRows = _a.tableBodyRows, tableDescription = _a.tableDescription, tableHeading = _a.tableHeading, tableHeadItems = _a.tableHeadItems, totalPages = _a.totalPages;
|
|
23
35
|
var renderCellContent = function (row, col) {
|
|
24
|
-
var
|
|
36
|
+
var _a, _b;
|
|
37
|
+
// Helper to safely resolve nested keys (max depth 3)
|
|
38
|
+
var resolveValue = function (source, key) {
|
|
39
|
+
if (!key)
|
|
40
|
+
return source;
|
|
41
|
+
if (typeof key === "string") {
|
|
42
|
+
if (source && typeof source === "object")
|
|
43
|
+
return source[key];
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
// array of keys
|
|
47
|
+
var path = key.slice(0, 3); // enforce max depth 3
|
|
48
|
+
var cur = source;
|
|
49
|
+
for (var _i = 0, path_1 = path; _i < path_1.length; _i++) {
|
|
50
|
+
var k = path_1[_i];
|
|
51
|
+
if (cur == null)
|
|
52
|
+
return undefined;
|
|
53
|
+
if (typeof cur !== "object")
|
|
54
|
+
return undefined;
|
|
55
|
+
cur = cur[k];
|
|
56
|
+
}
|
|
57
|
+
return cur;
|
|
58
|
+
};
|
|
59
|
+
var getProp = function (obj, prop) {
|
|
60
|
+
if (obj &&
|
|
61
|
+
typeof obj === "object" &&
|
|
62
|
+
prop in obj)
|
|
63
|
+
return obj[prop];
|
|
64
|
+
return undefined;
|
|
65
|
+
};
|
|
66
|
+
// Resolve value (supports nested key arrays)
|
|
67
|
+
var value = resolveValue(row, col.key);
|
|
68
|
+
// Normalize componentType so external string enums (like VISTA_TABLE_CELL_TYPE)
|
|
69
|
+
// remain compatible with this table. Unknown/unsupported types fall back to TEXT.
|
|
70
|
+
var normalizeComponentType = function (c) {
|
|
71
|
+
var _a;
|
|
72
|
+
if (!c)
|
|
73
|
+
return undefined;
|
|
74
|
+
if (Object.values(COMPONENT_TYPE).includes(c))
|
|
75
|
+
return c;
|
|
76
|
+
// Map common external values to our ComponentType using object notation
|
|
77
|
+
var MAP = {
|
|
78
|
+
ID: COMPONENT_TYPE.ID,
|
|
79
|
+
BOLD_TEXT: COMPONENT_TYPE.BOLD_TEXT,
|
|
80
|
+
BOOLEAN: COMPONENT_TYPE.BOOLEAN,
|
|
81
|
+
ACTIONS: COMPONENT_TYPE.ACTIONS,
|
|
82
|
+
TEXT: COMPONENT_TYPE.TEXT,
|
|
83
|
+
OBJECT: COMPONENT_TYPE.OBJECT,
|
|
84
|
+
MULTIPLE_TEXT_LINES: COMPONENT_TYPE.MULTIPLE_TEXT_LINES,
|
|
85
|
+
CREATED_UPDATED_AT: COMPONENT_TYPE.CREATED_UPDATED_AT,
|
|
86
|
+
};
|
|
87
|
+
return (_a = MAP[String(c)]) !== null && _a !== void 0 ? _a : COMPONENT_TYPE.TEXT;
|
|
88
|
+
};
|
|
89
|
+
var normalizedType = normalizeComponentType(col.componentType);
|
|
25
90
|
if (col.key === "action") {
|
|
26
91
|
return (react_1.default.createElement(dropdown_menu_1.DropdownMenu, null,
|
|
27
92
|
react_1.default.createElement(dropdown_menu_1.DropdownMenuTrigger, { asChild: true },
|
|
@@ -39,7 +104,7 @@ var EnhancedTable = function (_a) {
|
|
|
39
104
|
action.handleAction(row.id);
|
|
40
105
|
} }, action.label)); }))));
|
|
41
106
|
}
|
|
42
|
-
if (
|
|
107
|
+
if (normalizedType === COMPONENT_TYPE.ID) {
|
|
43
108
|
return (react_1.default.createElement(popover_1.Popover, null,
|
|
44
109
|
react_1.default.createElement(popover_1.PopoverTrigger, { asChild: true },
|
|
45
110
|
react_1.default.createElement("span", { className: "text-xs text-muted-foreground font-mono" }, typeof value === "string"
|
|
@@ -48,15 +113,59 @@ var EnhancedTable = function (_a) {
|
|
|
48
113
|
react_1.default.createElement(popover_1.PopoverContent, null,
|
|
49
114
|
react_1.default.createElement("span", { className: "text-xs text-muted-foreground font-mono" }, String(value)))));
|
|
50
115
|
}
|
|
51
|
-
if (
|
|
116
|
+
if (normalizedType === COMPONENT_TYPE.BOLD_TEXT) {
|
|
52
117
|
return react_1.default.createElement("span", { className: "font-semibold" }, String(value || ""));
|
|
53
118
|
}
|
|
54
|
-
if (
|
|
119
|
+
if (normalizedType === COMPONENT_TYPE.BOOLEAN) {
|
|
55
120
|
var isTrue = Boolean(value);
|
|
56
121
|
return (react_1.default.createElement(badge_1.Badge, { variant: "secondary", className: (0, utils_1.cn)("text-white font-medium", isTrue
|
|
57
122
|
? "bg-green-500 hover:bg-green-600"
|
|
58
123
|
: "bg-red-500 hover:bg-red-600") }, isTrue ? "Yes" : "No"));
|
|
59
124
|
}
|
|
125
|
+
// OBJECT => nested property path supplied as array of strings (max length 3)
|
|
126
|
+
if (normalizedType === COMPONENT_TYPE.OBJECT) {
|
|
127
|
+
var nested = resolveValue(row, col.key);
|
|
128
|
+
// If nested is primitive, show it. If object, stringify first-level value.
|
|
129
|
+
if (nested == null)
|
|
130
|
+
return react_1.default.createElement("span", null, "");
|
|
131
|
+
if (typeof nested === "object") {
|
|
132
|
+
// Render primitive values inside object or JSON fallback
|
|
133
|
+
var primitive = typeof nested === "object"
|
|
134
|
+
? // try to find a primitive child
|
|
135
|
+
Object.values(nested).find(function (v) {
|
|
136
|
+
return ["string", "number", "boolean"].includes(typeof v);
|
|
137
|
+
})
|
|
138
|
+
: nested;
|
|
139
|
+
return react_1.default.createElement("span", null, String(primitive !== null && primitive !== void 0 ? primitive : JSON.stringify(nested)));
|
|
140
|
+
}
|
|
141
|
+
return react_1.default.createElement("span", null, String(nested));
|
|
142
|
+
}
|
|
143
|
+
// MULTIPLE_TEXT_LINES => col.key is an array of keys, render up to 3 lines
|
|
144
|
+
if (normalizedType === COMPONENT_TYPE.MULTIPLE_TEXT_LINES) {
|
|
145
|
+
var keys = Array.isArray(col.key) ? col.key : [];
|
|
146
|
+
var lines = keys.slice(0, 3).map(function (k) {
|
|
147
|
+
var v = resolveValue(row, k);
|
|
148
|
+
return v == null ? "" : String(v);
|
|
149
|
+
});
|
|
150
|
+
return (react_1.default.createElement("div", { className: "flex flex-col" }, lines.map(function (line, idx) { return (react_1.default.createElement("span", { key: idx, className: "text-sm" }, line)); })));
|
|
151
|
+
}
|
|
152
|
+
// CREATED_UPDATED_AT => show createdAt and updatedAt from the object (or nested object)
|
|
153
|
+
if (normalizedType === COMPONENT_TYPE.CREATED_UPDATED_AT) {
|
|
154
|
+
var target = resolveValue(row, col.key);
|
|
155
|
+
var created = (_a = getProp(target, "createdAt")) !== null && _a !== void 0 ? _a : getProp(row, "createdAt");
|
|
156
|
+
var updated = (_b = getProp(target, "updatedAt")) !== null && _b !== void 0 ? _b : getProp(row, "updatedAt");
|
|
157
|
+
var fmt = function (d) {
|
|
158
|
+
if (d == null)
|
|
159
|
+
return "";
|
|
160
|
+
var date = d instanceof Date ? d : new Date(String(d));
|
|
161
|
+
if (isNaN(date.getTime()))
|
|
162
|
+
return String(d);
|
|
163
|
+
return date.toLocaleString();
|
|
164
|
+
};
|
|
165
|
+
return (react_1.default.createElement("div", { className: "flex flex-col text-sm text-muted-foreground" },
|
|
166
|
+
react_1.default.createElement("span", null, fmt(created)),
|
|
167
|
+
react_1.default.createElement("span", null, fmt(updated))));
|
|
168
|
+
}
|
|
60
169
|
return react_1.default.createElement("span", null, String(value || ""));
|
|
61
170
|
};
|
|
62
171
|
// Create loading skeleton rows
|
package/package.json
CHANGED