muffin-admin 3.5.0 → 3.6.2
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/MuffinResourceList.js +5 -4
- package/dist/buttons/ActionButton.d.ts +9 -2
- package/dist/buttons/ActionButton.js +48 -39
- package/dist/common/PayloadButtons.d.ts +3 -0
- package/dist/common/PayloadButtons.js +8 -0
- package/dist/common/index.d.ts +1 -0
- package/dist/common/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/MuffinResourceList.tsx +5 -2
- package/src/buttons/ActionButton.tsx +65 -53
- package/src/common/PayloadButtons.tsx +19 -0
- package/src/common/index.ts +1 -0
- package/src/types.ts +7 -6
|
@@ -3,7 +3,7 @@ import sortBy from "lodash/sortBy";
|
|
|
3
3
|
import uniq from "lodash/uniq";
|
|
4
4
|
import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, List, Pagination, SelectColumnsButton, TopToolbar, } from "react-admin";
|
|
5
5
|
import { buildRA } from "./buildRA";
|
|
6
|
-
import { BulkActionButton } from "./buttons";
|
|
6
|
+
import { ActionButton, BulkActionButton } from "./buttons";
|
|
7
7
|
import { useMuffinResourceOpts } from "./hooks";
|
|
8
8
|
import { buildAdmin, findBuilder, setupAdmin } from "./utils";
|
|
9
9
|
export function MuffinList() {
|
|
@@ -32,13 +32,14 @@ function MuffinListGridButtons() {
|
|
|
32
32
|
}
|
|
33
33
|
setupAdmin(["list-grid-buttons"], MuffinListGridButtons);
|
|
34
34
|
function MuffinListToolbar() {
|
|
35
|
-
const { list: { create }, } = useMuffinResourceOpts();
|
|
36
|
-
|
|
35
|
+
const { actions: baseActions = [], list: { create }, } = useMuffinResourceOpts();
|
|
36
|
+
const actions = baseActions.filter((a) => a.view.includes("list"));
|
|
37
|
+
return (_jsxs(TopToolbar, { children: [_jsx(SelectColumnsButton, {}), _jsx(FilterButton, {}), actions.length && actions.map((props) => _jsx(ActionButton, Object.assign({}, props), props.id)), create && _jsx(CreateButton, {}), _jsx(ExportButton, {})] }));
|
|
37
38
|
}
|
|
38
39
|
setupAdmin(["list-toolbar"], MuffinListToolbar);
|
|
39
40
|
function MuffinListBulkActions() {
|
|
40
41
|
const { actions: baseActions = [], list: { remove }, } = useMuffinResourceOpts();
|
|
41
|
-
const actions = baseActions.filter((a) => a.view.includes("
|
|
42
|
+
const actions = baseActions.filter((a) => a.view.includes("bulk"));
|
|
42
43
|
return (_jsxs(_Fragment, { children: [actions.map((props) => (_jsx(BulkActionButton, Object.assign({}, props), props.id))), _jsx(BulkExportButton, {}), remove && _jsx(BulkDeleteButton, {})] }));
|
|
43
44
|
}
|
|
44
45
|
setupAdmin(["list-bulk-actions"], MuffinListBulkActions);
|
|
@@ -4,5 +4,12 @@ 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({ action, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function BulkActionButton({ action, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare function CommonPayload({ active, onClose, onHandle, schema, title }: {
|
|
10
|
+
active: any;
|
|
11
|
+
onClose: any;
|
|
12
|
+
onHandle: any;
|
|
13
|
+
schema: any;
|
|
14
|
+
title: any;
|
|
15
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -7,59 +7,68 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
22
|
+
import { Button, Form, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
|
|
23
|
+
import { useState } from "react";
|
|
24
|
+
import { buildRA } from "../buildRA";
|
|
25
|
+
import { AdminModal, PayloadButtons, useConfirmation } from "../common";
|
|
14
26
|
import { useAction } from "../hooks/useAction";
|
|
15
27
|
import { buildIcon, findBuilder } from "../utils";
|
|
16
|
-
export function ActionButton(
|
|
28
|
+
export function ActionButton(_a) {
|
|
29
|
+
var { action, confirm } = _a, props = __rest(_a, ["action", "confirm"]);
|
|
17
30
|
const translate = useTranslate();
|
|
18
31
|
const record = useRecordContext();
|
|
19
|
-
const resource = useResourceContext();
|
|
20
32
|
const confirmation = useConfirmation();
|
|
21
33
|
const { mutate, isPending } = useAction(action);
|
|
22
|
-
const [payloadActive, setPayloadActive] = useState(false);
|
|
23
|
-
const [payloadResolver, setPayloadResolver] = useState();
|
|
24
|
-
const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
|
|
25
|
-
const buildPayload = useMemo(() => {
|
|
26
|
-
if (PayloadBuilder) {
|
|
27
|
-
return new Promise((resolve) => setPayloadResolver(() => resolve));
|
|
28
|
-
}
|
|
29
|
-
return Promise.resolve();
|
|
30
|
-
}, [PayloadBuilder]);
|
|
31
34
|
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
yield mutate({ record, payload });
|
|
39
|
-
}), disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: payloadResolver, onClose: () => setPayloadActive(false) }))] }));
|
|
35
|
+
const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
36
|
+
const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
|
|
37
|
+
if (process)
|
|
38
|
+
yield mutate({ record, payload });
|
|
39
|
+
});
|
|
40
|
+
return _jsx(ActionButtonBase, Object.assign({}, props, { isPending: isPending, onHandle: onHandle }));
|
|
40
41
|
}
|
|
41
|
-
export function BulkActionButton(
|
|
42
|
+
export function BulkActionButton(_a) {
|
|
43
|
+
var { action, confirm } = _a, props = __rest(_a, ["action", "confirm"]);
|
|
42
44
|
const translate = useTranslate();
|
|
43
45
|
const { selectedIds } = useListContext();
|
|
44
46
|
const { mutate, isPending } = useAction(action);
|
|
45
47
|
const confirmation = useConfirmation();
|
|
48
|
+
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
49
|
+
const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
|
|
51
|
+
if (process)
|
|
52
|
+
yield mutate({ ids: selectedIds, payload });
|
|
53
|
+
});
|
|
54
|
+
return _jsx(ActionButtonBase, Object.assign({}, props, { onHandle: onHandle, isPending: isPending }));
|
|
55
|
+
}
|
|
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
|
+
function ActionButtonBase({ label, title, onHandle, isPending, icon, schema, id, }) {
|
|
46
65
|
const resource = useResourceContext();
|
|
47
66
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
48
|
-
const [
|
|
49
|
-
|
|
50
|
-
const buildPayload = useMemo(() => {
|
|
51
|
-
if (PayloadBuilder) {
|
|
52
|
-
return new Promise((resolve) => setPayloadResolver(() => resolve));
|
|
53
|
-
}
|
|
54
|
-
return Promise.resolve();
|
|
55
|
-
}, [PayloadBuilder]);
|
|
56
|
-
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
57
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const PayloadBuilder = findBuilder(["action", "payload", id, resource]) || (schema && CommonPayload);
|
|
68
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => {
|
|
58
69
|
if (PayloadBuilder)
|
|
59
70
|
setPayloadActive(true);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
yield mutate({ ids: selectedIds, payload });
|
|
64
|
-
}), disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: payloadResolver, onClose: () => setPayloadActive(false) }))] }));
|
|
71
|
+
else
|
|
72
|
+
onHandle();
|
|
73
|
+
}, disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: onHandle, onClose: () => setPayloadActive(false), title: title || label, schema: schema }))] }));
|
|
65
74
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Stack } from "@mui/material";
|
|
3
|
+
import { Button } from "react-admin";
|
|
4
|
+
import { useFormContext } from "react-hook-form";
|
|
5
|
+
export function PayloadButtons({ onClose }) {
|
|
6
|
+
const { formState } = useFormContext();
|
|
7
|
+
return (_jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "flex-end", spacing: 1, children: [_jsx(Button, { type: "submit", label: "ra.action.confirm", variant: "contained", disabled: !formState.isValid, size: "medium" }), _jsx(Button, { label: "ra.action.cancel", variant: "outlined", size: "medium", onClick: onClose })] }));
|
|
8
|
+
}
|
package/dist/common/index.d.ts
CHANGED
package/dist/common/index.js
CHANGED