muffin-admin 2.4.0 → 2.5.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/buttons/ActionButton.js +29 -23
- package/dist/dataprovider.d.ts +6 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useAction.d.ts +1 -1
- package/dist/hooks/useAction.js +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/inputs/FKInput.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +13 -12
- package/src/buttons/ActionButton.tsx +46 -26
- package/src/dataprovider.ts +6 -1
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useAction.ts +5 -3
- package/src/index.tsx +1 -0
- package/src/inputs/FKInput.tsx +1 -1
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import * as icons from "@mui/icons-material";
|
|
3
3
|
import { Button, useListContext, useNotify, useRecordContext, useRefresh, useResourceContext, useUnselectAll, } from "react-admin";
|
|
4
|
+
import { useState } from "react";
|
|
4
5
|
import { useAction } from "../hooks/useAction";
|
|
5
|
-
import { buildIcon } from "../utils";
|
|
6
|
+
import { buildIcon, findBuilder } from "../utils";
|
|
6
7
|
export function BulkActionButton({ label, icon, title, action }) {
|
|
7
8
|
const resource = useResourceContext();
|
|
8
9
|
const { selectedIds } = useListContext();
|
|
9
10
|
const refresh = useRefresh(), unselectAll = useUnselectAll(resource), notify = useNotify();
|
|
10
|
-
const
|
|
11
|
+
const { mutate, isLoading } = useAction(action);
|
|
11
12
|
const onClick = () => {
|
|
12
|
-
|
|
13
|
+
mutate({
|
|
13
14
|
action,
|
|
14
15
|
ids: selectedIds,
|
|
15
16
|
}, {
|
|
@@ -24,28 +25,33 @@ export function BulkActionButton({ label, icon, title, action }) {
|
|
|
24
25
|
},
|
|
25
26
|
});
|
|
26
27
|
};
|
|
27
|
-
return (_jsx(Button, { label: label, title: title, onClick: onClick, disabled:
|
|
28
|
+
return (_jsx(Button, { label: label, title: title, onClick: onClick, disabled: isLoading, children: buildIcon(icon) }));
|
|
28
29
|
}
|
|
29
30
|
export function ActionButton(props) {
|
|
30
|
-
const { icon, label, title,
|
|
31
|
+
const { icon, label, title, action } = props;
|
|
32
|
+
const [payload, setPayload] = useState(null);
|
|
33
|
+
const [payloadActive, setPayloadActive] = useState(false);
|
|
31
34
|
const record = useRecordContext();
|
|
32
|
-
const {
|
|
35
|
+
const actionData = { record, payload };
|
|
36
|
+
const { mutate, isLoading } = useAction(action);
|
|
37
|
+
const PayloadBuilder = findBuilder(["action", "payload", action]);
|
|
33
38
|
const refresh = useRefresh(), notify = useNotify(), Icon = icons[icon];
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
const process = () => mutate(actionData, {
|
|
40
|
+
onSuccess: ({ data }) => {
|
|
41
|
+
if (data && data.message)
|
|
42
|
+
notify(data.message, { type: "success" });
|
|
43
|
+
if (data && data.redirectTo)
|
|
44
|
+
window.location = data.redirectTo;
|
|
45
|
+
else
|
|
37
46
|
refresh();
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
return (_jsx(Button, { label: label, title: title, onClick: onClick, disabled: isLoading, children: Icon && _jsx(Icon, {}) }));
|
|
47
|
+
},
|
|
48
|
+
onError: (err) => {
|
|
49
|
+
notify(typeof err === "string" ? err : err.message, { type: "error" });
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: PayloadBuilder ? () => setPayloadActive(true) : process, disabled: isLoading, children: Icon && _jsx(Icon, {}) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onChange: (payload) => {
|
|
53
|
+
setPayloadActive(false);
|
|
54
|
+
setPayload(payload);
|
|
55
|
+
process();
|
|
56
|
+
}, onClose: () => setPayloadActive(false) }))] }));
|
|
51
57
|
}
|
package/dist/dataprovider.d.ts
CHANGED
|
@@ -61,7 +61,12 @@ export declare function MuffinDataprovider({ apiUrl }: AdminOpts): {
|
|
|
61
61
|
data: any;
|
|
62
62
|
total: number;
|
|
63
63
|
}>;
|
|
64
|
-
runAction: (resource:
|
|
64
|
+
runAction: (resource: string, action: string, props: TActionProps) => Promise<{
|
|
65
65
|
data: any;
|
|
66
66
|
}>;
|
|
67
67
|
};
|
|
68
|
+
export type TActionProps = {
|
|
69
|
+
payload?: any;
|
|
70
|
+
ids?: string[];
|
|
71
|
+
record: any;
|
|
72
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useAction';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useAction';
|
package/dist/hooks/useAction.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { useDataProvider } from "react-admin";
|
|
1
|
+
import { useDataProvider, useResourceContext } from "react-admin";
|
|
2
2
|
import { useMutation } from "react-query";
|
|
3
|
-
export function useAction(
|
|
3
|
+
export function useAction(action) {
|
|
4
4
|
const dataProvider = useDataProvider();
|
|
5
|
+
const resource = useResourceContext();
|
|
5
6
|
return useMutation((params) => dataProvider.runAction(resource, action, params));
|
|
6
7
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from "./buildRA";
|
|
|
11
11
|
export * from "./buttons";
|
|
12
12
|
export * from "./dataprovider";
|
|
13
13
|
export * from "./fields";
|
|
14
|
+
export * from "./hooks";
|
|
14
15
|
export * from "./types";
|
|
15
16
|
export * from "./utils";
|
|
16
17
|
export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
|
package/dist/index.js
CHANGED
package/dist/inputs/FKInput.js
CHANGED
|
@@ -26,5 +26,5 @@ export function FKInput(_a) {
|
|
|
26
26
|
return `#${pk}`;
|
|
27
27
|
return (pk && `${record[refSource]} (#${pk})`) || "";
|
|
28
28
|
};
|
|
29
|
-
return (_jsx(ReferenceInput,
|
|
29
|
+
return (_jsx(ReferenceInput, { reference: reference, source: source, children: _jsx(AutocompleteInput, Object.assign({ source: refKey, optionText: renderText, fullWidth: fullWidth }, props)) }));
|
|
30
30
|
}
|