@ramesesinc/platform-core 0.1.4 → 0.1.6
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.
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/index.ts +1 -1
- package/dist/components/table/DataList.d.ts +4 -0
- package/dist/components/table/DataList.js +30 -12
- package/dist/components/table/DataList.tsx +41 -3
- package/dist/components/table/ListHandler.js +4 -4
- package/dist/components/table/ListHandler.ts +1 -1
- package/dist/core/PageCache.js +14 -1
- package/dist/core/PageContext.js +82 -20
- package/dist/core/PageViewContext.js +14 -3
- package/package.json +1 -1
- /package/dist/components/action/{UpdateContext.d.ts → UpdateState.d.ts} +0 -0
- /package/dist/components/action/{UpdateContext.js → UpdateState.js} +0 -0
- /package/dist/components/action/{UpdateContext.tsx → UpdateState.tsx} +0 -0
|
@@ -29,7 +29,7 @@ export { default as Refresh } from "./action/Refresh";
|
|
|
29
29
|
export { default as SaveData } from "./action/SaveData";
|
|
30
30
|
export { default as SelectData } from "./action/SelectData";
|
|
31
31
|
export { default as LookupPage } from "./action/LookupPage";
|
|
32
|
-
export { default as
|
|
32
|
+
export { default as UpdateState } from "./action/UpdateState";
|
|
33
33
|
export { default as ViewBackPage } from "./action/ViewBackPage";
|
|
34
34
|
export { default as ViewPage } from "./action/ViewPage";
|
|
35
35
|
export { default as PageView } from "./view/PageView";
|
package/dist/components/index.js
CHANGED
|
@@ -35,7 +35,7 @@ export { default as Refresh } from "./action/Refresh";
|
|
|
35
35
|
export { default as SaveData } from "./action/SaveData";
|
|
36
36
|
export { default as SelectData } from "./action/SelectData";
|
|
37
37
|
export { default as LookupPage } from "./action/LookupPage";
|
|
38
|
-
export { default as
|
|
38
|
+
export { default as UpdateState } from "./action/UpdateState";
|
|
39
39
|
export { default as ViewBackPage } from "./action/ViewBackPage";
|
|
40
40
|
export { default as ViewPage } from "./action/ViewPage";
|
|
41
41
|
export { default as PageView } from "./view/PageView";
|
package/dist/components/index.ts
CHANGED
|
@@ -41,7 +41,7 @@ export { default as SaveData } from "./action/SaveData";
|
|
|
41
41
|
export { default as SelectData } from "./action/SelectData";
|
|
42
42
|
|
|
43
43
|
export { default as LookupPage } from "./action/LookupPage";
|
|
44
|
-
export { default as
|
|
44
|
+
export { default as UpdateState } from "./action/UpdateState";
|
|
45
45
|
export { default as ViewBackPage } from "./action/ViewBackPage";
|
|
46
46
|
export { default as ViewPage } from "./action/ViewPage";
|
|
47
47
|
export { default as PageView } from "./view/PageView";
|
|
@@ -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
|
-
|
|
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 = (
|
|
64
|
-
hasMorePages = (
|
|
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/dist/core/PageCache.js
CHANGED
|
@@ -5,10 +5,23 @@ import React from "react";
|
|
|
5
5
|
import { DynamicTemplate } from "./DynamicTemplate";
|
|
6
6
|
// Simple in-memory cache
|
|
7
7
|
const cache = {};
|
|
8
|
+
const getPlatformInfo = async () => {
|
|
9
|
+
const platform = await localAPI.getPlatform();
|
|
10
|
+
const { multi_tenant, tenant_name } = platform !== null && platform !== void 0 ? platform : {};
|
|
11
|
+
return { multi_tenant, tenant_name };
|
|
12
|
+
};
|
|
8
13
|
export const getPage = async (name, fallback) => {
|
|
9
|
-
|
|
14
|
+
let { getTenant: tenant, getModule: module } = fallback;
|
|
10
15
|
const key = `${module}/${name}`; // ✅ unique per module
|
|
11
16
|
if (!cache[key]) {
|
|
17
|
+
if (tenant == null || tenant.trim() === "") {
|
|
18
|
+
// get tenant from platform/info API
|
|
19
|
+
const platform = await localAPI.getPlatform();
|
|
20
|
+
const { multi_tenant, tenant_name } = platform !== null && platform !== void 0 ? platform : {};
|
|
21
|
+
if (String(multi_tenant) === "false") {
|
|
22
|
+
tenant = tenant_name !== null && tenant_name !== void 0 ? tenant_name : "";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
12
25
|
const pageInfo = await localAPI.useMgmt(tenant, module).get("pages", name);
|
|
13
26
|
if (!pageInfo) {
|
|
14
27
|
return { template: _jsxs("div", { className: "text-red-500 p-2 border border-red-500", children: ["Page \"", name, "\" not found."] }), pageInfo: null };
|
package/dist/core/PageContext.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useBinding } from "@ramesesinc/client";
|
|
4
4
|
import { localAPI } from "@ramesesinc/lib/local-api";
|
|
5
|
-
import { createContext, useContext, useEffect, useLayoutEffect,
|
|
5
|
+
import { createContext, useContext, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
6
6
|
import { parseHashUrl } from "../lib/utils/PageUtils";
|
|
7
7
|
import { useApp } from "./AppContext";
|
|
8
8
|
import { DataBindingProvider } from "./DataContext";
|
|
@@ -39,18 +39,30 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
39
39
|
const pageView = usePageViewContext();
|
|
40
40
|
const binding = useBinding();
|
|
41
41
|
// setup the selectedPath from the handle
|
|
42
|
-
useMemo(() => {
|
|
42
|
+
// useMemo(() => {
|
|
43
|
+
useLayoutEffect(() => {
|
|
43
44
|
const path = handle === null || handle === void 0 ? void 0 : handle.getSelectedPath();
|
|
44
|
-
binding.set
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (binding && typeof binding.set === "function") {
|
|
46
|
+
binding.set("selectedPage", path);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
console.warn("binding.set is not available, skipping selectedPage setup");
|
|
50
|
+
}
|
|
51
|
+
// return path;
|
|
52
|
+
}, [handle, binding]);
|
|
47
53
|
// for DEV purposes only
|
|
48
|
-
useMemo(() => {
|
|
54
|
+
// useMemo(() => {
|
|
55
|
+
useLayoutEffect(() => {
|
|
49
56
|
const dependHandler = () => {
|
|
50
57
|
// console.log("selectedPage changed => ", binding.get("selectedPage"));
|
|
51
58
|
};
|
|
52
|
-
binding.dependsTo
|
|
53
|
-
|
|
59
|
+
if (binding && typeof binding.dependsTo === "function") {
|
|
60
|
+
binding.dependsTo("selectedPage", dependHandler);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
console.warn("binding.dependsTo is not available, skipping dependency setup");
|
|
64
|
+
}
|
|
65
|
+
}, [binding]);
|
|
54
66
|
const dataApiHandler = useRef(null);
|
|
55
67
|
const { tenant, module } = useApp();
|
|
56
68
|
const providerRef = {
|
|
@@ -90,14 +102,31 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
90
102
|
};
|
|
91
103
|
/* ------------------ Data ------------------ */
|
|
92
104
|
const getData = () => {
|
|
93
|
-
|
|
105
|
+
if (binding && typeof binding.getData === "function") {
|
|
106
|
+
return binding.getData();
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
console.warn("binding.getData is not available, returning {}");
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
94
112
|
};
|
|
95
113
|
const setData = (value, mode) => {
|
|
96
|
-
binding
|
|
114
|
+
if (binding && typeof binding.setData === "function") {
|
|
115
|
+
binding.setData(value, mode !== null && mode !== void 0 ? mode : "read");
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
console.warn("binding.setData is not available, skipping data set");
|
|
119
|
+
}
|
|
97
120
|
};
|
|
98
121
|
/* ------------------ Reactive deps ------------------ */
|
|
99
122
|
const dependsTo = (name, callback) => {
|
|
100
|
-
|
|
123
|
+
if (binding && typeof binding.dependsTo === "function") {
|
|
124
|
+
return binding.dependsTo(name, callback);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
console.warn("binding.dependsTo is not available, returning no-op function");
|
|
128
|
+
return () => { };
|
|
129
|
+
}
|
|
101
130
|
};
|
|
102
131
|
const notifyDepends = (name) => {
|
|
103
132
|
binding.notifyDepends(name);
|
|
@@ -110,19 +139,41 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
110
139
|
/* ------------------ Internal props setter ------------------ */
|
|
111
140
|
const set = (name, value) => {
|
|
112
141
|
if (name === "data") {
|
|
113
|
-
binding.setData
|
|
142
|
+
if (binding && typeof binding.setData === "function") {
|
|
143
|
+
binding.setData(value);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
console.warn("binding.setData is not available, skipping data set");
|
|
147
|
+
}
|
|
114
148
|
}
|
|
115
149
|
else {
|
|
116
|
-
binding.set
|
|
150
|
+
if (binding && typeof binding.set === "function") {
|
|
151
|
+
binding.set(name, value);
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
console.warn("binding.set is not available, skipping set:", name, value);
|
|
155
|
+
}
|
|
117
156
|
}
|
|
118
157
|
};
|
|
119
158
|
const get = (name) => {
|
|
120
159
|
if (name === "data") {
|
|
121
|
-
|
|
160
|
+
if (binding && typeof binding.getData === "function") {
|
|
161
|
+
return binding.getData();
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
console.warn("binding.getData is not available, returning {}");
|
|
165
|
+
return {};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (binding && typeof binding.get === "function") {
|
|
169
|
+
const val = binding.get(name);
|
|
170
|
+
// console.log("page context get", name, val, binding.getData());
|
|
171
|
+
return val;
|
|
172
|
+
}
|
|
173
|
+
else {
|
|
174
|
+
console.warn("binding.get is not available, returning undefined for:", name);
|
|
175
|
+
return undefined;
|
|
122
176
|
}
|
|
123
|
-
const val = binding.get(name);
|
|
124
|
-
// console.log("page context get", name, val, binding.getData());
|
|
125
|
-
return val;
|
|
126
177
|
};
|
|
127
178
|
const buildParams = (inputParams, queryParams) => {
|
|
128
179
|
return inputParams;
|
|
@@ -144,10 +195,21 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
144
195
|
return result;
|
|
145
196
|
};
|
|
146
197
|
const setPageParams = (params) => {
|
|
147
|
-
binding.set
|
|
198
|
+
if (binding && typeof binding.set === "function") {
|
|
199
|
+
binding.set("pageParams", params);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
console.warn("binding.set is not available, skipping pageParams set");
|
|
203
|
+
}
|
|
148
204
|
};
|
|
149
205
|
const getPageParams = () => {
|
|
150
|
-
|
|
206
|
+
if (binding && typeof binding.get === "function") {
|
|
207
|
+
return binding.get("pageParams");
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
console.warn("binding.get is not available, returning {} for pageParams");
|
|
211
|
+
return {};
|
|
212
|
+
}
|
|
151
213
|
};
|
|
152
214
|
/* ------------------ Context value ------------------ */
|
|
153
215
|
const values = {
|
|
@@ -170,7 +232,7 @@ export const PageProvider = ({ handle, children }) => {
|
|
|
170
232
|
getMgmt,
|
|
171
233
|
postMgmt,
|
|
172
234
|
getAllData: () => {
|
|
173
|
-
const allData = Object.assign(Object.assign({}, binding.getUiData()), { data: binding.getData(), pageParams: getPageParams() });
|
|
235
|
+
const allData = Object.assign(Object.assign({}, (binding && typeof binding.getUiData === "function" ? binding.getUiData() : {})), { data: binding && typeof binding.getData === "function" ? binding.getData() : {}, pageParams: getPageParams() });
|
|
174
236
|
return allData;
|
|
175
237
|
},
|
|
176
238
|
setPageParams,
|
|
@@ -187,7 +187,7 @@ export const PageViewProvider = ({ paths, handle, children, prefix = "page", eve
|
|
|
187
187
|
};
|
|
188
188
|
const popPage = () => {
|
|
189
189
|
var _a, _b, _c;
|
|
190
|
-
// console.log("popPage (pageChain)", uuid, prefix, pageChain);
|
|
190
|
+
// console.log("popPage (pageChain)", uuid, prefix, JSON.stringify(pageChain));
|
|
191
191
|
const { previous: prevChain } = pageChain;
|
|
192
192
|
if (prevChain == null) {
|
|
193
193
|
return;
|
|
@@ -205,15 +205,25 @@ export const PageViewProvider = ({ paths, handle, children, prefix = "page", eve
|
|
|
205
205
|
const idx = newPath.lastIndexOf("/");
|
|
206
206
|
if (idx >= 0) {
|
|
207
207
|
newPath = path.substring(idx + 1);
|
|
208
|
+
// newPath = newPath.substring(idx + 1);
|
|
208
209
|
}
|
|
209
210
|
page = newPath;
|
|
210
|
-
// console.log("popPage 1.
|
|
211
|
+
// console.log("popPage 1.3", uuid, page);
|
|
211
212
|
}
|
|
212
213
|
else {
|
|
213
214
|
const [, ...anchors] = path.split("#");
|
|
214
215
|
page = (_b = anchors.at(-1)) !== null && _b !== void 0 ? _b : "";
|
|
216
|
+
// console.log("popPage 1.4", uuid, "page:", page, "path:", path);
|
|
215
217
|
if (page === "") {
|
|
216
|
-
page = path;
|
|
218
|
+
// page = path;
|
|
219
|
+
const withoutHash = path.split("#")[0];
|
|
220
|
+
const idx = withoutHash.lastIndexOf("/");
|
|
221
|
+
if (idx >= 0) {
|
|
222
|
+
page = withoutHash.substring(idx + 1);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
page = path;
|
|
226
|
+
}
|
|
217
227
|
}
|
|
218
228
|
}
|
|
219
229
|
const newPageChain = Object.assign({}, prevChain);
|
|
@@ -221,6 +231,7 @@ export const PageViewProvider = ({ paths, handle, children, prefix = "page", eve
|
|
|
221
231
|
if (!standalone) {
|
|
222
232
|
history.pushState(null, "", path);
|
|
223
233
|
}
|
|
234
|
+
// console.log("popPage 2", uuid, page);
|
|
224
235
|
(_c = handleRef.current) === null || _c === void 0 ? void 0 : _c.renderPage(page);
|
|
225
236
|
};
|
|
226
237
|
const hasBackPage = () => {
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|