muffin-admin 3.4.0 → 3.4.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.
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { Button, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
|
|
12
|
-
import { useState } from "react";
|
|
12
|
+
import { useMemo, useState } from "react";
|
|
13
13
|
import { useConfirmation } from "../common";
|
|
14
14
|
import { useAction } from "../hooks/useAction";
|
|
15
15
|
import { buildIcon, findBuilder } from "../utils";
|
|
@@ -18,13 +18,16 @@ export function ActionButton({ icon, label, title, action, id, confirm }) {
|
|
|
18
18
|
const record = useRecordContext();
|
|
19
19
|
const resource = useResourceContext();
|
|
20
20
|
const confirmation = useConfirmation();
|
|
21
|
-
const { mutate, isPending } = useAction(action
|
|
21
|
+
const { mutate, isPending } = useAction(action);
|
|
22
22
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
23
23
|
const [payloadResolver, setPayloadResolver] = useState();
|
|
24
24
|
const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
|
|
25
|
-
const buildPayload =
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const buildPayload = useMemo(() => {
|
|
26
|
+
if (PayloadBuilder) {
|
|
27
|
+
return new Promise((resolve) => setPayloadResolver(() => resolve));
|
|
28
|
+
}
|
|
29
|
+
return Promise.resolve();
|
|
30
|
+
}, [PayloadBuilder]);
|
|
28
31
|
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
29
32
|
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
30
33
|
if (PayloadBuilder)
|
|
@@ -44,9 +47,12 @@ export function BulkActionButton({ label, icon, title, action, id, confirm }) {
|
|
|
44
47
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
45
48
|
const [payloadResolver, setPayloadResolver] = useState();
|
|
46
49
|
const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
|
|
47
|
-
const buildPayload =
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
const buildPayload = useMemo(() => {
|
|
51
|
+
if (PayloadBuilder) {
|
|
52
|
+
return new Promise((resolve) => setPayloadResolver(() => resolve));
|
|
53
|
+
}
|
|
54
|
+
return Promise.resolve();
|
|
55
|
+
}, [PayloadBuilder]);
|
|
50
56
|
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
51
57
|
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
52
58
|
if (PayloadBuilder)
|