muffin-admin 12.0.0 → 13.1.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.
Files changed (97) hide show
  1. package/dist/MuffinAdmin.d.ts +5 -5
  2. package/dist/MuffinAdmin.js +1 -1
  3. package/dist/MuffinDashboard.d.ts +1 -1
  4. package/dist/MuffinDashboard.js +3 -3
  5. package/dist/MuffinMenu.d.ts +2 -2
  6. package/dist/MuffinMenu.js +2 -2
  7. package/dist/MuffinRecordList.d.ts +2 -2
  8. package/dist/MuffinRecordList.js +1 -1
  9. package/dist/MuffinResource.d.ts +2 -2
  10. package/dist/MuffinResourceCreate.d.ts +3 -3
  11. package/dist/MuffinResourceEdit.d.ts +6 -6
  12. package/dist/MuffinResourceEdit.js +1 -1
  13. package/dist/MuffinResourceList.d.ts +2 -2
  14. package/dist/MuffinResourceList.js +3 -4
  15. package/dist/MuffinResourceShow.d.ts +5 -5
  16. package/dist/MuffinResourceShow.js +1 -1
  17. package/dist/actions/LinkAction.d.ts +2 -2
  18. package/dist/authprovider.js +7 -9
  19. package/dist/buildRA.d.ts +4 -3
  20. package/dist/buildRA.js +1 -1
  21. package/dist/buttons/ActionButton.d.ts +5 -5
  22. package/dist/buttons/ActionButton.js +5 -5
  23. package/dist/buttons/CopyButton.d.ts +1 -1
  24. package/dist/buttons/LinkButton.d.ts +2 -2
  25. package/dist/common/AdminModal.d.ts +4 -4
  26. package/dist/common/ConfirmationProvider.d.ts +2 -2
  27. package/dist/common/ConfirmationProvider.js +1 -1
  28. package/dist/common/HelpLink.d.ts +1 -1
  29. package/dist/common/PayloadButtons.d.ts +1 -1
  30. package/dist/common/PayloadButtons.js +1 -1
  31. package/dist/context.d.ts +1 -1
  32. package/dist/dataprovider.d.ts +7 -7
  33. package/dist/fields/AvatarField.d.ts +3 -3
  34. package/dist/fields/AvatarField.js +2 -2
  35. package/dist/fields/CopyField.d.ts +1 -1
  36. package/dist/fields/EditableBooleanField.d.ts +1 -1
  37. package/dist/fields/FKField.d.ts +4 -4
  38. package/dist/fields/FKField.js +1 -1
  39. package/dist/fields/JsonField.d.ts +1 -1
  40. package/dist/filters/DateRangeFilter.d.ts +1 -1
  41. package/dist/filters/Filter.d.ts +2 -2
  42. package/dist/filters/Filter.js +2 -2
  43. package/dist/filters/SearchFilter.d.ts +2 -2
  44. package/dist/filters/SearchFilter.js +6 -4
  45. package/dist/hooks/useAction.d.ts +2 -2
  46. package/dist/hooks/useAction.js +2 -2
  47. package/dist/i18n/en.d.ts +1 -1
  48. package/dist/i18n/provider.d.ts +3 -3
  49. package/dist/i18n/ru.d.ts +1 -1
  50. package/dist/index.d.ts +11 -11
  51. package/dist/index.js +12 -12
  52. package/dist/inputs/DateRangeInput.d.ts +2 -2
  53. package/dist/inputs/FKInput.d.ts +2 -2
  54. package/dist/inputs/ImgInput.d.ts +2 -2
  55. package/dist/inputs/JsonInput.d.ts +1 -1
  56. package/dist/inputs/JsonInput.js +1 -1
  57. package/dist/inputs/TimestampInput.d.ts +2 -2
  58. package/dist/utils.d.ts +2 -2
  59. package/dist/utils.js +1 -0
  60. package/dist/version.d.ts +1 -0
  61. package/dist/version.js +1 -0
  62. package/dist/web.js +0 -1
  63. package/package.json +15 -29
  64. package/src/MuffinAdmin.tsx +6 -7
  65. package/src/MuffinDashboard.tsx +6 -6
  66. package/src/MuffinMenu.tsx +3 -5
  67. package/src/MuffinRecordList.tsx +2 -2
  68. package/src/MuffinResource.tsx +1 -1
  69. package/src/MuffinResourceCreate.tsx +1 -1
  70. package/src/MuffinResourceEdit.tsx +1 -1
  71. package/src/MuffinResourceList.tsx +2 -5
  72. package/src/MuffinResourceShow.tsx +1 -1
  73. package/src/actions/LinkAction.tsx +1 -1
  74. package/src/authprovider.ts +88 -101
  75. package/src/buildRA.tsx +4 -3
  76. package/src/buttons/ActionButton.tsx +9 -10
  77. package/src/buttons/LinkButton.tsx +1 -1
  78. package/src/common/AdminModal.tsx +3 -3
  79. package/src/common/ConfirmationProvider.tsx +1 -1
  80. package/src/common/PayloadButtons.tsx +1 -1
  81. package/src/context.ts +1 -1
  82. package/src/dataprovider.ts +2 -2
  83. package/src/fields/AvatarField.tsx +8 -10
  84. package/src/fields/FKField.tsx +1 -1
  85. package/src/filters/Filter.tsx +2 -2
  86. package/src/filters/SearchFilter.tsx +14 -7
  87. package/src/globals.d.ts +1 -0
  88. package/src/hooks/useAction.ts +4 -4
  89. package/src/i18n/en.ts +1 -1
  90. package/src/i18n/ru.ts +1 -1
  91. package/src/index.tsx +12 -13
  92. package/src/inputs/DateRangeInput.tsx +1 -1
  93. package/src/inputs/JsonInput.tsx +1 -1
  94. package/src/utils.tsx +2 -1
  95. package/src/version.ts +1 -0
  96. package/src/web.ts +0 -1
  97. package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/i18n/en.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { TranslationMessages } from "ra-core";
1
+ import type { TranslationMessages } from "ra-core";
2
2
  declare const muffinEnglishMessages: TranslationMessages;
3
3
  export default muffinEnglishMessages;
@@ -1,5 +1,5 @@
1
1
  export declare const muffinTranslations: {
2
- en: import("react-admin").TranslationMessages;
3
- ru: import("react-admin").TranslationMessages;
2
+ en: import("ra-core").TranslationMessages;
3
+ ru: import("ra-core").TranslationMessages;
4
4
  };
5
- export declare const buildProvider: (translations: any) => import("react-admin").I18nProvider;
5
+ export declare const buildProvider: (translations: any) => import("ra-core").I18nProvider;
package/dist/i18n/ru.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { TranslationMessages } from "ra-core";
1
+ import type { TranslationMessages } from "ra-core";
2
2
  declare const muffinRussianMessages: TranslationMessages;
3
3
  export default muffinRussianMessages;
package/dist/index.d.ts CHANGED
@@ -1,13 +1,3 @@
1
- export * from "./utils";
2
- export * from "./MuffinAdmin";
3
- export * from "./MuffinDashboard";
4
- export * from "./MuffinMenu";
5
- export * from "./MuffinRecordList";
6
- export * from "./MuffinResource";
7
- export * from "./MuffinResourceCreate";
8
- export * from "./MuffinResourceEdit";
9
- export * from "./MuffinResourceList";
10
- export * from "./MuffinResourceShow";
11
1
  export * from "./actions";
12
2
  export * from "./authprovider";
13
3
  export * from "./buildRA";
@@ -17,6 +7,16 @@ export * from "./context";
17
7
  export * from "./dataprovider";
18
8
  export * from "./fields";
19
9
  export * from "./hooks";
10
+ export * from "./MuffinAdmin";
11
+ export * from "./MuffinDashboard";
12
+ export * from "./MuffinMenu";
13
+ export * from "./MuffinRecordList";
14
+ export * from "./MuffinResource";
15
+ export * from "./MuffinResourceCreate";
16
+ export * from "./MuffinResourceEdit";
17
+ export * from "./MuffinResourceList";
18
+ export * from "./MuffinResourceShow";
20
19
  export * from "./types";
20
+ export * from "./utils";
21
21
  export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
22
- export declare const VERSION = "12.0.0";
22
+ export { VERSION } from "./version";
package/dist/index.js CHANGED
@@ -9,18 +9,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  import { createRoot } from "react-dom/client";
12
- import { MuffinAdmin } from "./MuffinAdmin";
13
12
  import { MuffinAdminContext } from "./context";
14
- export * from "./utils";
15
- export * from "./MuffinAdmin";
16
- export * from "./MuffinDashboard";
17
- export * from "./MuffinMenu";
18
- export * from "./MuffinRecordList";
19
- export * from "./MuffinResource";
20
- export * from "./MuffinResourceCreate";
21
- export * from "./MuffinResourceEdit";
22
- export * from "./MuffinResourceList";
23
- export * from "./MuffinResourceShow";
13
+ import { MuffinAdmin } from "./MuffinAdmin";
24
14
  export * from "./actions";
25
15
  export * from "./authprovider";
26
16
  export * from "./buildRA";
@@ -30,7 +20,17 @@ export * from "./context";
30
20
  export * from "./dataprovider";
31
21
  export * from "./fields";
32
22
  export * from "./hooks";
23
+ export * from "./MuffinAdmin";
24
+ export * from "./MuffinDashboard";
25
+ export * from "./MuffinMenu";
26
+ export * from "./MuffinRecordList";
27
+ export * from "./MuffinResource";
28
+ export * from "./MuffinResourceCreate";
29
+ export * from "./MuffinResourceEdit";
30
+ export * from "./MuffinResourceList";
31
+ export * from "./MuffinResourceShow";
33
32
  export * from "./types";
33
+ export * from "./utils";
34
34
  export function initAdmin() {
35
35
  return __awaiter(this, arguments, void 0, function* (prefix = "", containerId = "root") {
36
36
  const response = yield fetch(`${prefix}/ra.json`);
@@ -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 = "12.0.0";
45
+ export { VERSION } from "./version";
@@ -1,8 +1,8 @@
1
- import { InputProps } from "react-admin";
1
+ import { type InputProps } from "react-admin";
2
2
  import "react-datepicker/dist/react-datepicker.css";
3
3
  type TProps = InputProps & {
4
4
  value: [Date, Date];
5
5
  onChange: (value: [Date, Date]) => void;
6
6
  };
7
- export declare function DateRangeInput({ value, onChange, ...props }: TProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function DateRangeInput({ value, onChange, ...props }: TProps): import("react").JSX.Element;
8
8
  export {};
@@ -1,8 +1,8 @@
1
1
  export declare function FKInput({ refKey, refSource, fullWidth, reference, source, ...props }: {
2
2
  [x: string]: any;
3
+ fullWidth: any;
3
4
  refKey: any;
4
5
  refSource: any;
5
- fullWidth: any;
6
6
  reference: any;
7
7
  source: any;
8
- }): import("react/jsx-runtime").JSX.Element;
8
+ }): import("react").JSX.Element;
@@ -1,5 +1,5 @@
1
1
  export declare function ImgInput({ source, label, ...props }: {
2
2
  [x: string]: any;
3
- source: any;
4
3
  label: any;
5
- }): import("react/jsx-runtime").JSX.Element;
4
+ source: any;
5
+ }): import("react").JSX.Element;
@@ -16,4 +16,4 @@
16
16
  * @example
17
17
  * <JsonInput source='config' label='JSON Config' parse={false}/>
18
18
  */
19
- export declare function JsonInput(props: any): import("react/jsx-runtime").JSX.Element;
19
+ export declare function JsonInput(props: any): import("react").JSX.Element;
@@ -19,7 +19,7 @@ const parseFunction = (json) => {
19
19
  retval = JSON.parse(json);
20
20
  }
21
21
  finally {
22
- // eslint-disable-next-line no-unsafe-finally
22
+ // biome-ignore lint/correctness/noUnsafeFinally: intentional - return parsed value or original on error
23
23
  return retval;
24
24
  }
25
25
  };
@@ -1,5 +1,5 @@
1
1
  export declare function TimestampInput({ source, ms, ...props }: {
2
2
  [x: string]: any;
3
- source: any;
4
3
  ms: any;
5
- }): import("react/jsx-runtime").JSX.Element;
4
+ source: any;
5
+ }): import("react").JSX.Element;
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TAdminPath } from "./types";
1
+ import type { TAdminPath } from "./types";
2
2
  export declare function setupAdmin<T>(adminType: TAdminPath, fc: (props: any) => T): void;
3
3
  export declare function buildAdmin(adminType: TAdminPath, props?: {}): any;
4
4
  export declare function findBuilder(adminType: TAdminPath): (props: any) => any;
@@ -23,6 +23,6 @@ export declare function makeRequest(url: string, params?: APIParams): Promise<{
23
23
  json: any;
24
24
  }>;
25
25
  export declare function findIcon(icon?: string): any;
26
- export declare function buildIcon(icon?: string): import("react/jsx-runtime").JSX.Element;
26
+ export declare function buildIcon(icon?: string): import("react").JSX.Element;
27
27
  export declare function deepMerge(target: any, ...sources: any[]): any;
28
28
  export declare function prepareFilters(filter: any): string;
package/dist/utils.js CHANGED
@@ -48,6 +48,7 @@ export function makeRequest(url, params = {}) {
48
48
  return fetchUtils.fetchJson(url, Object.assign(Object.assign({}, opts), { headers: new Headers(Object.assign(Object.assign({}, requestHeaders), opts.headers)) }));
49
49
  }
50
50
  export function findIcon(icon) {
51
+ // biome-ignore lint/performance/noDynamicNamespaceImportAccess: icons are looked up by name from admin config
51
52
  return icon ? icons[icon] : undefined;
52
53
  }
53
54
  export function buildIcon(icon) {
@@ -0,0 +1 @@
1
+ export declare const VERSION = "13.1.0";
@@ -0,0 +1 @@
1
+ export const VERSION = "13.1.0";
package/dist/web.js CHANGED
@@ -1,3 +1,2 @@
1
1
  import { initAdmin } from ".";
2
- // @ts-ignore
3
2
  globalThis.initAdmin = initAdmin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "12.0.0",
3
+ "version": "13.1.0",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -28,44 +28,30 @@
28
28
  "ra-language-russian": "^5.4.4",
29
29
  "react": "^19.1.1",
30
30
  "react-admin": "^5.10.1",
31
- "react-datepicker": "^8.5.0",
31
+ "react-datepicker": "^9.1.0",
32
32
  "react-dom": "^19.1.1",
33
33
  "validator": "^13.12.0"
34
34
  },
35
35
  "devDependencies": {
36
+ "@biomejs/biome": "^2.5.5",
36
37
  "@types/lodash": "^4.17.20",
37
- "@types/node": "24.1.0",
38
- "@types/react": "19.1.9",
39
- "@types/react-dom": "19.1.7",
40
- "@types/react-window": "^1.8.8",
41
- "@typescript-eslint/eslint-plugin": "^7.12.0",
42
- "@typescript-eslint/parser": "^7.12.0",
38
+ "@types/node": "26.1.1",
39
+ "@types/react": "19.2.17",
40
+ "@types/react-dom": "19.2.3",
41
+ "@types/react-window": "^2.0.0",
43
42
  "css-loader": "^7.1.2",
44
- "dotenv": "^16.4.5",
45
- "eslint": "^8",
46
- "eslint-config-prettier": "^9.1.0",
47
- "eslint-plugin-prettier": "^5.1.3",
48
- "eslint-plugin-react": "^7.34.2",
43
+ "dotenv": "^17.4.2",
44
+ "esbuild-loader": "^4.5.0",
49
45
  "html-webpack-plugin": "^5.6.0",
50
46
  "husky": "^9.0.11",
51
- "prettier": "^3.2",
52
- "prettier-plugin-organize-imports": "^3.2",
53
47
  "style-loader": "^4.0.0",
54
- "ts-loader": "^9.5.1",
55
- "typescript": "^5.4.5",
48
+ "typescript": "^7.0.2",
56
49
  "webpack": "^5.91.0",
57
- "webpack-cli": "^5.1.4",
58
- "webpack-dev-server": "^5.0.4"
50
+ "webpack-cli": "^7.2.1",
51
+ "webpack-dev-server": "^6.0.0"
59
52
  },
60
- "prettier": {
61
- "arrowParens": "always",
62
- "plugins": [
63
- "prettier-plugin-organize-imports"
64
- ],
65
- "printWidth": 100,
66
- "semi": false,
67
- "tabWidth": 2,
68
- "trailingComma": "es5",
69
- "useTabs": false
53
+ "resolutions": {
54
+ "@mui/material": "^9.2.0",
55
+ "@mui/icons-material": "^9.2.0"
70
56
  }
71
57
  }
@@ -3,20 +3,19 @@ import SvgIcon from "@mui/material/SvgIcon"
3
3
  import Tooltip from "@mui/material/Tooltip"
4
4
 
5
5
  import Typography from "@mui/material/Typography"
6
+ import { useEffect } from "react"
6
7
  import {
7
8
  AdminContext,
8
- AdminProps,
9
+ type AdminProps,
9
10
  AdminUI,
10
11
  AppBar,
11
- AppBarProps,
12
+ type AppBarProps,
12
13
  Layout,
13
- LayoutProps,
14
- localStorageStore,
14
+ type LayoutProps,
15
15
  Login,
16
- LoginProps,
16
+ type LoginProps,
17
+ localStorageStore,
17
18
  } from "react-admin"
18
-
19
- import { useEffect } from "react"
20
19
  import { ConfirmationProvider } from "./common"
21
20
  import { useMuffinAdminOpts } from "./hooks"
22
21
  import { buildProvider, muffinTranslations } from "./i18n"
@@ -8,18 +8,18 @@ import TableCell from "@mui/material/TableCell"
8
8
  import TableRow from "@mui/material/TableRow"
9
9
  import Typography from "@mui/material/Typography"
10
10
  import { useTranslate } from "react-admin"
11
- import { VERSION } from "."
12
11
  import { HelpLink } from "./common/HelpLink"
13
12
  import { useMuffinAdminOpts } from "./hooks"
14
- import { AdminDashboardBlock } from "./types"
13
+ import type { AdminDashboardBlock } from "./types"
15
14
  import { buildAdmin, setupAdmin } from "./utils"
15
+ import { VERSION } from "./version"
16
16
 
17
17
  export function MuffinDashboard() {
18
18
  const { dashboard, help } = useMuffinAdminOpts()
19
19
  const translate = useTranslate()
20
20
  return (
21
- <Stack gap={2} pt={1}>
22
- <Stack direction="row" flexWrap="wrap" gap={1}>
21
+ <Stack sx={{ gap: 2, pt: 1 }}>
22
+ <Stack direction="row" sx={{ flexWrap: "wrap", gap: 1 }}>
23
23
  {help && <HelpLink href={help} label={translate("muffin.how_to_use_admin")} />}
24
24
  {buildAdmin(["dashboard-actions"])}
25
25
  </Stack>
@@ -28,7 +28,7 @@ export function MuffinDashboard() {
28
28
  <AdminCards src={dashboard} />
29
29
  </Grid>
30
30
  {VERSION && (
31
- <Typography variant="body2" color="textSecondary" align="center" my={1}>
31
+ <Typography variant="body2" color="textSecondary" align="center" sx={{ my: 1 }}>
32
32
  Muffin Admin v.{VERSION}
33
33
  </Typography>
34
34
  )}
@@ -57,7 +57,7 @@ function DashboardCard({ title, value }: AdminDashboardBlock) {
57
57
  return (
58
58
  <Card>
59
59
  <CardContent>
60
- <Typography variant="h5" component="h2" m={2} style={{ textAlign: "center" }}>
60
+ <Typography variant="h5" component="h2" sx={{ m: 2, textAlign: "center" }}>
61
61
  {title}
62
62
  </Typography>
63
63
  {(Array.isArray(value) && <AdminTableView src={value} />) || (
@@ -4,15 +4,13 @@ import Collapse from "@mui/material/Collapse"
4
4
  import ListItemButton from "@mui/material/ListItemButton"
5
5
  import ListItemIcon from "@mui/material/ListItemIcon"
6
6
  import ListItemText from "@mui/material/ListItemText"
7
- import { matchPath, useLocation } from "react-router-dom"
8
-
9
- import { Menu, MenuProps, useBasename, useTheme, useTranslate } from "react-admin"
10
-
11
7
  import find from "lodash/find"
12
8
  import groupBy from "lodash/groupBy"
13
9
  import { useContext, useState } from "react"
10
+ import { Menu, type MenuProps, useBasename, useTheme, useTranslate } from "react-admin"
11
+ import { matchPath, useLocation } from "react-router-dom"
14
12
  import { MuffinAdminContext } from "./context"
15
- import { AdminResourceProps } from "./types"
13
+ import type { AdminResourceProps } from "./types"
16
14
  import { findIcon, setupAdmin } from "./utils"
17
15
 
18
16
  export function MuffinMenu(props: MenuProps) {
@@ -1,6 +1,6 @@
1
1
  import Box from "@mui/material/Box"
2
2
  import Typography from "@mui/material/Typography"
3
- import { Datagrid, SortPayload, useGetList, useRecordContext, useTranslate } from "react-admin"
3
+ import { Datagrid, type SortPayload, useGetList, useRecordContext, useTranslate } from "react-admin"
4
4
  import { useMuffinResourceOpts } from "./hooks"
5
5
  import { buildAdmin } from "./utils"
6
6
 
@@ -17,7 +17,7 @@ export function MuffinRecordList({ resource, filter, sort }: TProps) {
17
17
  } = useMuffinResourceOpts(resource)
18
18
  const { data, isPending } = useGetList(resource, { sort, filter: filter(record) })
19
19
  return (
20
- <Box p={2}>
20
+ <Box sx={{ p: 2 }}>
21
21
  <Typography variant="h6">
22
22
  {translate(`resources.${resource}.name`, { smart_count: 2 })}
23
23
  </Typography>
@@ -1,4 +1,4 @@
1
- import { Resource, ResourceProps } from "react-admin"
1
+ import { Resource, type ResourceProps } from "react-admin"
2
2
  import { useMuffinAdminOpts } from "./hooks"
3
3
  import { findBuilder, findIcon, setupAdmin } from "./utils"
4
4
 
@@ -1,4 +1,4 @@
1
- import { PropsWithChildren } from "react"
1
+ import type { PropsWithChildren } from "react"
2
2
  import { Create, ListButton, SimpleForm, TopToolbar } from "react-admin"
3
3
  import { buildRA } from "./buildRA"
4
4
  import { useMuffinResourceOpts } from "./hooks"
@@ -1,5 +1,5 @@
1
1
  import { Box, Typography } from "@mui/material"
2
- import { PropsWithChildren } from "react"
2
+ import type { PropsWithChildren } from "react"
3
3
  import {
4
4
  DeleteButton,
5
5
  Edit,
@@ -1,13 +1,12 @@
1
1
  import sortBy from "lodash/sortBy"
2
2
  import uniq from "lodash/uniq"
3
- import { PropsWithChildren } from "react"
3
+ import type { PropsWithChildren } from "react"
4
4
  import {
5
5
  BulkDeleteButton,
6
6
  BulkExportButton,
7
7
  CreateButton,
8
8
  DatagridConfigurable,
9
9
  EditButton,
10
- ExportButton,
11
10
  FilterButton,
12
11
  InfiniteList,
13
12
  List,
@@ -20,7 +19,7 @@ import { buildRA, buildRAComponent } from "./buildRA"
20
19
  import { BulkActionButton, ListActionButton } from "./buttons"
21
20
  import { HelpLink } from "./common/HelpLink"
22
21
  import { useMuffinResourceOpts } from "./hooks"
23
- import { AdminInput } from "./types"
22
+ import type { AdminInput } from "./types"
24
23
  import { buildAdmin, findBuilder, setupAdmin } from "./utils"
25
24
 
26
25
  export function MuffinList({ children }: PropsWithChildren) {
@@ -119,7 +118,6 @@ function MuffinListToolbar() {
119
118
  list: { create },
120
119
  } = useMuffinResourceOpts()
121
120
  const actions = baseActions.filter((a) => a.view?.includes("list"))
122
- const hasExport = actions.some((a) => a.id === "export")
123
121
  return (
124
122
  <TopToolbar>
125
123
  {help && <HelpLink href={help} />}
@@ -129,7 +127,6 @@ function MuffinListToolbar() {
129
127
  {actions.length
130
128
  ? actions.map((props) => <ListActionButton key={props.id} {...props} />)
131
129
  : null}
132
- {!hasExport && <ExportButton />}
133
130
  </TopToolbar>
134
131
  )
135
132
  }
@@ -1,5 +1,5 @@
1
1
  import { Box, Typography } from "@mui/material"
2
- import { PropsWithChildren } from "react"
2
+ import type { PropsWithChildren } from "react"
3
3
  import {
4
4
  EditButton,
5
5
  ListButton,
@@ -1,7 +1,7 @@
1
1
  import { useRecordContext, useResourceContext } from "react-admin"
2
2
  import LinkButton from "../buttons/LinkButton"
3
3
  import { useMuffinAdminOpts } from "../hooks"
4
- import { AdminShowLink } from "../types"
4
+ import type { AdminShowLink } from "../types"
5
5
 
6
6
  export function LinkAction({
7
7
  field,
@@ -1,107 +1,94 @@
1
- import Cookies from "js-cookie";
2
- import { findBuilder, makeRequest, requestHeaders, setupAdmin } from ".";
3
- import type { AdminOpts } from "./types";
1
+ import Cookies from "js-cookie"
2
+ import type { AdminOpts } from "./types"
3
+ import { findBuilder, makeRequest, requestHeaders, setupAdmin } from "./utils"
4
4
 
5
5
  setupAdmin(
6
- ["auth-storage-get"],
7
- ({ storage, storageName }: AdminOpts["auth"]) =>
8
- () =>
9
- storage == "localstorage"
10
- ? localStorage.getItem(storageName)
11
- : Cookies.get(storageName),
12
- );
13
-
14
- setupAdmin(
15
- ["auth-storage-set"],
16
- ({ storage }) =>
17
- (name, value, requestOnly) => {
18
- if (storage == "localstorage") {
19
- localStorage.setItem(name, value);
20
- requestHeaders["Authorization"] = value;
21
- } else Cookies.set(name, value);
22
- },
23
- );
6
+ ["auth-storage-get"],
7
+ ({ storage, storageName }: AdminOpts["auth"]) =>
8
+ () =>
9
+ storage == "localstorage" ? localStorage.getItem(storageName) : Cookies.get(storageName)
10
+ )
11
+
12
+ setupAdmin(["auth-storage-set"], ({ storage }) => (name, value, _requestOnly) => {
13
+ if (storage == "localstorage") {
14
+ localStorage.setItem(name, value)
15
+ requestHeaders.Authorization = value
16
+ } else Cookies.set(name, value)
17
+ })
24
18
 
25
19
  export function MuffinAuthProvider(props: AdminOpts["auth"]) {
26
- const {
27
- identityURL,
28
- authorizeURL,
29
- logoutURL,
30
- required,
31
- storageName,
32
- storage,
33
- } = props;
34
-
35
- const authGet = findBuilder(["auth-storage-get"])(props);
36
- const authSet = findBuilder(["auth-storage-set"])(props);
37
-
38
- // Initialize request headers
39
- if (storage == "localstorage") {
40
- const token = authGet(storageName);
41
- if (token) requestHeaders["Authorization"] = token;
42
- }
43
-
44
- const getIdentity = async () => {
45
- if (identityURL) {
46
- const { json } = await makeRequest(identityURL);
47
- return json;
48
- }
49
- };
50
-
51
- if (required)
52
- return {
53
- login: async (data) => {
54
- if (!authorizeURL) throw { message: "Authorization is not supported" };
55
-
56
- const { json } = await makeRequest(authorizeURL, {
57
- data,
58
- method: "POST",
59
- });
60
- authSet(storageName, json);
61
- },
62
-
63
- checkError: async (error) => {
64
- const { status } = error || {};
65
-
66
- if (status == 401 || status == 403) {
67
- // Clean storage
68
- authSet(storageName, "");
69
-
70
- throw {
71
- message: "Invalid authorization",
72
- redirectTo: logoutURL,
73
- logoutUser: !logoutURL,
74
- };
75
- }
76
- },
77
-
78
- checkAuth: async () => {
79
- const auth = authGet(storageName);
80
- if (!auth) throw { message: "Authorization required" };
81
-
82
- if (!identityURL) return auth;
83
-
84
- const user = await getIdentity();
85
- if (!user) throw { message: "Authorization required" };
86
-
87
- return user;
88
- },
89
-
90
- getAuthorization: () => authGet(storageName),
91
-
92
- logout: async () => {
93
- // Clean storage
94
- authSet(storageName, "");
95
- if (logoutURL) window.location.href = logoutURL;
96
- },
97
-
98
- getIdentity,
99
-
100
- getPermissions: async () => {
101
- const role = authGet(storageName + "_role");
102
- return role || "";
103
- },
104
- };
20
+ const { identityURL, authorizeURL, logoutURL, required, storageName, storage } = props
21
+
22
+ const authGet = findBuilder(["auth-storage-get"])(props)
23
+ const authSet = findBuilder(["auth-storage-set"])(props)
24
+
25
+ // Initialize request headers
26
+ if (storage == "localstorage") {
27
+ const token = authGet(storageName)
28
+ if (token) requestHeaders.Authorization = token
29
+ }
30
+
31
+ const getIdentity = async () => {
32
+ if (identityURL) {
33
+ const { json } = await makeRequest(identityURL)
34
+ return json
35
+ }
36
+ }
37
+
38
+ if (required)
39
+ return {
40
+ login: async (data) => {
41
+ if (!authorizeURL) throw { message: "Authorization is not supported" }
42
+
43
+ const { json } = await makeRequest(authorizeURL, {
44
+ data,
45
+ method: "POST",
46
+ })
47
+ authSet(storageName, json)
48
+ },
49
+
50
+ checkError: async (error) => {
51
+ const { status } = error || {}
52
+
53
+ if (status == 401 || status == 403) {
54
+ // Clean storage
55
+ authSet(storageName, "")
56
+
57
+ throw {
58
+ message: "Invalid authorization",
59
+ redirectTo: logoutURL,
60
+ logoutUser: !logoutURL,
61
+ }
62
+ }
63
+ },
64
+
65
+ checkAuth: async () => {
66
+ const auth = authGet(storageName)
67
+ if (!auth) throw { message: "Authorization required" }
68
+
69
+ if (!identityURL) return auth
70
+
71
+ const user = await getIdentity()
72
+ if (!user) throw { message: "Authorization required" }
73
+
74
+ return user
75
+ },
76
+
77
+ getAuthorization: () => authGet(storageName),
78
+
79
+ logout: async () => {
80
+ // Clean storage
81
+ authSet(storageName, "")
82
+ if (logoutURL) window.location.href = logoutURL
83
+ },
84
+
85
+ getIdentity,
86
+
87
+ getPermissions: async () => {
88
+ const role = authGet(`${storageName}_role`)
89
+ return role || ""
90
+ },
91
+ }
105
92
  }
106
93
 
107
- setupAdmin(["auth-provider"], MuffinAuthProvider);
94
+ setupAdmin(["auth-provider"], MuffinAuthProvider)