muffin-admin 9.4.0 → 9.4.2

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.
@@ -1,4 +1,5 @@
1
- import { AdminProps, AppBarProps, LayoutProps } from "react-admin";
1
+ import { AdminProps, AppBarProps, LayoutProps, LoginProps } from "react-admin";
2
2
  export declare function MuffinAdmin(props: AdminProps): import("react/jsx-runtime").JSX.Element;
3
3
  export declare function MuffinAdminLayout(props: LayoutProps): import("react/jsx-runtime").JSX.Element;
4
4
  export declare function MuffinAppBar(props: AppBarProps): import("react/jsx-runtime").JSX.Element;
5
+ export declare function MuffinLogin(props: LoginProps): import("react/jsx-runtime").JSX.Element;
@@ -4,6 +4,7 @@ import SvgIcon from "@mui/material/SvgIcon";
4
4
  import Tooltip from "@mui/material/Tooltip";
5
5
  import Typography from "@mui/material/Typography";
6
6
  import { AdminContext, AdminUI, AppBar, Layout, localStorageStore, Login, } from "react-admin";
7
+ import { useEffect } from "react";
7
8
  import { ConfirmationProvider } from "./common";
8
9
  import { useMuffinAdminOpts } from "./hooks";
9
10
  import { buildProvider, muffinTranslations } from "./i18n";
@@ -36,5 +37,17 @@ export function MuffinAppBar(props) {
36
37
  } }), appBarLinks.map((info) => (_jsx(Tooltip, { title: info.title, children: _jsx(IconButton, { color: "inherit", href: info.url, children: _jsx(SvgIcon, { component: findIcon(info.icon) }) }) }, info.url)))] })));
37
38
  }
38
39
  setupAdmin(["appbar"], MuffinAppBar);
40
+ export function MuffinLogin(props) {
41
+ const { auth: { loginURL }, } = useMuffinAdminOpts();
42
+ useEffect(() => {
43
+ if (loginURL) {
44
+ const { pathname, search } = window.location;
45
+ const url = new URL(loginURL);
46
+ url.searchParams.set("redirect", pathname + search);
47
+ window.location.replace(url.toString());
48
+ }
49
+ }, [loginURL]);
50
+ return _jsx(Login, Object.assign({}, props));
51
+ }
39
52
  // Initialize login page
40
- setupAdmin(["loginpage"], Login);
53
+ setupAdmin(["loginpage"], MuffinLogin);
@@ -6,6 +6,7 @@ import ListItemButton from "@mui/material/ListItemButton";
6
6
  import ListItemIcon from "@mui/material/ListItemIcon";
7
7
  import ListItemText from "@mui/material/ListItemText";
8
8
  import { Menu, useTranslate } from "react-admin";
9
+ import find from "lodash/find";
9
10
  import groupBy from "lodash/groupBy";
10
11
  import { useContext, useState } from "react";
11
12
  import { MuffinAdminContext } from "./context";
@@ -14,20 +15,21 @@ export function MuffinMenu(props) {
14
15
  const { resources } = useContext(MuffinAdminContext);
15
16
  const groups = groupBy(resources.filter((r) => r.group), "group");
16
17
  const groupRendered = [];
17
- return (_jsxs(Menu, Object.assign({}, props, { children: [_jsx(Menu.DashboardItem, {}), resources.map(({ name, group, icon }) => {
18
+ return (_jsxs(Menu, Object.assign({}, props, { children: [_jsx(Menu.DashboardItem, {}), resources.map(({ name, group }) => {
18
19
  if (!group)
19
20
  return _jsx(Menu.ResourceItem, { name: name }, name);
20
21
  if (groupRendered.includes(group))
21
22
  return null;
22
23
  groupRendered.push(group);
23
24
  const groupResources = groups[group];
24
- return _jsx(MenuGroup, { name: group, icon: icon, resources: groupResources }, group);
25
+ return _jsx(MenuGroup, { name: group, resources: groupResources }, group);
25
26
  })] })));
26
27
  }
27
28
  setupAdmin(["menu"], MuffinMenu);
28
- function MenuGroup({ name, icon, resources, }) {
29
- const Icon = findIcon(icon);
29
+ function MenuGroup({ name, resources }) {
30
+ const iconRes = find(resources, "icon");
31
+ const Icon = iconRes ? findIcon(iconRes.icon) : null;
30
32
  const translate = useTranslate();
31
33
  const [groupOpen, setGroupOpen] = useState(false);
32
- return (_jsxs("div", { children: [_jsxs(ListItemButton, { onClick: () => setGroupOpen(!groupOpen), children: [_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))) })] }));
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))) })] }));
33
35
  }
package/dist/index.d.ts CHANGED
@@ -19,4 +19,4 @@ export * from "./fields";
19
19
  export * from "./hooks";
20
20
  export * from "./types";
21
21
  export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
22
- export declare const VERSION = "9.4.0";
22
+ export declare const VERSION = "9.4.2";
package/dist/index.js CHANGED
@@ -42,4 +42,4 @@ export function initAdmin() {
42
42
  root.render(_jsx(MuffinAdminContext.Provider, { value: adminOpts, children: _jsx(MuffinAdmin, {}) }));
43
43
  });
44
44
  }
45
- export const VERSION = "9.4.0";
45
+ export const VERSION = "9.4.2";