muffin-admin 3.17.0 → 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.
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
TopToolbar,
|
|
15
15
|
} from "react-admin"
|
|
16
16
|
import { buildRA } from "./buildRA"
|
|
17
|
-
import {
|
|
17
|
+
import { BulkActionButton, ListActionButton } from "./buttons"
|
|
18
18
|
import { HelpLink } from "./common/HelpLink"
|
|
19
19
|
import { useMuffinResourceOpts } from "./hooks"
|
|
20
20
|
import { buildAdmin, findBuilder, setupAdmin } from "./utils"
|
|
@@ -85,7 +85,9 @@ function MuffinListToolbar() {
|
|
|
85
85
|
<SelectColumnsButton />
|
|
86
86
|
<FilterButton />
|
|
87
87
|
{create && <CreateButton />}
|
|
88
|
-
{actions.length
|
|
88
|
+
{actions.length
|
|
89
|
+
? actions.map((props) => <ListActionButton key={props.id} {...props} />)
|
|
90
|
+
: null}
|
|
89
91
|
{!hasExport && <ExportButton />}
|
|
90
92
|
</TopToolbar>
|
|
91
93
|
)
|
|
@@ -29,30 +29,38 @@ export function ActionButton({ paths, confirm, file, ...props }: AdminAction) {
|
|
|
29
29
|
const translate = useTranslate()
|
|
30
30
|
const record = useRecordContext()
|
|
31
31
|
const confirmation = useConfirmation()
|
|
32
|
+
|
|
32
33
|
const path = paths.find((p) => p.includes("{id}")) || paths[paths.length - 1]
|
|
33
34
|
const { mutate, isPending } = useAction(path)
|
|
34
|
-
const { apiUrl } = useMuffinAdminOpts()
|
|
35
35
|
|
|
36
|
-
if (file) {
|
|
37
|
-
let url = `${apiUrl}${path}`
|
|
38
|
-
if (record) url.replace("{id}", record.id as string)
|
|
36
|
+
if (file) return <FileButton path={path} record={record} {...props} />
|
|
39
37
|
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const confirmMessage =
|
|
39
|
+
typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?"
|
|
42
40
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
</Button>
|
|
47
|
-
)
|
|
41
|
+
const onHandle = async (payload?) => {
|
|
42
|
+
const process = confirm ? await confirmation.confirm({ message: confirmMessage }) : true
|
|
43
|
+
if (process) await mutate({ record, payload })
|
|
48
44
|
}
|
|
49
45
|
|
|
46
|
+
return <ActionButtonBase {...props} isPending={isPending} onHandle={onHandle} />
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function ListActionButton({ paths, confirm, file, ...props }: AdminAction) {
|
|
50
|
+
const translate = useTranslate()
|
|
51
|
+
const confirmation = useConfirmation()
|
|
52
|
+
const path = paths.find((p) => !p.includes("{id}")) || paths[paths.length - 1]
|
|
53
|
+
const { mutate, isPending } = useAction(path)
|
|
54
|
+
|
|
55
|
+
const { filterValues } = useListContext()
|
|
56
|
+
if (file) return <FileButton path={path} filterValues={filterValues} {...props} />
|
|
57
|
+
|
|
50
58
|
const confirmMessage =
|
|
51
59
|
typeof confirm === "string" ? translate(confirm) : "Do you confirm this action?"
|
|
52
60
|
|
|
53
61
|
const onHandle = async (payload?) => {
|
|
54
62
|
const process = confirm ? await confirmation.confirm({ message: confirmMessage }) : true
|
|
55
|
-
if (process) await mutate({
|
|
63
|
+
if (process) await mutate({ payload })
|
|
56
64
|
}
|
|
57
65
|
|
|
58
66
|
return <ActionButtonBase {...props} isPending={isPending} onHandle={onHandle} />
|
|
@@ -173,3 +181,29 @@ export function CommonPayload({
|
|
|
173
181
|
</FormProvider>
|
|
174
182
|
)
|
|
175
183
|
}
|
|
184
|
+
|
|
185
|
+
function FileButton({
|
|
186
|
+
path,
|
|
187
|
+
record,
|
|
188
|
+
label,
|
|
189
|
+
icon,
|
|
190
|
+
filterValues,
|
|
191
|
+
}: {
|
|
192
|
+
path: string
|
|
193
|
+
label: string
|
|
194
|
+
icon: string
|
|
195
|
+
record?: any
|
|
196
|
+
filterValues?: any
|
|
197
|
+
}) {
|
|
198
|
+
const { apiUrl } = useMuffinAdminOpts()
|
|
199
|
+
let url = `${apiUrl}${path}`
|
|
200
|
+
if (record) url = url.replace("{id}", record.id as string)
|
|
201
|
+
const authorization = requestHeaders["Authorization"]
|
|
202
|
+
if (authorization) url += `?t=${authorization}`
|
|
203
|
+
if (Object.keys(filterValues).length) url += `&where=${JSON.stringify(filterValues)}`
|
|
204
|
+
return (
|
|
205
|
+
<Button href={url} label={label} component={Link} target="_blank">
|
|
206
|
+
{buildIcon(icon)}
|
|
207
|
+
</Button>
|
|
208
|
+
)
|
|
209
|
+
}
|