muffin-admin 3.8.5 → 3.10.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/types.d.ts CHANGED
@@ -3,6 +3,7 @@ export type TProps = {
3
3
  };
4
4
  export type AdminAction = {
5
5
  view?: ("show" | "edit" | "list" | "bulk")[];
6
+ help?: string;
6
7
  id: string;
7
8
  label: string;
8
9
  title: string;
@@ -36,11 +37,13 @@ export type AdminPayloadProps = {
36
37
  onHandle: (payload?: any) => void;
37
38
  title?: string;
38
39
  schema?: AdminInput[];
40
+ help?: string;
39
41
  };
40
42
  export type AdminResourceProps = {
41
43
  name: string;
42
44
  icon?: string;
43
45
  label: string;
46
+ help?: string;
44
47
  actions: AdminAction[];
45
48
  create: AdminInput[] | false;
46
49
  edit: {
@@ -90,5 +93,6 @@ export type AdminOpts = {
90
93
  };
91
94
  dashboard: AdminDashboardBlock[] | AdminDashboardBlock;
92
95
  resources: AdminResourceProps[];
96
+ help?: string;
93
97
  version: string;
94
98
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "3.8.5",
3
+ "version": "3.10.0",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -24,6 +24,7 @@
24
24
  "homepage": "https://github.com/klen/muffin-admin#readme",
25
25
  "dependencies": {
26
26
  "js-cookie": "^3.0.5",
27
+ "ra-language-russian": "^4.14.2",
27
28
  "react": "^18.3.1",
28
29
  "react-admin": "^5.0.3",
29
30
  "react-dom": "^18.3.1",
@@ -8,7 +8,6 @@ import {
8
8
  AdminUI,
9
9
  AppBar,
10
10
  AppBarProps,
11
- defaultI18nProvider,
12
11
  Layout,
13
12
  LayoutProps,
14
13
  localStorageStore,
@@ -17,6 +16,7 @@ import {
17
16
 
18
17
  import { ConfirmationProvider } from "./common"
19
18
  import { useMuffinAdminOpts } from "./hooks"
19
+ import { muffinI18nProvider } from "./i18n"
20
20
  import { buildAdmin, findBuilder, findIcon, setupAdmin } from "./utils"
21
21
 
22
22
  export function MuffinAdmin(props: AdminProps) {
@@ -33,7 +33,7 @@ export function MuffinAdmin(props: AdminProps) {
33
33
  dashboard = findBuilder(["dashboard"]),
34
34
  disableTelemetry,
35
35
  error,
36
- i18nProvider = defaultI18nProvider,
36
+ i18nProvider = muffinI18nProvider,
37
37
  layout = findBuilder(["layout"]),
38
38
  loading,
39
39
  loginPage = findBuilder(["loginpage"]),
@@ -1,21 +1,34 @@
1
1
  import Card from "@mui/material/Card"
2
2
  import CardContent from "@mui/material/CardContent"
3
3
  import Grid from "@mui/material/Grid"
4
+ import Stack from "@mui/material/Stack"
4
5
  import Table from "@mui/material/Table"
5
6
  import TableBody from "@mui/material/TableBody"
6
7
  import TableCell from "@mui/material/TableCell"
7
8
  import TableRow from "@mui/material/TableRow"
8
9
  import Typography from "@mui/material/Typography"
10
+ import { useTranslate } from "react-admin"
11
+ import { HelpLink } from "./common/HelpLink"
9
12
  import { useMuffinAdminOpts } from "./hooks"
10
13
  import { AdminDashboardBlock } from "./types"
11
14
  import { setupAdmin } from "./utils"
12
15
 
13
16
  export function MuffinDashboard() {
14
- const { dashboard } = useMuffinAdminOpts()
17
+ const { dashboard, help } = useMuffinAdminOpts()
18
+ const translate = useTranslate()
15
19
  return (
16
- <Grid container spacing={1}>
17
- <AdminCards src={dashboard} />
18
- </Grid>
20
+ <Stack gap={2}>
21
+ {help && (
22
+ <Card>
23
+ <CardContent>
24
+ <HelpLink size="large" href={help} label={translate("muffin.how_to_use_admin")} />
25
+ </CardContent>
26
+ </Card>
27
+ )}
28
+ <Grid container spacing={1}>
29
+ <AdminCards src={dashboard} />
30
+ </Grid>
31
+ </Stack>
19
32
  )
20
33
  }
21
34
 
@@ -15,6 +15,7 @@ import {
15
15
  } from "react-admin"
16
16
  import { buildRA } from "./buildRA"
17
17
  import { ActionButton, BulkActionButton } from "./buttons"
18
+ import { HelpLink } from "./common/HelpLink"
18
19
  import { useMuffinResourceOpts } from "./hooks"
19
20
  import { buildAdmin, findBuilder, setupAdmin } from "./utils"
20
21
 
@@ -73,12 +74,14 @@ setupAdmin(["list-grid-buttons"], MuffinListGridButtons)
73
74
  function MuffinListToolbar() {
74
75
  const {
75
76
  actions: baseActions = [],
77
+ help,
76
78
  list: { create },
77
79
  } = useMuffinResourceOpts()
78
80
  const actions = baseActions.filter((a) => a.view.includes("list"))
79
81
  return (
80
82
  <TopToolbar>
81
83
  <SelectColumnsButton />
84
+ {help && <HelpLink href={help} />}
82
85
  <FilterButton />
83
86
  {actions.length ? actions.map((props) => <ActionButton key={props.id} {...props} />) : null}
84
87
  {create && <CreateButton />}
@@ -9,9 +9,11 @@ import {
9
9
  } from "react-admin"
10
10
  import { FormProvider } from "react-hook-form"
11
11
 
12
+ import { Stack } from "@mui/material"
12
13
  import { useState } from "react"
13
14
  import { buildRA } from "../buildRA"
14
15
  import { AdminModal, PayloadButtons, useConfirmation } from "../common"
16
+ import { HelpLink } from "../common/HelpLink"
15
17
  import { useAction } from "../hooks/useAction"
16
18
  import { AdminAction, AdminPayloadProps } from "../types"
17
19
  import { buildIcon, findBuilder } from "../utils"
@@ -66,6 +68,7 @@ function ActionButtonBase({
66
68
  icon,
67
69
  schema,
68
70
  id,
71
+ help,
69
72
  }: Omit<AdminAction, "paths"> & {
70
73
  isPending?: boolean
71
74
  onHandle: (payload?: any) => void
@@ -96,13 +99,21 @@ function ActionButtonBase({
96
99
  onClose={() => setPayloadActive(false)}
97
100
  title={title || label}
98
101
  schema={schema}
102
+ help={help}
99
103
  />
100
104
  )}
101
105
  </>
102
106
  )
103
107
  }
104
108
 
105
- export function CommonPayload({ active, onClose, onHandle, schema, title }: AdminPayloadProps) {
109
+ export function CommonPayload({
110
+ active,
111
+ onClose,
112
+ onHandle,
113
+ schema,
114
+ title,
115
+ help,
116
+ }: AdminPayloadProps) {
106
117
  schema[0][1] = { ...schema[0][1], autoFocus: true }
107
118
  const inputs = buildRA(schema)
108
119
  const translate = useTranslate()
@@ -122,7 +133,16 @@ export function CommonPayload({ active, onClose, onHandle, schema, title }: Admi
122
133
  maxWidth="sm"
123
134
  open={active}
124
135
  onClose={onClose}
125
- title={translate(title, { _: title })}
136
+ title={
137
+ help
138
+ ? ((
139
+ <Stack alignItems="flex-start">
140
+ <span>{translate(title, { _: title })}</span>
141
+ <HelpLink href={help} style={{ alignSelf: "flex-end" }} />
142
+ </Stack>
143
+ ) as any)
144
+ : translate(title, { _: title })
145
+ }
126
146
  actions={
127
147
  <PayloadButtons
128
148
  onClose={onClose}
@@ -0,0 +1,13 @@
1
+ import HelpIcon from "@mui/icons-material/Help"
2
+ import Link from "@mui/material/Link"
3
+ import { Button, useTranslate } from "react-admin"
4
+
5
+ export function HelpLink({ label, ...props }: Parameters<typeof Button>[0]) {
6
+ const translate = useTranslate()
7
+ label = label || translate("muffin.instructions")
8
+ return (
9
+ <Button component={Link} label={label} target="_blank" {...props}>
10
+ <HelpIcon />
11
+ </Button>
12
+ )
13
+ }
package/src/i18n/en.ts ADDED
@@ -0,0 +1,8 @@
1
+ const muffinEnglishMessages = {
2
+ muffin: {
3
+ instructions: "Instructions",
4
+ how_to_use_admin: "How to use Admin?",
5
+ },
6
+ }
7
+
8
+ export default muffinEnglishMessages
package/src/i18n/index.ts CHANGED
@@ -0,0 +1 @@
1
+ export * from "./provider"
@@ -0,0 +1,21 @@
1
+ import polyglotI18nProvider from "ra-i18n-polyglot"
2
+ import raEnglishMessages from "ra-language-english"
3
+ import raRussianMessages from "ra-language-russian"
4
+ import { resolveBrowserLocale } from "react-admin"
5
+ import muffinEnglishMessages from "./en"
6
+ import muffinRussianMessages from "./ru"
7
+
8
+ const translations = {
9
+ en: { ...raEnglishMessages, ...muffinEnglishMessages },
10
+ ru: { ...raRussianMessages, ...muffinRussianMessages },
11
+ }
12
+
13
+ export const muffinI18nProvider = polyglotI18nProvider(
14
+ (locale) => (translations[locale] ? translations[locale] : translations.en),
15
+ resolveBrowserLocale(),
16
+ [
17
+ { locale: "en", name: "English" },
18
+ { locale: "ru", name: "Русский" },
19
+ ],
20
+ { allowMissing: true }
21
+ )
package/src/i18n/ru.ts ADDED
@@ -0,0 +1,8 @@
1
+ const muffinRussianMessages = {
2
+ muffin: {
3
+ instructions: "Инструкции",
4
+ how_to_use_admin: "Как использовать админку?",
5
+ },
6
+ }
7
+
8
+ export default muffinRussianMessages
package/src/types.ts CHANGED
@@ -4,6 +4,7 @@ export type TProps = {
4
4
 
5
5
  export type AdminAction = {
6
6
  view?: ("show" | "edit" | "list" | "bulk")[]
7
+ help?: string
7
8
  id: string
8
9
  label: string
9
10
  title: string
@@ -14,7 +15,7 @@ export type AdminAction = {
14
15
  }
15
16
 
16
17
  export type AdminField = [string, { source: string }]
17
- export type AdminInput = [string, { required: boolean; source: string; [key: string]: any }]
18
+ export type AdminInput = [string, { required: boolean; source: string;[key: string]: any }]
18
19
 
19
20
  export type AdminShowLink = {
20
21
  label: string
@@ -34,20 +35,22 @@ export type AdminPayloadProps = {
34
35
  onHandle: (payload?: any) => void
35
36
  title?: string
36
37
  schema?: AdminInput[]
38
+ help?: string
37
39
  }
38
40
 
39
41
  export type AdminResourceProps = {
40
42
  name: string
41
43
  icon?: string
42
44
  label: string
45
+ help?: string
43
46
  actions: AdminAction[]
44
47
  create: AdminInput[] | false
45
48
  edit:
46
- | {
47
- inputs: AdminInput[]
48
- remove?: boolean
49
- }
50
- | false
49
+ | {
50
+ inputs: AdminInput[]
51
+ remove?: boolean
52
+ }
53
+ | false
51
54
  list: {
52
55
  limit: number
53
56
  limitMax: number
@@ -92,5 +95,6 @@ export type AdminOpts = {
92
95
  }
93
96
  dashboard: AdminDashboardBlock[] | AdminDashboardBlock
94
97
  resources: AdminResourceProps[]
98
+ help?: string
95
99
  version: string
96
100
  }