muffin-admin 9.2.4 → 9.4.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/MuffinAdmin.js +1 -1
- package/dist/MuffinMenu.d.ts +2 -0
- package/dist/MuffinMenu.js +33 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/MuffinAdmin.tsx +1 -1
- package/src/MuffinMenu.tsx +70 -0
- package/src/index.tsx +2 -1
- package/src/types.ts +8 -6
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
package/src/MuffinAdmin.tsx
CHANGED
|
@@ -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,70 @@
|
|
|
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 groupBy from "lodash/groupBy"
|
|
11
|
+
import { useContext, useState } from "react"
|
|
12
|
+
import { MuffinAdminContext } from "./context"
|
|
13
|
+
import { AdminResourceProps } from "./types"
|
|
14
|
+
import { findIcon, setupAdmin } from "./utils"
|
|
15
|
+
|
|
16
|
+
export function MuffinMenu(props: MenuProps) {
|
|
17
|
+
const { resources } = useContext(MuffinAdminContext)
|
|
18
|
+
|
|
19
|
+
const groups = groupBy(
|
|
20
|
+
resources.filter((r) => r.group),
|
|
21
|
+
"group"
|
|
22
|
+
)
|
|
23
|
+
const groupRendered = []
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<Menu {...props}>
|
|
27
|
+
<Menu.DashboardItem />
|
|
28
|
+
{resources.map(({ name, group, icon }) => {
|
|
29
|
+
if (!group) return <Menu.ResourceItem name={name} key={name} />
|
|
30
|
+
if (groupRendered.includes(group)) return null
|
|
31
|
+
groupRendered.push(group)
|
|
32
|
+
const groupResources = groups[group]
|
|
33
|
+
return <MenuGroup name={group} icon={icon} resources={groupResources} key={group} />
|
|
34
|
+
})}
|
|
35
|
+
</Menu>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
setupAdmin(["menu"], MuffinMenu)
|
|
40
|
+
|
|
41
|
+
function MenuGroup({
|
|
42
|
+
name,
|
|
43
|
+
icon,
|
|
44
|
+
resources,
|
|
45
|
+
}: {
|
|
46
|
+
name: string
|
|
47
|
+
icon: string
|
|
48
|
+
resources: AdminResourceProps[]
|
|
49
|
+
}) {
|
|
50
|
+
const Icon = findIcon(icon)
|
|
51
|
+
const translate = useTranslate()
|
|
52
|
+
const [groupOpen, setGroupOpen] = useState(false)
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div>
|
|
56
|
+
<ListItemButton onClick={() => setGroupOpen(!groupOpen)}>
|
|
57
|
+
<ListItemIcon sx={{ minWidth: 40 }}>
|
|
58
|
+
<Icon />
|
|
59
|
+
</ListItemIcon>
|
|
60
|
+
<ListItemText primary={translate(`groups.${name}`)} />
|
|
61
|
+
{groupOpen ? <ExpandLess /> : <ExpandMore />}
|
|
62
|
+
</ListItemButton>
|
|
63
|
+
<Collapse in={groupOpen} timeout="auto" unmountOnExit>
|
|
64
|
+
{resources.map(({ name }) => (
|
|
65
|
+
<Menu.ResourceItem name={name} key={name} />
|
|
66
|
+
))}
|
|
67
|
+
</Collapse>
|
|
68
|
+
</div>
|
|
69
|
+
)
|
|
70
|
+
}
|
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.
|
|
40
|
+
export const VERSION = "9.4.0"
|
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;
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
| {
|
|
92
|
+
inputs: AdminInput[]
|
|
93
|
+
remove?: boolean
|
|
94
|
+
}
|
|
95
|
+
| false
|
|
94
96
|
list: {
|
|
95
97
|
limit: number
|
|
96
98
|
limitMax: number
|