muffin-admin 2.5.4 → 2.6.1
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/MuffinResourceEdit.js +2 -2
- package/dist/MuffinResourceShow.js +11 -3
- package/dist/buttons/ActionButton.d.ts +3 -12
- package/dist/buttons/ActionButton.js +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/MuffinResourceEdit.tsx +16 -8
- package/src/MuffinResourceShow.tsx +26 -17
- package/src/buttons/ActionButton.tsx +5 -4
- package/src/types.ts +7 -6
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -30,14 +30,22 @@ export function MuffinResourceEdit(props: AdminResourceProps["edit"]) {
|
|
|
30
30
|
mutationMode={mutationMode || "optimistic"}
|
|
31
31
|
{...opts}
|
|
32
32
|
>
|
|
33
|
-
<SimpleForm
|
|
34
|
-
|
|
35
|
-
<
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
<SimpleForm
|
|
34
|
+
toolbar={
|
|
35
|
+
<Toolbar>
|
|
36
|
+
<SaveButton />
|
|
37
|
+
{remove && (
|
|
38
|
+
<DeleteButton
|
|
39
|
+
sx={{
|
|
40
|
+
marginLeft: "auto",
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
)}
|
|
44
|
+
</Toolbar>
|
|
45
|
+
}
|
|
46
|
+
>
|
|
47
|
+
{buildAdmin(["edit-inputs", resourceName], inputs)}
|
|
48
|
+
</SimpleForm>
|
|
41
49
|
</Edit>
|
|
42
50
|
)
|
|
43
51
|
}
|
|
@@ -9,13 +9,15 @@ import {
|
|
|
9
9
|
import { LinkAction } from "./actions"
|
|
10
10
|
import { buildRA } from "./buildRA"
|
|
11
11
|
import { ActionButton } from "./buttons"
|
|
12
|
-
import { AdminShowProps } from "./types"
|
|
13
|
-
import { buildAdmin, setupAdmin } from "./utils"
|
|
12
|
+
import { AdminAction, AdminShowProps } from "./types"
|
|
13
|
+
import { buildAdmin, findBuilder, setupAdmin } from "./utils"
|
|
14
14
|
|
|
15
15
|
export function MuffinResourceShow(props: AdminShowProps) {
|
|
16
16
|
const resourceName = useResourceContext()
|
|
17
|
+
const ShowActions = findBuilder(["show-actions", resourceName])
|
|
18
|
+
|
|
17
19
|
return (
|
|
18
|
-
<Show actions={
|
|
20
|
+
<Show actions={<ShowActions {...props} />}>
|
|
19
21
|
<SimpleShowLayout>{buildAdmin(["show-fields", resourceName], props)}</SimpleShowLayout>
|
|
20
22
|
</Show>
|
|
21
23
|
)
|
|
@@ -23,17 +25,24 @@ export function MuffinResourceShow(props: AdminShowProps) {
|
|
|
23
25
|
|
|
24
26
|
setupAdmin(["show"], (props) => <MuffinResourceShow {...props} />)
|
|
25
27
|
setupAdmin(["show-fields"], ({ fields }) => buildRA(fields))
|
|
26
|
-
setupAdmin(["
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
setupAdmin(["record-actions"], ({ actions }: { actions: AdminAction[] }) =>
|
|
29
|
+
actions.map((props, idx) => <ActionButton key={idx} {...props} />)
|
|
30
|
+
)
|
|
31
|
+
setupAdmin(["record-links"], ({ links }: { links: AdminShowProps["links"] }) =>
|
|
32
|
+
links.map(([key, props]) => <LinkAction key={key} resource={key} {...props} />)
|
|
33
|
+
)
|
|
34
|
+
setupAdmin(["show-actions"], ({ actions, links, edit }: AdminShowProps) => {
|
|
35
|
+
const resourceName = useResourceContext()
|
|
36
|
+
const Actions = findBuilder(["record-actions", resourceName])
|
|
37
|
+
const Links = findBuilder(["record-links", resourceName])
|
|
38
|
+
return (
|
|
39
|
+
<TopToolbar>
|
|
40
|
+
<div style={{ marginRight: "auto" }}>
|
|
41
|
+
<Links links={links} />
|
|
42
|
+
</div>
|
|
43
|
+
<Actions actions={actions} />
|
|
44
|
+
<ListButton />
|
|
45
|
+
{edit && <EditButton />}
|
|
46
|
+
</TopToolbar>
|
|
47
|
+
)
|
|
48
|
+
})
|
|
@@ -10,14 +10,15 @@ import {
|
|
|
10
10
|
|
|
11
11
|
import { useState } from "react"
|
|
12
12
|
import { useAction } from "../hooks/useAction"
|
|
13
|
+
import { AdminAction } from "../types"
|
|
13
14
|
import { buildIcon, findBuilder } from "../utils"
|
|
14
15
|
|
|
15
|
-
export function BulkActionButton({ label, icon, title, action }) {
|
|
16
|
+
export function BulkActionButton({ label, icon, title, action }: AdminAction) {
|
|
16
17
|
const resource = useResourceContext()
|
|
17
18
|
const { selectedIds } = useListContext()
|
|
18
19
|
const [payloadActive, setPayloadActive] = useState(false)
|
|
19
20
|
|
|
20
|
-
const PayloadBuilder = findBuilder(["action", "payload",
|
|
21
|
+
const PayloadBuilder = findBuilder(["action", "payload", label])
|
|
21
22
|
|
|
22
23
|
const refresh = useRefresh(),
|
|
23
24
|
unselectAll = useUnselectAll(resource),
|
|
@@ -64,13 +65,13 @@ export function BulkActionButton({ label, icon, title, action }) {
|
|
|
64
65
|
)
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
export function ActionButton({ icon, label, title, action }) {
|
|
68
|
+
export function ActionButton({ icon, label, title, action }: AdminAction) {
|
|
68
69
|
const [payloadActive, setPayloadActive] = useState(false)
|
|
69
70
|
|
|
70
71
|
const record = useRecordContext()
|
|
71
72
|
const { mutate, isLoading } = useAction(action)
|
|
72
73
|
|
|
73
|
-
const PayloadBuilder = findBuilder(["action", "payload",
|
|
74
|
+
const PayloadBuilder = findBuilder(["action", "payload", label])
|
|
74
75
|
|
|
75
76
|
const refresh = useRefresh(),
|
|
76
77
|
notify = useNotify()
|
package/src/types.ts
CHANGED
|
@@ -23,6 +23,7 @@ export type AdminShowProps = {
|
|
|
23
23
|
actions: AdminAction[]
|
|
24
24
|
fields: AdminField[]
|
|
25
25
|
links: [string, AdminShowLink][]
|
|
26
|
+
edit?: boolean
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
export type AdminResourceProps = {
|
|
@@ -31,12 +32,12 @@ export type AdminResourceProps = {
|
|
|
31
32
|
label: string
|
|
32
33
|
create: AdminInput[] | false
|
|
33
34
|
edit:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
| {
|
|
36
|
+
actions: AdminAction[]
|
|
37
|
+
inputs: AdminInput[]
|
|
38
|
+
remove?: boolean
|
|
39
|
+
}
|
|
40
|
+
| false
|
|
40
41
|
list: {
|
|
41
42
|
limit: number
|
|
42
43
|
limitMax: number
|