muffin-admin 2.5.3 → 2.6.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/types.d.ts CHANGED
@@ -25,6 +25,7 @@ export type AdminShowProps = {
25
25
  actions: AdminAction[];
26
26
  fields: AdminField[];
27
27
  links: [string, AdminShowLink][];
28
+ edit?: boolean;
28
29
  };
29
30
  export type AdminResourceProps = {
30
31
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "2.5.3",
3
+ "version": "2.6.0",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -30,14 +30,22 @@ export function MuffinResourceEdit(props: AdminResourceProps["edit"]) {
30
30
  mutationMode={mutationMode || "optimistic"}
31
31
  {...opts}
32
32
  >
33
- <SimpleForm toolbar={
34
- <Toolbar>
35
- <SaveButton />
36
- {remove && <DeleteButton sx={{
37
- marginLeft: "auto",
38
- }} />}
39
- </Toolbar>
40
- }>{buildAdmin(["edit-inputs", resourceName], inputs)}</SimpleForm>
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,7 +9,7 @@ import {
9
9
  import { LinkAction } from "./actions"
10
10
  import { buildRA } from "./buildRA"
11
11
  import { ActionButton } from "./buttons"
12
- import { AdminShowProps } from "./types"
12
+ import { AdminAction, AdminShowProps } from "./types"
13
13
  import { buildAdmin, setupAdmin } from "./utils"
14
14
 
15
15
  export function MuffinResourceShow(props: AdminShowProps) {
@@ -23,17 +23,21 @@ export function MuffinResourceShow(props: AdminShowProps) {
23
23
 
24
24
  setupAdmin(["show"], (props) => <MuffinResourceShow {...props} />)
25
25
  setupAdmin(["show-fields"], ({ fields }) => buildRA(fields))
26
- setupAdmin(["show-actions"], ({ actions, links, edit }) => (
27
- <TopToolbar>
28
- <div style={{ marginRight: "auto" }}>
29
- {links.map(([key, props]) => (
30
- <LinkAction key={key} resource={key} {...props} />
31
- ))}
32
- </div>
33
- {actions.map((props, idx) => (
34
- <ActionButton key={idx} {...props} />
35
- ))}
36
- <ListButton />
37
- {edit && <EditButton />}
38
- </TopToolbar>
39
- ))
26
+ setupAdmin(["record-actions"], (actions: AdminAction[]) =>
27
+ actions.map((props, idx) => <ActionButton key={idx} {...props} />)
28
+ )
29
+ setupAdmin(["show-actions"], ({ actions, links, edit }: AdminShowProps) => {
30
+ const resourceName = useResourceContext()
31
+ return (
32
+ <TopToolbar>
33
+ <div style={{ marginRight: "auto" }}>
34
+ {links.map(([key, props]) => (
35
+ <LinkAction key={key} resource={key} {...props} />
36
+ ))}
37
+ </div>
38
+ {buildAdmin(["record-actions", resourceName], actions)}
39
+ <ListButton />
40
+ {edit && <EditButton />}
41
+ </TopToolbar>
42
+ )
43
+ })
@@ -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", action])
21
+ const PayloadBuilder = findBuilder(["action", "payload", label])
21
22
 
22
23
  const refresh = useRefresh(),
23
24
  unselectAll = useUnselectAll(resource),
@@ -25,7 +26,7 @@ export function BulkActionButton({ label, icon, title, action }) {
25
26
 
26
27
  const { mutate, isLoading } = useAction(action)
27
28
 
28
- const process = (payload) =>
29
+ const process = (payload?) =>
29
30
  mutate(
30
31
  { ids: selectedIds, payload },
31
32
  {
@@ -48,7 +49,7 @@ export function BulkActionButton({ label, icon, title, action }) {
48
49
  <Button
49
50
  label={label}
50
51
  title={title}
51
- onClick={PayloadBuilder ? () => setPayloadActive(true) : process}
52
+ onClick={() => (PayloadBuilder ? setPayloadActive(true) : process())}
52
53
  disabled={isLoading}
53
54
  >
54
55
  {buildIcon(icon)}
@@ -64,18 +65,18 @@ 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", action])
74
+ const PayloadBuilder = findBuilder(["action", "payload", label])
74
75
 
75
76
  const refresh = useRefresh(),
76
77
  notify = useNotify()
77
78
 
78
- const process = (payload) =>
79
+ const process = (payload?) =>
79
80
  mutate(
80
81
  { record, payload },
81
82
  {
@@ -95,7 +96,7 @@ export function ActionButton({ icon, label, title, action }) {
95
96
  <Button
96
97
  label={label}
97
98
  title={title}
98
- onClick={PayloadBuilder ? () => setPayloadActive(true) : process}
99
+ onClick={() => (PayloadBuilder ? setPayloadActive(true) : process())}
99
100
  disabled={isLoading}
100
101
  >
101
102
  {buildIcon(icon)}
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
- actions: AdminAction[]
36
- inputs: AdminInput[]
37
- remove?: boolean
38
- }
39
- | false
35
+ | {
36
+ actions: AdminAction[]
37
+ inputs: AdminInput[]
38
+ remove?: boolean
39
+ }
40
+ | false
40
41
  list: {
41
42
  limit: number
42
43
  limitMax: number