muffin-admin 3.1.1 → 3.2.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/buttons/ActionButton.d.ts +1 -1
- package/dist/buttons/ActionButton.js +9 -40
- package/dist/dataprovider.d.ts +2 -2
- package/dist/hooks/useAction.d.ts +6 -4
- package/dist/hooks/useAction.js +18 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/buttons/ActionButton.tsx +11 -62
- package/src/dataprovider.ts +2 -2
- package/src/hooks/useAction.ts +31 -8
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { AdminAction } from "../types";
|
|
2
|
-
export declare function BulkActionButton({ label, icon, title, action, id }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
3
2
|
export declare function ActionButton({ icon, label, title, action, id }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare function BulkActionButton({ label, icon, title, action, id }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,50 +1,19 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, useListContext,
|
|
2
|
+
import { Button, useListContext, useRecordContext } from "react-admin";
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { useAction } from "../hooks/useAction";
|
|
5
5
|
import { buildIcon, findBuilder } from "../utils";
|
|
6
|
-
export function BulkActionButton({ label, icon, title, action, id }) {
|
|
7
|
-
const resource = useResourceContext();
|
|
8
|
-
const { selectedIds } = useListContext();
|
|
9
|
-
const [payloadActive, setPayloadActive] = useState(false);
|
|
10
|
-
const PayloadBuilder = findBuilder(["action", "payload", id]);
|
|
11
|
-
const refresh = useRefresh(), unselectAll = useUnselectAll(resource), notify = useNotify();
|
|
12
|
-
const { mutate, isLoading } = useAction(action);
|
|
13
|
-
const process = (payload) => mutate({ ids: selectedIds, payload }, {
|
|
14
|
-
onSuccess: ({ data }) => {
|
|
15
|
-
if (data && data.message)
|
|
16
|
-
notify(data.message, { type: "success" });
|
|
17
|
-
if (data && data.redirectTo)
|
|
18
|
-
window.location = data.redirectTo;
|
|
19
|
-
else {
|
|
20
|
-
unselectAll();
|
|
21
|
-
refresh();
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
onError: (err) => {
|
|
25
|
-
notify(typeof err === "string" ? err : err.message, { type: "error" });
|
|
26
|
-
},
|
|
27
|
-
});
|
|
28
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => (PayloadBuilder ? setPayloadActive(true) : process()), disabled: isLoading, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: (payload) => process(payload), onClose: () => setPayloadActive(false) }))] }));
|
|
29
|
-
}
|
|
30
6
|
export function ActionButton({ icon, label, title, action, id }) {
|
|
31
7
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
32
8
|
const record = useRecordContext();
|
|
9
|
+
const { mutate, isLoading } = useAction(action, {});
|
|
10
|
+
const PayloadBuilder = findBuilder(["action", "payload", id]);
|
|
11
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => (PayloadBuilder ? setPayloadActive(true) : mutate({ record })), disabled: isLoading, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: (payload) => mutate({ record, payload }), onClose: () => setPayloadActive(false) }))] }));
|
|
12
|
+
}
|
|
13
|
+
export function BulkActionButton({ label, icon, title, action, id }) {
|
|
14
|
+
const { selectedIds } = useListContext();
|
|
33
15
|
const { mutate, isLoading } = useAction(action);
|
|
16
|
+
const [payloadActive, setPayloadActive] = useState(false);
|
|
34
17
|
const PayloadBuilder = findBuilder(["action", "payload", id]);
|
|
35
|
-
|
|
36
|
-
const process = (payload) => mutate({ record, payload }, {
|
|
37
|
-
onSuccess: ({ data }) => {
|
|
38
|
-
if (data && data.message)
|
|
39
|
-
notify(data.message, { type: "success" });
|
|
40
|
-
if (data && data.redirectTo)
|
|
41
|
-
window.location = data.redirectTo;
|
|
42
|
-
else
|
|
43
|
-
refresh();
|
|
44
|
-
},
|
|
45
|
-
onError: (err) => {
|
|
46
|
-
notify(typeof err === "string" ? err : err.message, { type: "error" });
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => (PayloadBuilder ? setPayloadActive(true) : process()), disabled: isLoading, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: (payload) => process(payload), onClose: () => setPayloadActive(false) }))] }));
|
|
18
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => (PayloadBuilder ? setPayloadActive(true) : mutate({ ids: selectedIds })), disabled: isLoading, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: (payload) => mutate({ ids: selectedIds, payload }), onClose: () => setPayloadActive(false) }))] }));
|
|
50
19
|
}
|
package/dist/dataprovider.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { UseMutationOptions } from "react-query";
|
|
2
|
+
import { TActionProps } from "../dataprovider";
|
|
3
|
+
export declare function useAction(action: string, options?: UseMutationOptions<{
|
|
2
4
|
data: any;
|
|
3
|
-
},
|
|
4
|
-
|
|
5
|
-
}, any, unknown>;
|
|
5
|
+
}, any, TActionProps>): import("react-query").UseMutationResult<{
|
|
6
|
+
data: any;
|
|
7
|
+
}, any, TActionProps, unknown>;
|
package/dist/hooks/useAction.js
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
|
-
import { useDataProvider, useResourceContext } from "react-admin";
|
|
1
|
+
import { useDataProvider, useNotify, useRefresh, useResourceContext, useUnselectAll, } from "react-admin";
|
|
2
2
|
import { useMutation } from "react-query";
|
|
3
|
-
export function useAction(action) {
|
|
4
|
-
const
|
|
3
|
+
export function useAction(action, options) {
|
|
4
|
+
const notify = useNotify();
|
|
5
|
+
const refresh = useRefresh();
|
|
5
6
|
const resource = useResourceContext();
|
|
6
|
-
|
|
7
|
+
const unselectAll = useUnselectAll(resource);
|
|
8
|
+
const dataProvider = useDataProvider();
|
|
9
|
+
return useMutation((params) => dataProvider.runAction(resource, action, params), Object.assign({ onSuccess: ({ data }) => {
|
|
10
|
+
if (data && data.message)
|
|
11
|
+
notify(data.message, { type: "success" });
|
|
12
|
+
if (data && data.redirectTo)
|
|
13
|
+
window.location = data.redirectTo;
|
|
14
|
+
else {
|
|
15
|
+
unselectAll();
|
|
16
|
+
refresh();
|
|
17
|
+
}
|
|
18
|
+
}, onError: (err) => {
|
|
19
|
+
notify(typeof err === "string" ? err : err.message, { type: "error" });
|
|
20
|
+
} }, options));
|
|
7
21
|
}
|