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