muffin-admin 3.16.0 → 3.17.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/MuffinResourceList.js +2 -1
- package/dist/authprovider.d.ts +1 -0
- package/dist/authprovider.js +1 -0
- package/dist/buttons/ActionButton.js +11 -7
- package/dist/dataprovider.d.ts +0 -1
- package/dist/dataprovider.js +1 -18
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/MuffinResourceList.tsx +3 -2
- package/src/authprovider.ts +2 -0
- package/src/buttons/ActionButton.tsx +10 -11
- package/src/dataprovider.ts +1 -18
package/package.json
CHANGED
|
@@ -78,14 +78,15 @@ function MuffinListToolbar() {
|
|
|
78
78
|
list: { create },
|
|
79
79
|
} = useMuffinResourceOpts()
|
|
80
80
|
const actions = baseActions.filter((a) => a.view?.includes("list"))
|
|
81
|
+
const hasExport = actions.some((a) => a.id === "export")
|
|
81
82
|
return (
|
|
82
83
|
<TopToolbar>
|
|
83
84
|
{help && <HelpLink href={help} />}
|
|
84
85
|
<SelectColumnsButton />
|
|
85
86
|
<FilterButton />
|
|
86
|
-
{actions.length ? actions.map((props) => <ActionButton key={props.id} {...props} />) : null}
|
|
87
87
|
{create && <CreateButton />}
|
|
88
|
-
<
|
|
88
|
+
{actions.length ? actions.map((props) => <ActionButton key={props.id} {...props} />) : null}
|
|
89
|
+
{!hasExport && <ExportButton />}
|
|
89
90
|
</TopToolbar>
|
|
90
91
|
)
|
|
91
92
|
}
|
package/src/authprovider.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
Button,
|
|
3
3
|
FormGroupsProvider,
|
|
4
4
|
useAugmentedForm,
|
|
5
|
-
useDataProvider,
|
|
6
5
|
useListContext,
|
|
7
6
|
useRecordContext,
|
|
8
7
|
useResourceContext,
|
|
@@ -15,9 +14,10 @@ import { useState } from "react"
|
|
|
15
14
|
import { buildRA } from "../buildRA"
|
|
16
15
|
import { AdminModal, PayloadButtons, useConfirmation } from "../common"
|
|
17
16
|
import { HelpLink } from "../common/HelpLink"
|
|
17
|
+
import { useMuffinAdminOpts } from "../hooks"
|
|
18
18
|
import { useAction } from "../hooks/useAction"
|
|
19
19
|
import { AdminAction, AdminPayloadProps } from "../types"
|
|
20
|
-
import { buildIcon, findBuilder } from "../utils"
|
|
20
|
+
import { buildIcon, findBuilder, requestHeaders } from "../utils"
|
|
21
21
|
|
|
22
22
|
export type ActionPayloadProps = {
|
|
23
23
|
active: boolean
|
|
@@ -31,18 +31,17 @@ export function ActionButton({ paths, confirm, file, ...props }: AdminAction) {
|
|
|
31
31
|
const confirmation = useConfirmation()
|
|
32
32
|
const path = paths.find((p) => p.includes("{id}")) || paths[paths.length - 1]
|
|
33
33
|
const { mutate, isPending } = useAction(path)
|
|
34
|
-
const
|
|
34
|
+
const { apiUrl } = useMuffinAdminOpts()
|
|
35
35
|
|
|
36
36
|
if (file) {
|
|
37
|
+
let url = `${apiUrl}${path}`
|
|
38
|
+
if (record) url.replace("{id}", record.id as string)
|
|
39
|
+
|
|
40
|
+
const authorization = requestHeaders["Authorization"]
|
|
41
|
+
if (authorization) url += `?t=${authorization}`
|
|
42
|
+
|
|
37
43
|
return (
|
|
38
|
-
<Button
|
|
39
|
-
component={Link}
|
|
40
|
-
label={props.label}
|
|
41
|
-
onClick={(e) => {
|
|
42
|
-
e.stopPropagation()
|
|
43
|
-
dataprovider.downloadFile(path)
|
|
44
|
-
}}
|
|
45
|
-
>
|
|
44
|
+
<Button href={url} label={props.label} component={Link} target="_blank">
|
|
46
45
|
{buildIcon(props.icon)}
|
|
47
46
|
</Button>
|
|
48
47
|
)
|
package/src/dataprovider.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { APIParams, makeRequest,
|
|
1
|
+
import { APIParams, makeRequest, setupAdmin } from "./utils"
|
|
2
2
|
|
|
3
3
|
export function MuffinDataprovider(apiUrl: string) {
|
|
4
4
|
async function request(url: string, options?: APIParams) {
|
|
@@ -87,23 +87,6 @@ export function MuffinDataprovider(apiUrl: string) {
|
|
|
87
87
|
})
|
|
88
88
|
return { data: json }
|
|
89
89
|
},
|
|
90
|
-
|
|
91
|
-
downloadFile: async (path: string) => {
|
|
92
|
-
path = path.replace(/^\/+/, "")
|
|
93
|
-
const response = await fetch(`${apiUrl}/${path}`, {
|
|
94
|
-
headers: requestHeaders,
|
|
95
|
-
})
|
|
96
|
-
const url = window.URL.createObjectURL(await response.blob())
|
|
97
|
-
const link = document.createElement("a")
|
|
98
|
-
link.href = url
|
|
99
|
-
const filename =
|
|
100
|
-
response.headers.get("content-disposition")?.split("filename=")[1] || path.split("/").pop()
|
|
101
|
-
link.setAttribute("download", filename)
|
|
102
|
-
if (filename) link.setAttribute("download", filename)
|
|
103
|
-
link.click()
|
|
104
|
-
// no need to append link as child to body.
|
|
105
|
-
setTimeout(() => window.URL.revokeObjectURL(url), 0) // this is important too, otherwise we will be unnecessarily spiking memory!
|
|
106
|
-
},
|
|
107
90
|
}
|
|
108
91
|
return methods
|
|
109
92
|
}
|