@agilant/toga-blox 1.0.102 → 1.0.103-t

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.
@@ -1,6 +1,15 @@
1
+ /*****************************************************************************
2
+ * FILE 1: fromatTableData.ts (the library)
3
+ *
4
+ * Build/publish this so your Supply app can import:
5
+ * import { formatTableData, generateAccessors }
6
+ * from "@agilant/toga-blox/dist/utils/fromatTableData";
7
+ *****************************************************************************/
1
8
  import React from "react";
2
9
  import { CellProps } from "react-table";
3
- /** The shape your library expects for each column's config */
10
+ /**
11
+ * Basic shape for each column config in the library
12
+ */
4
13
  export interface SharedColumnConfig {
5
14
  key: string;
6
15
  type?: string;
@@ -11,7 +20,9 @@ export interface SharedColumnConfig {
11
20
  rightImage?: string;
12
21
  transform?: (value: any) => any;
13
22
  }
14
- /** The shape of the columns you return to React Table */
23
+ /**
24
+ * The shape of columns returned by the library for React Table
25
+ */
15
26
  export interface TableColumn {
16
27
  Header: string | (() => JSX.Element);
17
28
  accessor: string;
@@ -21,7 +32,7 @@ export interface TableColumn {
21
32
  sticky?: "left" | "right";
22
33
  }
23
34
  /**
24
- * The "renderers" your app provides for icons, images, statuses, currencies, etc.
35
+ * Callbacks for custom rendering
25
36
  */
26
37
  export interface Renderers {
27
38
  renderIcon?: (iconName: string, style?: "solid" | "regular") => JSX.Element;
@@ -35,10 +46,11 @@ export interface Renderers {
35
46
  renderStatus?: (value: string, extra?: any) => JSX.Element;
36
47
  renderCurrency?: (value: string) => string;
37
48
  }
38
- /** Additional options your apps might pass to the library */
49
+ /**
50
+ * Optional additional "options" your app might pass
51
+ */
39
52
  export interface FormatTableOptions {
40
53
  typeValues?: Record<string, any>;
41
- callFromFilter?: boolean;
42
54
  visibleListId?: string;
43
55
  handleIconClick?: (id: string, rowUuid: string) => void;
44
56
  actionList?: React.ReactNode;
@@ -46,19 +58,19 @@ export interface FormatTableOptions {
46
58
  deactivatedMenuUuids?: string[];
47
59
  }
48
60
  /**
49
- * The main function that shapes columns for React Table.
50
- * - `columnTitles`: array of column headers
51
- * - `accessors`: array of "col1", "col2", ...
52
- * - `columnConfigs`: array of raw backend configs (with booleans)
53
- * - `renderers`: your app's icon/image/status/currency callbacks
54
- * - `options`: an object with extra arguments like handleIconClick, rowData, etc.
61
+ * The main library function that shapes columns for React Table.
55
62
  */
56
- declare function formatTableData(columnTitles: string[], accessors: string[], columnConfigs: any[], renderers?: Renderers, options?: FormatTableOptions): TableColumn[];
63
+ export declare function formatTableData(columnTitles: string[], accessors: string[], columnConfigs: any[], // raw config array from the backend
64
+ renderers?: Renderers, // the app's custom rendering callbacks
65
+ options?: FormatTableOptions): TableColumn[];
57
66
  /**
58
67
  * Helper to generate "col1", "col2", "col3", etc.
59
68
  */
60
- declare function generateAccessors(columnTitles: string[]): string[];
61
- export { formatTableData, generateAccessors };
69
+ export declare function generateAccessors(columnTitles: string[]): string[];
70
+ /**
71
+ * Optional default export if you want
72
+ * `import something from '@agilant/toga-blox/dist/utils/fromatTableData'`
73
+ */
62
74
  declare const _default: {
63
75
  formatTableData: typeof formatTableData;
64
76
  generateAccessors: typeof generateAccessors;
@@ -1,17 +1,17 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  /**
3
- * Convert your backend booleans (e.g. `hasStatus`, `hasCurrency`)
4
- * into the library's expected fields (`type: "STATUS"`, `type: "CURRENCY"`, etc.).
3
+ * A helper to transform booleans like hasStatus -> type = "STATUS"
5
4
  */
6
5
  function transformBackendConfig(backendConfig) {
7
- console.log("[LIB] transformBackendConfig input:", backendConfig);
6
+ // For debugging, you can log the input
7
+ // console.log("[LIB] transformBackendConfig input:", backendConfig);
8
8
  const finalConfig = {
9
9
  key: backendConfig.key,
10
10
  type: backendConfig.type ?? "DEFAULT",
11
11
  linkClasses: backendConfig.linkClasses ?? "",
12
12
  transform: backendConfig.transform,
13
13
  };
14
- // e.g. booleans => library fields
14
+ // If the backend uses booleans
15
15
  if (backendConfig.hasStatus) {
16
16
  finalConfig.type = "STATUS";
17
17
  }
@@ -25,40 +25,37 @@ function transformBackendConfig(backendConfig) {
25
25
  finalConfig.rightIcon = "arrowRight";
26
26
  }
27
27
  if (backendConfig.hasLeftImage) {
28
- finalConfig.leftImage = "https://example.com/placeholder.png";
28
+ finalConfig.leftImage = "https://example.com/placeholder-left.png";
29
29
  }
30
30
  if (backendConfig.hasRightImage) {
31
- finalConfig.rightImage = "https://example.com/placeholder.png";
31
+ finalConfig.rightImage = "https://example.com/placeholder-right.png";
32
32
  }
33
- console.log("[LIB] transformBackendConfig output:", finalConfig);
33
+ // console.log("[LIB] transformBackendConfig output:", finalConfig);
34
34
  return finalConfig;
35
35
  }
36
36
  /**
37
- * The main function that shapes columns for React Table.
38
- * - `columnTitles`: array of column headers
39
- * - `accessors`: array of "col1", "col2", ...
40
- * - `columnConfigs`: array of raw backend configs (with booleans)
41
- * - `renderers`: your app's icon/image/status/currency callbacks
42
- * - `options`: an object with extra arguments like handleIconClick, rowData, etc.
37
+ * The main library function that shapes columns for React Table.
43
38
  */
44
- function formatTableData(columnTitles, accessors, columnConfigs, renderers = {}, options = {}) {
45
- console.log("[LIB] formatTableData called with options:", options);
39
+ export function formatTableData(columnTitles, accessors, columnConfigs, // raw config array from the backend
40
+ renderers = {}, // the app's custom rendering callbacks
41
+ options = {}) {
42
+ /**
43
+ * Creates the "Cell" renderer for each column,
44
+ * checking icons/images or type fields,
45
+ * then calling the relevant `renderers` method if found.
46
+ */
46
47
  function renderCellContent(config) {
47
48
  return ({ value }) => {
48
- console.log("[LIB] renderCellContent -> config.type:", config.type, "value:", value);
49
- // 1. Check icons/images
49
+ // 1) Check icons/images
50
50
  if (config.leftIcon && renderers.renderIcon) {
51
- console.log("[LIB] using leftIcon:", config.leftIcon);
52
51
  const icon = (_jsx("div", { className: "pr-2", children: renderers.renderIcon(config.leftIcon, "solid") }));
53
52
  return renderContent(config, value, icon, "left");
54
53
  }
55
54
  if (config.rightIcon && renderers.renderIcon) {
56
- console.log("[LIB] using rightIcon:", config.rightIcon);
57
55
  const icon = (_jsx("div", { className: "pl-2", children: renderers.renderIcon(config.rightIcon, "solid") }));
58
56
  return renderContent(config, value, icon, "right");
59
57
  }
60
58
  if (config.leftImage && renderers.renderImage) {
61
- console.log("[LIB] using leftImage:", config.leftImage);
62
59
  const image = (_jsx("div", { className: "pr-2", children: renderers.renderImage({
63
60
  imageUrl: config.leftImage,
64
61
  altText: "Image",
@@ -68,7 +65,6 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {},
68
65
  return renderContent(config, value, image, "left");
69
66
  }
70
67
  if (config.rightImage && renderers.renderImage) {
71
- console.log("[LIB] using rightImage:", config.rightImage);
72
68
  const image = (_jsx("div", { className: "pl-2", children: renderers.renderImage({
73
69
  imageUrl: config.rightImage,
74
70
  altText: "Image",
@@ -77,75 +73,67 @@ function formatTableData(columnTitles, accessors, columnConfigs, renderers = {},
77
73
  }) }));
78
74
  return renderContent(config, value, image, "right");
79
75
  }
80
- // 2. Check type
76
+ ``;
77
+ // 2) Check type
78
+ console.log(config, "CONFIG FROM LIB");
81
79
  switch (config.type) {
82
80
  case "STATUS":
83
- console.log("[LIB] checking STATUS case, value:", value);
84
81
  if (renderers.renderStatus && typeof value === "string") {
85
- console.log("[LIB] calling renderers.renderStatus!");
86
- // If you want to pass `options.typeValues` or something as extra:
82
+ console.log("HERE YOU GO");
87
83
  return renderContent(config, value, renderers.renderStatus(value, {
88
84
  typeValues: options.typeValues,
89
85
  }));
90
86
  }
91
87
  break;
92
88
  case "CURRENCY":
93
- console.log("[LIB] checking CURRENCY case, value:", value);
94
89
  if (renderers.renderCurrency && typeof value === "string") {
95
- console.log("[LIB] calling renderers.renderCurrency!");
96
90
  const formatted = renderers.renderCurrency(value);
97
91
  return renderContent(config, formatted);
98
92
  }
99
93
  break;
100
- default:
101
- console.log("[LIB] type is:", config.type, "falling back to raw text");
94
+ // Add more types if needed, e.g. "NUMBER", "DATE", etc.
102
95
  }
103
- // 3. Otherwise, raw text
96
+ // 3) Otherwise, raw text
104
97
  return (_jsx("div", { style: { display: "flex", alignItems: "center" }, children: typeof value === "string" ? _jsx("p", { children: value }) : value }));
105
98
  };
106
99
  }
100
+ /**
101
+ * Helper to wrap the content in a <div> or <a>
102
+ * and optionally place icons on the left/right side.
103
+ */
107
104
  function renderContent(config, value, content, position) {
108
105
  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] })) }));
109
106
  }
107
+ // Build columns
110
108
  const columns = columnTitles.map((title, i) => {
111
109
  const accessor = accessors[i];
112
110
  const key = `col${i + 1}`;
113
- // 1) Find the raw config from your backend array
114
- const rawBackendConfig = columnConfigs[0]?.default?.find((c) => c.key === key) || {
111
+ // 1) Find raw config by matching key
112
+ const rawConfig = columnConfigs.find((c) => c.key === key) || {
115
113
  key,
116
114
  type: "DEFAULT",
117
115
  };
118
- console.log("[LIB] rawBackendConfig for", key, ":", rawBackendConfig);
119
- // 2) Convert booleans => library fields
120
- const config = transformBackendConfig(rawBackendConfig);
121
- console.log("[LIB] final config for", key, ":", config);
116
+ // 2) Transform booleans -> library fields if needed
117
+ const config = transformBackendConfig(rawConfig);
118
+ // 3) Build the final column
122
119
  return {
123
120
  Header: title,
124
121
  accessor,
125
122
  Cell: ({ value }) => renderCellContent(config)({ value }),
126
123
  };
127
124
  });
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
- }
139
125
  return columns;
140
126
  }
141
127
  /**
142
128
  * Helper to generate "col1", "col2", "col3", etc.
143
129
  */
144
- function generateAccessors(columnTitles) {
130
+ export function generateAccessors(columnTitles) {
145
131
  return columnTitles.map((_, index) => `col${index + 1}`);
146
132
  }
147
- // Named exports
148
- export { formatTableData, generateAccessors };
133
+ /**
134
+ * Optional default export if you want
135
+ * `import something from '@agilant/toga-blox/dist/utils/fromatTableData'`
136
+ */
149
137
  export default {
150
138
  formatTableData,
151
139
  generateAccessors,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilant/toga-blox",
3
3
  "private": false,
4
- "version": "1.0.102",
4
+ "version": "1.0.103t",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",