muffin-admin 9.3.0 → 9.4.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/types.d.ts CHANGED
@@ -2,7 +2,7 @@ export type TID = string | number;
2
2
  export type TProps = {
3
3
  [key: string]: any;
4
4
  };
5
- export type TAdminType = "action-form" | "admin" | "appbar" | "auth-provider" | "auth-storage-get" | "auth-storage-set" | "create" | "create-toolbar" | "create-inputs" | "dashboard" | "dashboard-actions" | "dashboard-content" | "data-provider" | "edit" | "edit-actions" | "edit-toolbar" | "edit-form-toolbar" | "edit-inputs" | "layout" | "list" | "list-actions" | "list-toolbar" | "list-grid" | "list-grid-buttons" | "list-filters" | "list-fields" | "locale" | "loginpage" | "resource" | "show" | "show-actions" | "show-toolbar" | "show-fields" | "show-links";
5
+ export type TAdminType = "action-form" | "admin" | "appbar" | "auth-provider" | "auth-storage-get" | "auth-storage-set" | "create" | "create-toolbar" | "create-inputs" | "dashboard" | "dashboard-actions" | "dashboard-content" | "data-provider" | "edit" | "edit-actions" | "edit-toolbar" | "edit-form-toolbar" | "edit-inputs" | "layout" | "list" | "list-actions" | "list-toolbar" | "list-grid" | "list-grid-buttons" | "list-filters" | "list-fields" | "locale" | "loginpage" | "menu" | "resource" | "show" | "show-actions" | "show-toolbar" | "show-fields" | "show-links";
6
6
  export type TAdminPath = [type: TAdminType, ...ids: string[]];
7
7
  export type AdminAction = {
8
8
  view?: ("show" | "edit" | "list" | "bulk")[];
@@ -45,6 +45,7 @@ export type AdminPayloadProps = {
45
45
  };
46
46
  export type AdminResourceProps = {
47
47
  name: string;
48
+ group?: string;
48
49
  icon?: string;
49
50
  label: string;
50
51
  help?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "9.3.0",
3
+ "version": "9.4.1",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -99,7 +99,7 @@ export function MuffinAdmin(props: AdminProps) {
99
99
  setupAdmin(["admin"], MuffinAdmin)
100
100
 
101
101
  export function MuffinAdminLayout(props: LayoutProps) {
102
- return <Layout {...props} appBar={findBuilder(["appbar"])} />
102
+ return <Layout {...props} appBar={findBuilder(["appbar"])} menu={findBuilder(["menu"])} />
103
103
  }
104
104
 
105
105
  setupAdmin(["layout"], MuffinAdminLayout)
@@ -0,0 +1,66 @@
1
+ import ExpandLess from "@mui/icons-material/ExpandLess"
2
+ import ExpandMore from "@mui/icons-material/ExpandMore"
3
+ import Collapse from "@mui/material/Collapse"
4
+ import ListItemButton from "@mui/material/ListItemButton"
5
+ import ListItemIcon from "@mui/material/ListItemIcon"
6
+ import ListItemText from "@mui/material/ListItemText"
7
+
8
+ import { Menu, MenuProps, useTranslate } from "react-admin"
9
+
10
+ import find from "lodash/find"
11
+ import groupBy from "lodash/groupBy"
12
+ import { useContext, useState } from "react"
13
+ import { MuffinAdminContext } from "./context"
14
+ import { AdminResourceProps } from "./types"
15
+ import { findIcon, setupAdmin } from "./utils"
16
+
17
+ export function MuffinMenu(props: MenuProps) {
18
+ const { resources } = useContext(MuffinAdminContext)
19
+
20
+ const groups = groupBy(
21
+ resources.filter((r) => r.group),
22
+ "group"
23
+ )
24
+ const groupRendered = []
25
+
26
+ return (
27
+ <Menu {...props}>
28
+ <Menu.DashboardItem />
29
+ {resources.map(({ name, group }) => {
30
+ if (!group) return <Menu.ResourceItem name={name} key={name} />
31
+ if (groupRendered.includes(group)) return null
32
+ groupRendered.push(group)
33
+ const groupResources = groups[group]
34
+ return <MenuGroup name={group} resources={groupResources} key={group} />
35
+ })}
36
+ </Menu>
37
+ )
38
+ }
39
+
40
+ setupAdmin(["menu"], MuffinMenu)
41
+
42
+ function MenuGroup({ name, resources }: { name: string; resources: AdminResourceProps[] }) {
43
+ const iconRes = find(resources, "icon")
44
+ const Icon = iconRes ? findIcon(iconRes.icon) : null
45
+ const translate = useTranslate()
46
+ const [groupOpen, setGroupOpen] = useState(false)
47
+
48
+ return (
49
+ <div>
50
+ <ListItemButton onClick={() => setGroupOpen(!groupOpen)}>
51
+ {Icon && (
52
+ <ListItemIcon sx={{ minWidth: 40 }}>
53
+ <Icon />
54
+ </ListItemIcon>
55
+ )}
56
+ <ListItemText primary={translate(`groups.${name}`)} />
57
+ {groupOpen ? <ExpandLess /> : <ExpandMore />}
58
+ </ListItemButton>
59
+ <Collapse in={groupOpen} timeout="auto" unmountOnExit>
60
+ {resources.map(({ name }) => (
61
+ <Menu.ResourceItem name={name} key={name} />
62
+ ))}
63
+ </Collapse>
64
+ </div>
65
+ )
66
+ }
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 "./MuffinMenu"
9
10
  export * from "./MuffinRecordList"
10
11
  export * from "./MuffinResource"
11
12
  export * from "./MuffinResourceCreate"
@@ -36,4 +37,4 @@ export async function initAdmin(prefix = "", containerId: string = "root") {
36
37
  )
37
38
  }
38
39
 
39
- export const VERSION = "9.3.0"
40
+ export const VERSION = "9.4.1"
package/src/types.ts CHANGED
@@ -33,6 +33,7 @@ export type TAdminType =
33
33
  | "list-fields"
34
34
  | "locale"
35
35
  | "loginpage"
36
+ | "menu"
36
37
  | "resource"
37
38
  | "show"
38
39
  | "show-actions"
@@ -55,7 +56,7 @@ export type AdminAction = {
55
56
  }
56
57
 
57
58
  export type AdminField = [string, { source: string }]
58
- export type AdminInput = [string, { required: boolean; source: string; [key: string]: any }]
59
+ export type AdminInput = [string, { required: boolean; source: string;[key: string]: any }]
59
60
 
60
61
  export type AdminShowLink = {
61
62
  label: string
@@ -80,17 +81,18 @@ export type AdminPayloadProps = {
80
81
 
81
82
  export type AdminResourceProps = {
82
83
  name: string
84
+ group?: string
83
85
  icon?: string
84
86
  label: string
85
87
  help?: string
86
88
  actions: AdminAction[]
87
89
  create: AdminInput[] | false
88
90
  edit:
89
- | {
90
- inputs: AdminInput[]
91
- remove?: boolean
92
- }
93
- | false
91
+ | {
92
+ inputs: AdminInput[]
93
+ remove?: boolean
94
+ }
95
+ | false
94
96
  list: {
95
97
  limit: number
96
98
  limitMax: number