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
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
Button,
|
|
3
3
|
FormGroupsProvider,
|
|
4
4
|
useAugmentedForm,
|
|
5
|
+
useDataProvider,
|
|
5
6
|
useListContext,
|
|
6
7
|
useRecordContext,
|
|
7
8
|
useResourceContext,
|
|
@@ -9,7 +10,7 @@ import {
|
|
|
9
10
|
} from "react-admin"
|
|
10
11
|
import { FormProvider } from "react-hook-form"
|
|
11
12
|
|
|
12
|
-
import { Stack } from "@mui/material"
|
|
13
|
+
import { Link, Stack } from "@mui/material"
|
|
13
14
|
import { useState } from "react"
|
|
14
15
|
import { buildRA } from "../buildRA"
|
|
15
16
|
import { AdminModal, PayloadButtons, useConfirmation } from "../common"
|
|
@@ -24,12 +25,28 @@ export type ActionPayloadProps = {
|
|
|
24
25
|
onHandle: (payload: any) => void
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export function ActionButton({ paths, confirm, ...props }: AdminAction) {
|
|
28
|
+
export function ActionButton({ paths, confirm, file, ...props }: AdminAction) {
|
|
28
29
|
const translate = useTranslate()
|
|
29
30
|
const record = useRecordContext()
|
|
30
31
|
const confirmation = useConfirmation()
|
|
31
32
|
const path = paths.find((p) => p.includes("{id}")) || paths[paths.length - 1]
|
|
32
33
|
const { mutate, isPending } = useAction(path)
|
|
34
|
+
const dataprovider = useDataProvider()
|
|
35
|
+
|
|
36
|
+
if (file) {
|
|
37
|
+
return (
|
|
38
|
+
<Button
|
|
39
|
+
component={Link}
|
|
40
|
+
label={props.label}
|
|
41
|
+
onClick={(e) => {
|
|
42
|
+
e.stopPropagation()
|
|
43
|
+
dataprovider.downloadFile(path)
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
{buildIcon(props.icon)}
|
|
47
|
+
</Button>
|
|
48
|
+
)
|
|
49
|
+
}
|
|
33
50
|
|
|
34
51
|
const confirmMessage =
|
|
35
52
|
typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?"
|
package/src/dataprovider.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIParams, makeRequest, setupAdmin } from "./utils"
|
|
1
|
+
import { APIParams, makeRequest, requestHeaders, setupAdmin } from "./utils"
|
|
2
2
|
|
|
3
3
|
export function MuffinDataprovider(apiUrl: string) {
|
|
4
4
|
async function request(url: string, options?: APIParams) {
|
|
@@ -87,6 +87,19 @@ export function MuffinDataprovider(apiUrl: string) {
|
|
|
87
87
|
})
|
|
88
88
|
return { data: json }
|
|
89
89
|
},
|
|
90
|
+
|
|
91
|
+
downloadFile: async (path: string) => {
|
|
92
|
+
const response = await fetch(`${apiUrl}/${path}`, {
|
|
93
|
+
headers: requestHeaders,
|
|
94
|
+
})
|
|
95
|
+
const url = window.URL.createObjectURL(await response.blob())
|
|
96
|
+
const link = document.createElement("a")
|
|
97
|
+
link.href = url
|
|
98
|
+
link.setAttribute("download", path)
|
|
99
|
+
link.click()
|
|
100
|
+
// no need to append link as child to body.
|
|
101
|
+
setTimeout(() => window.URL.revokeObjectURL(url), 0) // this is important too, otherwise we will be unnecessarily spiking memory!
|
|
102
|
+
},
|
|
90
103
|
}
|
|
91
104
|
return methods
|
|
92
105
|
}
|