muffin-admin 11.8.0 → 13.0.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 (99) 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 +36 -4
  13. package/dist/MuffinResourceList.d.ts +2 -2
  14. package/dist/MuffinResourceList.js +10 -5
  15. package/dist/MuffinResourceShow.d.ts +5 -5
  16. package/dist/MuffinResourceShow.js +43 -6
  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/buttons/LinkButton.js +8 -2
  26. package/dist/common/AdminModal.d.ts +6 -4
  27. package/dist/common/AdminModal.js +2 -2
  28. package/dist/common/ConfirmationProvider.d.ts +2 -2
  29. package/dist/common/ConfirmationProvider.js +1 -1
  30. package/dist/common/HelpLink.d.ts +1 -1
  31. package/dist/common/PayloadButtons.d.ts +1 -1
  32. package/dist/common/PayloadButtons.js +1 -1
  33. package/dist/context.d.ts +1 -1
  34. package/dist/dataprovider.d.ts +7 -7
  35. package/dist/fields/AvatarField.d.ts +3 -3
  36. package/dist/fields/AvatarField.js +2 -2
  37. package/dist/fields/CopyField.d.ts +1 -1
  38. package/dist/fields/EditableBooleanField.d.ts +1 -1
  39. package/dist/fields/FKField.d.ts +4 -4
  40. package/dist/fields/FKField.js +12 -2
  41. package/dist/fields/JsonField.d.ts +1 -1
  42. package/dist/filters/DateRangeFilter.d.ts +1 -1
  43. package/dist/filters/Filter.d.ts +2 -2
  44. package/dist/filters/Filter.js +2 -2
  45. package/dist/filters/SearchFilter.d.ts +2 -2
  46. package/dist/filters/SearchFilter.js +6 -4
  47. package/dist/hooks/useAction.d.ts +2 -2
  48. package/dist/hooks/useAction.js +2 -2
  49. package/dist/i18n/en.d.ts +1 -1
  50. package/dist/i18n/provider.d.ts +3 -3
  51. package/dist/i18n/ru.d.ts +1 -1
  52. package/dist/index.d.ts +11 -11
  53. package/dist/index.js +12 -12
  54. package/dist/inputs/DateRangeInput.d.ts +2 -2
  55. package/dist/inputs/FKInput.d.ts +2 -2
  56. package/dist/inputs/ImgInput.d.ts +2 -2
  57. package/dist/inputs/JsonInput.d.ts +1 -1
  58. package/dist/inputs/JsonInput.js +1 -1
  59. package/dist/inputs/TimestampInput.d.ts +2 -2
  60. package/dist/utils.d.ts +2 -2
  61. package/dist/utils.js +1 -0
  62. package/dist/version.d.ts +1 -0
  63. package/dist/version.js +1 -0
  64. package/dist/web.js +0 -1
  65. package/package.json +15 -29
  66. package/src/MuffinAdmin.tsx +6 -7
  67. package/src/MuffinDashboard.tsx +6 -6
  68. package/src/MuffinMenu.tsx +3 -5
  69. package/src/MuffinRecordList.tsx +2 -2
  70. package/src/MuffinResource.tsx +1 -1
  71. package/src/MuffinResourceCreate.tsx +1 -1
  72. package/src/MuffinResourceEdit.tsx +73 -12
  73. package/src/MuffinResourceList.tsx +17 -6
  74. package/src/MuffinResourceShow.tsx +93 -15
  75. package/src/actions/LinkAction.tsx +1 -1
  76. package/src/authprovider.ts +88 -101
  77. package/src/buildRA.tsx +4 -3
  78. package/src/buttons/ActionButton.tsx +9 -10
  79. package/src/buttons/LinkButton.tsx +11 -3
  80. package/src/common/AdminModal.tsx +8 -5
  81. package/src/common/ConfirmationProvider.tsx +1 -1
  82. package/src/common/PayloadButtons.tsx +1 -1
  83. package/src/context.ts +1 -1
  84. package/src/dataprovider.ts +2 -2
  85. package/src/fields/AvatarField.tsx +8 -10
  86. package/src/fields/FKField.tsx +14 -2
  87. package/src/filters/Filter.tsx +2 -2
  88. package/src/filters/SearchFilter.tsx +14 -7
  89. package/src/globals.d.ts +1 -0
  90. package/src/hooks/useAction.ts +4 -4
  91. package/src/i18n/en.ts +1 -1
  92. package/src/i18n/ru.ts +1 -1
  93. package/src/index.tsx +12 -13
  94. package/src/inputs/DateRangeInput.tsx +1 -1
  95. package/src/inputs/JsonInput.tsx +1 -1
  96. package/src/utils.tsx +2 -1
  97. package/src/version.ts +1 -0
  98. package/src/web.ts +0 -1
  99. package/dist/tsconfig.tsbuildinfo +0 -1
@@ -1,11 +1,13 @@
1
- import { Dialog, DialogActions, DialogContent, DialogProps, DialogTitle } from "@mui/material"
2
- import { PropsWithChildren } from "react"
1
+ import { Dialog, DialogActions, DialogContent, type DialogProps, DialogTitle } from "@mui/material"
2
+ import type { SxProps, Theme } from "@mui/material/styles"
3
+ import type { PropsWithChildren } from "react"
3
4
 
4
- interface IProps {
5
+ interface IProps extends Omit<DialogProps, "title" | "open" | "onClose"> {
5
6
  open: boolean
6
7
  onClose: () => void
7
8
  title?: React.ReactNode
8
9
  actions?: React.ReactNode
10
+ contentSx?: SxProps<Theme>
9
11
  }
10
12
 
11
13
  export function AdminModal({
@@ -14,12 +16,13 @@ export function AdminModal({
14
16
  children,
15
17
  title,
16
18
  actions,
19
+ contentSx,
17
20
  ...props
18
- }: PropsWithChildren<IProps & DialogProps>) {
21
+ }: PropsWithChildren<IProps>) {
19
22
  return (
20
23
  <Dialog open={open} onClose={onClose} fullWidth maxWidth="md" {...props}>
21
24
  {title && <DialogTitle>{title}</DialogTitle>}
22
- <DialogContent>{children}</DialogContent>
25
+ <DialogContent sx={contentSx}>{children}</DialogContent>
23
26
  {actions && <DialogActions>{actions}</DialogActions>}
24
27
  </Dialog>
25
28
  )
@@ -1,5 +1,5 @@
1
1
  import { Button, Typography } from "@mui/material"
2
- import { createContext, PropsWithChildren, useContext, useState } from "react"
2
+ import { createContext, type PropsWithChildren, useContext, useState } from "react"
3
3
  import { useTranslate } from "react-admin"
4
4
  import { AdminModal } from "./AdminModal"
5
5
 
@@ -11,7 +11,7 @@ export function PayloadButtons({
11
11
  isValid: boolean
12
12
  }) {
13
13
  return (
14
- <Stack direction="row" alignItems="center" justifyContent="flex-end" spacing={1}>
14
+ <Stack direction="row" spacing={1} sx={{ alignItems: "center", justifyContent: "flex-end" }}>
15
15
  <Button
16
16
  label="ra.action.confirm"
17
17
  variant="contained"
package/src/context.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { createContext } from "react"
2
- import { AdminOpts } from "./types"
2
+ import type { AdminOpts } from "./types"
3
3
 
4
4
  export const MuffinAdminContext = createContext<AdminOpts>(null)
@@ -1,5 +1,5 @@
1
- import { TID } from "./types"
2
- import { APIParams, makeRequest, prepareFilters, setupAdmin } from "./utils"
1
+ import type { TID } from "./types"
2
+ import { type APIParams, makeRequest, prepareFilters, setupAdmin } from "./utils"
3
3
 
4
4
  type TQueryMeta = {
5
5
  key?: string
@@ -5,28 +5,26 @@ import { useRecordContext } from "ra-core"
5
5
 
6
6
  export function AvatarField({ source, alt, style, nameProp, ...props }) {
7
7
  const record = useRecordContext(props)
8
- let value = get(record, source),
8
+ const value = get(record, source),
9
9
  name = record[nameProp]
10
10
 
11
11
  // Check value is a valid URL
12
12
  if (value) {
13
13
  try {
14
- new URL(value);
14
+ new URL(value)
15
15
  } catch {
16
16
  // Not a valid URL, return loader
17
- return (
18
- <CircularProgress size={24} />
19
- )
17
+ return <CircularProgress size={24} />
20
18
  }
21
19
  }
22
20
 
23
21
  const letters = name
24
22
  ? name
25
- .trim(" ")
26
- .split(/\s+/)
27
- .slice(0, 2)
28
- .map((n: string) => n[0]?.toUpperCase())
29
- .join("")
23
+ .trim(" ")
24
+ .split(/\s+/)
25
+ .slice(0, 2)
26
+ .map((n: string) => n[0]?.toUpperCase())
27
+ .join("")
30
28
  : ""
31
29
 
32
30
  return (
@@ -1,11 +1,23 @@
1
- import { ReferenceField, TextField, useFieldValue, UseFieldValueOptions } from "react-admin"
1
+ import { ReferenceField, TextField, type UseFieldValueOptions, useFieldValue } from "react-admin"
2
+ import { useLocation } from "react-router-dom"
2
3
 
3
4
  export function FKField({ reference, refSource, refKey, link, source, ...props }) {
5
+ const location = useLocation()
4
6
  refKey = refKey || "id"
7
+ const returnTo = `${location.pathname}${location.search}`
8
+
9
+ const resolveLink =
10
+ link ||
11
+ ((record) => {
12
+ const id = record?.[refKey]
13
+ if (id === undefined || id === null) return false
14
+ return `/${reference}/${id}/show?returnTo=${encodeURIComponent(returnTo)}`
15
+ })
16
+
5
17
  return (
6
18
  <ReferenceField
7
19
  source={source}
8
- link={link || "show"}
20
+ link={resolveLink}
9
21
  reference={reference}
10
22
  queryOptions={{ meta: { key: refKey } }}
11
23
  {...props}
@@ -4,7 +4,7 @@ import Menu from "@mui/material/Menu"
4
4
  import MenuItem from "@mui/material/MenuItem"
5
5
  import TextField from "@mui/material/TextField"
6
6
  import { useState } from "react"
7
- import { FieldTitle, InputProps, useInput } from "react-admin"
7
+ import { FieldTitle, type InputProps, useInput } from "react-admin"
8
8
 
9
9
  const OPERATORS = {
10
10
  $eq: "=",
@@ -22,7 +22,7 @@ export function Filter({ type = "text", ...props }: InputProps) {
22
22
  })
23
23
  const [op, setOp] = useState((field.value && Object.keys(field.value)[0]) || "$eq")
24
24
 
25
- const onChange = function(e: any) {
25
+ const onChange = (e: any) => {
26
26
  field.onChange({ [op]: e.target.value })
27
27
  }
28
28
 
@@ -4,7 +4,12 @@ import clsx from "clsx"
4
4
  import debounce from "lodash/debounce"
5
5
  import { useTranslate } from "ra-core"
6
6
  import { useState } from "react"
7
- import { ResettableTextField, SearchInputProps, useInput, useResourceContext } from "react-admin"
7
+ import {
8
+ ResettableTextField,
9
+ type SearchInputProps,
10
+ useInput,
11
+ useResourceContext,
12
+ } from "react-admin"
8
13
 
9
14
  export function SearchFilter({ source, className, ...props }: SearchInputProps) {
10
15
  const translate = useTranslate()
@@ -29,12 +34,14 @@ export function SearchFilter({ source, className, ...props }: SearchInputProps)
29
34
  }}
30
35
  {...props}
31
36
  className={clsx("ra-input", `ra-input-${source}`, className)}
32
- InputProps={{
33
- endAdornment: (
34
- <InputAdornment position="end">
35
- <SearchIcon color="disabled" />
36
- </InputAdornment>
37
- ),
37
+ slotProps={{
38
+ input: {
39
+ endAdornment: (
40
+ <InputAdornment position="end">
41
+ <SearchIcon color="disabled" />
42
+ </InputAdornment>
43
+ ),
44
+ },
38
45
  }}
39
46
  />
40
47
  )
@@ -0,0 +1 @@
1
+ declare module "*.css"
@@ -1,4 +1,4 @@
1
- import { UseMutationOptions, useMutation } from "@tanstack/react-query"
1
+ import { type UseMutationOptions, useMutation } from "@tanstack/react-query"
2
2
  import {
3
3
  useDataProvider,
4
4
  useNotify,
@@ -6,7 +6,7 @@ import {
6
6
  useResourceContext,
7
7
  useUnselectAll,
8
8
  } from "react-admin"
9
- import { MuffinDataprovider, TActionProps } from "../dataprovider"
9
+ import type { MuffinDataprovider, TActionProps } from "../dataprovider"
10
10
 
11
11
  export function useAction(
12
12
  action: string,
@@ -21,8 +21,8 @@ export function useAction(
21
21
  return useMutation({
22
22
  mutationFn: (params: TActionProps) => dataProvider.runAction(resource, action, params),
23
23
  onSuccess: ({ data }) => {
24
- if (data && data.message) notify(data.message, { type: "success" })
25
- if (data && data.redirectTo) window.location = data.redirectTo
24
+ if (data?.message) notify(data.message, { type: "success" })
25
+ if (data?.redirectTo) window.location = data.redirectTo
26
26
  else {
27
27
  unselectAll()
28
28
  refresh()
package/src/i18n/en.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TranslationMessages } from "ra-core"
1
+ import type { TranslationMessages } from "ra-core"
2
2
  import raEnglishMessages from "ra-language-english"
3
3
 
4
4
  const muffinEnglishMessages: TranslationMessages = {
package/src/i18n/ru.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TranslationMessages } from "ra-core"
1
+ import type { TranslationMessages } from "ra-core"
2
2
  import raRussianMessages from "ra-language-russian"
3
3
 
4
4
  const muffinRussianMessages = {
package/src/index.tsx CHANGED
@@ -1,18 +1,7 @@
1
1
  import { createRoot } from "react-dom/client"
2
- import { MuffinAdmin } from "./MuffinAdmin"
3
2
  import { MuffinAdminContext } from "./context"
3
+ import { MuffinAdmin } from "./MuffinAdmin"
4
4
 
5
- export * from "./utils"
6
-
7
- export * from "./MuffinAdmin"
8
- export * from "./MuffinDashboard"
9
- export * from "./MuffinMenu"
10
- export * from "./MuffinRecordList"
11
- export * from "./MuffinResource"
12
- export * from "./MuffinResourceCreate"
13
- export * from "./MuffinResourceEdit"
14
- export * from "./MuffinResourceList"
15
- export * from "./MuffinResourceShow"
16
5
  export * from "./actions"
17
6
  export * from "./authprovider"
18
7
  export * from "./buildRA"
@@ -22,7 +11,17 @@ export * from "./context"
22
11
  export * from "./dataprovider"
23
12
  export * from "./fields"
24
13
  export * from "./hooks"
14
+ export * from "./MuffinAdmin"
15
+ export * from "./MuffinDashboard"
16
+ export * from "./MuffinMenu"
17
+ export * from "./MuffinRecordList"
18
+ export * from "./MuffinResource"
19
+ export * from "./MuffinResourceCreate"
20
+ export * from "./MuffinResourceEdit"
21
+ export * from "./MuffinResourceList"
22
+ export * from "./MuffinResourceShow"
25
23
  export * from "./types"
24
+ export * from "./utils"
26
25
 
27
26
  export async function initAdmin(prefix = "", containerId: string = "root") {
28
27
  const response = await fetch(`${prefix}/ra.json`)
@@ -37,4 +36,4 @@ export async function initAdmin(prefix = "", containerId: string = "root") {
37
36
  )
38
37
  }
39
38
 
40
- export const VERSION = "11.8.0"
39
+ export { VERSION } from "./version"
@@ -1,6 +1,6 @@
1
1
  import TextField from "@mui/material/TextField"
2
2
  import { enGB, ru } from "date-fns/locale"
3
- import { FieldTitle, InputProps, useLocale } from "react-admin"
3
+ import { FieldTitle, type InputProps, useLocale } from "react-admin"
4
4
  import DatePicker, { registerLocale } from "react-datepicker"
5
5
  import "react-datepicker/dist/react-datepicker.css"
6
6
 
@@ -8,7 +8,7 @@ const parseFunction = (json) => {
8
8
  try {
9
9
  retval = JSON.parse(json)
10
10
  } finally {
11
- // eslint-disable-next-line no-unsafe-finally
11
+ // biome-ignore lint/correctness/noUnsafeFinally: intentional - return parsed value or original on error
12
12
  return retval
13
13
  }
14
14
  }
package/src/utils.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as icons from "@mui/icons-material"
2
2
  import { stringify } from "query-string"
3
3
  import { fetchUtils } from "ra-core"
4
- import { TAdminPath } from "./types"
4
+ import type { TAdminPath } from "./types"
5
5
 
6
6
  const builders = new Map<string, (props: any) => any>()
7
7
 
@@ -58,6 +58,7 @@ export function makeRequest(url: string, params: APIParams = {}) {
58
58
  }
59
59
 
60
60
  export function findIcon(icon?: string) {
61
+ // biome-ignore lint/performance/noDynamicNamespaceImportAccess: icons are looked up by name from admin config
61
62
  return icon ? icons[icon] : undefined
62
63
  }
63
64
 
package/src/version.ts ADDED
@@ -0,0 +1 @@
1
+ export const VERSION = "13.0.0"
package/src/web.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  import { initAdmin } from "."
2
2
 
3
- // @ts-ignore
4
3
  globalThis.initAdmin = initAdmin