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.
@@ -23,7 +23,7 @@ export function MuffinAdmin(props) {
23
23
  }
24
24
  setupAdmin(["admin"], MuffinAdmin);
25
25
  export function MuffinAdminLayout(props) {
26
- return _jsx(Layout, Object.assign({}, props, { appBar: findBuilder(["appbar"]) }));
26
+ return _jsx(Layout, Object.assign({}, props, { appBar: findBuilder(["appbar"]), menu: findBuilder(["menu"]) }));
27
27
  }
28
28
  setupAdmin(["layout"], MuffinAdminLayout);
29
29
  export function MuffinAppBar(props) {
@@ -0,0 +1,2 @@
1
+ import { MenuProps } from "react-admin";
2
+ export declare function MuffinMenu(props: MenuProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import ExpandLess from "@mui/icons-material/ExpandLess";
3
+ import ExpandMore from "@mui/icons-material/ExpandMore";
4
+ import Collapse from "@mui/material/Collapse";
5
+ import ListItemButton from "@mui/material/ListItemButton";
6
+ import ListItemIcon from "@mui/material/ListItemIcon";
7
+ import ListItemText from "@mui/material/ListItemText";
8
+ import { Menu, useTranslate } from "react-admin";
9
+ import find from "lodash/find";
10
+ import groupBy from "lodash/groupBy";
11
+ import { useContext, useState } from "react";
12
+ import { MuffinAdminContext } from "./context";
13
+ import { findIcon, setupAdmin } from "./utils";
14
+ export function MuffinMenu(props) {
15
+ const { resources } = useContext(MuffinAdminContext);
16
+ const groups = groupBy(resources.filter((r) => r.group), "group");
17
+ const groupRendered = [];
18
+ return (_jsxs(Menu, Object.assign({}, props, { children: [_jsx(Menu.DashboardItem, {}), resources.map(({ name, group }) => {
19
+ if (!group)
20
+ return _jsx(Menu.ResourceItem, { name: name }, name);
21
+ if (groupRendered.includes(group))
22
+ return null;
23
+ groupRendered.push(group);
24
+ const groupResources = groups[group];
25
+ return _jsx(MenuGroup, { name: group, resources: groupResources }, group);
26
+ })] })));
27
+ }
28
+ setupAdmin(["menu"], MuffinMenu);
29
+ function MenuGroup({ name, resources }) {
30
+ const iconRes = find(resources, "icon");
31
+ const Icon = iconRes ? findIcon(iconRes.icon) : null;
32
+ const translate = useTranslate();
33
+ const [groupOpen, setGroupOpen] = useState(false);
34
+ return (_jsxs("div", { children: [_jsxs(ListItemButton, { onClick: () => setGroupOpen(!groupOpen), children: [Icon && (_jsx(ListItemIcon, { sx: { minWidth: 40 }, children: _jsx(Icon, {}) })), _jsx(ListItemText, { primary: translate(`groups.${name}`) }), groupOpen ? _jsx(ExpandLess, {}) : _jsx(ExpandMore, {})] }), _jsx(Collapse, { in: groupOpen, timeout: "auto", unmountOnExit: true, children: resources.map(({ name }) => (_jsx(Menu.ResourceItem, { name: name }, name))) })] }));
35
+ }
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from "./utils";
2
2
  export * from "./MuffinAdmin";
3
3
  export * from "./MuffinDashboard";
4
+ export * from "./MuffinMenu";
4
5
  export * from "./MuffinRecordList";
5
6
  export * from "./MuffinResource";
6
7
  export * from "./MuffinResourceCreate";
@@ -18,4 +19,4 @@ export * from "./fields";
18
19
  export * from "./hooks";
19
20
  export * from "./types";
20
21
  export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
21
- export declare const VERSION = "9.3.0";
22
+ export declare const VERSION = "9.4.1";
package/dist/index.js CHANGED
@@ -14,6 +14,7 @@ import { MuffinAdminContext } from "./context";
14
14
  export * from "./utils";
15
15
  export * from "./MuffinAdmin";
16
16
  export * from "./MuffinDashboard";
17
+ export * from "./MuffinMenu";
17
18
  export * from "./MuffinRecordList";
18
19
  export * from "./MuffinResource";
19
20
  export * from "./MuffinResourceCreate";
@@ -41,4 +42,4 @@ export function initAdmin() {
41
42
  root.render(_jsx(MuffinAdminContext.Provider, { value: adminOpts, children: _jsx(MuffinAdmin, {}) }));
42
43
  });
43
44
  }
44
- export const VERSION = "9.3.0";
45
+ export const VERSION = "9.4.1";