muffin-admin 8.1.2 → 8.3.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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "8.1.2",
3
+ "version": "8.3.0",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -0,0 +1,29 @@
1
+ import Box from "@mui/material/Box"
2
+ import Typography from "@mui/material/Typography"
3
+ import { Datagrid, SortPayload, useGetList, useRecordContext, useTranslate } from "react-admin"
4
+ import { useMuffinResourceOpts } from "./hooks"
5
+ import { buildAdmin } from "./utils"
6
+
7
+ type TProps = {
8
+ resource: string
9
+ filter: (record: any) => Record<string, any>
10
+ sort?: SortPayload
11
+ }
12
+ export function MuffinRecordList({ resource, filter, sort }: TProps) {
13
+ const record = useRecordContext()
14
+ const translate = useTranslate()
15
+ const {
16
+ list: { fields },
17
+ } = useMuffinResourceOpts(resource)
18
+ const { data, isPending } = useGetList(resource, { sort, filter: filter(record) })
19
+ return (
20
+ <Box p={2}>
21
+ <Typography variant="h6">
22
+ {translate(`resources.${resource}.name`, { smart_count: 2 })}
23
+ </Typography>
24
+ <Datagrid resource={resource} bulkActionButtons={false} isPending={isPending} data={data}>
25
+ {buildAdmin(["list-fields", resource], fields)}
26
+ </Datagrid>
27
+ </Box>
28
+ )
29
+ }
@@ -12,8 +12,8 @@ export function MuffinShow({ children }: PropsWithChildren) {
12
12
 
13
13
  return (
14
14
  <Show actions={<ShowToolbar />}>
15
- {children}
16
15
  <SimpleShowLayout>{buildAdmin(["show-fields", name], show)}</SimpleShowLayout>
16
+ {children}
17
17
  </Show>
18
18
  )
19
19
  }
@@ -1,8 +1,8 @@
1
1
  import { useResourceContext } from "react-admin"
2
2
  import { useMuffinAdminOpts } from "./useMuffinAdminOpts"
3
3
 
4
- export function useMuffinResourceOpts() {
5
- const resource = useResourceContext()
4
+ export function useMuffinResourceOpts(resource?) {
5
+ resource = useResourceContext({ resource })
6
6
  const { resources } = useMuffinAdminOpts()
7
7
  return resources.find((r) => r.name === resource)
8
8
  }
package/src/index.tsx CHANGED
@@ -6,6 +6,7 @@ export * from "./utils"
6
6
 
7
7
  export * from "./MuffinAdmin"
8
8
  export * from "./MuffinDashboard"
9
+ export * from "./MuffinRecordList"
9
10
  export * from "./MuffinResource"
10
11
  export * from "./MuffinResourceCreate"
11
12
  export * from "./MuffinResourceEdit"
@@ -35,4 +36,4 @@ export async function initAdmin(prefix = "", containerId: string = "root") {
35
36
  )
36
37
  }
37
38
 
38
- export const VERSION = "8.1.2"
39
+ export const VERSION = "8.3.0"