@ramesesinc/platform-core 0.1.0

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.
Files changed (285) hide show
  1. package/dist/components/action/AlertMessage.d.ts +8 -0
  2. package/dist/components/action/AlertMessage.js +19 -0
  3. package/dist/components/action/AlertMessage.tsx +38 -0
  4. package/dist/components/action/Button.d.ts +21 -0
  5. package/dist/components/action/Button.js +139 -0
  6. package/dist/components/action/Button.tsx +230 -0
  7. package/dist/components/action/CancelEdit.d.ts +9 -0
  8. package/dist/components/action/CancelEdit.js +21 -0
  9. package/dist/components/action/CancelEdit.tsx +40 -0
  10. package/dist/components/action/DeleteData.d.ts +13 -0
  11. package/dist/components/action/DeleteData.js +43 -0
  12. package/dist/components/action/DeleteData.tsx +73 -0
  13. package/dist/components/action/Edit.d.ts +9 -0
  14. package/dist/components/action/Edit.js +21 -0
  15. package/dist/components/action/Edit.tsx +40 -0
  16. package/dist/components/action/LookupPage.d.ts +16 -0
  17. package/dist/components/action/LookupPage.js +62 -0
  18. package/dist/components/action/LookupPage.tsx +113 -0
  19. package/dist/components/action/ProcessRunner.d.ts +62 -0
  20. package/dist/components/action/ProcessRunner.js +156 -0
  21. package/dist/components/action/ProcessRunner.tsx +337 -0
  22. package/dist/components/action/Refresh.d.ts +7 -0
  23. package/dist/components/action/Refresh.js +17 -0
  24. package/dist/components/action/Refresh.tsx +35 -0
  25. package/dist/components/action/SaveData.d.ts +10 -0
  26. package/dist/components/action/SaveData.js +54 -0
  27. package/dist/components/action/SaveData.tsx +74 -0
  28. package/dist/components/action/SelectData.d.ts +8 -0
  29. package/dist/components/action/SelectData.js +29 -0
  30. package/dist/components/action/SelectData.tsx +47 -0
  31. package/dist/components/action/Undo.d.ts +9 -0
  32. package/dist/components/action/Undo.js +31 -0
  33. package/dist/components/action/Undo.tsx +50 -0
  34. package/dist/components/action/UpdateContext.d.ts +9 -0
  35. package/dist/components/action/UpdateContext.js +21 -0
  36. package/dist/components/action/UpdateContext.tsx +40 -0
  37. package/dist/components/action/UpdateData.d.ts +9 -0
  38. package/dist/components/action/UpdateData.js +33 -0
  39. package/dist/components/action/UpdateData.tsx +49 -0
  40. package/dist/components/action/ViewBackPage.d.ts +9 -0
  41. package/dist/components/action/ViewBackPage.js +19 -0
  42. package/dist/components/action/ViewBackPage.tsx +46 -0
  43. package/dist/components/action/ViewPage.d.ts +14 -0
  44. package/dist/components/action/ViewPage.js +88 -0
  45. package/dist/components/action/ViewPage.tsx +141 -0
  46. package/dist/components/common/UIComponent.d.ts +11 -0
  47. package/dist/components/common/UIComponent.js +52 -0
  48. package/dist/components/common/UIComponent.tsx +84 -0
  49. package/dist/components/common/UIInput.d.ts +12 -0
  50. package/dist/components/common/UIInput.js +37 -0
  51. package/dist/components/common/UIInput.tsx +49 -0
  52. package/dist/components/common/UIMenu.d.ts +23 -0
  53. package/dist/components/common/UIMenu.js +61 -0
  54. package/dist/components/common/UIMenu.tsx +91 -0
  55. package/dist/components/index.d.ts +37 -0
  56. package/dist/components/index.js +44 -0
  57. package/dist/components/index.ts +51 -0
  58. package/dist/components/input/CodeEditor.d.ts +12 -0
  59. package/dist/components/input/CodeEditor.js +132 -0
  60. package/dist/components/input/CodeEditor.tsx +188 -0
  61. package/dist/components/input/DateField.d.ts +9 -0
  62. package/dist/components/input/DateField.js +140 -0
  63. package/dist/components/input/DateField.tsx +274 -0
  64. package/dist/components/input/DayPicker.d.ts +2 -0
  65. package/dist/components/input/DayPicker.js +5 -0
  66. package/dist/components/input/DayPicker.tsx +5 -0
  67. package/dist/components/input/HtmlCode.d.ts +8 -0
  68. package/dist/components/input/HtmlCode.js +157 -0
  69. package/dist/components/input/HtmlCode.tsx +203 -0
  70. package/dist/components/input/JsonCode.d.ts +9 -0
  71. package/dist/components/input/JsonCode.js +159 -0
  72. package/dist/components/input/JsonCode.tsx +205 -0
  73. package/dist/components/input/MonthPicker.d.ts +2 -0
  74. package/dist/components/input/MonthPicker.js +5 -0
  75. package/dist/components/input/MonthPicker.tsx +5 -0
  76. package/dist/components/input/ScriptCode.d.ts +8 -0
  77. package/dist/components/input/ScriptCode.js +153 -0
  78. package/dist/components/input/ScriptCode.tsx +195 -0
  79. package/dist/components/input/Select.d.ts +14 -0
  80. package/dist/components/input/Select.js +40 -0
  81. package/dist/components/input/Select.tsx +78 -0
  82. package/dist/components/input/SqlCode.d.ts +8 -0
  83. package/dist/components/input/SqlCode.js +121 -0
  84. package/dist/components/input/SqlCode.tsx +162 -0
  85. package/dist/components/input/StringDecision.d.ts +2 -0
  86. package/dist/components/input/StringDecision.js +34 -0
  87. package/dist/components/input/StringDecision.tsx +64 -0
  88. package/dist/components/input/Text.d.ts +7 -0
  89. package/dist/components/input/Text.js +39 -0
  90. package/dist/components/input/Text.tsx +57 -0
  91. package/dist/components/input/YearPicker.d.ts +8 -0
  92. package/dist/components/input/YearPicker.js +44 -0
  93. package/dist/components/input/YearPicker.tsx +81 -0
  94. package/dist/components/list/IconMenu.d.ts +14 -0
  95. package/dist/components/list/IconMenu.js +72 -0
  96. package/dist/components/list/IconMenu.tsx +115 -0
  97. package/dist/components/list/TabMenu.d.ts +10 -0
  98. package/dist/components/list/TabMenu.js +72 -0
  99. package/dist/components/list/TabMenu.tsx +127 -0
  100. package/dist/components/list/TreeMenu.d.ts +14 -0
  101. package/dist/components/list/TreeMenu.js +207 -0
  102. package/dist/components/list/TreeMenu.tsx +279 -0
  103. package/dist/components/list/TxnTaskList.d.ts +2 -0
  104. package/dist/components/list/TxnTaskList.js +77 -0
  105. package/dist/components/list/TxnTaskList.tsx +198 -0
  106. package/dist/components/output/Label.d.ts +8 -0
  107. package/dist/components/output/Label.js +33 -0
  108. package/dist/components/output/Label.tsx +51 -0
  109. package/dist/components/table/DataList.d.ts +88 -0
  110. package/dist/components/table/DataList.js +361 -0
  111. package/dist/components/table/DataList.tsx +782 -0
  112. package/dist/components/table/DataTable.d.ts +46 -0
  113. package/dist/components/table/DataTable.js +253 -0
  114. package/dist/components/table/DataTable.tsx +572 -0
  115. package/dist/components/table/ListHandler.d.ts +42 -0
  116. package/dist/components/table/ListHandler.js +197 -0
  117. package/dist/components/table/ListHandler.ts +276 -0
  118. package/dist/components/table/TableContext.d.ts +33 -0
  119. package/dist/components/table/TableContext.js +57 -0
  120. package/dist/components/table/TableContext.tsx +122 -0
  121. package/dist/components/view/ComponentView.d.ts +8 -0
  122. package/dist/components/view/ComponentView.js +78 -0
  123. package/dist/components/view/ComponentView.tsx +102 -0
  124. package/dist/components/view/FilterView.d.ts +2 -0
  125. package/dist/components/view/FilterView.js +14 -0
  126. package/dist/components/view/FilterView.tsx +21 -0
  127. package/dist/components/view/HtmlForm.d.ts +7 -0
  128. package/dist/components/view/HtmlForm.js +145 -0
  129. package/dist/components/view/HtmlForm.tsx +186 -0
  130. package/dist/components/view/HtmlView.d.ts +9 -0
  131. package/dist/components/view/HtmlView.js +85 -0
  132. package/dist/components/view/HtmlView.tsx +114 -0
  133. package/dist/components/view/IFrameView.d.ts +2 -0
  134. package/dist/components/view/IFrameView.js +34 -0
  135. package/dist/components/view/IFrameView.tsx +48 -0
  136. package/dist/components/view/Modal.d.ts +14 -0
  137. package/dist/components/view/Modal.js +28 -0
  138. package/dist/components/view/Modal.tsx +72 -0
  139. package/dist/components/view/PageView.d.ts +9 -0
  140. package/dist/components/view/PageView.js +90 -0
  141. package/dist/components/view/PageView.tsx +131 -0
  142. package/dist/components/view/PopupView.d.ts +9 -0
  143. package/dist/components/view/PopupView.js +91 -0
  144. package/dist/components/view/PopupView.tsx +160 -0
  145. package/dist/components/view/RootView.d.ts +8 -0
  146. package/dist/components/view/RootView.js +75 -0
  147. package/dist/components/view/RootView.tsx +109 -0
  148. package/dist/components/view/WizardView.d.ts +6 -0
  149. package/dist/components/view/WizardView.js +34 -0
  150. package/dist/components/view/WizardView.tsx +48 -0
  151. package/dist/core/AppContext.d.ts +25 -0
  152. package/dist/core/AppContext.js +159 -0
  153. package/dist/core/AuthContext.d.ts +13 -0
  154. package/dist/core/AuthContext.js +80 -0
  155. package/dist/core/ComponentCache.d.ts +15 -0
  156. package/dist/core/ComponentCache.js +25 -0
  157. package/dist/core/DataContext.d.ts +20 -0
  158. package/dist/core/DataContext.js +41 -0
  159. package/dist/core/DynamicComponent.d.ts +12 -0
  160. package/dist/core/DynamicComponent.js +30 -0
  161. package/dist/core/DynamicIcon.d.ts +6 -0
  162. package/dist/core/DynamicIcon.js +48 -0
  163. package/dist/core/DynamicTemplate.d.ts +4 -0
  164. package/dist/core/DynamicTemplate.js +17 -0
  165. package/dist/core/ErrorMessage.d.ts +5 -0
  166. package/dist/core/ErrorMessage.js +7 -0
  167. package/dist/core/EventHandler.d.ts +3 -0
  168. package/dist/core/EventHandler.js +1 -0
  169. package/dist/core/HtmlCache.d.ts +6 -0
  170. package/dist/core/HtmlCache.js +17 -0
  171. package/dist/core/Page.d.ts +6 -0
  172. package/dist/core/Page.js +141 -0
  173. package/dist/core/PageCache.d.ts +15 -0
  174. package/dist/core/PageCache.js +26 -0
  175. package/dist/core/PageContext.d.ts +49 -0
  176. package/dist/core/PageContext.js +207 -0
  177. package/dist/core/PageRegistry.d.ts +7 -0
  178. package/dist/core/PageRegistry.js +11 -0
  179. package/dist/core/PageViewContext.d.ts +45 -0
  180. package/dist/core/PageViewContext.js +277 -0
  181. package/dist/core/Panel.d.ts +16 -0
  182. package/dist/core/Panel.js +39 -0
  183. package/dist/core/RowContext.d.ts +11 -0
  184. package/dist/core/RowContext.js +16 -0
  185. package/dist/core/StepHandler.d.ts +9 -0
  186. package/dist/core/StepHandler.js +39 -0
  187. package/dist/core/UIDependHandler.d.ts +6 -0
  188. package/dist/core/UIDependHandler.js +31 -0
  189. package/dist/core/auth/index.d.ts +18 -0
  190. package/dist/core/auth/index.js +187 -0
  191. package/dist/core/auth/session.d.ts +4 -0
  192. package/dist/core/auth/session.js +45 -0
  193. package/dist/core/index.d.ts +3 -0
  194. package/dist/core/index.js +1 -0
  195. package/dist/core/page-helper.d.ts +27 -0
  196. package/dist/core/page-helper.js +47 -0
  197. package/dist/hooks/useUrlParams.d.ts +11 -0
  198. package/dist/hooks/useUrlParams.js +164 -0
  199. package/dist/index.d.ts +65 -0
  200. package/dist/index.js +69 -0
  201. package/dist/layouts/BorderLayout.d.ts +14 -0
  202. package/dist/layouts/BorderLayout.js +8 -0
  203. package/dist/layouts/CardLayout.d.ts +27 -0
  204. package/dist/layouts/CardLayout.js +36 -0
  205. package/dist/layouts/CenterLayout.d.ts +8 -0
  206. package/dist/layouts/CenterLayout.js +6 -0
  207. package/dist/layouts/GridLayout.d.ts +9 -0
  208. package/dist/layouts/GridLayout.js +5 -0
  209. package/dist/layouts/HPanel.d.ts +11 -0
  210. package/dist/layouts/HPanel.js +8 -0
  211. package/dist/layouts/HorizontalLayout.d.ts +11 -0
  212. package/dist/layouts/HorizontalLayout.js +6 -0
  213. package/dist/layouts/MainLayout.d.ts +6 -0
  214. package/dist/layouts/MainLayout.js +5 -0
  215. package/dist/layouts/PageLayout.d.ts +11 -0
  216. package/dist/layouts/PageLayout.js +6 -0
  217. package/dist/layouts/VPanel.d.ts +9 -0
  218. package/dist/layouts/VPanel.js +7 -0
  219. package/dist/layouts/XLayout.d.ts +10 -0
  220. package/dist/layouts/XLayout.js +10 -0
  221. package/dist/layouts/YLayout.d.ts +10 -0
  222. package/dist/layouts/YLayout.js +10 -0
  223. package/dist/lib/PlatformRoute.d.ts +5 -0
  224. package/dist/lib/PlatformRoute.js +288 -0
  225. package/dist/lib/WebPlatform.d.ts +13 -0
  226. package/dist/lib/WebPlatform.js +124 -0
  227. package/dist/lib/components/ActivityBar.d.ts +13 -0
  228. package/dist/lib/components/ActivityBar.js +39 -0
  229. package/dist/lib/components/CopyButton.d.ts +8 -0
  230. package/dist/lib/components/CopyButton.js +50 -0
  231. package/dist/lib/components/Header.d.ts +2 -0
  232. package/dist/lib/components/Header.js +74 -0
  233. package/dist/lib/components/QuickActionMenu.d.ts +18 -0
  234. package/dist/lib/components/QuickActionMenu.js +50 -0
  235. package/dist/lib/components/UserButton.d.ts +11 -0
  236. package/dist/lib/components/UserButton.js +66 -0
  237. package/dist/lib/layouts/BorderLayout.tsx +31 -0
  238. package/dist/lib/layouts/CardLayout.tsx +73 -0
  239. package/dist/lib/layouts/CenterLayout.tsx +20 -0
  240. package/dist/lib/layouts/GridLayout.tsx +20 -0
  241. package/dist/lib/layouts/HPanel.tsx +31 -0
  242. package/dist/lib/layouts/HorizontalLayout.tsx +29 -0
  243. package/dist/lib/layouts/MainLayout.tsx +16 -0
  244. package/dist/lib/layouts/PageLayout.tsx +29 -0
  245. package/dist/lib/layouts/VPanel.tsx +27 -0
  246. package/dist/lib/layouts/XLayout.tsx +29 -0
  247. package/dist/lib/layouts/YLayout.tsx +29 -0
  248. package/dist/lib/utils/BeanUtils.d.ts +3 -0
  249. package/dist/lib/utils/BeanUtils.js +75 -0
  250. package/dist/lib/utils/ComponentLoader.d.ts +13 -0
  251. package/dist/lib/utils/ComponentLoader.js +26 -0
  252. package/dist/lib/utils/ExprUtil.d.ts +7 -0
  253. package/dist/lib/utils/ExprUtil.js +44 -0
  254. package/dist/lib/utils/PageUtils.d.ts +6 -0
  255. package/dist/lib/utils/PageUtils.js +121 -0
  256. package/dist/lib/utils/ResourceLoader.d.ts +11 -0
  257. package/dist/lib/utils/ResourceLoader.js +37 -0
  258. package/dist/lib/utils/SectionProvider.d.ts +5 -0
  259. package/dist/lib/utils/SectionProvider.js +39 -0
  260. package/dist/lib/utils/initResourceLoader.d.ts +0 -0
  261. package/dist/lib/utils/initResourceLoader.js +95 -0
  262. package/dist/styles/index.css +38 -0
  263. package/dist/templates/BasicTemplate.d.ts +2 -0
  264. package/dist/templates/BasicTemplate.js +14 -0
  265. package/dist/templates/CrudFormTemplate.d.ts +2 -0
  266. package/dist/templates/CrudFormTemplate.js +38 -0
  267. package/dist/templates/DataListTemplate.d.ts +2 -0
  268. package/dist/templates/DataListTemplate.js +13 -0
  269. package/dist/templates/ExplorerTemplate.d.ts +10 -0
  270. package/dist/templates/ExplorerTemplate.js +17 -0
  271. package/dist/templates/TxnFormTemplate.d.ts +2 -0
  272. package/dist/templates/TxnFormTemplate.js +66 -0
  273. package/dist/templates/WizardTemplate.d.ts +9 -0
  274. package/dist/templates/WizardTemplate.js +37 -0
  275. package/dist/templates/index.d.ts +5 -0
  276. package/dist/templates/index.js +5 -0
  277. package/dist/types/action.d.ts +8 -0
  278. package/dist/types/action.js +1 -0
  279. package/dist/types/component.d.ts +18 -0
  280. package/dist/types/component.js +1 -0
  281. package/dist/types/list.d.ts +14 -0
  282. package/dist/types/list.js +1 -0
  283. package/dist/types/template.d.ts +6 -0
  284. package/dist/types/template.js +1 -0
  285. package/package.json +56 -0
@@ -0,0 +1,197 @@
1
+ /**
2
+ * ListHandler - Functional style implementation for managing data fetching,
3
+ * pagination, filtering, and sorting for DataList, DataTable, or any list-like components.
4
+ */
5
+ var __rest = (this && this.__rest) || function (s, e) {
6
+ var t = {};
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
8
+ t[p] = s[p];
9
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
10
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
11
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
12
+ t[p[i]] = s[p[i]];
13
+ }
14
+ return t;
15
+ };
16
+ import { localAPI } from "@ramesesinc/lib/local-api";
17
+ // FIX: removed the erroneous second parameter `ListHandlerConfig: any`
18
+ export const ListHandler = (config) => {
19
+ var _a;
20
+ const api = config.api;
21
+ const cols = config.cols;
22
+ const _b = (_a = config.params) !== null && _a !== void 0 ? _a : {}, { filter = {} } = _b, rest = __rest(_b, ["filter"]);
23
+ const disableTotalCount = config.disableTotalCount || false;
24
+ const useCursorPagination = config.useCursorPagination || false;
25
+ let rowsPerPage = config.rowsPerPage || 20;
26
+ let currentPage = 1;
27
+ let customFilter = {};
28
+ let searchText = "";
29
+ let sortColumn = null;
30
+ let sortDirection = null;
31
+ let lastCursor = null;
32
+ let dataResult = [];
33
+ let totalRecordCount = 0;
34
+ let totalPageCount = 0;
35
+ let hasMorePages = false;
36
+ const getData = () => dataResult;
37
+ const load = async () => {
38
+ var _a, _b;
39
+ const queryParams = {
40
+ cols,
41
+ start: (currentPage - 1) * rowsPerPage,
42
+ limit: rowsPerPage,
43
+ filter: Object.assign(Object.assign({}, filter), customFilter),
44
+ };
45
+ if (useCursorPagination && lastCursor) {
46
+ queryParams.cursor = lastCursor;
47
+ }
48
+ if (disableTotalCount) {
49
+ queryParams.skipCount = true;
50
+ }
51
+ if (searchText) {
52
+ queryParams.search = searchText;
53
+ }
54
+ if (sortColumn && sortDirection) {
55
+ queryParams.sort = { column: sortColumn, direction: sortDirection };
56
+ }
57
+ try {
58
+ // console.log("datalist pass 1", { api, query: { ...queryParams, ...rest } });
59
+ const result = await localAPI.exec(`/services/exec/${config.tenant}/${config.module}/${api}`, Object.assign(Object.assign({}, queryParams), rest));
60
+ // console.log("datalist pass 2", { result });
61
+ dataResult = result.data || [];
62
+ if (useCursorPagination) {
63
+ lastCursor = (_a = result.nextCursor) !== null && _a !== void 0 ? _a : null;
64
+ hasMorePages = (_b = result.hasMore) !== null && _b !== void 0 ? _b : false;
65
+ }
66
+ if (!disableTotalCount) {
67
+ totalRecordCount = result.total || 0;
68
+ totalPageCount = result.totalPages || Math.ceil(totalRecordCount / rowsPerPage);
69
+ }
70
+ else {
71
+ hasMorePages = result.data && result.data.length === rowsPerPage;
72
+ }
73
+ }
74
+ catch (error) {
75
+ console.error("Error loading data:", error);
76
+ dataResult = [];
77
+ totalRecordCount = 0;
78
+ totalPageCount = 0;
79
+ hasMorePages = false;
80
+ throw error;
81
+ }
82
+ };
83
+ const reset = async () => {
84
+ currentPage = 1;
85
+ await load();
86
+ };
87
+ const moveNextPage = async () => {
88
+ if (hasNextPage()) {
89
+ currentPage++;
90
+ await load();
91
+ }
92
+ };
93
+ const movePrevPage = async () => {
94
+ if (hasPrevPage()) {
95
+ currentPage--;
96
+ await load();
97
+ }
98
+ };
99
+ const moveFirstPage = async () => {
100
+ currentPage = 1;
101
+ await load();
102
+ };
103
+ const moveLastPage = async () => {
104
+ if (disableTotalCount) {
105
+ console.warn("moveLastPage is not available when total count is disabled");
106
+ return;
107
+ }
108
+ if (totalPageCount > 0) {
109
+ currentPage = totalPageCount;
110
+ await load();
111
+ }
112
+ };
113
+ const moveToPage = async (page) => {
114
+ if (page >= 1 && page <= totalPageCount) {
115
+ currentPage = page;
116
+ await load();
117
+ }
118
+ else {
119
+ console.warn(`Invalid page number: ${page}. Must be between 1 and ${totalPageCount}`);
120
+ }
121
+ };
122
+ const setFilter = async (filter) => {
123
+ customFilter = Object.assign({}, filter);
124
+ currentPage = 1;
125
+ await load();
126
+ };
127
+ const resetFilter = async () => {
128
+ customFilter = {};
129
+ currentPage = 1;
130
+ await load();
131
+ };
132
+ const doSearch = async (text) => {
133
+ searchText = text;
134
+ currentPage = 1;
135
+ await load();
136
+ };
137
+ const sortAsc = async (column) => {
138
+ sortColumn = column;
139
+ sortDirection = "asc";
140
+ currentPage = 1;
141
+ await load();
142
+ };
143
+ const sortDesc = async (column) => {
144
+ sortColumn = column;
145
+ sortDirection = "desc";
146
+ currentPage = 1;
147
+ await load();
148
+ };
149
+ const setRowsPerPage = async (rows) => {
150
+ if (rows > 0) {
151
+ rowsPerPage = rows;
152
+ currentPage = 1;
153
+ await load();
154
+ }
155
+ };
156
+ const hasNextPage = () => {
157
+ if (disableTotalCount || useCursorPagination)
158
+ return hasMorePages;
159
+ return currentPage < totalPageCount;
160
+ };
161
+ const hasPrevPage = () => currentPage > 1;
162
+ const getTotalPageCount = () => totalPageCount;
163
+ const getTotalRecordCount = () => totalRecordCount;
164
+ const getCurrentPage = () => currentPage;
165
+ const getCurrentSortedColumn = () => sortColumn;
166
+ const getCurrentSortDirection = () => sortDirection;
167
+ const getRowsPerPage = () => rowsPerPage;
168
+ const getSearchText = () => searchText;
169
+ const getCustomFilter = () => (Object.assign({}, customFilter));
170
+ return {
171
+ getData,
172
+ load,
173
+ reset,
174
+ moveNextPage,
175
+ movePrevPage,
176
+ moveFirstPage,
177
+ moveLastPage,
178
+ moveToPage,
179
+ setFilter,
180
+ resetFilter,
181
+ doSearch,
182
+ sortAsc,
183
+ sortDesc,
184
+ setRowsPerPage,
185
+ hasNextPage,
186
+ hasPrevPage,
187
+ getTotalPageCount,
188
+ getTotalRecordCount,
189
+ getCurrentPage,
190
+ getCurrentSortedColumn,
191
+ getCurrentSortDirection,
192
+ getRowsPerPage,
193
+ getSearchText,
194
+ getCustomFilter,
195
+ };
196
+ };
197
+ export default ListHandler;
@@ -0,0 +1,276 @@
1
+ /**
2
+ * ListHandler - Functional style implementation for managing data fetching,
3
+ * pagination, filtering, and sorting for DataList, DataTable, or any list-like components.
4
+ */
5
+
6
+ import { localAPI } from "@ramesesinc/lib/local-api";
7
+
8
+ export interface ListHandlerConfig {
9
+ tenant: string;
10
+ module: string;
11
+ api: string;
12
+ params?: Record<string, any>;
13
+ cols: string[];
14
+ rowsPerPage?: number;
15
+ disableTotalCount?: boolean;
16
+ useCursorPagination?: boolean;
17
+ }
18
+
19
+ interface QueryParams {
20
+ cols: string[];
21
+ start: number;
22
+ limit: number;
23
+ sort?: {
24
+ column: string;
25
+ direction: "asc" | "desc";
26
+ };
27
+ search?: string;
28
+ skipCount?: boolean;
29
+ cursor?: string;
30
+ [key: string]: any;
31
+ }
32
+
33
+ interface DataResult {
34
+ data: any[];
35
+ total?: number;
36
+ page: number;
37
+ totalPages?: number;
38
+ hasMore?: boolean;
39
+ nextCursor?: string;
40
+ }
41
+
42
+ export type ListActionHandler = {
43
+ getData: () => any[];
44
+ load: () => Promise<void>;
45
+ reset: () => Promise<void>;
46
+ moveNextPage: () => Promise<void>;
47
+ movePrevPage: () => Promise<void>;
48
+ moveFirstPage: () => Promise<void>;
49
+ moveLastPage: () => Promise<void>;
50
+ moveToPage: (page: number) => Promise<void>;
51
+ setFilter: (filter: Record<string, any>) => Promise<void>;
52
+ resetFilter: () => Promise<void>;
53
+ doSearch: (text: string) => Promise<void>;
54
+ sortAsc: (column: string) => Promise<void>;
55
+ sortDesc: (column: string) => Promise<void>;
56
+ setRowsPerPage: (rows: number) => Promise<void>;
57
+ hasNextPage: () => boolean;
58
+ hasPrevPage: () => boolean;
59
+ getTotalPageCount: () => number;
60
+ getTotalRecordCount: () => number;
61
+ getCurrentPage: () => number;
62
+ getCurrentSortedColumn: () => string | null;
63
+ getCurrentSortDirection: () => "asc" | "desc" | null;
64
+ getRowsPerPage: () => number;
65
+ getSearchText: () => string;
66
+ getCustomFilter: () => Record<string, any>;
67
+ };
68
+
69
+ // FIX: removed the erroneous second parameter `ListHandlerConfig: any`
70
+ export const ListHandler = (config: ListHandlerConfig): ListActionHandler => {
71
+ const api = config.api;
72
+ const cols = config.cols;
73
+
74
+ const { filter = {}, ...rest } = config.params ?? {};
75
+
76
+ const disableTotalCount = config.disableTotalCount || false;
77
+ const useCursorPagination = config.useCursorPagination || false;
78
+
79
+ let rowsPerPage = config.rowsPerPage || 20;
80
+ let currentPage = 1;
81
+ let customFilter: Record<string, any> = {};
82
+ let searchText = "";
83
+ let sortColumn: string | null = null;
84
+ let sortDirection: "asc" | "desc" | null = null;
85
+ let lastCursor: string | null = null;
86
+
87
+ let dataResult: any[] = [];
88
+ let totalRecordCount = 0;
89
+ let totalPageCount = 0;
90
+ let hasMorePages = false;
91
+
92
+ const getData = (): any[] => dataResult;
93
+
94
+ const load = async (): Promise<void> => {
95
+ const queryParams: QueryParams = {
96
+ cols,
97
+ start: (currentPage - 1) * rowsPerPage,
98
+ limit: rowsPerPage,
99
+ filter: {
100
+ ...filter,
101
+ ...customFilter,
102
+ },
103
+ };
104
+
105
+ if (useCursorPagination && lastCursor) {
106
+ queryParams.cursor = lastCursor;
107
+ }
108
+
109
+ if (disableTotalCount) {
110
+ queryParams.skipCount = true;
111
+ }
112
+
113
+ if (searchText) {
114
+ queryParams.search = searchText;
115
+ }
116
+
117
+ if (sortColumn && sortDirection) {
118
+ queryParams.sort = { column: sortColumn, direction: sortDirection };
119
+ }
120
+
121
+ try {
122
+ // console.log("datalist pass 1", { api, query: { ...queryParams, ...rest } });
123
+ const result = await localAPI.exec(`/services/exec/${config.tenant}/${config.module}/${api}`, { ...queryParams, ...rest });
124
+ // console.log("datalist pass 2", { result });
125
+ dataResult = result.data || [];
126
+
127
+ if (useCursorPagination) {
128
+ lastCursor = result.nextCursor ?? null;
129
+ hasMorePages = result.hasMore ?? false;
130
+ }
131
+
132
+ if (!disableTotalCount) {
133
+ totalRecordCount = result.total || 0;
134
+ totalPageCount = result.totalPages || Math.ceil(totalRecordCount / rowsPerPage);
135
+ } else {
136
+ hasMorePages = result.data && result.data.length === rowsPerPage;
137
+ }
138
+ } catch (error) {
139
+ console.error("Error loading data:", error);
140
+ dataResult = [];
141
+ totalRecordCount = 0;
142
+ totalPageCount = 0;
143
+ hasMorePages = false;
144
+ throw error;
145
+ }
146
+ };
147
+
148
+ const reset = async (): Promise<void> => {
149
+ currentPage = 1;
150
+ await load();
151
+ };
152
+
153
+ const moveNextPage = async (): Promise<void> => {
154
+ if (hasNextPage()) {
155
+ currentPage++;
156
+ await load();
157
+ }
158
+ };
159
+
160
+ const movePrevPage = async (): Promise<void> => {
161
+ if (hasPrevPage()) {
162
+ currentPage--;
163
+ await load();
164
+ }
165
+ };
166
+
167
+ const moveFirstPage = async (): Promise<void> => {
168
+ currentPage = 1;
169
+ await load();
170
+ };
171
+
172
+ const moveLastPage = async (): Promise<void> => {
173
+ if (disableTotalCount) {
174
+ console.warn("moveLastPage is not available when total count is disabled");
175
+ return;
176
+ }
177
+ if (totalPageCount > 0) {
178
+ currentPage = totalPageCount;
179
+ await load();
180
+ }
181
+ };
182
+
183
+ const moveToPage = async (page: number): Promise<void> => {
184
+ if (page >= 1 && page <= totalPageCount) {
185
+ currentPage = page;
186
+ await load();
187
+ } else {
188
+ console.warn(`Invalid page number: ${page}. Must be between 1 and ${totalPageCount}`);
189
+ }
190
+ };
191
+
192
+ const setFilter = async (filter: Record<string, any>): Promise<void> => {
193
+ customFilter = { ...filter };
194
+ currentPage = 1;
195
+ await load();
196
+ };
197
+
198
+ const resetFilter = async (): Promise<void> => {
199
+ customFilter = {};
200
+ currentPage = 1;
201
+ await load();
202
+ };
203
+
204
+ const doSearch = async (text: string): Promise<void> => {
205
+ searchText = text;
206
+ currentPage = 1;
207
+ await load();
208
+ };
209
+
210
+ const sortAsc = async (column: string): Promise<void> => {
211
+ sortColumn = column;
212
+ sortDirection = "asc";
213
+ currentPage = 1;
214
+ await load();
215
+ };
216
+
217
+ const sortDesc = async (column: string): Promise<void> => {
218
+ sortColumn = column;
219
+ sortDirection = "desc";
220
+ currentPage = 1;
221
+ await load();
222
+ };
223
+
224
+ const setRowsPerPage = async (rows: number): Promise<void> => {
225
+ if (rows > 0) {
226
+ rowsPerPage = rows;
227
+ currentPage = 1;
228
+ await load();
229
+ }
230
+ };
231
+
232
+ const hasNextPage = (): boolean => {
233
+ if (disableTotalCount || useCursorPagination) return hasMorePages;
234
+ return currentPage < totalPageCount;
235
+ };
236
+
237
+ const hasPrevPage = (): boolean => currentPage > 1;
238
+
239
+ const getTotalPageCount = (): number => totalPageCount;
240
+ const getTotalRecordCount = (): number => totalRecordCount;
241
+ const getCurrentPage = (): number => currentPage;
242
+ const getCurrentSortedColumn = (): string | null => sortColumn;
243
+ const getCurrentSortDirection = (): "asc" | "desc" | null => sortDirection;
244
+ const getRowsPerPage = (): number => rowsPerPage;
245
+ const getSearchText = (): string => searchText;
246
+ const getCustomFilter = (): Record<string, any> => ({ ...customFilter });
247
+
248
+ return {
249
+ getData,
250
+ load,
251
+ reset,
252
+ moveNextPage,
253
+ movePrevPage,
254
+ moveFirstPage,
255
+ moveLastPage,
256
+ moveToPage,
257
+ setFilter,
258
+ resetFilter,
259
+ doSearch,
260
+ sortAsc,
261
+ sortDesc,
262
+ setRowsPerPage,
263
+ hasNextPage,
264
+ hasPrevPage,
265
+ getTotalPageCount,
266
+ getTotalRecordCount,
267
+ getCurrentPage,
268
+ getCurrentSortedColumn,
269
+ getCurrentSortDirection,
270
+ getRowsPerPage,
271
+ getSearchText,
272
+ getCustomFilter,
273
+ };
274
+ };
275
+
276
+ export default ListHandler;
@@ -0,0 +1,33 @@
1
+ import React, { ReactNode } from "react";
2
+ import { ColumnDefinition } from "./DataTable";
3
+ import { ListHandlerConfig, ListActionHandler } from "./ListHandler";
4
+ export interface DataConfig {
5
+ api: string;
6
+ params?: Record<string, any>;
7
+ }
8
+ export interface TableContextValue {
9
+ listHandler: ListActionHandler | null;
10
+ columns: ColumnDefinition[];
11
+ setColumns: React.Dispatch<React.SetStateAction<ColumnDefinition[]>>;
12
+ rows: any[];
13
+ setRows: React.Dispatch<React.SetStateAction<any[]>>;
14
+ loading: boolean;
15
+ setLoading: React.Dispatch<React.SetStateAction<boolean>>;
16
+ }
17
+ declare const TableContext: React.Context<TableContextValue | null>;
18
+ export declare const useTableContext: () => TableContextValue;
19
+ export interface TableProviderProps {
20
+ data: DataConfig;
21
+ columns?: ColumnDefinition[];
22
+ rowsPerPage?: number;
23
+ disableTotalCount?: boolean;
24
+ useCursorPagination?: boolean;
25
+ children: ReactNode;
26
+ listHandlerFactory: (config: ListHandlerConfig) => ListActionHandler;
27
+ tenant: string;
28
+ module: string;
29
+ resolvedParams: Record<string, any> | undefined;
30
+ }
31
+ export declare const TableProvider: React.FC<TableProviderProps>;
32
+ export type { ListHandlerConfig };
33
+ export default TableContext;
@@ -0,0 +1,57 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useState, useEffect, useRef } from "react";
3
+ // ============================================================================
4
+ // CONTEXT
5
+ // ============================================================================
6
+ const TableContext = createContext(null);
7
+ export const useTableContext = () => {
8
+ const ctx = useContext(TableContext);
9
+ if (!ctx)
10
+ throw new Error("useTableContext must be used inside <TableProvider>");
11
+ return ctx;
12
+ };
13
+ // ============================================================================
14
+ // PROVIDER
15
+ // ============================================================================
16
+ export const TableProvider = ({ data, columns: initialColumns = [], rowsPerPage = 20, disableTotalCount = true, useCursorPagination = false, children, listHandlerFactory, tenant, module, resolvedParams, }) => {
17
+ const colIds = initialColumns.map((c) => { var _a, _b; return (_b = (_a = c.id) !== null && _a !== void 0 ? _a : c.expr) !== null && _b !== void 0 ? _b : ""; }).filter(Boolean);
18
+ // ListHandler created ONCE via ref.
19
+ // resolvedParams already has all placeholders replaced — passed in from DataList.
20
+ const listHandlerRef = useRef(null);
21
+ if (listHandlerRef.current === null) {
22
+ listHandlerRef.current = listHandlerFactory({
23
+ tenant,
24
+ module,
25
+ api: data.api,
26
+ params: resolvedParams,
27
+ cols: colIds,
28
+ rowsPerPage,
29
+ disableTotalCount,
30
+ useCursorPagination,
31
+ });
32
+ }
33
+ const [columns, setColumns] = useState(initialColumns);
34
+ const [rows, setRows] = useState([]);
35
+ const [loading, setLoading] = useState(false);
36
+ // Initial data load on mount
37
+ useEffect(() => {
38
+ const lh = listHandlerRef.current;
39
+ if (!lh)
40
+ return;
41
+ setLoading(true);
42
+ lh.load()
43
+ .then(() => setRows([...lh.getData()]))
44
+ .catch((err) => console.error("TableProvider initial load failed:", err))
45
+ .finally(() => setLoading(false));
46
+ }, []);
47
+ return (_jsx(TableContext.Provider, { value: {
48
+ listHandler: listHandlerRef.current,
49
+ columns,
50
+ setColumns,
51
+ rows,
52
+ setRows,
53
+ loading,
54
+ setLoading,
55
+ }, children: children }));
56
+ };
57
+ export default TableContext;
@@ -0,0 +1,122 @@
1
+ import React, { createContext, useContext, useState, useEffect, useRef, ReactNode } from "react";
2
+ import { ColumnDefinition } from "./DataTable";
3
+ import { ListHandlerConfig, ListActionHandler } from "./ListHandler";
4
+
5
+ // ============================================================================
6
+ // INTERFACES
7
+ // ============================================================================
8
+
9
+ export interface DataConfig {
10
+ api: string;
11
+ params?: Record<string, any>;
12
+ }
13
+
14
+ export interface TableContextValue {
15
+ listHandler: ListActionHandler | null;
16
+ columns: ColumnDefinition[];
17
+ setColumns: React.Dispatch<React.SetStateAction<ColumnDefinition[]>>;
18
+ rows: any[];
19
+ setRows: React.Dispatch<React.SetStateAction<any[]>>;
20
+ loading: boolean;
21
+ setLoading: React.Dispatch<React.SetStateAction<boolean>>;
22
+ }
23
+
24
+ // ============================================================================
25
+ // CONTEXT
26
+ // ============================================================================
27
+
28
+ const TableContext = createContext<TableContextValue | null>(null);
29
+
30
+ export const useTableContext = (): TableContextValue => {
31
+ const ctx = useContext(TableContext);
32
+ if (!ctx) throw new Error("useTableContext must be used inside <TableProvider>");
33
+ return ctx;
34
+ };
35
+
36
+ // ============================================================================
37
+ // PROVIDER PROPS
38
+ // ============================================================================
39
+
40
+ export interface TableProviderProps {
41
+ data: DataConfig;
42
+ columns?: ColumnDefinition[];
43
+ rowsPerPage?: number;
44
+ disableTotalCount?: boolean;
45
+ useCursorPagination?: boolean;
46
+ children: ReactNode;
47
+ listHandlerFactory: (config: ListHandlerConfig) => ListActionHandler;
48
+ // Resolved by DataList before being passed here — no hooks needed inside Provider
49
+ tenant: string;
50
+ module: string;
51
+ resolvedParams: Record<string, any> | undefined;
52
+ }
53
+
54
+ // ============================================================================
55
+ // PROVIDER
56
+ // ============================================================================
57
+
58
+ export const TableProvider: React.FC<TableProviderProps> = ({
59
+ data,
60
+ columns: initialColumns = [],
61
+ rowsPerPage = 20,
62
+ disableTotalCount = true,
63
+ useCursorPagination = false,
64
+ children,
65
+ listHandlerFactory,
66
+ tenant,
67
+ module,
68
+ resolvedParams,
69
+ }) => {
70
+ const colIds = initialColumns.map((c) => c.id ?? c.expr ?? "").filter(Boolean);
71
+
72
+ // ListHandler created ONCE via ref.
73
+ // resolvedParams already has all placeholders replaced — passed in from DataList.
74
+ const listHandlerRef = useRef<ListActionHandler | null>(null);
75
+ if (listHandlerRef.current === null) {
76
+ listHandlerRef.current = listHandlerFactory({
77
+ tenant,
78
+ module,
79
+ api: data.api,
80
+ params: resolvedParams,
81
+ cols: colIds,
82
+ rowsPerPage,
83
+ disableTotalCount,
84
+ useCursorPagination,
85
+ });
86
+ }
87
+
88
+ const [columns, setColumns] = useState<ColumnDefinition[]>(initialColumns);
89
+ const [rows, setRows] = useState<any[]>([]);
90
+ const [loading, setLoading] = useState(false);
91
+
92
+ // Initial data load on mount
93
+ useEffect(() => {
94
+ const lh = listHandlerRef.current;
95
+ if (!lh) return;
96
+
97
+ setLoading(true);
98
+ lh.load()
99
+ .then(() => setRows([...lh.getData()]))
100
+ .catch((err) => console.error("TableProvider initial load failed:", err))
101
+ .finally(() => setLoading(false));
102
+ }, []);
103
+
104
+ return (
105
+ <TableContext.Provider
106
+ value={{
107
+ listHandler: listHandlerRef.current,
108
+ columns,
109
+ setColumns,
110
+ rows,
111
+ setRows,
112
+ loading,
113
+ setLoading,
114
+ }}
115
+ >
116
+ {children}
117
+ </TableContext.Provider>
118
+ );
119
+ };
120
+
121
+ export type { ListHandlerConfig };
122
+ export default TableContext;
@@ -0,0 +1,8 @@
1
+ import { UIComponentProps } from "../common/UIComponent";
2
+ interface ComponentViewProps extends UIComponentProps {
3
+ id?: string;
4
+ depends?: string;
5
+ component?: React.ReactNode;
6
+ }
7
+ declare const ComponentView: (props: ComponentViewProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default ComponentView;