muffin-admin 3.17.1 → 3.18.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.
@@ -3,7 +3,7 @@ import sortBy from "lodash/sortBy";
3
3
  import uniq from "lodash/uniq";
4
4
  import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, List, Pagination, SelectColumnsButton, TopToolbar, } from "react-admin";
5
5
  import { buildRA } from "./buildRA";
6
- import { ActionButton, BulkActionButton } from "./buttons";
6
+ import { BulkActionButton, ListActionButton } from "./buttons";
7
7
  import { HelpLink } from "./common/HelpLink";
8
8
  import { useMuffinResourceOpts } from "./hooks";
9
9
  import { buildAdmin, findBuilder, setupAdmin } from "./utils";
@@ -36,7 +36,9 @@ function MuffinListToolbar() {
36
36
  const { actions: baseActions = [], help, list: { create }, } = useMuffinResourceOpts();
37
37
  const actions = baseActions.filter((a) => { var _a; return (_a = a.view) === null || _a === void 0 ? void 0 : _a.includes("list"); });
38
38
  const hasExport = actions.some((a) => a.id === "export");
39
- return (_jsxs(TopToolbar, { children: [help && _jsx(HelpLink, { href: help }), _jsx(SelectColumnsButton, {}), _jsx(FilterButton, {}), create && _jsx(CreateButton, {}), actions.length ? actions.map((props) => _jsx(ActionButton, Object.assign({}, props), props.id)) : null, !hasExport && _jsx(ExportButton, {})] }));
39
+ return (_jsxs(TopToolbar, { children: [help && _jsx(HelpLink, { href: help }), _jsx(SelectColumnsButton, {}), _jsx(FilterButton, {}), create && _jsx(CreateButton, {}), actions.length
40
+ ? actions.map((props) => _jsx(ListActionButton, Object.assign({}, props), props.id))
41
+ : null, !hasExport && _jsx(ExportButton, {})] }));
40
42
  }
41
43
  setupAdmin(["list-toolbar"], MuffinListToolbar);
42
44
  function MuffinListBulkActions() {
@@ -5,5 +5,6 @@ export type ActionPayloadProps = {
5
5
  onHandle: (payload: any) => void;
6
6
  };
7
7
  export declare function ActionButton({ paths, confirm, file, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
8
+ export declare function ListActionButton({ paths, confirm, file, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
8
9
  export declare function BulkActionButton({ paths, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
9
10
  export declare function CommonPayload({ active, onClose, onHandle, schema, title, help, }: AdminPayloadProps): import("react/jsx-runtime").JSX.Element;
@@ -36,16 +36,8 @@ export function ActionButton(_a) {
36
36
  const confirmation = useConfirmation();
37
37
  const path = paths.find((p) => p.includes("{id}")) || paths[paths.length - 1];
38
38
  const { mutate, isPending } = useAction(path);
39
- const { apiUrl } = useMuffinAdminOpts();
40
- if (file) {
41
- let url = `${apiUrl}${path}`;
42
- if (record)
43
- url.replace("{id}", record.id);
44
- const authorization = requestHeaders["Authorization"];
45
- if (authorization)
46
- url += `?t=${authorization}`;
47
- return (_jsx(Button, { href: url, label: props.label, component: Link, target: "_blank", children: buildIcon(props.icon) }));
48
- }
39
+ if (file)
40
+ return _jsx(FileButton, Object.assign({ path: path, record: record }, props));
49
41
  const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
50
42
  const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
51
43
  const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
@@ -54,6 +46,23 @@ export function ActionButton(_a) {
54
46
  });
55
47
  return _jsx(ActionButtonBase, Object.assign({}, props, { isPending: isPending, onHandle: onHandle }));
56
48
  }
49
+ export function ListActionButton(_a) {
50
+ var { paths, confirm, file } = _a, props = __rest(_a, ["paths", "confirm", "file"]);
51
+ const translate = useTranslate();
52
+ const confirmation = useConfirmation();
53
+ const path = paths.find((p) => !p.includes("{id}")) || paths[paths.length - 1];
54
+ const { mutate, isPending } = useAction(path);
55
+ const { filterValues } = useListContext();
56
+ if (file)
57
+ return _jsx(FileButton, Object.assign({ path: path, filterValues: filterValues }, props));
58
+ const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
59
+ const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
60
+ const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
61
+ if (process)
62
+ yield mutate({ payload });
63
+ });
64
+ return _jsx(ActionButtonBase, Object.assign({}, props, { isPending: isPending, onHandle: onHandle }));
65
+ }
57
66
  export function BulkActionButton(_a) {
58
67
  var { paths, confirm } = _a, props = __rest(_a, ["paths", "confirm"]);
59
68
  const translate = useTranslate();
@@ -96,3 +105,15 @@ export function CommonPayload({ active, onClose, onHandle, schema, title, help,
96
105
  ? (_jsxs(Stack, { alignItems: "flex-start", children: [_jsx("span", { children: translate(title, { _: title }) }), _jsx(HelpLink, { href: help, style: { alignSelf: "flex-end" } })] }))
97
106
  : translate(title, { _: title }), actions: _jsx(PayloadButtons, { onClose: onClose, onSubmit: formHandleSubmit, isValid: form.formState.isValid }), children: inputs }) }) })));
98
107
  }
108
+ function FileButton({ path, record, label, icon, filterValues, }) {
109
+ const { apiUrl } = useMuffinAdminOpts();
110
+ let url = `${apiUrl}${path}`;
111
+ if (record)
112
+ url = url.replace("{id}", record.id);
113
+ const authorization = requestHeaders["Authorization"];
114
+ if (authorization)
115
+ url += `?t=${authorization}`;
116
+ if (Object.keys(filterValues).length)
117
+ url += `&where=${JSON.stringify(filterValues)}`;
118
+ return (_jsx(Button, { href: url, label: label, component: Link, target: "_blank", children: buildIcon(icon) }));
119
+ }