@agilant/toga-blox 1.0.99 → 1.0.101
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.
|
@@ -35,14 +35,25 @@ export interface Renderers {
|
|
|
35
35
|
renderStatus?: (value: string, extra?: any) => JSX.Element;
|
|
36
36
|
renderCurrency?: (value: string) => string;
|
|
37
37
|
}
|
|
38
|
+
/** Additional options your apps might pass to the library */
|
|
39
|
+
export interface FormatTableOptions {
|
|
40
|
+
typeValues?: Record<string, any>;
|
|
41
|
+
callFromFilter?: boolean;
|
|
42
|
+
visibleListId?: string;
|
|
43
|
+
handleIconClick?: (id: string, rowUuid: string) => void;
|
|
44
|
+
actionList?: React.ReactNode;
|
|
45
|
+
rowData?: Record<string, any>;
|
|
46
|
+
deactivatedMenuUuids?: string[];
|
|
47
|
+
}
|
|
38
48
|
/**
|
|
39
49
|
* The main function that shapes columns for React Table.
|
|
40
50
|
* - `columnTitles`: array of column headers
|
|
41
51
|
* - `accessors`: array of "col1", "col2", ...
|
|
42
52
|
* - `columnConfigs`: array of raw backend configs (with booleans)
|
|
43
53
|
* - `renderers`: your app's icon/image/status/currency callbacks
|
|
54
|
+
* - `options`: an object with extra arguments like handleIconClick, rowData, etc.
|
|
44
55
|
*/
|
|
45
|
-
declare function formatTableData(columnTitles: string[], accessors: string[], columnConfigs: any[], renderers?: Renderers): TableColumn[];
|
|
56
|
+
declare function formatTableData(columnTitles: string[], accessors: string[], columnConfigs: any[], renderers?: Renderers, options?: FormatTableOptions): TableColumn[];
|
|
46
57
|
/**
|
|
47
58
|
* Helper to generate "col1", "col2", "col3", etc.
|
|
48
59
|
*/
|
|
@@ -4,12 +4,14 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
4
4
|
* into the library's expected fields (`type: "STATUS"`, `type: "CURRENCY"`, etc.).
|
|
5
5
|
*/
|
|
6
6
|
function transformBackendConfig(backendConfig) {
|
|
7
|
+
console.log("[LIB] transformBackendConfig input:", backendConfig);
|
|
7
8
|
const finalConfig = {
|
|
8
9
|
key: backendConfig.key,
|
|
9
10
|
type: backendConfig.type ?? "DEFAULT",
|
|
10
11
|
linkClasses: backendConfig.linkClasses ?? "",
|
|
11
12
|
transform: backendConfig.transform,
|
|
12
13
|
};
|
|
14
|
+
// e.g. booleans => library fields
|
|
13
15
|
if (backendConfig.hasStatus) {
|
|
14
16
|
finalConfig.type = "STATUS";
|
|
15
17
|
}
|
|
@@ -17,10 +19,10 @@ function transformBackendConfig(backendConfig) {
|
|
|
17
19
|
finalConfig.type = "CURRENCY";
|
|
18
20
|
}
|
|
19
21
|
if (backendConfig.hasLeftIcon) {
|
|
20
|
-
finalConfig.leftIcon = "check";
|
|
22
|
+
finalConfig.leftIcon = "check";
|
|
21
23
|
}
|
|
22
24
|
if (backendConfig.hasRightIcon) {
|
|
23
|
-
finalConfig.rightIcon = "arrowRight";
|
|
25
|
+
finalConfig.rightIcon = "arrowRight";
|
|
24
26
|
}
|
|
25
27
|
if (backendConfig.hasLeftImage) {
|
|
26
28
|
finalConfig.leftImage = "https://example.com/placeholder.png";
|
|
@@ -28,6 +30,7 @@ function transformBackendConfig(backendConfig) {
|
|
|
28
30
|
if (backendConfig.hasRightImage) {
|
|
29
31
|
finalConfig.rightImage = "https://example.com/placeholder.png";
|
|
30
32
|
}
|
|
33
|
+
console.log("[LIB] transformBackendConfig output:", finalConfig);
|
|
31
34
|
return finalConfig;
|
|
32
35
|
}
|
|
33
36
|
/**
|
|
@@ -36,25 +39,26 @@ function transformBackendConfig(backendConfig) {
|
|
|
36
39
|
* - `accessors`: array of "col1", "col2", ...
|
|
37
40
|
* - `columnConfigs`: array of raw backend configs (with booleans)
|
|
38
41
|
* - `renderers`: your app's icon/image/status/currency callbacks
|
|
42
|
+
* - `options`: an object with extra arguments like handleIconClick, rowData, etc.
|
|
39
43
|
*/
|
|
40
|
-
function formatTableData(columnTitles, accessors, columnConfigs, renderers = {}) {
|
|
41
|
-
|
|
42
|
-
* Creates the "Cell" renderer for each column,
|
|
43
|
-
* checking icons/images or type fields,
|
|
44
|
-
* then calling the relevant `renderers` method.
|
|
45
|
-
*/
|
|
44
|
+
function formatTableData(columnTitles, accessors, columnConfigs, renderers = {}, options = {}) {
|
|
45
|
+
console.log("[LIB] formatTableData called with options:", options);
|
|
46
46
|
function renderCellContent(config) {
|
|
47
47
|
return ({ value }) => {
|
|
48
|
+
console.log("[LIB] renderCellContent -> config.type:", config.type, "value:", value);
|
|
48
49
|
// 1. Check icons/images
|
|
49
50
|
if (config.leftIcon && renderers.renderIcon) {
|
|
51
|
+
console.log("[LIB] using leftIcon:", config.leftIcon);
|
|
50
52
|
const icon = (_jsx("div", { className: "pr-2", children: renderers.renderIcon(config.leftIcon, "solid") }));
|
|
51
53
|
return renderContent(config, value, icon, "left");
|
|
52
54
|
}
|
|
53
55
|
if (config.rightIcon && renderers.renderIcon) {
|
|
56
|
+
console.log("[LIB] using rightIcon:", config.rightIcon);
|
|
54
57
|
const icon = (_jsx("div", { className: "pl-2", children: renderers.renderIcon(config.rightIcon, "solid") }));
|
|
55
58
|
return renderContent(config, value, icon, "right");
|
|
56
59
|
}
|
|
57
60
|
if (config.leftImage && renderers.renderImage) {
|
|
61
|
+
console.log("[LIB] using leftImage:", config.leftImage);
|
|
58
62
|
const image = (_jsx("div", { className: "pr-2", children: renderers.renderImage({
|
|
59
63
|
imageUrl: config.leftImage,
|
|
60
64
|
altText: "Image",
|
|
@@ -64,6 +68,7 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {})
|
|
|
64
68
|
return renderContent(config, value, image, "left");
|
|
65
69
|
}
|
|
66
70
|
if (config.rightImage && renderers.renderImage) {
|
|
71
|
+
console.log("[LIB] using rightImage:", config.rightImage);
|
|
67
72
|
const image = (_jsx("div", { className: "pl-2", children: renderers.renderImage({
|
|
68
73
|
imageUrl: config.rightImage,
|
|
69
74
|
altText: "Image",
|
|
@@ -75,30 +80,33 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {})
|
|
|
75
80
|
// 2. Check type
|
|
76
81
|
switch (config.type) {
|
|
77
82
|
case "STATUS":
|
|
83
|
+
console.log("[LIB] checking STATUS case, value:", value);
|
|
78
84
|
if (renderers.renderStatus && typeof value === "string") {
|
|
79
|
-
|
|
85
|
+
console.log("[LIB] calling renderers.renderStatus!");
|
|
86
|
+
// If you want to pass `options.typeValues` or something as extra:
|
|
87
|
+
return renderContent(config, value, renderers.renderStatus(value, {
|
|
88
|
+
typeValues: options.typeValues,
|
|
89
|
+
}));
|
|
80
90
|
}
|
|
81
91
|
break;
|
|
82
92
|
case "CURRENCY":
|
|
93
|
+
console.log("[LIB] checking CURRENCY case, value:", value);
|
|
83
94
|
if (renderers.renderCurrency && typeof value === "string") {
|
|
95
|
+
console.log("[LIB] calling renderers.renderCurrency!");
|
|
84
96
|
const formatted = renderers.renderCurrency(value);
|
|
85
97
|
return renderContent(config, formatted);
|
|
86
98
|
}
|
|
87
99
|
break;
|
|
88
|
-
|
|
100
|
+
default:
|
|
101
|
+
console.log("[LIB] type is:", config.type, "falling back to raw text");
|
|
89
102
|
}
|
|
90
103
|
// 3. Otherwise, raw text
|
|
91
104
|
return (_jsx("div", { style: { display: "flex", alignItems: "center" }, children: typeof value === "string" ? _jsx("p", { children: value }) : value }));
|
|
92
105
|
};
|
|
93
106
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Helper that wraps the cell in <div> or <a>,
|
|
96
|
-
* optionally placing icons left/right.
|
|
97
|
-
*/
|
|
98
107
|
function renderContent(config, value, content, position) {
|
|
99
108
|
return (_jsx("div", { style: { display: "flex", alignItems: "center" }, className: "flex w-full", children: config.linkClasses ? (_jsxs("a", { href: "#", className: `flex ${config.linkClasses}`, onClick: (e) => e.stopPropagation(), children: [position === "left" && content, typeof value === "string" ? _jsx("p", { children: value }) : value, position === "right" && content] })) : (_jsxs(_Fragment, { children: [position === "left" && content, typeof value === "string" ? _jsx("p", { children: value }) : value, position === "right" && content] })) }));
|
|
100
109
|
}
|
|
101
|
-
// Build columns, mapping each "raw config" through `transformBackendConfig`
|
|
102
110
|
const columns = columnTitles.map((title, i) => {
|
|
103
111
|
const accessor = accessors[i];
|
|
104
112
|
const key = `col${i + 1}`;
|
|
@@ -107,14 +115,27 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {})
|
|
|
107
115
|
key,
|
|
108
116
|
type: "DEFAULT",
|
|
109
117
|
};
|
|
118
|
+
console.log("[LIB] rawBackendConfig for", key, ":", rawBackendConfig);
|
|
110
119
|
// 2) Convert booleans => library fields
|
|
111
120
|
const config = transformBackendConfig(rawBackendConfig);
|
|
121
|
+
console.log("[LIB] final config for", key, ":", config);
|
|
112
122
|
return {
|
|
113
123
|
Header: title,
|
|
114
124
|
accessor,
|
|
115
125
|
Cell: ({ value }) => renderCellContent(config)({ value }),
|
|
116
126
|
};
|
|
117
127
|
});
|
|
128
|
+
console.log("[LIB] final columns:", columns);
|
|
129
|
+
if (options.handleIconClick || options.actionList) {
|
|
130
|
+
columns.push({
|
|
131
|
+
Header: "Sticky",
|
|
132
|
+
accessor: "sticky-column",
|
|
133
|
+
Cell: ({ row }) => {
|
|
134
|
+
// e.g. use row.index, options.rowData, etc.
|
|
135
|
+
return _jsx("div", { children: "Custom Sticky Cell" });
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
}
|
|
118
139
|
return columns;
|
|
119
140
|
}
|
|
120
141
|
/**
|
|
@@ -125,7 +146,6 @@ function generateAccessors(columnTitles) {
|
|
|
125
146
|
}
|
|
126
147
|
// Named exports
|
|
127
148
|
export { formatTableData, generateAccessors };
|
|
128
|
-
// Default export object (so you can import the entire thing as default if you want)
|
|
129
149
|
export default {
|
|
130
150
|
formatTableData,
|
|
131
151
|
generateAccessors,
|