muffin-admin 3.13.4 → 3.14.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/buttons/ActionButton.d.ts +1 -1
- package/dist/buttons/ActionButton.js +10 -3
- package/dist/dataprovider.d.ts +1 -0
- package/dist/dataprovider.js +13 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/buttons/ActionButton.tsx +19 -2
- package/src/dataprovider.ts +14 -1
- package/src/types.ts +1 -0
|
@@ -4,6 +4,6 @@ export type ActionPayloadProps = {
|
|
|
4
4
|
onClose: () => void;
|
|
5
5
|
onHandle: (payload: any) => void;
|
|
6
6
|
};
|
|
7
|
-
export declare function ActionButton({ paths, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
export declare function ActionButton({ paths, confirm, file, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
export declare function BulkActionButton({ paths, confirm, ...props }: AdminAction): import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
export declare function CommonPayload({ active, onClose, onHandle, schema, title, help, }: AdminPayloadProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -19,9 +19,9 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
-
import { Button, FormGroupsProvider, useAugmentedForm, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
|
|
22
|
+
import { Button, FormGroupsProvider, useAugmentedForm, useDataProvider, useListContext, useRecordContext, useResourceContext, useTranslate, } from "react-admin";
|
|
23
23
|
import { FormProvider } from "react-hook-form";
|
|
24
|
-
import { Stack } from "@mui/material";
|
|
24
|
+
import { Link, Stack } from "@mui/material";
|
|
25
25
|
import { useState } from "react";
|
|
26
26
|
import { buildRA } from "../buildRA";
|
|
27
27
|
import { AdminModal, PayloadButtons, useConfirmation } from "../common";
|
|
@@ -29,12 +29,19 @@ import { HelpLink } from "../common/HelpLink";
|
|
|
29
29
|
import { useAction } from "../hooks/useAction";
|
|
30
30
|
import { buildIcon, findBuilder } from "../utils";
|
|
31
31
|
export function ActionButton(_a) {
|
|
32
|
-
var { paths, confirm } = _a, props = __rest(_a, ["paths", "confirm"]);
|
|
32
|
+
var { paths, confirm, file } = _a, props = __rest(_a, ["paths", "confirm", "file"]);
|
|
33
33
|
const translate = useTranslate();
|
|
34
34
|
const record = useRecordContext();
|
|
35
35
|
const confirmation = useConfirmation();
|
|
36
36
|
const path = paths.find((p) => p.includes("{id}")) || paths[paths.length - 1];
|
|
37
37
|
const { mutate, isPending } = useAction(path);
|
|
38
|
+
const dataprovider = useDataProvider();
|
|
39
|
+
if (file) {
|
|
40
|
+
return (_jsx(Button, { component: Link, label: props.label, onClick: (e) => {
|
|
41
|
+
e.stopPropagation();
|
|
42
|
+
dataprovider.downloadFile(path);
|
|
43
|
+
}, children: buildIcon(props.icon) }));
|
|
44
|
+
}
|
|
38
45
|
const confirmMessage = typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?";
|
|
39
46
|
const onHandle = (payload) => __awaiter(this, void 0, void 0, function* () {
|
|
40
47
|
const process = confirm ? yield confirmation.confirm({ message: confirmMessage }) : true;
|
package/dist/dataprovider.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export declare function MuffinDataprovider(apiUrl: string): {
|
|
|
60
60
|
runAction: (resource: string, action: string, props: TActionProps) => Promise<{
|
|
61
61
|
data: any;
|
|
62
62
|
}>;
|
|
63
|
+
downloadFile: (path: string) => Promise<void>;
|
|
63
64
|
};
|
|
64
65
|
export type TActionProps<T = any> = {
|
|
65
66
|
payload?: any;
|
package/dist/dataprovider.js
CHANGED
|
@@ -18,7 +18,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
18
18
|
}
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
|
-
import { makeRequest, setupAdmin } from "./utils";
|
|
21
|
+
import { makeRequest, requestHeaders, setupAdmin } from "./utils";
|
|
22
22
|
export function MuffinDataprovider(apiUrl) {
|
|
23
23
|
function request(url, options) {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -101,6 +101,18 @@ export function MuffinDataprovider(apiUrl) {
|
|
|
101
101
|
});
|
|
102
102
|
return { data: json };
|
|
103
103
|
}),
|
|
104
|
+
downloadFile: (path) => __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const response = yield fetch(`${apiUrl}/${path}`, {
|
|
106
|
+
headers: requestHeaders,
|
|
107
|
+
});
|
|
108
|
+
const url = window.URL.createObjectURL(yield response.blob());
|
|
109
|
+
const link = document.createElement("a");
|
|
110
|
+
link.href = url;
|
|
111
|
+
link.setAttribute("download", path);
|
|
112
|
+
link.click();
|
|
113
|
+
// no need to append link as child to body.
|
|
114
|
+
setTimeout(() => window.URL.revokeObjectURL(url), 0); // this is important too, otherwise we will be unnecessarily spiking memory!
|
|
115
|
+
}),
|
|
104
116
|
};
|
|
105
117
|
return methods;
|
|
106
118
|
}
|