@agilant/toga-blox 1.0.100 → 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
|
*/
|
|
@@ -11,6 +11,7 @@ function transformBackendConfig(backendConfig) {
|
|
|
11
11
|
linkClasses: backendConfig.linkClasses ?? "",
|
|
12
12
|
transform: backendConfig.transform,
|
|
13
13
|
};
|
|
14
|
+
// e.g. booleans => library fields
|
|
14
15
|
if (backendConfig.hasStatus) {
|
|
15
16
|
finalConfig.type = "STATUS";
|
|
16
17
|
}
|
|
@@ -18,10 +19,10 @@ function transformBackendConfig(backendConfig) {
|
|
|
18
19
|
finalConfig.type = "CURRENCY";
|
|
19
20
|
}
|
|
20
21
|
if (backendConfig.hasLeftIcon) {
|
|
21
|
-
finalConfig.leftIcon = "check";
|
|
22
|
+
finalConfig.leftIcon = "check";
|
|
22
23
|
}
|
|
23
24
|
if (backendConfig.hasRightIcon) {
|
|
24
|
-
finalConfig.rightIcon = "arrowRight";
|
|
25
|
+
finalConfig.rightIcon = "arrowRight";
|
|
25
26
|
}
|
|
26
27
|
if (backendConfig.hasLeftImage) {
|
|
27
28
|
finalConfig.leftImage = "https://example.com/placeholder.png";
|
|
@@ -38,16 +39,12 @@ function transformBackendConfig(backendConfig) {
|
|
|
38
39
|
* - `accessors`: array of "col1", "col2", ...
|
|
39
40
|
* - `columnConfigs`: array of raw backend configs (with booleans)
|
|
40
41
|
* - `renderers`: your app's icon/image/status/currency callbacks
|
|
42
|
+
* - `options`: an object with extra arguments like handleIconClick, rowData, etc.
|
|
41
43
|
*/
|
|
42
|
-
function formatTableData(columnTitles, accessors, columnConfigs, renderers = {}) {
|
|
43
|
-
|
|
44
|
-
* Creates the "Cell" renderer for each column,
|
|
45
|
-
* checking icons/images or type fields,
|
|
46
|
-
* then calling the relevant `renderers` method.
|
|
47
|
-
*/
|
|
44
|
+
function formatTableData(columnTitles, accessors, columnConfigs, renderers = {}, options = {}) {
|
|
45
|
+
console.log("[LIB] formatTableData called with options:", options);
|
|
48
46
|
function renderCellContent(config) {
|
|
49
47
|
return ({ value }) => {
|
|
50
|
-
// Log to see which type we ended up with, and what the cell value is
|
|
51
48
|
console.log("[LIB] renderCellContent -> config.type:", config.type, "value:", value);
|
|
52
49
|
// 1. Check icons/images
|
|
53
50
|
if (config.leftIcon && renderers.renderIcon) {
|
|
@@ -86,7 +83,10 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {})
|
|
|
86
83
|
console.log("[LIB] checking STATUS case, value:", value);
|
|
87
84
|
if (renderers.renderStatus && typeof value === "string") {
|
|
88
85
|
console.log("[LIB] calling renderers.renderStatus!");
|
|
89
|
-
|
|
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
|
+
}));
|
|
90
90
|
}
|
|
91
91
|
break;
|
|
92
92
|
case "CURRENCY":
|
|
@@ -97,7 +97,6 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {})
|
|
|
97
97
|
return renderContent(config, formatted);
|
|
98
98
|
}
|
|
99
99
|
break;
|
|
100
|
-
// Add other types if needed
|
|
101
100
|
default:
|
|
102
101
|
console.log("[LIB] type is:", config.type, "falling back to raw text");
|
|
103
102
|
}
|
|
@@ -105,14 +104,9 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {})
|
|
|
105
104
|
return (_jsx("div", { style: { display: "flex", alignItems: "center" }, children: typeof value === "string" ? _jsx("p", { children: value }) : value }));
|
|
106
105
|
};
|
|
107
106
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Helper that wraps the cell in <div> or <a>,
|
|
110
|
-
* optionally placing icons left/right.
|
|
111
|
-
*/
|
|
112
107
|
function renderContent(config, value, content, position) {
|
|
113
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] })) }));
|
|
114
109
|
}
|
|
115
|
-
// Build columns, mapping each "raw config" through `transformBackendConfig`
|
|
116
110
|
const columns = columnTitles.map((title, i) => {
|
|
117
111
|
const accessor = accessors[i];
|
|
118
112
|
const key = `col${i + 1}`;
|
|
@@ -132,6 +126,16 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {})
|
|
|
132
126
|
};
|
|
133
127
|
});
|
|
134
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
|
+
}
|
|
135
139
|
return columns;
|
|
136
140
|
}
|
|
137
141
|
/**
|
|
@@ -142,7 +146,6 @@ function generateAccessors(columnTitles) {
|
|
|
142
146
|
}
|
|
143
147
|
// Named exports
|
|
144
148
|
export { formatTableData, generateAccessors };
|
|
145
|
-
// Default export object (so you can import the entire thing as default if you want)
|
|
146
149
|
export default {
|
|
147
150
|
formatTableData,
|
|
148
151
|
generateAccessors,
|