muffin-admin 3.6.1 → 3.6.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.
@@ -4,8 +4,8 @@ export type ActionPayloadProps = {
4
4
  onClose: () => void;
5
5
  onHandle: (payload: any) => void;
6
6
  };
7
- export declare function ActionButton({ icon, label, title, action, id, confirm, schema }: 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;
7
+ export declare function ActionButton({ action, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
8
+ export declare function BulkActionButton({ action, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
9
9
  export declare function CommonPayload({ active, onClose, onHandle, schema, title }: {
10
10
  active: any;
11
11
  onClose: any;
@@ -7,58 +7,51 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
22
  import { Button, Form, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
12
- import { useMemo, useState } from "react";
23
+ import { useState } from "react";
13
24
  import { buildRA } from "../buildRA";
14
25
  import { AdminModal, PayloadButtons, useConfirmation } from "../common";
15
26
  import { useAction } from "../hooks/useAction";
16
27
  import { buildIcon, findBuilder } from "../utils";
17
- export function ActionButton({ icon, label, title, action, id, confirm, schema }) {
28
+ export function ActionButton(_a) {
29
+ var { action, confirm } = _a, props = __rest(_a, ["action", "confirm"]);
18
30
  const translate = useTranslate();
19
31
  const record = useRecordContext();
20
- const resource = useResourceContext();
21
32
  const confirmation = useConfirmation();
22
33
  const { mutate, isPending } = useAction(action);
23
- const [payloadActive, setPayloadActive] = useState(false);
24
- const PayloadBuilder = findBuilder(["action", "payload", id, resource]) || (schema && CommonPayload);
25
34
  const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
26
35
  const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
27
36
  const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
28
37
  if (process)
29
38
  yield mutate({ record, payload });
30
39
  });
31
- return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => {
32
- if (PayloadBuilder)
33
- setPayloadActive(true);
34
- else
35
- onHandle();
36
- }, disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: onHandle, onClose: () => setPayloadActive(false), title: title || label, schema: schema }))] }));
40
+ return _jsx(ActionButtonBase, Object.assign({}, props, { isPending: isPending, onHandle: onHandle }));
37
41
  }
38
- export function BulkActionButton({ label, icon, title, action, id, confirm }) {
42
+ export function BulkActionButton(_a) {
43
+ var { action, confirm } = _a, props = __rest(_a, ["action", "confirm"]);
39
44
  const translate = useTranslate();
40
45
  const { selectedIds } = useListContext();
41
46
  const { mutate, isPending } = useAction(action);
42
47
  const confirmation = useConfirmation();
43
- const resource = useResourceContext();
44
- const [payloadActive, setPayloadActive] = useState(false);
45
- const [payloadResolver, setPayloadResolver] = useState();
46
- const PayloadBuilder = findBuilder(["action", "payload", id, resource]);
47
- const buildPayload = useMemo(() => {
48
- if (PayloadBuilder) {
49
- return new Promise((resolve) => setPayloadResolver(() => resolve));
50
- }
51
- return Promise.resolve();
52
- }, [PayloadBuilder]);
53
48
  const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
54
- return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => __awaiter(this, void 0, void 0, function* () {
55
- if (PayloadBuilder)
56
- setPayloadActive(true);
57
- const payload = yield buildPayload;
58
- const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
59
- if (process)
60
- yield mutate({ ids: selectedIds, payload });
61
- }), disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: payloadResolver, onClose: () => setPayloadActive(false) }))] }));
49
+ const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
50
+ const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
51
+ if (process)
52
+ yield mutate({ ids: selectedIds, payload });
53
+ });
54
+ return _jsx(ActionButtonBase, Object.assign({}, props, { onHandle: onHandle, isPending: isPending }));
62
55
  }
63
56
  export function CommonPayload({ active, onClose, onHandle, schema, title }) {
64
57
  const inputs = buildRA(schema);
@@ -68,3 +61,14 @@ export function CommonPayload({ active, onClose, onHandle, schema, title }) {
68
61
  onHandle(data);
69
62
  }, children: [inputs, _jsx(PayloadButtons, { onClose: onClose })] }) }));
70
63
  }
64
+ function ActionButtonBase({ label, title, onHandle, isPending, icon, schema, id, }) {
65
+ const resource = useResourceContext();
66
+ const [payloadActive, setPayloadActive] = useState(false);
67
+ const PayloadBuilder = findBuilder(["action", "payload", id, resource]) || (schema && CommonPayload);
68
+ return (_jsxs(_Fragment, { children: [_jsx(Button, { label: label, title: title, onClick: () => {
69
+ if (PayloadBuilder)
70
+ setPayloadActive(true);
71
+ else
72
+ onHandle();
73
+ }, disabled: isPending, children: buildIcon(icon) }), PayloadBuilder && (_jsx(PayloadBuilder, { active: payloadActive, onHandle: onHandle, onClose: () => setPayloadActive(false), title: title || label, schema: schema }))] }));
74
+ }