@dakataa/crud-react 1.0.0 → 1.0.1
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/crud-react.css +5 -0
- package/dist/crud-react.js +14467 -0
- package/dist/denied-CgoMpaA7.js +27 -0
- package/dist/info-D-NzIEYs.js +144 -0
- package/dist/main.d.ts +19 -0
- package/dist/success-Bu_BJcf1.js +27 -0
- package/dist/warning-B1nr7TsB.js +27 -0
- package/package.json +11 -3
- package/.env +0 -3
- package/babel-plugin-macros.config.js +0 -5
- package/index.html +0 -12
- package/public/favicon.ico +0 -0
- package/public/logo192.png +0 -0
- package/public/logo512.png +0 -0
- package/public/manifest.json +0 -25
- package/public/robots.txt +0 -3
- package/src/Crud.tsx +0 -29
- package/src/CrudContext.tsx +0 -21
- package/src/CrudLoader.tsx +0 -27
- package/src/assets/images/alert/denied.json +0 -1
- package/src/assets/images/alert/info.json +0 -1
- package/src/assets/images/alert/success.json +0 -1
- package/src/assets/images/alert/warning.json +0 -1
- package/src/assets/style/alert.scss +0 -97
- package/src/component/Animation.tsx +0 -50
- package/src/component/BaseButton.tsx +0 -26
- package/src/component/Button.tsx +0 -15
- package/src/component/Dropdown.tsx +0 -55
- package/src/component/EmptyView.tsx +0 -5
- package/src/component/Link.tsx +0 -11
- package/src/component/Modal.tsx +0 -174
- package/src/component/ModifyForm.tsx +0 -139
- package/src/component/TemplateBlock.tsx +0 -21
- package/src/component/TemplateExtend.tsx +0 -17
- package/src/component/TemplateParentBlock.tsx +0 -7
- package/src/component/Translation.tsx +0 -7
- package/src/component/ViewLoader.tsx +0 -33
- package/src/component/crud/DynamicView.tsx +0 -42
- package/src/component/crud/FormView.tsx +0 -29
- package/src/component/crud/GridTableView.tsx +0 -205
- package/src/component/crud/PaginatorView.tsx +0 -80
- package/src/component/error/ErrorBoundary.tsx +0 -78
- package/src/component/error/Exception.tsx +0 -17
- package/src/component/error/HttpException.tsx +0 -24
- package/src/component/form/Choice.tsx +0 -119
- package/src/component/form/Form.tsx +0 -233
- package/src/component/form/FormAlert.tsx +0 -19
- package/src/component/form/FormFieldError.tsx +0 -16
- package/src/component/form/FormGroup.tsx +0 -53
- package/src/component/form/FormWidget.tsx +0 -34
- package/src/component/form/Input.tsx +0 -63
- package/src/component/form/constraint/Contraint.tsx +0 -8
- package/src/component/form/constraint/NotBlank.tsx +0 -20
- package/src/component/hooks/GetData.tsx +0 -137
- package/src/context/ActionContext.tsx +0 -99
- package/src/context/AlertContext.tsx +0 -181
- package/src/context/ModalContext.tsx +0 -56
- package/src/context/SessionContext.tsx +0 -97
- package/src/helper/ObjectUtils.tsx +0 -36
- package/src/helper/RouterUtils.tsx +0 -24
- package/src/helper/StingUtils.tsx +0 -25
- package/src/index.tsx +0 -23
- package/src/layout/default/Base.tsx +0 -15
- package/src/layout/default/Error.tsx +0 -27
- package/src/layout/default/Main.tsx +0 -64
- package/src/layout/default/component/Navigation.tsx +0 -197
- package/src/page/List.tsx +0 -268
- package/src/page/Modify.tsx +0 -156
- package/src/react-app-env.d.ts +0 -2
- package/src/setupTests.ts +0 -5
- package/src/type/ActionType.tsx +0 -10
- package/src/type/ColumnType.tsx +0 -18
- package/src/type/ExceptionType.tsx +0 -7
- package/src/type/FormType.tsx +0 -6
- package/src/type/FormViewType.tsx +0 -37
- package/src/type/ListMetaType.tsx +0 -7
- package/src/type/ListType.tsx +0 -20
- package/src/type/ModifyType.tsx +0 -10
- package/src/type/RedirectType.tsx +0 -6
- package/src/type/RouteType.tsx +0 -5
- package/tsconfig.app.json +0 -46
- package/tsconfig.json +0 -11
- package/tsconfig.node.json +0 -15
- package/vite.config.ts +0 -33
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
createRef,
|
|
3
|
-
ForwardedRef,
|
|
4
|
-
forwardRef,
|
|
5
|
-
useDeferredValue,
|
|
6
|
-
useEffect,
|
|
7
|
-
useImperativeHandle,
|
|
8
|
-
useRef
|
|
9
|
-
} from "react";
|
|
10
|
-
import {Link, useLocation} from "react-router-dom";
|
|
11
|
-
import {generateRoute} from "@src/helper/RouterUtils.tsx";
|
|
12
|
-
import {RouteType} from "@src/type/RouteType";
|
|
13
|
-
|
|
14
|
-
export type MenuItem = {
|
|
15
|
-
title: string;
|
|
16
|
-
route?: RouteType;
|
|
17
|
-
icon?: any;
|
|
18
|
-
items?: MenuItem[];
|
|
19
|
-
target?: '_blank' | '_self',
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type NavigationItemContextType = {
|
|
23
|
-
toggle: (value?: boolean) => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const NavigationItemContext = React.createContext<NavigationItemContextType | null>(null);
|
|
27
|
-
|
|
28
|
-
const UseParentNavigationItem = () => {
|
|
29
|
-
return React.useContext<NavigationItemContextType | null>(NavigationItemContext);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const MainNavigationItem = ({item, open = false}: {
|
|
33
|
-
item: MenuItem;
|
|
34
|
-
open?: boolean;
|
|
35
|
-
}) => {
|
|
36
|
-
|
|
37
|
-
const isGroup = !!item.items?.length;
|
|
38
|
-
const location = useLocation();
|
|
39
|
-
const currentLocationPath = location.pathname.replace(/(.*?)\/?$/i, '$1');
|
|
40
|
-
const itemPath = generateRoute(item.route);
|
|
41
|
-
const isActive = currentLocationPath.includes(itemPath, 0);
|
|
42
|
-
const [active, setActive] = React.useState(isActive);
|
|
43
|
-
const parentNavigationMenu = UseParentNavigationItem();
|
|
44
|
-
const containerRef = useRef<HTMLElement | null>(null);
|
|
45
|
-
const startAnimationTimeout = useRef<number | null>(null);
|
|
46
|
-
|
|
47
|
-
const collapseClass = 'collapse';
|
|
48
|
-
const animatingClass = 'collapsing';
|
|
49
|
-
|
|
50
|
-
const context = {
|
|
51
|
-
toggle: (value?: boolean) => {
|
|
52
|
-
setActive(value !== undefined ? value : !active);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const onAnimationEnd = () => {
|
|
57
|
-
containerRef.current?.classList.remove(animatingClass);
|
|
58
|
-
containerRef.current?.classList.add(collapseClass);
|
|
59
|
-
containerRef.current?.classList.toggle('show', active);
|
|
60
|
-
containerRef.current?.style.removeProperty('height');
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
const onAnimationStart = () => {
|
|
64
|
-
if (startAnimationTimeout.current) {
|
|
65
|
-
clearTimeout(startAnimationTimeout.current);
|
|
66
|
-
startAnimationTimeout.current = null;
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
if (active && parentNavigationMenu) {
|
|
72
|
-
parentNavigationMenu.toggle(true);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Add animation events
|
|
76
|
-
containerRef.current?.addEventListener('animationstart', onAnimationStart);
|
|
77
|
-
containerRef.current?.addEventListener('transitionstart', onAnimationStart);
|
|
78
|
-
containerRef.current?.addEventListener('animationend', onAnimationEnd);
|
|
79
|
-
containerRef.current?.addEventListener('transitionend', onAnimationEnd);
|
|
80
|
-
|
|
81
|
-
containerRef.current?.style.setProperty('height', (!active ? containerRef.current?.scrollHeight : 0) + 'px');
|
|
82
|
-
|
|
83
|
-
// Add animating class
|
|
84
|
-
containerRef.current?.classList.remove('show');
|
|
85
|
-
containerRef.current?.classList.remove(collapseClass);
|
|
86
|
-
containerRef.current?.classList.add(animatingClass);
|
|
87
|
-
|
|
88
|
-
// Set height depend on activity
|
|
89
|
-
setTimeout(() => {
|
|
90
|
-
containerRef.current?.style.setProperty('height', (active ? containerRef.current?.scrollHeight : 0) + 'px');
|
|
91
|
-
}, 10)
|
|
92
|
-
|
|
93
|
-
// End animation if not started in first 50 ms (in case no animation)
|
|
94
|
-
startAnimationTimeout.current = setTimeout(onAnimationEnd, 50);
|
|
95
|
-
|
|
96
|
-
return () => {
|
|
97
|
-
onAnimationStart();
|
|
98
|
-
|
|
99
|
-
containerRef.current?.removeEventListener('animationstart', onAnimationStart);
|
|
100
|
-
containerRef.current?.removeEventListener('transitionstart', onAnimationStart);
|
|
101
|
-
containerRef.current?.removeEventListener('animationend', onAnimationEnd);
|
|
102
|
-
containerRef.current?.removeEventListener('transitionend', onAnimationEnd);
|
|
103
|
-
};
|
|
104
|
-
}, [active]);
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
if (open !== active) {
|
|
108
|
-
setActive(open);
|
|
109
|
-
}
|
|
110
|
-
}, [open]);
|
|
111
|
-
|
|
112
|
-
return (
|
|
113
|
-
<NavigationItemContext.Provider value={context}>
|
|
114
|
-
<nav className={["item", ...(active || isActive ? ['active'] : [])].join(' ')}>
|
|
115
|
-
<Link
|
|
116
|
-
to={isGroup ? '#' : generateRoute(item.route)}
|
|
117
|
-
{...(item.icon && {icon: item.icon})}
|
|
118
|
-
{...(isGroup && {
|
|
119
|
-
onClick: (e) => {
|
|
120
|
-
setActive(!active);
|
|
121
|
-
}
|
|
122
|
-
})}
|
|
123
|
-
>
|
|
124
|
-
<span className={"icon"}></span>
|
|
125
|
-
<span className={"title"}>{item.title}</span>
|
|
126
|
-
</Link>
|
|
127
|
-
|
|
128
|
-
{isGroup && !!item.items?.length && (
|
|
129
|
-
<nav ref={containerRef} className={collapseClass}>
|
|
130
|
-
<NavigationGroup items={item.items}/>
|
|
131
|
-
</nav>
|
|
132
|
-
)}
|
|
133
|
-
</nav>
|
|
134
|
-
</NavigationItemContext.Provider>
|
|
135
|
-
)
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const NavigationGroup = ({items}: {
|
|
139
|
-
items: MenuItem[];
|
|
140
|
-
}) => {
|
|
141
|
-
return (
|
|
142
|
-
items.map((item) => {
|
|
143
|
-
const key = [parent, item.title].filter(v => v).join('-').toLowerCase();
|
|
144
|
-
return (
|
|
145
|
-
<MainNavigationItem key={key} item={item}/>
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
)
|
|
149
|
-
);
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const Navigation = forwardRef(({items, className, open = false}: {
|
|
153
|
-
items: MenuItem[];
|
|
154
|
-
className?: string;
|
|
155
|
-
open?: boolean;
|
|
156
|
-
props?: any;
|
|
157
|
-
}, ref: ForwardedRef<NavigationItemContextType>) => {
|
|
158
|
-
const containerRef = useRef<HTMLElement | null>(null);
|
|
159
|
-
|
|
160
|
-
const [active, setActive] = React.useState(open);
|
|
161
|
-
ref = ref || createRef<NavigationItemContextType>();
|
|
162
|
-
|
|
163
|
-
const context = {
|
|
164
|
-
toggle: (value?: boolean) => {
|
|
165
|
-
setActive(value !== undefined ? value : !active)
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
useImperativeHandle(ref, () => context);
|
|
170
|
-
|
|
171
|
-
useEffect(() => {
|
|
172
|
-
document.body.classList.toggle('toggle-nav', active);
|
|
173
|
-
|
|
174
|
-
const onClickOutside = (e: Event) => {
|
|
175
|
-
if (!containerRef.current?.contains(e.target as Node)) {
|
|
176
|
-
setActive(false);
|
|
177
|
-
document.body.removeEventListener('click', onClickOutside);
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
if (active) {
|
|
182
|
-
document.body.addEventListener('click', onClickOutside);
|
|
183
|
-
return () => {
|
|
184
|
-
document.body.removeEventListener('click', onClickOutside);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}, [active]);
|
|
188
|
-
|
|
189
|
-
return (
|
|
190
|
-
<nav ref={containerRef}>
|
|
191
|
-
<NavigationGroup items={items}/>
|
|
192
|
-
</nav>
|
|
193
|
-
)
|
|
194
|
-
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
export default Navigation;
|
package/src/page/List.tsx
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import React, {memo, useEffect, useRef} from "react";
|
|
2
|
-
import {
|
|
3
|
-
convertFormDataToObject,
|
|
4
|
-
convertObjectToURLSearchParams,
|
|
5
|
-
convertURLSearchParamsToObject,
|
|
6
|
-
default as Requester,
|
|
7
|
-
Method
|
|
8
|
-
} from "@dakataa/requester";
|
|
9
|
-
import GridTableView, {OnClickAction} from "@src/component/crud/GridTableView.tsx";
|
|
10
|
-
import PaginatorView from "@src/component/crud/PaginatorView.tsx";
|
|
11
|
-
import {Link, useLocation, useSearchParams} from "react-router-dom";
|
|
12
|
-
import {Form, FormRef, nameToId} from "@src/component/form/Form.tsx";
|
|
13
|
-
import Dropdown, {DropdownButton, DropdownContent} from "@src/component/Dropdown.tsx";
|
|
14
|
-
import Button from "@src/component/Button.tsx";
|
|
15
|
-
import {generateRoute} from "@src/helper/RouterUtils.tsx";
|
|
16
|
-
import FormView from "@src/component/crud/FormView.tsx";
|
|
17
|
-
import {objectRemoveEmpty} from "@src/helper/ObjectUtils.tsx";
|
|
18
|
-
import DynamicView from "@src/component/crud/DynamicView.tsx";
|
|
19
|
-
import GetData, {GetDataType} from "@src/component/hooks/GetData.tsx";
|
|
20
|
-
import {ListType} from "@src/type/ListType.tsx";
|
|
21
|
-
import {ActionType} from "@src/type/ActionType.tsx";
|
|
22
|
-
import {UseModal} from "@src/context/ModalContext.tsx";
|
|
23
|
-
import {Icon, Result, UseAlert} from "@src/context/AlertContext.tsx";
|
|
24
|
-
import {default as T} from "@src/component/Translation.tsx";
|
|
25
|
-
import {FormViewType} from "@src/type/FormViewType.tsx";
|
|
26
|
-
|
|
27
|
-
const List = memo(({action, embedded = false}: {
|
|
28
|
-
action: OnClickAction,
|
|
29
|
-
embedded?: boolean
|
|
30
|
-
}) => {
|
|
31
|
-
const location = useLocation();
|
|
32
|
-
const [searchParams, setSearchParams] = useSearchParams();
|
|
33
|
-
const sort = useRef<{ [key: string]: any } | undefined>(undefined);
|
|
34
|
-
const filter = useRef<{ [key: string]: any } | undefined>(convertURLSearchParamsToObject(searchParams));
|
|
35
|
-
const filterFormRef = useRef<FormRef | null>(null);
|
|
36
|
-
const {openModal} = UseModal()
|
|
37
|
-
const {open: openAlert} = UseAlert();
|
|
38
|
-
|
|
39
|
-
const entity = action.action.entity;
|
|
40
|
-
|
|
41
|
-
if (!entity) {
|
|
42
|
-
throw new Error('Invalid Entity');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const {results, refresh, setQueryParameters}: GetDataType & {
|
|
46
|
-
results: ListType | null;
|
|
47
|
-
} = GetData({entityAction: action.action, initParameters: action.parameters, initQueryParameters: filter.current});
|
|
48
|
-
const actions = (Object.values(results?.action ?? []) as ActionType[]).filter(a => !a.object && a.name !== action.action.name);
|
|
49
|
-
|
|
50
|
-
const filterData = (excludeFilterParameters?: [string]): void => {
|
|
51
|
-
excludeFilterParameters?.forEach((key) => {
|
|
52
|
-
delete filter.current?.filter?.[key];
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
const query = {
|
|
56
|
-
...(filter.current && filter.current),
|
|
57
|
-
...(sort.current && {sort: sort.current}),
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const searchQuery = convertObjectToURLSearchParams(objectRemoveEmpty(query));
|
|
61
|
-
if (embedded) {
|
|
62
|
-
setQueryParameters(searchQuery)
|
|
63
|
-
} else {
|
|
64
|
-
setSearchParams(searchQuery);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const handleBatchAction = (method: string, ids: any, data: FormData) => {
|
|
69
|
-
console.log('method', ids, data);
|
|
70
|
-
|
|
71
|
-
openAlert({
|
|
72
|
-
title: 'Are you sure?',
|
|
73
|
-
icon: Icon.confirm,
|
|
74
|
-
onResult: (result: Result) => {
|
|
75
|
-
if (result.isConfirmed) {
|
|
76
|
-
(new Requester).post(generateRoute(action.action.route, action.parameters), data).catch((e:any) => {
|
|
77
|
-
console.log('error', e);
|
|
78
|
-
}).finally(() => {
|
|
79
|
-
console.log('done');
|
|
80
|
-
refresh();
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const handleAction = (onClickAction: OnClickAction, event?: React.MouseEvent) => {
|
|
88
|
-
if (onClickAction.parameters !== undefined) {
|
|
89
|
-
onClickAction.parameters = objectRemoveEmpty(onClickAction.parameters as object);
|
|
90
|
-
if (!Object.keys(onClickAction.parameters as object).length) {
|
|
91
|
-
onClickAction.parameters = undefined;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
switch (onClickAction.action.name) {
|
|
96
|
-
case 'filter': {
|
|
97
|
-
event?.preventDefault();
|
|
98
|
-
filter.current = onClickAction.parameters;
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
case 'sort': {
|
|
102
|
-
event?.preventDefault();
|
|
103
|
-
sort.current = onClickAction.parameters;
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
case 'delete': {
|
|
107
|
-
event?.preventDefault();
|
|
108
|
-
openAlert({
|
|
109
|
-
title: 'Are you sure?',
|
|
110
|
-
icon: Icon.confirm,
|
|
111
|
-
onResult: (result: Result) => {
|
|
112
|
-
if (result.isConfirmed) {
|
|
113
|
-
(new Requester).fetch({
|
|
114
|
-
url: generateRoute(onClickAction.action.route, {...action.parameters, ...onClickAction.parameters}),
|
|
115
|
-
method: Method.DELETE
|
|
116
|
-
}).catch((e:any) => {
|
|
117
|
-
console.log('error', e);
|
|
118
|
-
}).finally(() => {
|
|
119
|
-
refresh();
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
default: {
|
|
127
|
-
if (embedded) {
|
|
128
|
-
event?.preventDefault();
|
|
129
|
-
openModal({
|
|
130
|
-
action: onClickAction, props: {
|
|
131
|
-
onClose: () => {
|
|
132
|
-
refresh();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
filterData();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
useEffect(() => {
|
|
145
|
-
setQueryParameters(searchParams);
|
|
146
|
-
}, [location]);
|
|
147
|
-
|
|
148
|
-
return (
|
|
149
|
-
<>
|
|
150
|
-
<section className={"list"}>
|
|
151
|
-
<header className="content-header d-md-flex mb-3 justify-content-between align-items-center">
|
|
152
|
-
<h2>
|
|
153
|
-
{results?.title}
|
|
154
|
-
</h2>
|
|
155
|
-
<div className={"d-flex align-items-center"}>
|
|
156
|
-
{!!actions.length && (
|
|
157
|
-
<div className="btn-group btn-group-sm me-2">
|
|
158
|
-
{actions.map((item, index) => (
|
|
159
|
-
<Link
|
|
160
|
-
key={index}
|
|
161
|
-
to={generateRoute(item.route, action.parameters)}
|
|
162
|
-
onClick={(event) => handleAction({
|
|
163
|
-
action: item,
|
|
164
|
-
parameters: action.parameters
|
|
165
|
-
}, event)}
|
|
166
|
-
className="btn btn-outline-secondary">
|
|
167
|
-
{item.title || item.name}
|
|
168
|
-
</Link>
|
|
169
|
-
))}
|
|
170
|
-
</div>
|
|
171
|
-
)}
|
|
172
|
-
{results?.form?.filter && (
|
|
173
|
-
<div className={"btn-group btn-group-sm"}>
|
|
174
|
-
<Dropdown className={"btn-group btn-group-sm"}>
|
|
175
|
-
<DropdownButton className={"btn-outline-dark"}><T>Filter</T></DropdownButton>
|
|
176
|
-
<DropdownContent>
|
|
177
|
-
<div className="filter">
|
|
178
|
-
<Form
|
|
179
|
-
id={"filter_" + nameToId(entity)}
|
|
180
|
-
ref={filterFormRef}
|
|
181
|
-
onSubmit={(formData: FormData) => handleAction({
|
|
182
|
-
action: {
|
|
183
|
-
name: 'filter',
|
|
184
|
-
object: false,
|
|
185
|
-
namespace: action.action.namespace,
|
|
186
|
-
entity: entity
|
|
187
|
-
}, parameters: convertFormDataToObject(formData)
|
|
188
|
-
})}
|
|
189
|
-
onReset={() => handleAction({
|
|
190
|
-
action: {
|
|
191
|
-
name: 'filter',
|
|
192
|
-
object: false,
|
|
193
|
-
namespace: action.action.namespace,
|
|
194
|
-
entity: entity
|
|
195
|
-
}
|
|
196
|
-
})}
|
|
197
|
-
>
|
|
198
|
-
{
|
|
199
|
-
results?.form?.filter && (
|
|
200
|
-
<FormView view={results.form.filter.view}/>
|
|
201
|
-
)
|
|
202
|
-
}
|
|
203
|
-
<button className={"btn btn-primary me-2"} type={"submit"}>
|
|
204
|
-
<T>Submit</T>
|
|
205
|
-
</button>
|
|
206
|
-
</Form>
|
|
207
|
-
</div>
|
|
208
|
-
</DropdownContent>
|
|
209
|
-
</Dropdown>
|
|
210
|
-
{!!Object.values(filter.current?.filter || []).length && (
|
|
211
|
-
<Button onClick={() => {
|
|
212
|
-
filterFormRef.current?.reset();
|
|
213
|
-
}} className="btn btn-outline-dark">x</Button>
|
|
214
|
-
)}
|
|
215
|
-
</div>
|
|
216
|
-
)}
|
|
217
|
-
</div>
|
|
218
|
-
</header>
|
|
219
|
-
{results?.form?.filter && (
|
|
220
|
-
<FiltersView formView={results.form.filter.view} onClick={(key) => filterData([key])}/>
|
|
221
|
-
)}
|
|
222
|
-
<DynamicView namespace={action.action.namespace} key={"modify"} prefix={"modify"} view={"content"} data={results}>
|
|
223
|
-
<div className={"table-responsive"}>
|
|
224
|
-
<GridTableView
|
|
225
|
-
data={results}
|
|
226
|
-
onClick={handleAction}
|
|
227
|
-
onBatchClick={handleBatchAction}
|
|
228
|
-
namespace={action.action.namespace}
|
|
229
|
-
routeParams={action.parameters}/>
|
|
230
|
-
</div>
|
|
231
|
-
{results && <PaginatorView meta={results.entity.data.meta}/>}
|
|
232
|
-
</DynamicView>
|
|
233
|
-
</section>
|
|
234
|
-
</>
|
|
235
|
-
);
|
|
236
|
-
})
|
|
237
|
-
|
|
238
|
-
const FiltersView = ({formView, onClick}: { formView: FormViewType, onClick: (key: string) => void }) => {
|
|
239
|
-
const getValue = (view: FormViewType) => {
|
|
240
|
-
if (view.choices !== undefined) {
|
|
241
|
-
return (view.choices ? Object.values(view.data instanceof Object ? view.data : [view.data]).map((k: any) => view.choices?.[k]?.label ?? k).join(', ') : view.data);
|
|
242
|
-
} else if (view.checked !== undefined) {
|
|
243
|
-
return view.checked ? 'Yes' : 'No';
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return view.data;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
return (
|
|
250
|
-
<div className={"filters d-flex mb-sm overflow-auto"}>
|
|
251
|
-
{Object.values<FormViewType>(formView.children || []).filter(item => item.data !== null).map((item, index) => (
|
|
252
|
-
<div key={index} className="filters-item d-flex text-nowrap flex-column me-2 mb-2">
|
|
253
|
-
<small className="mb-2">{item.label}</small>
|
|
254
|
-
<div className="btn btn-sm btn-primary me-1 mb-1">
|
|
255
|
-
{getValue(item)}
|
|
256
|
-
{onClick && (
|
|
257
|
-
<span onClick={() => onClick(item.name)} className={"ms-2"}>
|
|
258
|
-
×
|
|
259
|
-
</span>
|
|
260
|
-
)}
|
|
261
|
-
</div>
|
|
262
|
-
</div>
|
|
263
|
-
))}
|
|
264
|
-
</div>
|
|
265
|
-
)
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
export default List;
|
package/src/page/Modify.tsx
DELETED
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import React, {ReactNode, useEffect, useRef} from "react";
|
|
2
|
-
import {Link, useParams} from "react-router-dom";
|
|
3
|
-
import TemplateBlock from "@src/component/TemplateBlock.tsx";
|
|
4
|
-
import {UseActions} from "@src/context/ActionContext.tsx";
|
|
5
|
-
import ModifyForm, {ModifyFormRefType} from "@src/component/ModifyForm.tsx";
|
|
6
|
-
import {ModifyType} from "@src/type/ModifyType.tsx";
|
|
7
|
-
import GetData from "@src/component/hooks/GetData.tsx";
|
|
8
|
-
import {ActionType} from "@src/type/ActionType.tsx";
|
|
9
|
-
import TemplateExtend from "@src/component/TemplateExtend.tsx";
|
|
10
|
-
import Modal, {ModalRefType} from "@src/component/Modal.tsx";
|
|
11
|
-
import {generateRoute} from "@src/helper/RouterUtils.tsx";
|
|
12
|
-
import {Icon as AlertIcon, UseAlert} from "@src/context/AlertContext.tsx";
|
|
13
|
-
import {ExceptionType} from "@src/type/ExceptionType.tsx";
|
|
14
|
-
import {OnClickAction} from "@src/component/crud/GridTableView.tsx";
|
|
15
|
-
import DynamicView from "@src/component/crud/DynamicView.tsx";
|
|
16
|
-
|
|
17
|
-
const DefaultModifyTemplate = ({action, children, routeParams, results}: {
|
|
18
|
-
action: ActionType;
|
|
19
|
-
children?: ReactNode;
|
|
20
|
-
routeParams?: { [key: string]: any };
|
|
21
|
-
results?: ModifyType;
|
|
22
|
-
}) => {
|
|
23
|
-
|
|
24
|
-
const {getAction} = UseActions();
|
|
25
|
-
const listAction = getAction(action.entity, 'list', action.namespace);
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<section className="edit">
|
|
29
|
-
<header>
|
|
30
|
-
<h2 className="title">
|
|
31
|
-
{listAction && (
|
|
32
|
-
<Link to={generateRoute(listAction.route, routeParams)}>←</Link>
|
|
33
|
-
)}
|
|
34
|
-
<TemplateBlock name={"title"} content={children} data={results}/>
|
|
35
|
-
</h2>
|
|
36
|
-
<nav>
|
|
37
|
-
<TemplateBlock name={"navigation"} content={children} data={results}/>
|
|
38
|
-
</nav>
|
|
39
|
-
</header>
|
|
40
|
-
|
|
41
|
-
<main>
|
|
42
|
-
<TemplateBlock name={"content"} content={children} data={results}/>
|
|
43
|
-
</main>
|
|
44
|
-
</section>
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const Modify = ({action, children, onSuccess, modal, props}: {
|
|
49
|
-
action: OnClickAction;
|
|
50
|
-
children?: ReactNode;
|
|
51
|
-
onSuccess?: (event: CustomEvent, data: ModifyType) => void;
|
|
52
|
-
modal?: boolean;
|
|
53
|
-
props?: any;
|
|
54
|
-
}) => {
|
|
55
|
-
const routeParams = {...(action.parameters || {}), ...useParams()}
|
|
56
|
-
const modifyFormRef = useRef<ModifyFormRefType>(undefined);
|
|
57
|
-
const modalRef = useRef<ModalRefType>(undefined);
|
|
58
|
-
const {results, setParameters}: any & { results: ModifyType } = GetData({
|
|
59
|
-
entityAction: action.action,
|
|
60
|
-
initParameters: routeParams
|
|
61
|
-
});
|
|
62
|
-
const {open: openAlert} = UseAlert();
|
|
63
|
-
|
|
64
|
-
useEffect(() => {
|
|
65
|
-
setParameters(routeParams);
|
|
66
|
-
}, [JSON.stringify(routeParams)]);
|
|
67
|
-
|
|
68
|
-
useEffect(() => {
|
|
69
|
-
modalRef.current?.open();
|
|
70
|
-
}, [JSON.stringify(results)]);
|
|
71
|
-
|
|
72
|
-
const ComponentTemplate = modal ? Modal : DefaultModifyTemplate;
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<ComponentTemplate ref={modalRef} {...props} action={action} routeParams={routeParams}>
|
|
76
|
-
<TemplateExtend name={"title"}>
|
|
77
|
-
<TemplateBlock name={"title"} content={children} data={results}>
|
|
78
|
-
{results?.title || 'Title'}
|
|
79
|
-
</TemplateBlock>
|
|
80
|
-
</TemplateExtend>
|
|
81
|
-
|
|
82
|
-
<TemplateExtend name={"navigation"}>
|
|
83
|
-
<DynamicView namespace={action.action.namespace} view={"navigation"} prefix={"modify"}>
|
|
84
|
-
<TemplateBlock name={"navigation"} content={children} data={results}>
|
|
85
|
-
original {action.action.namespace}
|
|
86
|
-
</TemplateBlock>
|
|
87
|
-
</DynamicView>
|
|
88
|
-
</TemplateExtend>
|
|
89
|
-
|
|
90
|
-
<TemplateExtend name={"content"}>
|
|
91
|
-
<DynamicView namespace={action.action.namespace} view={"content"} prefix={"modify"}>
|
|
92
|
-
<TemplateBlock name={"content"} content={children} data={results}>
|
|
93
|
-
<ModifyForm
|
|
94
|
-
ref={modifyFormRef}
|
|
95
|
-
data={results}
|
|
96
|
-
action={action.action}
|
|
97
|
-
onSuccess={(data: ModifyType) => {
|
|
98
|
-
modalRef.current?.close();
|
|
99
|
-
const event = new CustomEvent('success', {detail: data})
|
|
100
|
-
onSuccess && onSuccess(event, data);
|
|
101
|
-
|
|
102
|
-
if (event.defaultPrevented) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
openAlert({
|
|
107
|
-
title: 'Success',
|
|
108
|
-
text: Object.values(data.messages?.success ?? []).join(' ') ?? 'Item was saved successful!',
|
|
109
|
-
icon: AlertIcon.success,
|
|
110
|
-
actions: {
|
|
111
|
-
close: {
|
|
112
|
-
label: 'OK'
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
}}
|
|
117
|
-
onError={(error: ExceptionType) => {
|
|
118
|
-
openAlert({
|
|
119
|
-
title: error.status + ' ' + error.detail,
|
|
120
|
-
text: error.detail,
|
|
121
|
-
icon: AlertIcon.denied,
|
|
122
|
-
actions: {
|
|
123
|
-
close: {
|
|
124
|
-
label: 'OK'
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}}
|
|
129
|
-
onLoad={() => {
|
|
130
|
-
console.log('loaded');
|
|
131
|
-
// modalRef.current?.open();
|
|
132
|
-
}}
|
|
133
|
-
embedded={modal}
|
|
134
|
-
parameters={routeParams}
|
|
135
|
-
>
|
|
136
|
-
{modal && <TemplateExtend name={"actions"}></TemplateExtend>}
|
|
137
|
-
</ModifyForm>
|
|
138
|
-
</TemplateBlock>
|
|
139
|
-
</DynamicView>
|
|
140
|
-
</TemplateExtend>
|
|
141
|
-
<TemplateExtend name={"actions"}>
|
|
142
|
-
<TemplateBlock name={"actions"} content={children} data={results}>
|
|
143
|
-
<button
|
|
144
|
-
type={"submit"}
|
|
145
|
-
className={"btn btn-primary"}
|
|
146
|
-
onClick={() => modifyFormRef.current?.getFormRef()?.submit()}>
|
|
147
|
-
Submit
|
|
148
|
-
</button>
|
|
149
|
-
</TemplateBlock>
|
|
150
|
-
</TemplateExtend>
|
|
151
|
-
|
|
152
|
-
</ComponentTemplate>
|
|
153
|
-
);
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
export default Modify;
|
package/src/react-app-env.d.ts
DELETED
package/src/setupTests.ts
DELETED
package/src/type/ActionType.tsx
DELETED
package/src/type/ColumnType.tsx
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export type ColumnType = {
|
|
2
|
-
field: string;
|
|
3
|
-
label: string;
|
|
4
|
-
options: string[];
|
|
5
|
-
searchable: boolean | null;
|
|
6
|
-
sortable: boolean;
|
|
7
|
-
identifier: boolean;
|
|
8
|
-
value?: CallableFunction;
|
|
9
|
-
group?: string | false | null;
|
|
10
|
-
view?: {
|
|
11
|
-
header?: {
|
|
12
|
-
attr?: {[key: string]: string}
|
|
13
|
-
},
|
|
14
|
-
content?: {
|
|
15
|
-
attr?: {[key: string]: string}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|