muffin-admin 3.2.2 → 3.4.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/MuffinAdmin.js +4 -4
- package/dist/MuffinResourceList.js +5 -5
- package/dist/buttons/ActionButton.d.ts +7 -2
- package/dist/buttons/ActionButton.js +46 -8
- package/dist/common/AdminModal.d.ts +10 -0
- package/dist/common/AdminModal.js +17 -0
- package/dist/common/ConfirmationProvider.d.ts +13 -0
- package/dist/common/ConfirmationProvider.js +36 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.js +2 -0
- package/dist/context.d.ts +0 -1
- package/dist/dataprovider.js +7 -7
- package/dist/hooks/useAction.d.ts +2 -2
- package/dist/hooks/useAction.js +2 -2
- package/dist/i18n/index.d.ts +0 -0
- package/dist/i18n/index.js +0 -0
- package/dist/i18n/provider.d.ts +0 -0
- package/dist/i18n/provider.js +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +2 -2
- package/src/MuffinAdmin.tsx +58 -14
- package/src/MuffinResourceList.tsx +7 -3
- package/src/buttons/ActionButton.tsx +52 -12
- package/src/common/AdminModal.tsx +26 -0
- package/src/common/ConfirmationProvider.tsx +75 -0
- package/src/common/index.ts +2 -0
- package/src/hooks/useAction.ts +4 -2
- package/src/i18n/index.ts +0 -0
- package/src/i18n/provider.ts +0 -0
- package/src/index.tsx +1 -0
- package/src/types.ts +1 -0
package/dist/MuffinAdmin.js
CHANGED
|
@@ -3,16 +3,16 @@ import IconButton from "@mui/material/IconButton";
|
|
|
3
3
|
import SvgIcon from "@mui/material/SvgIcon";
|
|
4
4
|
import Tooltip from "@mui/material/Tooltip";
|
|
5
5
|
import Typography from "@mui/material/Typography";
|
|
6
|
-
import {
|
|
6
|
+
import { AdminContext, AdminUI, AppBar, defaultI18nProvider, Layout, localStorageStore, Login, } from "react-admin";
|
|
7
|
+
import { ConfirmationProvider } from "./common";
|
|
7
8
|
import { useMuffinAdminOpts } from "./hooks";
|
|
8
9
|
import { buildAdmin, findBuilder, findIcon, setupAdmin } from "./utils";
|
|
9
10
|
export function MuffinAdmin(props) {
|
|
10
11
|
const opts = useMuffinAdminOpts();
|
|
11
12
|
const { resources = [], auth, adminProps, apiUrl } = opts;
|
|
12
13
|
document.title = (adminProps === null || adminProps === void 0 ? void 0 : adminProps.title) || "Muffin Admin";
|
|
13
|
-
const authProvider = findBuilder(["authprovider"])(auth);
|
|
14
|
-
|
|
15
|
-
return (_jsx(Admin, Object.assign({ requireAuth: auth.required, authProvider: authProvider, dataProvider: dataProvider, layout: findBuilder(["layout"]), loginPage: findBuilder(["loginpage"]), dashboard: findBuilder(["dashboard"]), darkTheme: { palette: { mode: "dark" } } }, props, { children: resources === null || resources === void 0 ? void 0 : resources.map(({ name }) => buildAdmin(["resource", name], { name })) })));
|
|
14
|
+
const { basename, authProvider = findBuilder(["authprovider"])(auth), dataProvider = findBuilder(["dataprovider"])(apiUrl), catchAll, dashboard = findBuilder(["dashboard"]), disableTelemetry, error, i18nProvider = defaultI18nProvider, layout = findBuilder(["layout"]), loading, loginPage = findBuilder(["loginpage"]), authCallbackPage, notification, queryClient, requireAuth = auth.required, store = localStorageStore(), ready, theme, lightTheme, darkTheme, defaultTheme, title = "React Admin", } = props;
|
|
15
|
+
return (_jsx(AdminContext, { authProvider: authProvider, basename: basename, dataProvider: dataProvider, i18nProvider: i18nProvider, store: store, queryClient: queryClient, theme: theme, lightTheme: lightTheme, darkTheme: darkTheme, defaultTheme: defaultTheme, children: _jsx(ConfirmationProvider, { children: _jsx(AdminUI, { layout: layout, dashboard: dashboard, disableTelemetry: disableTelemetry, catchAll: catchAll, error: error, title: title, loading: loading, loginPage: loginPage, authCallbackPage: authCallbackPage, notification: notification, requireAuth: requireAuth, ready: ready, children: resources === null || resources === void 0 ? void 0 : resources.map(({ name }) => buildAdmin(["resource", name], { name })) }) }) }));
|
|
16
16
|
}
|
|
17
17
|
setupAdmin(["admin"], MuffinAdmin);
|
|
18
18
|
export function MuffinAdminLayout(props) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import sortBy from "lodash/sortBy";
|
|
3
3
|
import uniq from "lodash/uniq";
|
|
4
|
-
import { BulkDeleteButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, List, Pagination, SelectColumnsButton, TopToolbar, } from "react-admin";
|
|
4
|
+
import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, List, Pagination, SelectColumnsButton, TopToolbar, } from "react-admin";
|
|
5
5
|
import { buildRA } from "./buildRA";
|
|
6
6
|
import { BulkActionButton } from "./buttons";
|
|
7
7
|
import { useMuffinResourceOpts } from "./hooks";
|
|
@@ -11,8 +11,7 @@ export function MuffinList() {
|
|
|
11
11
|
const { limit, limitMax, filters, sort } = list;
|
|
12
12
|
const DataGrid = findBuilder(["list-grid", name]);
|
|
13
13
|
const Toolbar = findBuilder(["list-toolbar", name]);
|
|
14
|
-
|
|
15
|
-
return (_jsx(List, { sort: sort, perPage: limit, actions: _jsx(Toolbar, {}), filters: buildAdmin(["list-filters", name], filters), bulkActionButtons: _jsx(BulkActions, {}), pagination: _jsx(Pagination, { rowsPerPageOptions: sortBy(uniq([10, 25, 50, 100, limit, limitMax])) }), children: _jsx(DataGrid, {}) }));
|
|
14
|
+
return (_jsx(List, { sort: sort, perPage: limit, actions: _jsx(Toolbar, {}), filters: buildAdmin(["list-filters", name], filters), pagination: _jsx(Pagination, { rowsPerPageOptions: sortBy(uniq([10, 25, 50, 100, limit, limitMax])) }), children: _jsx(DataGrid, {}) }));
|
|
16
15
|
}
|
|
17
16
|
setupAdmin(["list"], MuffinList);
|
|
18
17
|
setupAdmin(["list-fields"], buildRA);
|
|
@@ -20,7 +19,8 @@ setupAdmin(["list-filters"], buildRA);
|
|
|
20
19
|
function MuffinListDatagrid() {
|
|
21
20
|
const { name, list } = useMuffinResourceOpts();
|
|
22
21
|
const { fields, edit, show } = list;
|
|
23
|
-
|
|
22
|
+
const BulkActions = findBuilder(["list-bulk-actions", name]);
|
|
23
|
+
return (_jsxs(DatagridConfigurable, { rowClick: show ? "show" : edit ? "edit" : false, bulkActionButtons: _jsx(BulkActions, {}), children: [buildAdmin(["list-fields", name], fields), buildAdmin(["list-grid-buttons", name])] }));
|
|
24
24
|
}
|
|
25
25
|
setupAdmin(["list-grid"], MuffinListDatagrid);
|
|
26
26
|
function MuffinListGridButtons() {
|
|
@@ -38,6 +38,6 @@ function MuffinListToolbar() {
|
|
|
38
38
|
setupAdmin(["list-toolbar"], MuffinListToolbar);
|
|
39
39
|
function MuffinListBulkActions() {
|
|
40
40
|
const { list: { actions, remove }, } = useMuffinResourceOpts();
|
|
41
|
-
return (_jsxs(_Fragment, { children: [actions.map((props) => (_jsx(BulkActionButton, Object.assign({}, props), props.id))), remove && _jsx(BulkDeleteButton, {})] }));
|
|
41
|
+
return (_jsxs(_Fragment, { children: [actions.map((props) => (_jsx(BulkActionButton, Object.assign({}, props), props.id))), _jsx(BulkExportButton, {}), remove && _jsx(BulkDeleteButton, {})] }));
|
|
42
42
|
}
|
|
43
43
|
setupAdmin(["list-bulk-actions"], MuffinListBulkActions);
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { AdminAction } from "../types";
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export type ActionPayloadProps = {
|
|
3
|
+
active: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
onHandle: (payload: any) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare function ActionButton({ icon, label, title, action, id, confirm }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export declare function BulkActionButton({ label, icon, title, action, id, confirm }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,21 +1,59 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Button, useListContext, useRecordContext, useResourceContext } from "react-admin";
|
|
11
|
+
import { Button, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
|
|
3
12
|
import { useState } from "react";
|
|
13
|
+
import { useConfirmation } from "../common";
|
|
4
14
|
import { useAction } from "../hooks/useAction";
|
|
5
15
|
import { buildIcon, findBuilder } from "../utils";
|
|
6
|
-
export function ActionButton({ icon, label, title, action, id }) {
|
|
7
|
-
const
|
|
16
|
+
export function ActionButton({ icon, label, title, action, id, confirm }) {
|
|
17
|
+
const translate = useTranslate();
|
|
8
18
|
const record = useRecordContext();
|
|
9
19
|
const resource = useResourceContext();
|
|
10
|
-
const
|
|
20
|
+
const confirmation = useConfirmation();
|
|
21
|
+
const { mutate, isPending } = useAction(action, {});
|
|
22
|
+
const [payloadActive, setPayloadActive] = useState(false);
|
|
23
|
+
const [payloadResolver, setPayloadResolver] = useState();
|
|
11
24
|
const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
|
|
12
|
-
|
|
25
|
+
const buildPayload = PayloadBuilder
|
|
26
|
+
? new Promise((resolve) => setPayloadResolver(() => resolve))
|
|
27
|
+
: Promise.resolve();
|
|
28
|
+
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
29
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
if (PayloadBuilder)
|
|
31
|
+
setPayloadActive(true);
|
|
32
|
+
const payload = yield buildPayload;
|
|
33
|
+
const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
|
|
34
|
+
if (process)
|
|
35
|
+
yield mutate({ record, payload });
|
|
36
|
+
}), disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: payloadResolver, onClose: () => setPayloadActive(false) }))] }));
|
|
13
37
|
}
|
|
14
|
-
export function BulkActionButton({ label, icon, title, action, id }) {
|
|
38
|
+
export function BulkActionButton({ label, icon, title, action, id, confirm }) {
|
|
39
|
+
const translate = useTranslate();
|
|
15
40
|
const { selectedIds } = useListContext();
|
|
16
|
-
const { mutate,
|
|
41
|
+
const { mutate, isPending } = useAction(action);
|
|
42
|
+
const confirmation = useConfirmation();
|
|
17
43
|
const resource = useResourceContext();
|
|
18
44
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
45
|
+
const [payloadResolver, setPayloadResolver] = useState();
|
|
19
46
|
const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
|
|
20
|
-
|
|
47
|
+
const buildPayload = PayloadBuilder
|
|
48
|
+
? new Promise((resolve) => setPayloadResolver(() => resolve))
|
|
49
|
+
: Promise.resolve();
|
|
50
|
+
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
51
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
if (PayloadBuilder)
|
|
53
|
+
setPayloadActive(true);
|
|
54
|
+
const payload = yield buildPayload;
|
|
55
|
+
const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
|
|
56
|
+
if (process)
|
|
57
|
+
yield mutate({ ids: selectedIds, payload });
|
|
58
|
+
}), disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: payloadResolver, onClose: () => setPayloadActive(false) }))] }));
|
|
21
59
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DialogProps } from "@mui/material";
|
|
2
|
+
import { PropsWithChildren } from "react";
|
|
3
|
+
interface IProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
title?: string;
|
|
7
|
+
actions?: React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function AdminModal({ open, onClose, children, title, actions, ...props }: PropsWithChildren<IProps & DialogProps>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Dialog, DialogActions, DialogContent, DialogTitle } from "@mui/material";
|
|
14
|
+
export function AdminModal(_a) {
|
|
15
|
+
var { open, onClose, children, title, actions } = _a, props = __rest(_a, ["open", "onClose", "children", "title", "actions"]);
|
|
16
|
+
return (_jsxs(Dialog, Object.assign({ open: open, onClose: onClose, fullWidth: true, maxWidth: "md" }, props, { children: [title && _jsx(DialogTitle, { children: title }), _jsx(DialogContent, { children: children }), actions && _jsx(DialogActions, { children: actions })] })));
|
|
17
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PropsWithChildren } from "react";
|
|
2
|
+
type TConfirmProps = {
|
|
3
|
+
title?: string;
|
|
4
|
+
message: string;
|
|
5
|
+
actions?: React.ReactNode;
|
|
6
|
+
};
|
|
7
|
+
type TConfirmContext = {
|
|
8
|
+
confirm: (props: TConfirmProps) => Promise<boolean>;
|
|
9
|
+
};
|
|
10
|
+
export declare const ConfirmContext: import("react").Context<TConfirmContext>;
|
|
11
|
+
export declare function ConfirmationProvider({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export declare const useConfirmation: () => TConfirmContext;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Typography } from "@mui/material";
|
|
3
|
+
import { createContext, useContext, useState } from "react";
|
|
4
|
+
import { useTranslate } from "react-admin";
|
|
5
|
+
import { AdminModal } from "./AdminModal";
|
|
6
|
+
export const ConfirmContext = createContext({});
|
|
7
|
+
export function ConfirmationProvider({ children }) {
|
|
8
|
+
const translate = useTranslate();
|
|
9
|
+
const [open, setOpen] = useState(false);
|
|
10
|
+
const [title, setTitle] = useState(translate("ra.message.are_you_sure"));
|
|
11
|
+
const [message, setMessage] = useState(null);
|
|
12
|
+
const [resolver, setResolve] = useState(null);
|
|
13
|
+
function handleConfirm({ title, message }) {
|
|
14
|
+
setOpen(true);
|
|
15
|
+
if (title)
|
|
16
|
+
setTitle(title);
|
|
17
|
+
if (message)
|
|
18
|
+
setMessage(message);
|
|
19
|
+
return new Promise((resolve) => {
|
|
20
|
+
setResolve(() => resolve);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
const confirmContext = {
|
|
24
|
+
confirm: handleConfirm,
|
|
25
|
+
};
|
|
26
|
+
return (_jsxs(ConfirmContext.Provider, { value: confirmContext, children: [children, _jsx(AdminModal, { open: open, onClose: () => setOpen(false), title: title, maxWidth: "xs", actions: _jsxs(_Fragment, { children: [_jsx(Button, { variant: "contained", onClick: () => {
|
|
27
|
+
setOpen(false);
|
|
28
|
+
resolver(true);
|
|
29
|
+
}, children: translate("ra.action.confirm") }), _jsx(Button, { variant: "outlined", onClick: () => {
|
|
30
|
+
setOpen(false);
|
|
31
|
+
resolver(false);
|
|
32
|
+
}, children: translate("ra.action.cancel") })] }), children: _jsx(Typography, { children: message }) })] }));
|
|
33
|
+
}
|
|
34
|
+
export const useConfirmation = () => {
|
|
35
|
+
return useContext(ConfirmContext);
|
|
36
|
+
};
|
package/dist/context.d.ts
CHANGED
package/dist/dataprovider.js
CHANGED
|
@@ -50,27 +50,27 @@ export function MuffinDataprovider(apiUrl) {
|
|
|
50
50
|
getOne: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { id }) {
|
|
51
51
|
return yield request(`${resource}/${id}`);
|
|
52
52
|
}),
|
|
53
|
-
create: (
|
|
53
|
+
create: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { data }) {
|
|
54
54
|
return yield request(resource, {
|
|
55
55
|
data,
|
|
56
56
|
method: "POST",
|
|
57
57
|
});
|
|
58
58
|
}),
|
|
59
|
-
update: (
|
|
59
|
+
update: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { id, data }) {
|
|
60
60
|
return yield makeRequest(`${apiUrl}/${resource}/${id}`, {
|
|
61
61
|
data,
|
|
62
62
|
method: "PUT",
|
|
63
63
|
}).then(({ json }) => ({ data: json }));
|
|
64
64
|
}),
|
|
65
|
-
updateMany: (
|
|
65
|
+
updateMany: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { ids, data }) {
|
|
66
66
|
yield Promise.all(ids.map((id) => methods.update(resource, { id, data })));
|
|
67
67
|
return { data: ids };
|
|
68
68
|
}),
|
|
69
|
-
delete: (
|
|
69
|
+
delete: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { id }) {
|
|
70
70
|
yield request(`${resource}/${id}`, { method: "DELETE" });
|
|
71
71
|
return { data: { id } };
|
|
72
72
|
}),
|
|
73
|
-
deleteMany: (
|
|
73
|
+
deleteMany: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { ids }) {
|
|
74
74
|
yield request(resource, {
|
|
75
75
|
data: ids,
|
|
76
76
|
method: "DELETE",
|
|
@@ -82,8 +82,8 @@ export function MuffinDataprovider(apiUrl) {
|
|
|
82
82
|
const key = (meta === null || meta === void 0 ? void 0 : meta.key) || "id";
|
|
83
83
|
return methods.getList(resource, { filter: { [key]: { $in: ids } } });
|
|
84
84
|
},
|
|
85
|
-
getManyReference: (resource,
|
|
86
|
-
var { target, id, filter } =
|
|
85
|
+
getManyReference: (resource, _a) => __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
var { target, id, filter } = _a, opts = __rest(_a, ["target", "id", "filter"]);
|
|
87
87
|
filter = filter || {};
|
|
88
88
|
filter[target] = id;
|
|
89
89
|
return yield methods.getList(resource, Object.assign({ filter }, opts));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { UseMutationOptions } from "react-query";
|
|
1
|
+
import { UseMutationOptions } from "@tanstack/react-query";
|
|
2
2
|
import { TActionProps } from "../dataprovider";
|
|
3
3
|
export declare function useAction(action: string, options?: UseMutationOptions<{
|
|
4
4
|
data: any;
|
|
5
|
-
}, any, TActionProps>): import("react-query").UseMutationResult<{
|
|
5
|
+
}, any, TActionProps>): import("@tanstack/react-query").UseMutationResult<{
|
|
6
6
|
data: any;
|
|
7
7
|
}, any, TActionProps, unknown>;
|
package/dist/hooks/useAction.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { useMutation } from "@tanstack/react-query";
|
|
1
2
|
import { useDataProvider, useNotify, useRefresh, useResourceContext, useUnselectAll, } from "react-admin";
|
|
2
|
-
import { useMutation } from "react-query";
|
|
3
3
|
export function useAction(action, options) {
|
|
4
4
|
const notify = useNotify();
|
|
5
5
|
const refresh = useRefresh();
|
|
6
6
|
const resource = useResourceContext();
|
|
7
7
|
const unselectAll = useUnselectAll(resource);
|
|
8
8
|
const dataProvider = useDataProvider();
|
|
9
|
-
return useMutation((params) => dataProvider.runAction(resource, action, params),
|
|
9
|
+
return useMutation(Object.assign({ mutationFn: (params) => dataProvider.runAction(resource, action, params), onSuccess: ({ data }) => {
|
|
10
10
|
if (data && data.message)
|
|
11
11
|
notify(data.message, { type: "success" });
|
|
12
12
|
if (data && data.redirectTo)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED