muffin-admin 3.6.3 → 3.7.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/buildRA.js +0 -2
- package/dist/buttons/ActionButton.d.ts +2 -2
- package/dist/buttons/ActionButton.js +23 -14
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/buildRA.tsx +0 -2
- package/src/buttons/ActionButton.tsx +42 -29
- package/src/types.ts +6 -6
package/dist/buildRA.js
CHANGED
|
@@ -45,7 +45,6 @@ const UI = {
|
|
|
45
45
|
FKInput,
|
|
46
46
|
};
|
|
47
47
|
export function buildRAComponent(name, props) {
|
|
48
|
-
var _a;
|
|
49
48
|
const Item = UI[name];
|
|
50
49
|
if (!Item)
|
|
51
50
|
return null;
|
|
@@ -53,7 +52,6 @@ export function buildRAComponent(name, props) {
|
|
|
53
52
|
props.validate = required();
|
|
54
53
|
delete props.required;
|
|
55
54
|
}
|
|
56
|
-
props.fullWidth = (_a = props.fullWidth) !== null && _a !== void 0 ? _a : true;
|
|
57
55
|
if (props.children)
|
|
58
56
|
props.children = buildRA(props.children)[0];
|
|
59
57
|
return _jsx(Item, Object.assign({}, props), props.source);
|
|
@@ -4,8 +4,8 @@ export type ActionPayloadProps = {
|
|
|
4
4
|
onClose: () => void;
|
|
5
5
|
onHandle: (payload: any) => void;
|
|
6
6
|
};
|
|
7
|
-
export declare function ActionButton({
|
|
8
|
-
export declare function BulkActionButton({
|
|
7
|
+
export declare function ActionButton({ paths, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function BulkActionButton({ paths, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
export declare function CommonPayload({ active, onClose, onHandle, schema, title }: {
|
|
10
10
|
active: any;
|
|
11
11
|
onClose: any;
|
|
@@ -18,19 +18,21 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
18
18
|
}
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
|
-
import { jsx as _jsx,
|
|
22
|
-
import { Button,
|
|
21
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
import { Button, FormGroupsProvider, useAugmentedForm, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
|
|
23
|
+
import { FormProvider } from "react-hook-form";
|
|
23
24
|
import { useState } from "react";
|
|
24
25
|
import { buildRA } from "../buildRA";
|
|
25
26
|
import { AdminModal, PayloadButtons, useConfirmation } from "../common";
|
|
26
27
|
import { useAction } from "../hooks/useAction";
|
|
27
28
|
import { buildIcon, findBuilder } from "../utils";
|
|
28
29
|
export function ActionButton(_a) {
|
|
29
|
-
var {
|
|
30
|
+
var { paths, confirm } = _a, props = __rest(_a, ["paths", "confirm"]);
|
|
30
31
|
const translate = useTranslate();
|
|
31
32
|
const record = useRecordContext();
|
|
32
33
|
const confirmation = useConfirmation();
|
|
33
|
-
const
|
|
34
|
+
const path = paths.find((p) => p.includes("{id}")) || paths[paths.length - 1];
|
|
35
|
+
const { mutate, isPending } = useAction(path);
|
|
34
36
|
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
35
37
|
const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
36
38
|
const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
|
|
@@ -40,10 +42,11 @@ export function ActionButton(_a) {
|
|
|
40
42
|
return _jsx(ActionButtonBase, Object.assign({}, props, { isPending: isPending, onHandle: onHandle }));
|
|
41
43
|
}
|
|
42
44
|
export function BulkActionButton(_a) {
|
|
43
|
-
var {
|
|
45
|
+
var { paths, confirm } = _a, props = __rest(_a, ["paths", "confirm"]);
|
|
44
46
|
const translate = useTranslate();
|
|
45
47
|
const { selectedIds } = useListContext();
|
|
46
|
-
const
|
|
48
|
+
const path = paths.find((p) => !p.includes("{id}")) || paths[0];
|
|
49
|
+
const { mutate, isPending } = useAction(path);
|
|
47
50
|
const confirmation = useConfirmation();
|
|
48
51
|
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
49
52
|
const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -53,14 +56,6 @@ export function BulkActionButton(_a) {
|
|
|
53
56
|
});
|
|
54
57
|
return _jsx(ActionButtonBase, Object.assign({}, props, { onHandle: onHandle, isPending: isPending }));
|
|
55
58
|
}
|
|
56
|
-
export function CommonPayload({ active, onClose, onHandle, schema, title }) {
|
|
57
|
-
const inputs = buildRA(schema);
|
|
58
|
-
const translate = useTranslate();
|
|
59
|
-
return (_jsx(AdminModal, { maxWidth: "sm", open: active, onClose: onClose, title: translate(title, { _: title }), children: _jsxs(Form, { onSubmit: (data) => {
|
|
60
|
-
onClose();
|
|
61
|
-
onHandle(data);
|
|
62
|
-
}, children: [inputs, _jsx(PayloadButtons, { onClose: onClose })] }) }));
|
|
63
|
-
}
|
|
64
59
|
function ActionButtonBase({ label, title, onHandle, isPending, icon, schema, id, }) {
|
|
65
60
|
const resource = useResourceContext();
|
|
66
61
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
@@ -72,3 +67,17 @@ function ActionButtonBase({ label, title, onHandle, isPending, icon, schema, id,
|
|
|
72
67
|
onHandle();
|
|
73
68
|
}, disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: onHandle, onClose: () => setPayloadActive(false), title: title || label, schema: schema }))] }));
|
|
74
69
|
}
|
|
70
|
+
export function CommonPayload({ active, onClose, onHandle, schema, title }) {
|
|
71
|
+
schema[0][1] = Object.assign(Object.assign({}, schema[0][1]), { autoFocus: true });
|
|
72
|
+
const inputs = buildRA(schema);
|
|
73
|
+
const translate = useTranslate();
|
|
74
|
+
const { form, formHandleSubmit } = useAugmentedForm({
|
|
75
|
+
onSubmit: (data) => {
|
|
76
|
+
onClose();
|
|
77
|
+
onHandle(data);
|
|
78
|
+
form.reset();
|
|
79
|
+
},
|
|
80
|
+
record: {},
|
|
81
|
+
});
|
|
82
|
+
return (_jsx(AdminModal, { maxWidth: "sm", open: active, onClose: onClose, title: translate(title, { _: title }), children: _jsx(FormProvider, Object.assign({}, form, { children: _jsx(FormGroupsProvider, { children: _jsxs("form", { onSubmit: formHandleSubmit, children: [inputs, _jsx(PayloadButtons, { onClose: onClose })] }) }) })) }));
|
|
83
|
+
}
|