@ramesesinc/platform-core 0.1.4 → 0.1.5

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.
@@ -80,9 +80,13 @@ export interface DataListAttr {
80
80
  className?: string;
81
81
  rowClassName?: (row: any, rowIndex: number) => string;
82
82
  depends?: string;
83
+ handle?: InnerDataListHandle;
83
84
  }
84
85
  export interface DataListProps {
85
86
  attr: DataListAttr;
86
87
  }
88
+ type InnerDataListHandle = {
89
+ init: (ref: any) => void;
90
+ };
87
91
  export declare const DataList: React.FC<DataListProps>;
88
92
  export default DataList;
@@ -11,8 +11,9 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { Columns, Eye, RefreshCcw, Search, Trash } from "lucide-react";
14
- import { useCallback, useState } from "react";
14
+ import { useCallback, useRef, useState } from "react";
15
15
  import { useApp } from "../../core/AppContext";
16
+ import { useDataContext } from "../../core/DataContext";
16
17
  import { DynamicComponent } from "../../core/DynamicComponent";
17
18
  import { usePageContext } from "../../core/PageContext";
18
19
  import Panel from "../../core/Panel";
@@ -22,7 +23,7 @@ import { getUrlPageParams } from "../../lib/utils/PageUtils";
22
23
  import { DataTable } from "./DataTable";
23
24
  import ListHandler from "./ListHandler";
24
25
  import { TableProvider, useTableContext } from "./TableContext";
25
- const InnerDataList = ({ cols, emptyMessage = "No data available", errorMessage, striped = false, bordered = false, hover = true, dense = false, showPagination = true, paginationPosition = "bottom", showPageInfo = true, showTotalCount = true, showRowsPerPage = true, rowsPerPageOptions = [5, 10, 20, 50, 100], searchable = false, searchPlaceholder = "Search...", searchDebounce = 300, onSearchChange, filters = [], showFilterPanel = false, onFilterChange, sortable = true, showSortIndicator = true, selectable = false, selectionMode = "multiple", onSelectionChange, selectOnRowClick = false, onRowClick, rowActions = [], bulkActions = [], showBulkActions = true, toolbarActions = [], showToolbar = true, toolbarTitle, showRefreshButton = true, showExportButton = false, onLoad, onError, onRefresh, onExport, className = "", rowClassName, depends, }) => {
26
+ const InnerDataList = ({ cols, emptyMessage = "No data available", errorMessage, striped = false, bordered = false, hover = true, dense = false, showPagination = true, paginationPosition = "bottom", showPageInfo = true, showTotalCount = true, showRowsPerPage = true, rowsPerPageOptions = [5, 10, 20, 50, 100], searchable = false, searchPlaceholder = "Search...", searchDebounce = 300, onSearchChange, filters = [], showFilterPanel = false, onFilterChange, sortable = true, showSortIndicator = true, selectable = false, selectionMode = "multiple", onSelectionChange, selectOnRowClick = false, onRowClick, rowActions = [], bulkActions = [], showBulkActions = true, toolbarActions = [], showToolbar = true, toolbarTitle, showRefreshButton = true, showExportButton = false, onLoad, onError, onRefresh, onExport, className = "", rowClassName, depends, handle, }) => {
26
27
  const { listHandler, columns, rows, setRows, loading: ctxLoading, setLoading } = useTableContext();
27
28
  // ============================================================================
28
29
  // STATE
@@ -37,6 +38,17 @@ const InnerDataList = ({ cols, emptyMessage = "No data available", errorMessage,
37
38
  const [hiddenColumns, setHiddenColumns] = useState([]);
38
39
  const isLoading = ctxLoading || internalLoading;
39
40
  const pageContext = usePageContext();
41
+ const handleRef = {
42
+ setFilter: async (filter) => {
43
+ if (filter == null || listHandler == null)
44
+ return;
45
+ await listHandler.setFilter(filter);
46
+ await loadData();
47
+ },
48
+ };
49
+ if (handle != null) {
50
+ handle.init(handleRef);
51
+ }
40
52
  const refreshHandler = async () => {
41
53
  // console.log("refresh via notify depends", pageContext?.uuid);
42
54
  await handleRefresh();
@@ -284,18 +296,12 @@ const InnerDataList = ({ cols, emptyMessage = "No data available", errorMessage,
284
296
  // ============================================================================
285
297
  return (_jsxs("div", { className: `data-list ${className}`, children: [renderToolbar(), renderFilterPanel(), (paginationPosition === "both" || paginationPosition === "top") && renderPagination(), _jsx(DataTable, { data: rows, columns: sortableColumns, loading: isLoading, emptyMessage: emptyMessage, striped: striped, bordered: bordered, hover: hover, dense: dense, rowKey: "id", onRowClick: handleRowClick, selectedRows: selectedRows, onSelectionChange: handleSelectionChange, selectable: selectable, rowClassName: rowClassName }), (paginationPosition === "both" || paginationPosition === "bottom") && rows.length > 0 && renderPagination()] }));
286
298
  };
287
- // ============================================================================
288
- // PUBLIC DATALIST
289
- // - Only accepts attr
290
- // - All hooks (useApp, usePageContext) called here
291
- // - factory defined here
292
- // - resolves dynamic filter params before passing to TableProvider
293
- // ============================================================================
294
299
  export const DataList = ({ attr }) => {
295
- const { cols, data, rowsPerPage, disableTotalCount, commonActions, rowActions, toolbarActions } = attr, rest = __rest(attr, ["cols", "data", "rowsPerPage", "disableTotalCount", "commonActions", "rowActions", "toolbarActions"]);
300
+ const { depends, cols, data, rowsPerPage, disableTotalCount, commonActions, rowActions, toolbarActions } = attr, rest = __rest(attr, ["depends", "cols", "data", "rowsPerPage", "disableTotalCount", "commonActions", "rowActions", "toolbarActions"]);
296
301
  // All hooks called here — this is a React component so hooks are valid
297
302
  const { tenant, module } = useApp();
298
303
  const pageContext = usePageContext();
304
+ const dataContext = useDataContext();
299
305
  // Factory defined here — ListHandler is a local import, no prop needed
300
306
  const listHandlerFactory = (config) => ListHandler(config);
301
307
  // Resolve dynamic placeholders in filter before ListHandler is constructed.
@@ -335,10 +341,22 @@ export const DataList = ({ attr }) => {
335
341
  newToolbarActions.push({
336
342
  label: "Filter",
337
343
  component: "LookupPage",
338
- attr: Object.assign(Object.assign({}, commonActions.filterPage), { title: "Filter" }),
344
+ attr: Object.assign(Object.assign({}, commonActions.filterPage), { name: "customFilter", title: "Filter" }),
339
345
  });
340
346
  }
341
- return (_jsx(TableProvider, { data: data, columns: cols, rowsPerPage: rowsPerPage, disableTotalCount: disableTotalCount, listHandlerFactory: listHandlerFactory, tenant: tenant !== null && tenant !== void 0 ? tenant : "", module: module !== null && module !== void 0 ? module : "", resolvedParams: resolveParams(), children: _jsx(InnerDataList, Object.assign({}, rest, { cols: cols, rowActions: newRowActions, toolbarActions: newToolbarActions })) }));
347
+ const handleRef = useRef(null);
348
+ const onRefresh = () => {
349
+ var _a;
350
+ const filter = dataContext === null || dataContext === void 0 ? void 0 : dataContext.get("customFilter");
351
+ (_a = handleRef.current) === null || _a === void 0 ? void 0 : _a.setFilter(filter !== null && filter !== void 0 ? filter : {});
352
+ };
353
+ useDependHandler({ name: "customFilter", onRefresh });
354
+ const innerHandle = {
355
+ init: (ref) => {
356
+ handleRef.current = ref;
357
+ },
358
+ };
359
+ return (_jsx(TableProvider, { data: data, columns: cols, rowsPerPage: rowsPerPage, disableTotalCount: disableTotalCount, listHandlerFactory: listHandlerFactory, tenant: tenant !== null && tenant !== void 0 ? tenant : "", module: module !== null && module !== void 0 ? module : "", resolvedParams: resolveParams(), children: _jsx(InnerDataList, Object.assign({}, rest, { cols: cols, rowActions: newRowActions, toolbarActions: newToolbarActions, depends: depends, handle: innerHandle })) }));
342
360
  };
343
361
  export default DataList;
344
362
  const RefreshButton = ({ show, onClick, size = 18 }) => {
@@ -1,6 +1,7 @@
1
1
  import { Columns, Eye, RefreshCcw, Search, Trash } from "lucide-react";
2
- import React, { useCallback, useState } from "react";
2
+ import React, { useCallback, useRef, useState } from "react";
3
3
  import { useApp } from "../../core/AppContext";
4
+ import { useDataContext } from "../../core/DataContext";
4
5
  import { DynamicComponent } from "../../core/DynamicComponent";
5
6
  import { usePageContext } from "../../core/PageContext";
6
7
  import Panel from "../../core/Panel";
@@ -123,6 +124,7 @@ export interface DataListAttr {
123
124
  rowClassName?: (row: any, rowIndex: number) => string;
124
125
 
125
126
  depends?: string;
127
+ handle?: InnerDataListHandle;
126
128
  }
127
129
 
128
130
  // ============================================================================
@@ -191,6 +193,8 @@ const InnerDataList: React.FC<InnerProps> = ({
191
193
  className = "",
192
194
  rowClassName,
193
195
  depends,
196
+
197
+ handle,
194
198
  }) => {
195
199
  const { listHandler, columns, rows, setRows, loading: ctxLoading, setLoading } = useTableContext();
196
200
 
@@ -211,6 +215,19 @@ const InnerDataList: React.FC<InnerProps> = ({
211
215
 
212
216
  const pageContext = usePageContext();
213
217
 
218
+ const handleRef = {
219
+ setFilter: async (filter: Record<string, any>): Promise<void> => {
220
+ if (filter == null || listHandler == null) return;
221
+
222
+ await listHandler.setFilter(filter);
223
+ await loadData();
224
+ },
225
+ };
226
+
227
+ if (handle != null) {
228
+ handle.init(handleRef);
229
+ }
230
+
214
231
  const refreshHandler = async () => {
215
232
  // console.log("refresh via notify depends", pageContext?.uuid);
216
233
  await handleRefresh();
@@ -611,12 +628,17 @@ const InnerDataList: React.FC<InnerProps> = ({
611
628
  // - resolves dynamic filter params before passing to TableProvider
612
629
  // ============================================================================
613
630
 
631
+ type InnerDataListHandle = {
632
+ init: (ref: any) => void;
633
+ };
634
+
614
635
  export const DataList: React.FC<DataListProps> = ({ attr }) => {
615
- const { cols, data, rowsPerPage, disableTotalCount, commonActions, rowActions, toolbarActions, ...rest } = attr;
636
+ const { depends, cols, data, rowsPerPage, disableTotalCount, commonActions, rowActions, toolbarActions, ...rest } = attr;
616
637
 
617
638
  // All hooks called here — this is a React component so hooks are valid
618
639
  const { tenant, module } = useApp();
619
640
  const pageContext = usePageContext();
641
+ const dataContext = useDataContext();
620
642
 
621
643
  // Factory defined here — ListHandler is a local import, no prop needed
622
644
  const listHandlerFactory = (config: ListHandlerConfig): ListActionHandler => ListHandler(config);
@@ -676,11 +698,27 @@ export const DataList: React.FC<DataListProps> = ({ attr }) => {
676
698
  component: "LookupPage",
677
699
  attr: {
678
700
  ...commonActions.filterPage,
701
+ name: "customFilter",
679
702
  title: "Filter",
680
703
  },
681
704
  });
682
705
  }
683
706
 
707
+ const handleRef = useRef<any>(null);
708
+
709
+ const onRefresh = () => {
710
+ const filter = dataContext?.get("customFilter");
711
+ handleRef.current?.setFilter(filter ?? {});
712
+ };
713
+
714
+ useDependHandler({ name: "customFilter", onRefresh });
715
+
716
+ const innerHandle = {
717
+ init: (ref: any) => {
718
+ handleRef.current = ref;
719
+ },
720
+ } as InnerDataListHandle;
721
+
684
722
  return (
685
723
  <TableProvider
686
724
  data={data}
@@ -692,7 +730,7 @@ export const DataList: React.FC<DataListProps> = ({ attr }) => {
692
730
  module={module ?? ""}
693
731
  resolvedParams={resolveParams()}
694
732
  >
695
- <InnerDataList {...rest} cols={cols} rowActions={newRowActions} toolbarActions={newToolbarActions} />
733
+ <InnerDataList {...rest} cols={cols} rowActions={newRowActions} toolbarActions={newToolbarActions} depends={depends} handle={innerHandle} />
696
734
  </TableProvider>
697
735
  );
698
736
  };
@@ -35,7 +35,7 @@ export const ListHandler = (config) => {
35
35
  let hasMorePages = false;
36
36
  const getData = () => dataResult;
37
37
  const load = async () => {
38
- var _a, _b;
38
+ var _a, _b, _c, _d;
39
39
  const queryParams = {
40
40
  cols,
41
41
  start: (currentPage - 1) * rowsPerPage,
@@ -58,10 +58,10 @@ export const ListHandler = (config) => {
58
58
  // console.log("datalist pass 1", { api, query: { ...queryParams, ...rest } });
59
59
  const result = await localAPI.exec(`/services/exec/${config.tenant}/${config.module}/${api}`, Object.assign(Object.assign({}, queryParams), rest));
60
60
  // console.log("datalist pass 2", { result });
61
- dataResult = result.data || [];
61
+ dataResult = (_b = (_a = result.data) !== null && _a !== void 0 ? _a : result) !== null && _b !== void 0 ? _b : [];
62
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;
63
+ lastCursor = (_c = result.nextCursor) !== null && _c !== void 0 ? _c : null;
64
+ hasMorePages = (_d = result.hasMore) !== null && _d !== void 0 ? _d : false;
65
65
  }
66
66
  if (!disableTotalCount) {
67
67
  totalRecordCount = result.total || 0;
@@ -122,7 +122,7 @@ export const ListHandler = (config: ListHandlerConfig): ListActionHandler => {
122
122
  // console.log("datalist pass 1", { api, query: { ...queryParams, ...rest } });
123
123
  const result = await localAPI.exec(`/services/exec/${config.tenant}/${config.module}/${api}`, { ...queryParams, ...rest });
124
124
  // console.log("datalist pass 2", { result });
125
- dataResult = result.data || [];
125
+ dataResult = result.data ?? result ?? [];
126
126
 
127
127
  if (useCursorPagination) {
128
128
  lastCursor = result.nextCursor ?? null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramesesinc/platform-core",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Platform Core Library",
5
5
  "author": "Rameses Systems Inc.",
6
6
  "license": "MIT",