muffin-admin 3.1.0 → 3.1.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 +1 -1
- package/dist/buttons/ActionButton.d.ts +1 -1
- package/dist/buttons/ActionButton.js +18 -19
- package/dist/dataprovider.d.ts +2 -2
- package/dist/hooks/useAction.d.ts +6 -4
- package/dist/hooks/useAction.js +3 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/MuffinResourceList.tsx +1 -1
- package/src/buttons/ActionButton.tsx +36 -50
- package/src/dataprovider.ts +2 -2
- package/src/hooks/useAction.ts +10 -6
|
@@ -20,7 +20,7 @@ setupAdmin(["list-filters"], buildRA);
|
|
|
20
20
|
function MuffinListDatagrid() {
|
|
21
21
|
const { name, list } = useMuffinResourceOpts();
|
|
22
22
|
const { fields, edit, show } = list;
|
|
23
|
-
return (_jsxs(DatagridConfigurable, { rowClick: show ? "show" : edit ? "edit" : false, children: [buildAdmin(["list-fields", name], fields), buildAdmin(["list-grid-buttons"
|
|
23
|
+
return (_jsxs(DatagridConfigurable, { rowClick: show ? "show" : edit ? "edit" : false, children: [buildAdmin(["list-fields", name], fields), buildAdmin(["list-grid-buttons", name])] }));
|
|
24
24
|
}
|
|
25
25
|
setupAdmin(["list-grid"], MuffinListDatagrid);
|
|
26
26
|
function MuffinListGridButtons() {
|
|
@@ -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;
|
|
@@ -3,48 +3,47 @@ import { Button, useListContext, useNotify, useRecordContext, useRefresh, useRes
|
|
|
3
3
|
import { useState } from "react";
|
|
4
4
|
import { useAction } from "../hooks/useAction";
|
|
5
5
|
import { buildIcon, findBuilder } from "../utils";
|
|
6
|
-
export function
|
|
7
|
-
const resource = useResourceContext();
|
|
8
|
-
const { selectedIds } = useListContext();
|
|
6
|
+
export function ActionButton({ icon, label, title, action, id }) {
|
|
9
7
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
8
|
+
const record = useRecordContext();
|
|
9
|
+
const notify = useNotify();
|
|
10
|
+
const refresh = useRefresh();
|
|
11
|
+
const { mutate, isLoading } = useAction(action, {
|
|
14
12
|
onSuccess: ({ data }) => {
|
|
15
13
|
if (data && data.message)
|
|
16
14
|
notify(data.message, { type: "success" });
|
|
17
15
|
if (data && data.redirectTo)
|
|
18
16
|
window.location = data.redirectTo;
|
|
19
|
-
else
|
|
20
|
-
unselectAll();
|
|
17
|
+
else
|
|
21
18
|
refresh();
|
|
22
|
-
}
|
|
23
19
|
},
|
|
24
20
|
onError: (err) => {
|
|
25
21
|
notify(typeof err === "string" ? err : err.message, { type: "error" });
|
|
26
22
|
},
|
|
27
23
|
});
|
|
28
|
-
|
|
24
|
+
const PayloadBuilder = findBuilder(["action", "payload", id]);
|
|
25
|
+
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) }))] }));
|
|
29
26
|
}
|
|
30
|
-
export function
|
|
27
|
+
export function BulkActionButton({ label, icon, title, action, id }) {
|
|
28
|
+
const resource = useResourceContext();
|
|
29
|
+
const { selectedIds } = useListContext();
|
|
31
30
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
32
|
-
const
|
|
33
|
-
const { mutate, isLoading } = useAction(action
|
|
34
|
-
const PayloadBuilder = findBuilder(["action", "payload", id]);
|
|
35
|
-
const refresh = useRefresh(), notify = useNotify();
|
|
36
|
-
const process = (payload) => mutate({ record, payload }, {
|
|
31
|
+
const refresh = useRefresh(), unselectAll = useUnselectAll(resource), notify = useNotify();
|
|
32
|
+
const { mutate, isLoading } = useAction(action, {
|
|
37
33
|
onSuccess: ({ data }) => {
|
|
38
34
|
if (data && data.message)
|
|
39
35
|
notify(data.message, { type: "success" });
|
|
40
36
|
if (data && data.redirectTo)
|
|
41
37
|
window.location = data.redirectTo;
|
|
42
|
-
else
|
|
38
|
+
else {
|
|
39
|
+
unselectAll();
|
|
43
40
|
refresh();
|
|
41
|
+
}
|
|
44
42
|
},
|
|
45
43
|
onError: (err) => {
|
|
46
44
|
notify(typeof err === "string" ? err : err.message, { type: "error" });
|
|
47
45
|
},
|
|
48
46
|
});
|
|
49
|
-
|
|
47
|
+
const PayloadBuilder = findBuilder(["action", "payload", id]);
|
|
48
|
+
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
49
|
}
|
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,7 @@
|
|
|
1
1
|
import { useDataProvider, useResourceContext } from "react-admin";
|
|
2
2
|
import { useMutation } from "react-query";
|
|
3
|
-
export function useAction(action) {
|
|
4
|
-
const dataProvider = useDataProvider();
|
|
3
|
+
export function useAction(action, options) {
|
|
5
4
|
const resource = useResourceContext();
|
|
6
|
-
|
|
5
|
+
const dataProvider = useDataProvider();
|
|
6
|
+
return useMutation((params) => dataProvider.runAction(resource, action, params), options);
|
|
7
7
|
}
|