muffin-admin 3.10.1 → 3.11.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.
package/dist/types.d.ts CHANGED
@@ -94,5 +94,6 @@ export type AdminOpts = {
94
94
  dashboard: AdminDashboardBlock[] | AdminDashboardBlock;
95
95
  resources: AdminResourceProps[];
96
96
  help?: string;
97
+ locales: Record<string, Record<string, any>>;
97
98
  version: string;
98
99
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "3.10.1",
3
+ "version": "3.11.1",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -16,14 +16,24 @@ import {
16
16
 
17
17
  import { ConfirmationProvider } from "./common"
18
18
  import { useMuffinAdminOpts } from "./hooks"
19
- import { muffinI18nProvider } from "./i18n"
19
+ import { buildProvider, muffinTranslations } from "./i18n"
20
20
  import { buildAdmin, findBuilder, findIcon, setupAdmin } from "./utils"
21
21
 
22
22
  export function MuffinAdmin(props: AdminProps) {
23
23
  const opts = useMuffinAdminOpts()
24
- const { resources = [], auth, adminProps, apiUrl } = opts
24
+ const { resources = [], auth, adminProps, apiUrl, locales: backendLocales } = opts
25
25
 
26
26
  document.title = adminProps?.title || "Muffin Admin"
27
+ const muffinI18nProvider = buildProvider(
28
+ backendLocales
29
+ ? Object.fromEntries(
30
+ Object.entries(muffinTranslations).map(([locale, messages]) => [
31
+ locale,
32
+ { ...messages, ...backendLocales[locale], ...(buildAdmin(["locale", locale]) || {}) },
33
+ ])
34
+ )
35
+ : muffinTranslations
36
+ )
27
37
 
28
38
  const {
29
39
  basename,
@@ -11,20 +11,17 @@ import { useTranslate } from "react-admin"
11
11
  import { HelpLink } from "./common/HelpLink"
12
12
  import { useMuffinAdminOpts } from "./hooks"
13
13
  import { AdminDashboardBlock } from "./types"
14
- import { setupAdmin } from "./utils"
14
+ import { buildAdmin, setupAdmin } from "./utils"
15
15
 
16
16
  export function MuffinDashboard() {
17
17
  const { dashboard, help } = useMuffinAdminOpts()
18
18
  const translate = useTranslate()
19
19
  return (
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
- )}
20
+ <Stack gap={2} pt={1}>
21
+ <Stack direction="row">
22
+ {help && <HelpLink size="large" href={help} label={translate("muffin.how_to_use_admin")} />}
23
+ {buildAdmin(["dashboard-actions"])}
24
+ </Stack>
28
25
  <Grid container spacing={1}>
29
26
  <AdminCards src={dashboard} />
30
27
  </Grid>
@@ -1,3 +1,4 @@
1
1
  export * from "./useAction"
2
+ export * from "./useForceUpdate"
2
3
  export * from "./useMuffinAdminOpts"
3
4
  export * from "./useMuffinResourceOpts"
@@ -0,0 +1,6 @@
1
+ import { useState } from "react"
2
+
3
+ export function useForceUpdate() {
4
+ const [, setTick] = useState(0)
5
+ return () => setTick((tick) => tick + 1)
6
+ }
package/src/i18n/en.ts CHANGED
@@ -1,4 +1,8 @@
1
- const muffinEnglishMessages = {
1
+ import { TranslationMessages } from "ra-core"
2
+ import raEnglishMessages from "ra-language-english"
3
+
4
+ const muffinEnglishMessages: TranslationMessages = {
5
+ ...raEnglishMessages,
2
6
  muffin: {
3
7
  instructions: "Instructions",
4
8
  how_to_use_admin: "How to use Admin?",
package/src/i18n/index.ts CHANGED
@@ -1 +1,3 @@
1
+ export * from "./en"
1
2
  export * from "./provider"
3
+ export * from "./ru"
@@ -1,21 +1,23 @@
1
1
  import polyglotI18nProvider from "ra-i18n-polyglot"
2
- import raEnglishMessages from "ra-language-english"
3
- import raRussianMessages from "ra-language-russian"
4
2
  import { resolveBrowserLocale } from "react-admin"
5
3
  import muffinEnglishMessages from "./en"
6
4
  import muffinRussianMessages from "./ru"
7
5
 
8
- const translations = {
9
- en: { ...raEnglishMessages, ...muffinEnglishMessages },
10
- ru: { ...raRussianMessages, ...muffinRussianMessages },
6
+ export const muffinTranslations = {
7
+ en: muffinEnglishMessages,
8
+ ru: muffinRussianMessages,
11
9
  }
12
10
 
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
- )
11
+ const defaultLocale = "en"
12
+
13
+ export const buildProvider = (translations) => {
14
+ return polyglotI18nProvider(
15
+ (locale) => (translations[locale] ? translations[locale] : translations[defaultLocale]),
16
+ resolveBrowserLocale(),
17
+ [
18
+ { locale: "en", name: "English" },
19
+ { locale: "ru", name: "Русский" },
20
+ ],
21
+ { allowMissing: true }
22
+ )
23
+ }
package/src/i18n/ru.ts CHANGED
@@ -1,4 +1,8 @@
1
- const muffinRussianMessages = {
1
+ import { TranslationMessages } from "ra-core"
2
+ import raRussianMessages from "ra-language-russian"
3
+
4
+ const muffinRussianMessages: TranslationMessages = {
5
+ ...raRussianMessages,
2
6
  muffin: {
3
7
  instructions: "Инструкции",
4
8
  how_to_use_admin: "Как использовать админку?",
package/src/types.ts CHANGED
@@ -15,7 +15,7 @@ export type AdminAction = {
15
15
  }
16
16
 
17
17
  export type AdminField = [string, { source: string }]
18
- export type AdminInput = [string, { required: boolean; source: string;[key: string]: any }]
18
+ export type AdminInput = [string, { required: boolean; source: string; [key: string]: any }]
19
19
 
20
20
  export type AdminShowLink = {
21
21
  label: string
@@ -46,11 +46,11 @@ export type AdminResourceProps = {
46
46
  actions: AdminAction[]
47
47
  create: AdminInput[] | false
48
48
  edit:
49
- | {
50
- inputs: AdminInput[]
51
- remove?: boolean
52
- }
53
- | false
49
+ | {
50
+ inputs: AdminInput[]
51
+ remove?: boolean
52
+ }
53
+ | false
54
54
  list: {
55
55
  limit: number
56
56
  limitMax: number
@@ -96,5 +96,6 @@ export type AdminOpts = {
96
96
  dashboard: AdminDashboardBlock[] | AdminDashboardBlock
97
97
  resources: AdminResourceProps[]
98
98
  help?: string
99
+ locales: Record<string, Record<string, any>>
99
100
  version: string
100
101
  }