@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.
- package/dist/components/action/AlertMessage.d.ts +8 -0
- package/dist/components/action/AlertMessage.js +19 -0
- package/dist/components/action/AlertMessage.tsx +38 -0
- package/dist/components/action/Button.d.ts +21 -0
- package/dist/components/action/Button.js +139 -0
- package/dist/components/action/Button.tsx +230 -0
- package/dist/components/action/CancelEdit.d.ts +9 -0
- package/dist/components/action/CancelEdit.js +21 -0
- package/dist/components/action/CancelEdit.tsx +40 -0
- package/dist/components/action/DeleteData.d.ts +13 -0
- package/dist/components/action/DeleteData.js +43 -0
- package/dist/components/action/DeleteData.tsx +73 -0
- package/dist/components/action/Edit.d.ts +9 -0
- package/dist/components/action/Edit.js +21 -0
- package/dist/components/action/Edit.tsx +40 -0
- package/dist/components/action/LookupPage.d.ts +16 -0
- package/dist/components/action/LookupPage.js +62 -0
- package/dist/components/action/LookupPage.tsx +113 -0
- package/dist/components/action/ProcessRunner.d.ts +62 -0
- package/dist/components/action/ProcessRunner.js +156 -0
- package/dist/components/action/ProcessRunner.tsx +337 -0
- package/dist/components/action/Refresh.d.ts +7 -0
- package/dist/components/action/Refresh.js +17 -0
- package/dist/components/action/Refresh.tsx +35 -0
- package/dist/components/action/SaveData.d.ts +10 -0
- package/dist/components/action/SaveData.js +54 -0
- package/dist/components/action/SaveData.tsx +74 -0
- package/dist/components/action/SelectData.d.ts +8 -0
- package/dist/components/action/SelectData.js +29 -0
- package/dist/components/action/SelectData.tsx +47 -0
- package/dist/components/action/Undo.d.ts +9 -0
- package/dist/components/action/Undo.js +31 -0
- package/dist/components/action/Undo.tsx +50 -0
- package/dist/components/action/UpdateContext.d.ts +9 -0
- package/dist/components/action/UpdateContext.js +21 -0
- package/dist/components/action/UpdateContext.tsx +40 -0
- package/dist/components/action/UpdateData.d.ts +9 -0
- package/dist/components/action/UpdateData.js +33 -0
- package/dist/components/action/UpdateData.tsx +49 -0
- package/dist/components/action/ViewBackPage.d.ts +9 -0
- package/dist/components/action/ViewBackPage.js +19 -0
- package/dist/components/action/ViewBackPage.tsx +46 -0
- package/dist/components/action/ViewPage.d.ts +14 -0
- package/dist/components/action/ViewPage.js +88 -0
- package/dist/components/action/ViewPage.tsx +141 -0
- package/dist/components/common/UIComponent.d.ts +11 -0
- package/dist/components/common/UIComponent.js +52 -0
- package/dist/components/common/UIComponent.tsx +84 -0
- package/dist/components/common/UIInput.d.ts +12 -0
- package/dist/components/common/UIInput.js +37 -0
- package/dist/components/common/UIInput.tsx +49 -0
- package/dist/components/common/UIMenu.d.ts +23 -0
- package/dist/components/common/UIMenu.js +61 -0
- package/dist/components/common/UIMenu.tsx +91 -0
- package/dist/components/index.d.ts +37 -0
- package/dist/components/index.js +44 -0
- package/dist/components/index.ts +51 -0
- package/dist/components/input/CodeEditor.d.ts +12 -0
- package/dist/components/input/CodeEditor.js +132 -0
- package/dist/components/input/CodeEditor.tsx +188 -0
- package/dist/components/input/DateField.d.ts +9 -0
- package/dist/components/input/DateField.js +140 -0
- package/dist/components/input/DateField.tsx +274 -0
- package/dist/components/input/DayPicker.d.ts +2 -0
- package/dist/components/input/DayPicker.js +5 -0
- package/dist/components/input/DayPicker.tsx +5 -0
- package/dist/components/input/HtmlCode.d.ts +8 -0
- package/dist/components/input/HtmlCode.js +157 -0
- package/dist/components/input/HtmlCode.tsx +203 -0
- package/dist/components/input/JsonCode.d.ts +9 -0
- package/dist/components/input/JsonCode.js +159 -0
- package/dist/components/input/JsonCode.tsx +205 -0
- package/dist/components/input/MonthPicker.d.ts +2 -0
- package/dist/components/input/MonthPicker.js +5 -0
- package/dist/components/input/MonthPicker.tsx +5 -0
- package/dist/components/input/ScriptCode.d.ts +8 -0
- package/dist/components/input/ScriptCode.js +153 -0
- package/dist/components/input/ScriptCode.tsx +195 -0
- package/dist/components/input/Select.d.ts +14 -0
- package/dist/components/input/Select.js +40 -0
- package/dist/components/input/Select.tsx +78 -0
- package/dist/components/input/SqlCode.d.ts +8 -0
- package/dist/components/input/SqlCode.js +121 -0
- package/dist/components/input/SqlCode.tsx +162 -0
- package/dist/components/input/StringDecision.d.ts +2 -0
- package/dist/components/input/StringDecision.js +34 -0
- package/dist/components/input/StringDecision.tsx +64 -0
- package/dist/components/input/Text.d.ts +7 -0
- package/dist/components/input/Text.js +39 -0
- package/dist/components/input/Text.tsx +57 -0
- package/dist/components/input/YearPicker.d.ts +8 -0
- package/dist/components/input/YearPicker.js +44 -0
- package/dist/components/input/YearPicker.tsx +81 -0
- package/dist/components/list/IconMenu.d.ts +14 -0
- package/dist/components/list/IconMenu.js +72 -0
- package/dist/components/list/IconMenu.tsx +115 -0
- package/dist/components/list/TabMenu.d.ts +10 -0
- package/dist/components/list/TabMenu.js +72 -0
- package/dist/components/list/TabMenu.tsx +127 -0
- package/dist/components/list/TreeMenu.d.ts +14 -0
- package/dist/components/list/TreeMenu.js +207 -0
- package/dist/components/list/TreeMenu.tsx +279 -0
- package/dist/components/list/TxnTaskList.d.ts +2 -0
- package/dist/components/list/TxnTaskList.js +77 -0
- package/dist/components/list/TxnTaskList.tsx +198 -0
- package/dist/components/output/Label.d.ts +8 -0
- package/dist/components/output/Label.js +33 -0
- package/dist/components/output/Label.tsx +51 -0
- package/dist/components/table/DataList.d.ts +88 -0
- package/dist/components/table/DataList.js +361 -0
- package/dist/components/table/DataList.tsx +782 -0
- package/dist/components/table/DataTable.d.ts +46 -0
- package/dist/components/table/DataTable.js +253 -0
- package/dist/components/table/DataTable.tsx +572 -0
- package/dist/components/table/ListHandler.d.ts +42 -0
- package/dist/components/table/ListHandler.js +197 -0
- package/dist/components/table/ListHandler.ts +276 -0
- package/dist/components/table/TableContext.d.ts +33 -0
- package/dist/components/table/TableContext.js +57 -0
- package/dist/components/table/TableContext.tsx +122 -0
- package/dist/components/view/ComponentView.d.ts +8 -0
- package/dist/components/view/ComponentView.js +78 -0
- package/dist/components/view/ComponentView.tsx +102 -0
- package/dist/components/view/FilterView.d.ts +2 -0
- package/dist/components/view/FilterView.js +14 -0
- package/dist/components/view/FilterView.tsx +21 -0
- package/dist/components/view/HtmlForm.d.ts +7 -0
- package/dist/components/view/HtmlForm.js +145 -0
- package/dist/components/view/HtmlForm.tsx +186 -0
- package/dist/components/view/HtmlView.d.ts +9 -0
- package/dist/components/view/HtmlView.js +85 -0
- package/dist/components/view/HtmlView.tsx +114 -0
- package/dist/components/view/IFrameView.d.ts +2 -0
- package/dist/components/view/IFrameView.js +34 -0
- package/dist/components/view/IFrameView.tsx +48 -0
- package/dist/components/view/Modal.d.ts +14 -0
- package/dist/components/view/Modal.js +28 -0
- package/dist/components/view/Modal.tsx +72 -0
- package/dist/components/view/PageView.d.ts +9 -0
- package/dist/components/view/PageView.js +90 -0
- package/dist/components/view/PageView.tsx +131 -0
- package/dist/components/view/PopupView.d.ts +9 -0
- package/dist/components/view/PopupView.js +91 -0
- package/dist/components/view/PopupView.tsx +160 -0
- package/dist/components/view/RootView.d.ts +8 -0
- package/dist/components/view/RootView.js +75 -0
- package/dist/components/view/RootView.tsx +109 -0
- package/dist/components/view/WizardView.d.ts +6 -0
- package/dist/components/view/WizardView.js +34 -0
- package/dist/components/view/WizardView.tsx +48 -0
- package/dist/core/AppContext.d.ts +25 -0
- package/dist/core/AppContext.js +159 -0
- package/dist/core/AuthContext.d.ts +13 -0
- package/dist/core/AuthContext.js +80 -0
- package/dist/core/ComponentCache.d.ts +15 -0
- package/dist/core/ComponentCache.js +25 -0
- package/dist/core/DataContext.d.ts +20 -0
- package/dist/core/DataContext.js +41 -0
- package/dist/core/DynamicComponent.d.ts +12 -0
- package/dist/core/DynamicComponent.js +30 -0
- package/dist/core/DynamicIcon.d.ts +6 -0
- package/dist/core/DynamicIcon.js +48 -0
- package/dist/core/DynamicTemplate.d.ts +4 -0
- package/dist/core/DynamicTemplate.js +17 -0
- package/dist/core/ErrorMessage.d.ts +5 -0
- package/dist/core/ErrorMessage.js +7 -0
- package/dist/core/EventHandler.d.ts +3 -0
- package/dist/core/EventHandler.js +1 -0
- package/dist/core/HtmlCache.d.ts +6 -0
- package/dist/core/HtmlCache.js +17 -0
- package/dist/core/Page.d.ts +6 -0
- package/dist/core/Page.js +141 -0
- package/dist/core/PageCache.d.ts +15 -0
- package/dist/core/PageCache.js +26 -0
- package/dist/core/PageContext.d.ts +49 -0
- package/dist/core/PageContext.js +207 -0
- package/dist/core/PageRegistry.d.ts +7 -0
- package/dist/core/PageRegistry.js +11 -0
- package/dist/core/PageViewContext.d.ts +45 -0
- package/dist/core/PageViewContext.js +277 -0
- package/dist/core/Panel.d.ts +16 -0
- package/dist/core/Panel.js +39 -0
- package/dist/core/RowContext.d.ts +11 -0
- package/dist/core/RowContext.js +16 -0
- package/dist/core/StepHandler.d.ts +9 -0
- package/dist/core/StepHandler.js +39 -0
- package/dist/core/UIDependHandler.d.ts +6 -0
- package/dist/core/UIDependHandler.js +31 -0
- package/dist/core/auth/index.d.ts +18 -0
- package/dist/core/auth/index.js +187 -0
- package/dist/core/auth/session.d.ts +4 -0
- package/dist/core/auth/session.js +45 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.js +1 -0
- package/dist/core/page-helper.d.ts +27 -0
- package/dist/core/page-helper.js +47 -0
- package/dist/hooks/useUrlParams.d.ts +11 -0
- package/dist/hooks/useUrlParams.js +164 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +69 -0
- package/dist/layouts/BorderLayout.d.ts +14 -0
- package/dist/layouts/BorderLayout.js +8 -0
- package/dist/layouts/CardLayout.d.ts +27 -0
- package/dist/layouts/CardLayout.js +36 -0
- package/dist/layouts/CenterLayout.d.ts +8 -0
- package/dist/layouts/CenterLayout.js +6 -0
- package/dist/layouts/GridLayout.d.ts +9 -0
- package/dist/layouts/GridLayout.js +5 -0
- package/dist/layouts/HPanel.d.ts +11 -0
- package/dist/layouts/HPanel.js +8 -0
- package/dist/layouts/HorizontalLayout.d.ts +11 -0
- package/dist/layouts/HorizontalLayout.js +6 -0
- package/dist/layouts/MainLayout.d.ts +6 -0
- package/dist/layouts/MainLayout.js +5 -0
- package/dist/layouts/PageLayout.d.ts +11 -0
- package/dist/layouts/PageLayout.js +6 -0
- package/dist/layouts/VPanel.d.ts +9 -0
- package/dist/layouts/VPanel.js +7 -0
- package/dist/layouts/XLayout.d.ts +10 -0
- package/dist/layouts/XLayout.js +10 -0
- package/dist/layouts/YLayout.d.ts +10 -0
- package/dist/layouts/YLayout.js +10 -0
- package/dist/lib/PlatformRoute.d.ts +5 -0
- package/dist/lib/PlatformRoute.js +288 -0
- package/dist/lib/WebPlatform.d.ts +13 -0
- package/dist/lib/WebPlatform.js +124 -0
- package/dist/lib/components/ActivityBar.d.ts +13 -0
- package/dist/lib/components/ActivityBar.js +39 -0
- package/dist/lib/components/CopyButton.d.ts +8 -0
- package/dist/lib/components/CopyButton.js +50 -0
- package/dist/lib/components/Header.d.ts +2 -0
- package/dist/lib/components/Header.js +74 -0
- package/dist/lib/components/QuickActionMenu.d.ts +18 -0
- package/dist/lib/components/QuickActionMenu.js +50 -0
- package/dist/lib/components/UserButton.d.ts +11 -0
- package/dist/lib/components/UserButton.js +66 -0
- package/dist/lib/layouts/BorderLayout.tsx +31 -0
- package/dist/lib/layouts/CardLayout.tsx +73 -0
- package/dist/lib/layouts/CenterLayout.tsx +20 -0
- package/dist/lib/layouts/GridLayout.tsx +20 -0
- package/dist/lib/layouts/HPanel.tsx +31 -0
- package/dist/lib/layouts/HorizontalLayout.tsx +29 -0
- package/dist/lib/layouts/MainLayout.tsx +16 -0
- package/dist/lib/layouts/PageLayout.tsx +29 -0
- package/dist/lib/layouts/VPanel.tsx +27 -0
- package/dist/lib/layouts/XLayout.tsx +29 -0
- package/dist/lib/layouts/YLayout.tsx +29 -0
- package/dist/lib/utils/BeanUtils.d.ts +3 -0
- package/dist/lib/utils/BeanUtils.js +75 -0
- package/dist/lib/utils/ComponentLoader.d.ts +13 -0
- package/dist/lib/utils/ComponentLoader.js +26 -0
- package/dist/lib/utils/ExprUtil.d.ts +7 -0
- package/dist/lib/utils/ExprUtil.js +44 -0
- package/dist/lib/utils/PageUtils.d.ts +6 -0
- package/dist/lib/utils/PageUtils.js +121 -0
- package/dist/lib/utils/ResourceLoader.d.ts +11 -0
- package/dist/lib/utils/ResourceLoader.js +37 -0
- package/dist/lib/utils/SectionProvider.d.ts +5 -0
- package/dist/lib/utils/SectionProvider.js +39 -0
- package/dist/lib/utils/initResourceLoader.d.ts +0 -0
- package/dist/lib/utils/initResourceLoader.js +95 -0
- package/dist/styles/index.css +38 -0
- package/dist/templates/BasicTemplate.d.ts +2 -0
- package/dist/templates/BasicTemplate.js +14 -0
- package/dist/templates/CrudFormTemplate.d.ts +2 -0
- package/dist/templates/CrudFormTemplate.js +38 -0
- package/dist/templates/DataListTemplate.d.ts +2 -0
- package/dist/templates/DataListTemplate.js +13 -0
- package/dist/templates/ExplorerTemplate.d.ts +10 -0
- package/dist/templates/ExplorerTemplate.js +17 -0
- package/dist/templates/TxnFormTemplate.d.ts +2 -0
- package/dist/templates/TxnFormTemplate.js +66 -0
- package/dist/templates/WizardTemplate.d.ts +9 -0
- package/dist/templates/WizardTemplate.js +37 -0
- package/dist/templates/index.d.ts +5 -0
- package/dist/templates/index.js +5 -0
- package/dist/types/action.d.ts +8 -0
- package/dist/types/action.js +1 -0
- package/dist/types/component.d.ts +18 -0
- package/dist/types/component.js +1 -0
- package/dist/types/list.d.ts +14 -0
- package/dist/types/list.js +1 -0
- package/dist/types/template.d.ts +6 -0
- package/dist/types/template.js +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { ChevronDown } from "lucide-react";
|
|
4
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import DynamicIcon from "../../core/DynamicIcon";
|
|
6
|
+
import { usePageContext } from "../../core/PageContext";
|
|
7
|
+
import { usePageViewContext } from "../../core/PageViewContext";
|
|
8
|
+
import useUIMenu from "../common/UIMenu";
|
|
9
|
+
/* ------------------------------------------------------------------ */
|
|
10
|
+
/* Helpers */
|
|
11
|
+
const buildItems = (raw) => {
|
|
12
|
+
var _a;
|
|
13
|
+
const mapped = [];
|
|
14
|
+
for (const entry of raw) {
|
|
15
|
+
if (Array.isArray(entry.items)) {
|
|
16
|
+
mapped.push(Object.assign(Object.assign({}, entry), { isDropdown: (_a = entry.isDropdown) !== null && _a !== void 0 ? _a : true, items: buildItems(entry.items) }));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
const lastGroup = mapped[mapped.length - 1];
|
|
20
|
+
if (lastGroup && lastGroup.title === "" && !lastGroup.isDropdown) {
|
|
21
|
+
lastGroup.items.push(entry);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
mapped.push({ title: "", icon: undefined, isDropdown: false, items: [entry] });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return mapped;
|
|
29
|
+
};
|
|
30
|
+
const findFirstItem = (groups) => {
|
|
31
|
+
for (const group of groups) {
|
|
32
|
+
for (const item of group.items) {
|
|
33
|
+
if (Array.isArray(item.items)) {
|
|
34
|
+
const found = findFirstItem([item]);
|
|
35
|
+
if (found)
|
|
36
|
+
return found;
|
|
37
|
+
}
|
|
38
|
+
else if (item.page)
|
|
39
|
+
return item;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
44
|
+
const findGroupPath = (groups, targetPage, depth = 0) => {
|
|
45
|
+
for (let i = 0; i < groups.length; i++) {
|
|
46
|
+
const group = groups[i];
|
|
47
|
+
const key = `${depth}-${i}`;
|
|
48
|
+
for (const item of group.items) {
|
|
49
|
+
if (Array.isArray(item.items)) {
|
|
50
|
+
const path = findGroupPath([item], targetPage, depth + 1);
|
|
51
|
+
if (path.length)
|
|
52
|
+
return [key, ...path];
|
|
53
|
+
}
|
|
54
|
+
else if (item.page === targetPage)
|
|
55
|
+
return [key];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return [];
|
|
59
|
+
};
|
|
60
|
+
const findItemByPage = (groups, targetPage) => {
|
|
61
|
+
for (const group of groups) {
|
|
62
|
+
for (const item of group.items) {
|
|
63
|
+
if (Array.isArray(item.items)) {
|
|
64
|
+
const found = findItemByPage([item], targetPage);
|
|
65
|
+
if (found)
|
|
66
|
+
return found;
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
// console.log("treemenu findItemByPage", targetPage, item.page);
|
|
70
|
+
if (item.page === targetPage)
|
|
71
|
+
return item;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
const isActiveItemInTree = (groups, page) => groups.some((group) => group.items.some((item) => (Array.isArray(item.items) ? isActiveItemInTree([item], page) : item.page === page)));
|
|
78
|
+
const TreeMenu = (props) => {
|
|
79
|
+
var _a;
|
|
80
|
+
const { name = "selectedPage", menugroup, depends, items: itemsProp, data } = props !== null && props !== void 0 ? props : {};
|
|
81
|
+
const pageContext = usePageContext();
|
|
82
|
+
const pageView = usePageViewContext();
|
|
83
|
+
const contextKey = (_a = name !== null && name !== void 0 ? name : depends) !== null && _a !== void 0 ? _a : "";
|
|
84
|
+
const [openGroups, setOpenGroups] = useState([]);
|
|
85
|
+
const [activeItem, setActiveItem] = useState({});
|
|
86
|
+
const [items, setItems] = useState([]);
|
|
87
|
+
const initializedRef = useRef(false);
|
|
88
|
+
const { items: rawItems } = useUIMenu({
|
|
89
|
+
items: itemsProp,
|
|
90
|
+
data,
|
|
91
|
+
menugroup,
|
|
92
|
+
});
|
|
93
|
+
useLayoutEffect(() => {
|
|
94
|
+
var _a;
|
|
95
|
+
const { path = "" } = (_a = pageView.getOriginalLocationInfo()) !== null && _a !== void 0 ? _a : {};
|
|
96
|
+
const [, ...anchors] = path.split("#");
|
|
97
|
+
const [selectedPath] = anchors;
|
|
98
|
+
pageContext.set(contextKey, selectedPath);
|
|
99
|
+
}, []);
|
|
100
|
+
/* ---------------------- Sync active item from page view ---------------------- */
|
|
101
|
+
useLayoutEffect(() => {
|
|
102
|
+
if (items.length === 0 || !pageView.getSelectedPage())
|
|
103
|
+
return;
|
|
104
|
+
if (initializedRef.current)
|
|
105
|
+
return;
|
|
106
|
+
const item = findItemByPage(items, pageView.getSelectedPage());
|
|
107
|
+
if (item)
|
|
108
|
+
setActiveItem(item);
|
|
109
|
+
}, [items, pageView.getSelectedPage()]);
|
|
110
|
+
/* ---------------------- Build items ---------------------- */
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!Array.isArray(rawItems) || rawItems.length === 0)
|
|
113
|
+
return;
|
|
114
|
+
setItems(buildItems(rawItems));
|
|
115
|
+
}, [rawItems]);
|
|
116
|
+
/* ---------------------- Auto-select first item on init ---------------------- */
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
if (initializedRef.current || items.length === 0)
|
|
119
|
+
return;
|
|
120
|
+
const firstItem = findFirstItem(items);
|
|
121
|
+
if (!(firstItem === null || firstItem === void 0 ? void 0 : firstItem.page))
|
|
122
|
+
return;
|
|
123
|
+
let selectedPage = pageContext.get(contextKey);
|
|
124
|
+
// console.log("treemenu selected page from context", contextKey, selectedPage);
|
|
125
|
+
if (selectedPage == null && contextKey === "selectedPage") {
|
|
126
|
+
selectedPage = pageView.getSelectedPage();
|
|
127
|
+
// console.log("treemenu selected page fallback from context", contextKey, selectedPage);
|
|
128
|
+
}
|
|
129
|
+
// console.log("treemenu selected page final", contextKey, selectedPage);
|
|
130
|
+
if (selectedPage != null) {
|
|
131
|
+
const selectedItem = findItemByPage(items, selectedPage);
|
|
132
|
+
// console.log("treemenu findItemByPage", selectedPage, selectedItem);
|
|
133
|
+
if (selectedItem) {
|
|
134
|
+
setOpenGroups(findGroupPath(items, selectedPage));
|
|
135
|
+
setActiveItem(selectedItem);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
setOpenGroups(findGroupPath(items, firstItem.page));
|
|
139
|
+
setActiveItem(firstItem);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
setOpenGroups(findGroupPath(items, firstItem.page));
|
|
144
|
+
setActiveItem(firstItem);
|
|
145
|
+
}
|
|
146
|
+
initializedRef.current = true;
|
|
147
|
+
}, [items, contextKey]);
|
|
148
|
+
/* ---------------------- Sync page context on active item change ---------------------- */
|
|
149
|
+
useEffect(() => {
|
|
150
|
+
const { mode, page } = (activeItem !== null && activeItem !== void 0 ? activeItem : {});
|
|
151
|
+
if (!page)
|
|
152
|
+
return;
|
|
153
|
+
const idx = ["window", "popup"].indexOf(String(mode).toLowerCase());
|
|
154
|
+
if (idx >= 0) {
|
|
155
|
+
pageView.setPage(page, { mode });
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
pageView.setSelectedPage(page);
|
|
159
|
+
pageContext.set(contextKey, page);
|
|
160
|
+
}
|
|
161
|
+
}, [activeItem]);
|
|
162
|
+
/* ---------------------- Auto-open group containing active item ---------------------- */
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (!(activeItem === null || activeItem === void 0 ? void 0 : activeItem.page) || items.length === 0)
|
|
165
|
+
return;
|
|
166
|
+
const path = findGroupPath(items, activeItem.page);
|
|
167
|
+
if (path.length) {
|
|
168
|
+
setOpenGroups((prev) => Array.from(new Set([...prev, ...path])));
|
|
169
|
+
}
|
|
170
|
+
}, [activeItem, items]);
|
|
171
|
+
/* ---------------------- Helpers ---------------------- */
|
|
172
|
+
const toggleGroup = (key) => setOpenGroups((prev) => (prev.includes(key) ? prev.filter((k) => k !== key) : [...prev, key]));
|
|
173
|
+
const isGroupOpen = (key) => openGroups.includes(key);
|
|
174
|
+
const calculateHeight = (items, depth) => {
|
|
175
|
+
return items.reduce((total, item, idx) => {
|
|
176
|
+
if (Array.isArray(item.items)) {
|
|
177
|
+
const key = `${depth + 1}-${idx}`;
|
|
178
|
+
return total + 36 + (isGroupOpen(key) ? calculateHeight(item.items, depth + 1) : 0);
|
|
179
|
+
}
|
|
180
|
+
return total + 36;
|
|
181
|
+
}, 0);
|
|
182
|
+
};
|
|
183
|
+
/* ---------------------- Events ---------------------- */
|
|
184
|
+
const handleSubItemClick = (item) => {
|
|
185
|
+
if (!item.page || item.page === activeItem.page)
|
|
186
|
+
return;
|
|
187
|
+
setActiveItem(item);
|
|
188
|
+
};
|
|
189
|
+
/* ---------------------- Recursive render ---------------------- */
|
|
190
|
+
const renderGroup = (group, index, depth = 0) => {
|
|
191
|
+
const paddingLeft = depth * 12;
|
|
192
|
+
const key = `${depth}-${index}`;
|
|
193
|
+
return (_jsxs("div", { children: [group.title && (_jsxs("div", { onClick: () => group.isDropdown && toggleGroup(key), className: "flex items-center justify-between px-3 py-2 cursor-pointer rounded-md", style: { paddingLeft: `${12 + paddingLeft}px` }, children: [_jsxs("div", { className: "flex items-center gap-2 h-6", children: [_jsx("div", { className: "w-5 h-5 flex items-center justify-center", children: _jsx(DynamicIcon, { icon: group.icon, size: 18 }) }), _jsx("span", { className: "text-sm font-medium truncate", children: group.title })] }), group.isDropdown && _jsx(ChevronDown, { size: 16, className: `transition-transform duration-200 ${isGroupOpen(key) ? "rotate-90" : ""}` })] })), _jsx("div", { style: {
|
|
194
|
+
maxHeight: !group.title || isGroupOpen(key) ? `${calculateHeight(group.items, depth)}px` : "0px",
|
|
195
|
+
}, className: "overflow-hidden transition-[max-height] duration-300", children: group.items.map((item, idx) => {
|
|
196
|
+
if (Array.isArray(item.items)) {
|
|
197
|
+
return renderGroup(item, idx, depth + 1);
|
|
198
|
+
}
|
|
199
|
+
const isActive = item.page === activeItem.page;
|
|
200
|
+
const itemPadding = group.title ? `${24 + paddingLeft}px` : `${12 + paddingLeft}px`;
|
|
201
|
+
return (_jsxs("div", { onClick: () => handleSubItemClick(item), className: `py-2 text-sm cursor-pointer rounded-md flex items-center gap-2 hover:bg-[#d3e3fd] ${isActive ? "bg-[#e8f0fe] text-blue-700 font-medium" : ""}`, style: { paddingLeft: itemPadding }, children: [_jsx("div", { className: "w-5 h-5 flex items-center justify-center", children: _jsx(DynamicIcon, { icon: item.icon, size: 16 }) }), _jsx("span", { className: "text-sm truncate", children: item.title })] }, idx));
|
|
202
|
+
}) })] }, key));
|
|
203
|
+
};
|
|
204
|
+
/* ---------------------- Render ---------------------- */
|
|
205
|
+
return _jsx("div", { className: "flex flex-col gap-1 px-4 py-3 h-full overflow-y-auto", children: items.map((group, index) => renderGroup(group, index, 0)) });
|
|
206
|
+
};
|
|
207
|
+
export default TreeMenu;
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { ChevronDown } from "lucide-react";
|
|
4
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import DynamicIcon from "../../core/DynamicIcon";
|
|
6
|
+
import { usePageContext } from "../../core/PageContext";
|
|
7
|
+
import { usePageViewContext } from "../../core/PageViewContext";
|
|
8
|
+
import { AbstractComponent } from "../../types/component";
|
|
9
|
+
import useUIMenu, { MenuGroup, MenuItem } from "../common/UIMenu";
|
|
10
|
+
|
|
11
|
+
/* ------------------------------------------------------------------ */
|
|
12
|
+
/* Local type */
|
|
13
|
+
type TreeMenuGroup = MenuGroup & { isDropdown?: boolean };
|
|
14
|
+
|
|
15
|
+
/* ------------------------------------------------------------------ */
|
|
16
|
+
/* Helpers */
|
|
17
|
+
|
|
18
|
+
const buildItems = (raw: any[]): TreeMenuGroup[] => {
|
|
19
|
+
const mapped: TreeMenuGroup[] = [];
|
|
20
|
+
|
|
21
|
+
for (const entry of raw) {
|
|
22
|
+
if (Array.isArray(entry.items)) {
|
|
23
|
+
mapped.push({
|
|
24
|
+
...entry,
|
|
25
|
+
isDropdown: entry.isDropdown ?? true,
|
|
26
|
+
items: buildItems(entry.items),
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
const lastGroup = mapped[mapped.length - 1];
|
|
30
|
+
if (lastGroup && lastGroup.title === "" && !lastGroup.isDropdown) {
|
|
31
|
+
lastGroup.items.push(entry);
|
|
32
|
+
} else {
|
|
33
|
+
mapped.push({ title: "", icon: undefined, isDropdown: false, items: [entry] });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return mapped;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const findFirstItem = (groups: TreeMenuGroup[]): MenuItem | null => {
|
|
42
|
+
for (const group of groups) {
|
|
43
|
+
for (const item of group.items) {
|
|
44
|
+
if (Array.isArray((item as any).items)) {
|
|
45
|
+
const found = findFirstItem([item as any as TreeMenuGroup]);
|
|
46
|
+
if (found) return found;
|
|
47
|
+
} else if (item.page) return item;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const findGroupPath = (groups: TreeMenuGroup[], targetPage: string | null, depth = 0): string[] => {
|
|
54
|
+
for (let i = 0; i < groups.length; i++) {
|
|
55
|
+
const group = groups[i];
|
|
56
|
+
const key = `${depth}-${i}`;
|
|
57
|
+
|
|
58
|
+
for (const item of group.items) {
|
|
59
|
+
if (Array.isArray((item as any).items)) {
|
|
60
|
+
const path = findGroupPath([item as any as TreeMenuGroup], targetPage, depth + 1);
|
|
61
|
+
if (path.length) return [key, ...path];
|
|
62
|
+
} else if (item.page === targetPage) return [key];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return [];
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const findItemByPage = (groups: TreeMenuGroup[], targetPage: string | null): MenuItem | null => {
|
|
69
|
+
for (const group of groups) {
|
|
70
|
+
for (const item of group.items) {
|
|
71
|
+
if (Array.isArray((item as any).items)) {
|
|
72
|
+
const found = findItemByPage([item as any as TreeMenuGroup], targetPage);
|
|
73
|
+
if (found) return found;
|
|
74
|
+
} else {
|
|
75
|
+
// console.log("treemenu findItemByPage", targetPage, item.page);
|
|
76
|
+
if (item.page === targetPage) return item;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const isActiveItemInTree = (groups: TreeMenuGroup[], page: string | null): boolean =>
|
|
84
|
+
groups.some((group) =>
|
|
85
|
+
group.items.some((item) => (Array.isArray((item as any).items) ? isActiveItemInTree([item as any as TreeMenuGroup], page) : item.page === page)),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
/* ------------------------------------------------------------------ */
|
|
89
|
+
/* Component */
|
|
90
|
+
|
|
91
|
+
interface TreeMenuProps extends AbstractComponent {
|
|
92
|
+
name?: string;
|
|
93
|
+
items?: TreeMenuGroup[] | MenuItem[];
|
|
94
|
+
data?: Record<string, any>;
|
|
95
|
+
menugroup?: string;
|
|
96
|
+
depends?: string;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const TreeMenu = (props: TreeMenuProps) => {
|
|
100
|
+
const { name = "selectedPage", menugroup, depends, items: itemsProp, data } = props ?? {};
|
|
101
|
+
|
|
102
|
+
const pageContext = usePageContext();
|
|
103
|
+
const pageView = usePageViewContext();
|
|
104
|
+
|
|
105
|
+
const contextKey = name ?? depends ?? "";
|
|
106
|
+
|
|
107
|
+
const [openGroups, setOpenGroups] = useState<string[]>([]);
|
|
108
|
+
const [activeItem, setActiveItem] = useState<Record<string, any>>({});
|
|
109
|
+
const [items, setItems] = useState<TreeMenuGroup[]>([]);
|
|
110
|
+
const initializedRef = useRef(false);
|
|
111
|
+
|
|
112
|
+
const { items: rawItems } = useUIMenu({
|
|
113
|
+
items: itemsProp as Record<string, any>[],
|
|
114
|
+
data,
|
|
115
|
+
menugroup,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
useLayoutEffect(() => {
|
|
119
|
+
const { path = "" } = pageView.getOriginalLocationInfo() ?? {};
|
|
120
|
+
const [, ...anchors] = path.split("#");
|
|
121
|
+
const [selectedPath] = anchors;
|
|
122
|
+
pageContext.set(contextKey, selectedPath);
|
|
123
|
+
}, []);
|
|
124
|
+
|
|
125
|
+
/* ---------------------- Sync active item from page view ---------------------- */
|
|
126
|
+
useLayoutEffect(() => {
|
|
127
|
+
if (items.length === 0 || !pageView.getSelectedPage()) return;
|
|
128
|
+
if (initializedRef.current) return;
|
|
129
|
+
|
|
130
|
+
const item = findItemByPage(items, pageView.getSelectedPage());
|
|
131
|
+
if (item) setActiveItem(item);
|
|
132
|
+
}, [items, pageView.getSelectedPage()]);
|
|
133
|
+
|
|
134
|
+
/* ---------------------- Build items ---------------------- */
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (!Array.isArray(rawItems) || rawItems.length === 0) return;
|
|
137
|
+
setItems(buildItems(rawItems as any[]));
|
|
138
|
+
}, [rawItems]);
|
|
139
|
+
|
|
140
|
+
/* ---------------------- Auto-select first item on init ---------------------- */
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
if (initializedRef.current || items.length === 0) return;
|
|
143
|
+
|
|
144
|
+
const firstItem = findFirstItem(items);
|
|
145
|
+
if (!firstItem?.page) return;
|
|
146
|
+
|
|
147
|
+
let selectedPage = pageContext.get(contextKey);
|
|
148
|
+
// console.log("treemenu selected page from context", contextKey, selectedPage);
|
|
149
|
+
if (selectedPage == null && contextKey === "selectedPage") {
|
|
150
|
+
selectedPage = pageView.getSelectedPage();
|
|
151
|
+
// console.log("treemenu selected page fallback from context", contextKey, selectedPage);
|
|
152
|
+
}
|
|
153
|
+
// console.log("treemenu selected page final", contextKey, selectedPage);
|
|
154
|
+
if (selectedPage != null) {
|
|
155
|
+
const selectedItem = findItemByPage(items, selectedPage);
|
|
156
|
+
// console.log("treemenu findItemByPage", selectedPage, selectedItem);
|
|
157
|
+
if (selectedItem) {
|
|
158
|
+
setOpenGroups(findGroupPath(items, selectedPage));
|
|
159
|
+
setActiveItem(selectedItem);
|
|
160
|
+
} else {
|
|
161
|
+
setOpenGroups(findGroupPath(items, firstItem.page));
|
|
162
|
+
setActiveItem(firstItem);
|
|
163
|
+
}
|
|
164
|
+
} else {
|
|
165
|
+
setOpenGroups(findGroupPath(items, firstItem.page));
|
|
166
|
+
setActiveItem(firstItem);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
initializedRef.current = true;
|
|
170
|
+
}, [items, contextKey]);
|
|
171
|
+
|
|
172
|
+
/* ---------------------- Sync page context on active item change ---------------------- */
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
const { mode, page } = (activeItem ?? {}) as Record<string, any>;
|
|
175
|
+
if (!page) return;
|
|
176
|
+
|
|
177
|
+
const idx = ["window", "popup"].indexOf(String(mode).toLowerCase());
|
|
178
|
+
if (idx >= 0) {
|
|
179
|
+
pageView.setPage(page, { mode });
|
|
180
|
+
} else {
|
|
181
|
+
pageView.setSelectedPage(page);
|
|
182
|
+
pageContext.set(contextKey, page);
|
|
183
|
+
}
|
|
184
|
+
}, [activeItem]);
|
|
185
|
+
|
|
186
|
+
/* ---------------------- Auto-open group containing active item ---------------------- */
|
|
187
|
+
useEffect(() => {
|
|
188
|
+
if (!activeItem?.page || items.length === 0) return;
|
|
189
|
+
|
|
190
|
+
const path = findGroupPath(items, activeItem.page);
|
|
191
|
+
if (path.length) {
|
|
192
|
+
setOpenGroups((prev) => Array.from(new Set([...prev, ...path])));
|
|
193
|
+
}
|
|
194
|
+
}, [activeItem, items]);
|
|
195
|
+
|
|
196
|
+
/* ---------------------- Helpers ---------------------- */
|
|
197
|
+
const toggleGroup = (key: string) => setOpenGroups((prev) => (prev.includes(key) ? prev.filter((k) => k !== key) : [...prev, key]));
|
|
198
|
+
|
|
199
|
+
const isGroupOpen = (key: string) => openGroups.includes(key);
|
|
200
|
+
|
|
201
|
+
const calculateHeight = (items: any[], depth: number): number => {
|
|
202
|
+
return items.reduce((total: number, item: any, idx: number) => {
|
|
203
|
+
if (Array.isArray(item.items)) {
|
|
204
|
+
const key = `${depth + 1}-${idx}`;
|
|
205
|
+
return total + 36 + (isGroupOpen(key) ? calculateHeight(item.items, depth + 1) : 0);
|
|
206
|
+
}
|
|
207
|
+
return total + 36;
|
|
208
|
+
}, 0);
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
/* ---------------------- Events ---------------------- */
|
|
212
|
+
const handleSubItemClick = (item: MenuItem) => {
|
|
213
|
+
if (!item.page || item.page === activeItem.page) return;
|
|
214
|
+
setActiveItem(item);
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/* ---------------------- Recursive render ---------------------- */
|
|
218
|
+
const renderGroup = (group: TreeMenuGroup, index: number, depth: number = 0): React.ReactNode => {
|
|
219
|
+
const paddingLeft = depth * 12;
|
|
220
|
+
const key = `${depth}-${index}`;
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
<div key={key}>
|
|
224
|
+
{group.title && (
|
|
225
|
+
<div
|
|
226
|
+
onClick={() => group.isDropdown && toggleGroup(key)}
|
|
227
|
+
className="flex items-center justify-between px-3 py-2 cursor-pointer rounded-md"
|
|
228
|
+
style={{ paddingLeft: `${12 + paddingLeft}px` }}
|
|
229
|
+
>
|
|
230
|
+
<div className="flex items-center gap-2 h-6">
|
|
231
|
+
<div className="w-5 h-5 flex items-center justify-center">
|
|
232
|
+
<DynamicIcon icon={group.icon} size={18} />
|
|
233
|
+
</div>
|
|
234
|
+
<span className="text-sm font-medium truncate">{group.title}</span>
|
|
235
|
+
</div>
|
|
236
|
+
{group.isDropdown && <ChevronDown size={16} className={`transition-transform duration-200 ${isGroupOpen(key) ? "rotate-90" : ""}`} />}
|
|
237
|
+
</div>
|
|
238
|
+
)}
|
|
239
|
+
|
|
240
|
+
<div
|
|
241
|
+
style={{
|
|
242
|
+
maxHeight: !group.title || isGroupOpen(key) ? `${calculateHeight(group.items, depth)}px` : "0px",
|
|
243
|
+
}}
|
|
244
|
+
className="overflow-hidden transition-[max-height] duration-300"
|
|
245
|
+
>
|
|
246
|
+
{group.items.map((item: any, idx: number) => {
|
|
247
|
+
if (Array.isArray(item.items)) {
|
|
248
|
+
return renderGroup(item as TreeMenuGroup, idx, depth + 1);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const isActive = item.page === activeItem.page;
|
|
252
|
+
const itemPadding = group.title ? `${24 + paddingLeft}px` : `${12 + paddingLeft}px`;
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<div
|
|
256
|
+
key={idx}
|
|
257
|
+
onClick={() => handleSubItemClick(item)}
|
|
258
|
+
className={`py-2 text-sm cursor-pointer rounded-md flex items-center gap-2 hover:bg-[#d3e3fd] ${
|
|
259
|
+
isActive ? "bg-[#e8f0fe] text-blue-700 font-medium" : ""
|
|
260
|
+
}`}
|
|
261
|
+
style={{ paddingLeft: itemPadding }}
|
|
262
|
+
>
|
|
263
|
+
<div className="w-5 h-5 flex items-center justify-center">
|
|
264
|
+
<DynamicIcon icon={item.icon} size={16} />
|
|
265
|
+
</div>
|
|
266
|
+
<span className="text-sm truncate">{item.title}</span>
|
|
267
|
+
</div>
|
|
268
|
+
);
|
|
269
|
+
})}
|
|
270
|
+
</div>
|
|
271
|
+
</div>
|
|
272
|
+
);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/* ---------------------- Render ---------------------- */
|
|
276
|
+
return <div className="flex flex-col gap-1 px-4 py-3 h-full overflow-y-auto">{items.map((group, index) => renderGroup(group, index, 0))}</div>;
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
export default TreeMenu;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button } from "@ramesesinc/client";
|
|
3
|
+
import { Eye, Newspaper, Pen, Plus } from "lucide-react";
|
|
4
|
+
import { useRouter } from "next/router";
|
|
5
|
+
import { useEffect, useState } from "react";
|
|
6
|
+
import { usePageContext } from "../../core/PageContext";
|
|
7
|
+
import { parseHashUrl } from "../../lib/utils/PageUtils";
|
|
8
|
+
const rootItems = [
|
|
9
|
+
{
|
|
10
|
+
id: "mytasklist",
|
|
11
|
+
title: "My Tasks",
|
|
12
|
+
},
|
|
13
|
+
{ id: "unassignedtasklist", title: "Unassigned" },
|
|
14
|
+
{ id: "assignedtasklist", title: "Active Tasks" },
|
|
15
|
+
];
|
|
16
|
+
const TxnTaskList = () => {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
const [tasklist, setTaskList] = useState({});
|
|
19
|
+
const [loading, setLoading] = useState(false);
|
|
20
|
+
const router = useRouter();
|
|
21
|
+
const url = router.asPath.replace(/^\/[^/]+\/[^/]+\//, "");
|
|
22
|
+
const pageContext = usePageContext();
|
|
23
|
+
const fetchData = async () => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const { page, params } = parseHashUrl(url);
|
|
26
|
+
const data = {
|
|
27
|
+
api: "mongo/list",
|
|
28
|
+
params: {
|
|
29
|
+
schemaname: "tasks",
|
|
30
|
+
filter: Object.assign({}, params),
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
setLoading(true);
|
|
34
|
+
const result = await (pageContext === null || pageContext === void 0 ? void 0 : pageContext.execService(data.api, data.params));
|
|
35
|
+
const resData = (_a = ((result === null || result === void 0 ? void 0 : result.data) ? result === null || result === void 0 ? void 0 : result.data : result)) !== null && _a !== void 0 ? _a : [];
|
|
36
|
+
const record = (_b = resData[0]) !== null && _b !== void 0 ? _b : {};
|
|
37
|
+
const taskData = {};
|
|
38
|
+
rootItems.forEach((item) => {
|
|
39
|
+
if (record[item.id]) {
|
|
40
|
+
taskData[item.id] = record[item.id];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
setTaskList(taskData);
|
|
44
|
+
setLoading(false);
|
|
45
|
+
};
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
fetchData();
|
|
48
|
+
}, []);
|
|
49
|
+
const renderEmpty = (key, title) => (_jsxs("div", { className: "mb-4", children: [_jsx("h5", { className: "font-bold mb-2", children: title }), _jsx("p", { className: "text-sm text-gray-400", children: "No tasks available." })] }, key));
|
|
50
|
+
const renderShowMore = (show, onToggle) => (_jsx("p", { className: "text-sm text-blue-500 cursor-pointer hover:underline flex justify-center mb-2", onClick: onToggle, children: show ? "Show less" : "Show more" }));
|
|
51
|
+
const [showAllMyTasks, setShowAllMyTasks] = useState(false);
|
|
52
|
+
const renderMyTasks = (tasks) => {
|
|
53
|
+
if (tasks.length === 0)
|
|
54
|
+
return renderEmpty("mytasklist", "My Tasks");
|
|
55
|
+
const visibleTasks = showAllMyTasks ? tasks : tasks.slice(0, 5);
|
|
56
|
+
// ============= My Tasks =============
|
|
57
|
+
return (_jsxs("div", { className: "", children: [_jsx("h5", { className: "font-bold mb-2 border-t border-b border-gray-200 py-2", children: "My Tasks" }), visibleTasks.map((task) => (_jsx("div", { className: "p-3", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsxs("div", { className: "flex items-center gap-4", children: [_jsx(Newspaper, {}), _jsxs("div", { className: "flex flex-col", children: [_jsx("p", { className: "font-medium", children: task.title }), _jsx("div", { className: "flex gap-2 items-center", children: _jsx(Button, { size: "sm", variant: "text", radius: "full", icon: _jsx(Eye, { size: 16 }), className: "text-xs gap-0", children: "View" }) })] })] }), _jsx("p", { className: "text-sm text-gray-500", children: task.elapsedtime })] }) }, task.objid))), tasks.length > 5 && renderShowMore(showAllMyTasks, () => setShowAllMyTasks(!showAllMyTasks))] }));
|
|
58
|
+
};
|
|
59
|
+
const [showAllUnassigned, setShowAllUnassigned] = useState(false);
|
|
60
|
+
const renderUnassigned = (tasks) => {
|
|
61
|
+
if (tasks.length === 0)
|
|
62
|
+
return renderEmpty("unassignedtasklist", "Unassigned");
|
|
63
|
+
const visibleTasks = showAllUnassigned ? tasks : tasks.slice(0, 5);
|
|
64
|
+
// ============= Unassigned Tasks =============
|
|
65
|
+
return (_jsxs("div", { className: "", children: [_jsx("div", { className: "border-t border-b border-gray-200 py-2", children: _jsxs("div", { className: "flex items-center justify-between", children: [_jsx("h5", { className: "font-bold", children: "Unassigned" }), _jsx("span", { className: "text-gray-600 hover:bg-gray-200 rounded p-1 cursor-pointer flex items-center", children: _jsx(Plus, { size: 18 }) })] }) }), visibleTasks.map((task) => (_jsx("div", { className: "p-3", children: _jsxs("div", { className: "flex items-center gap-4", children: [_jsx(Newspaper, {}), _jsxs("div", { className: "flex items-center justify-between w-full", children: [_jsxs("div", { children: [_jsx("p", { className: "font-medium", children: task.title }), _jsx(Button, { size: "sm", variant: "text", radius: "full", icon: _jsx(Pen, { size: 16 }), className: "text-xs gap-0", children: "Assign to Me" })] }), _jsx("p", { className: "text-sm text-gray-500", children: task.elapsedtime })] })] }) }, task.objid))), tasks.length > 5 && renderShowMore(showAllUnassigned, () => setShowAllUnassigned(!showAllUnassigned))] }));
|
|
66
|
+
};
|
|
67
|
+
// ============= Assigned Tasks =============
|
|
68
|
+
const [showAllAssigned, setShowAllAssigned] = useState(false);
|
|
69
|
+
const renderAssigned = (tasks) => {
|
|
70
|
+
if (tasks.length === 0)
|
|
71
|
+
return renderEmpty("assignedtasklist", "Active Tasks");
|
|
72
|
+
const visibleTasks = showAllAssigned ? tasks : tasks.slice(0, 5);
|
|
73
|
+
return (_jsxs("div", { className: "", children: [_jsxs("div", { className: "flex items-center justify-between border-t border-b border-gray-200 py-2", children: [_jsx("h5", { className: "font-bold", children: "Active Tasks" }), _jsx("span", { className: "text-gray-600 hover:bg-gray-200 rounded p-1 cursor-pointer flex items-center", children: _jsx(Plus, { size: 18 }) })] }), visibleTasks.map((task) => (_jsxs("div", { className: "flex items-center justify-between p-3 mb-2", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("img", { src: `data:image/png;base64,${task.assignee.img}`, alt: task.assignee.name, className: "w-10 h-10 rounded-full object-cover" }), _jsxs("div", { children: [_jsx("p", { className: "font-medium", children: task.title }), task.findings !== undefined && (_jsxs("span", { className: "text-xs bg-yellow-100 text-yellow-700 rounded-full px-2 py-1", children: [task.findings, " finding", task.findings !== 1 ? "s" : ""] }))] })] }), _jsx("p", { className: "text-sm text-gray-500", children: task.elapsedtime })] }, task.objid))), tasks.length > 5 && renderShowMore(showAllAssigned, () => setShowAllAssigned(!showAllAssigned))] }));
|
|
74
|
+
};
|
|
75
|
+
return (_jsx("div", { className: "p-2", children: loading ? (_jsx("div", { className: "flex items-center justify-center h-24", children: _jsx("div", { className: "w-6 h-6 border-2 border-gray-300 border-t-gray-600 rounded-full animate-spin" }) })) : (_jsxs("div", { className: "overflow-y-auto h-[calc(100vh-154px)]", children: [renderMyTasks((_a = tasklist["mytasklist"]) !== null && _a !== void 0 ? _a : []), renderUnassigned((_b = tasklist["unassignedtasklist"]) !== null && _b !== void 0 ? _b : []), renderAssigned((_c = tasklist["assignedtasklist"]) !== null && _c !== void 0 ? _c : [])] })) }));
|
|
76
|
+
};
|
|
77
|
+
export default TxnTaskList;
|