muffin-admin 3.2.2 → 3.3.12
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 +5 -5
- package/dist/buttons/ActionButton.js +4 -4
- 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/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/MuffinResourceList.tsx +7 -3
- package/src/buttons/ActionButton.tsx +4 -4
- package/src/hooks/useAction.ts +4 -2
|
@@ -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);
|
|
@@ -7,15 +7,15 @@ export function ActionButton({ icon, label, title, action, id }) {
|
|
|
7
7
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
8
8
|
const record = useRecordContext();
|
|
9
9
|
const resource = useResourceContext();
|
|
10
|
-
const { mutate,
|
|
10
|
+
const { mutate, isPending } = useAction(action, {});
|
|
11
11
|
const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
|
|
12
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => (PayloadBuilder ? setPayloadActive(true) : mutate({ record })), disabled:
|
|
12
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => (PayloadBuilder ? setPayloadActive(true) : mutate({ record })), disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: (payload) => mutate({ record, payload }), onClose: () => setPayloadActive(false) }))] }));
|
|
13
13
|
}
|
|
14
14
|
export function BulkActionButton({ label, icon, title, action, id }) {
|
|
15
15
|
const { selectedIds } = useListContext();
|
|
16
|
-
const { mutate,
|
|
16
|
+
const { mutate, isPending } = useAction(action);
|
|
17
17
|
const resource = useResourceContext();
|
|
18
18
|
const [payloadActive, setPayloadActive] = useState(false);
|
|
19
19
|
const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
|
|
20
|
-
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => (PayloadBuilder ? setPayloadActive(true) : mutate({ ids: selectedIds })), disabled:
|
|
20
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => (PayloadBuilder ? setPayloadActive(true) : mutate({ ids: selectedIds })), disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: (payload) => mutate({ ids: selectedIds, payload }), onClose: () => setPayloadActive(false) }))] }));
|
|
21
21
|
}
|
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)
|