muffin-admin 3.12.2 → 3.12.4

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/utils.d.ts CHANGED
@@ -23,3 +23,4 @@ export declare function makeRequest(url: string, params?: APIParams): Promise<{
23
23
  }>;
24
24
  export declare function findIcon(icon?: string): any;
25
25
  export declare function buildIcon(icon?: string): import("react/jsx-runtime").JSX.Element;
26
+ export declare function deepMerge(target: any, ...sources: any[]): any;
package/dist/utils.js CHANGED
@@ -55,3 +55,24 @@ export function buildIcon(icon) {
55
55
  if (Icon)
56
56
  return _jsx(Icon, {});
57
57
  }
58
+ function isObject(item) {
59
+ return item && typeof item === "object" && !Array.isArray(item);
60
+ }
61
+ export function deepMerge(target, ...sources) {
62
+ if (!sources.length)
63
+ return target;
64
+ const source = sources.shift();
65
+ if (isObject(target) && isObject(source)) {
66
+ for (const key in source) {
67
+ if (isObject(source[key])) {
68
+ if (!target[key])
69
+ Object.assign(target, { [key]: {} });
70
+ deepMerge(target[key], source[key]);
71
+ }
72
+ else {
73
+ Object.assign(target, { [key]: source[key] });
74
+ }
75
+ }
76
+ }
77
+ return deepMerge(target, ...sources);
78
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "3.12.2",
3
+ "version": "3.12.4",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -17,7 +17,7 @@ import {
17
17
  import { ConfirmationProvider } from "./common"
18
18
  import { useMuffinAdminOpts } from "./hooks"
19
19
  import { buildProvider, muffinTranslations } from "./i18n"
20
- import { buildAdmin, findBuilder, findIcon, setupAdmin } from "./utils"
20
+ import { buildAdmin, deepMerge, findBuilder, findIcon, setupAdmin } from "./utils"
21
21
 
22
22
  export function MuffinAdmin(props: AdminProps) {
23
23
  const opts = useMuffinAdminOpts()
@@ -29,7 +29,7 @@ export function MuffinAdmin(props: AdminProps) {
29
29
  ? Object.fromEntries(
30
30
  Object.entries(muffinTranslations).map(([locale, messages]) => [
31
31
  locale,
32
- { ...messages, ...backendLocales[locale], ...(buildAdmin(["locale", locale]) || {}) },
32
+ deepMerge({}, messages, backendLocales[locale], buildAdmin(["locale", locale]) || {}),
33
33
  ])
34
34
  )
35
35
  : muffinTranslations
@@ -3,7 +3,7 @@ import LinkButton from "../buttons/LinkButton"
3
3
  import { useMuffinAdminOpts } from "../hooks"
4
4
  import { AdminShowLink } from "../types"
5
5
 
6
- export function LinkAction({ field, icon, ...props }: AdminShowLink & { resource: string }) {
6
+ export function LinkAction({ field, icon, label, ...props }: AdminShowLink & { resource: string }) {
7
7
  const { resources } = useMuffinAdminOpts()
8
8
  const record = useRecordContext()
9
9
  const currentResource = useResourceContext()
@@ -15,6 +15,7 @@ export function LinkAction({ field, icon, ...props }: AdminShowLink & { resource
15
15
  <LinkButton
16
16
  {...props}
17
17
  icon={icon || resource?.icon}
18
+ label={label || `resources.${props.resource}.name`}
18
19
  filters={{ [currentResource]: encodeURIComponent(record[field || "id"]) }}
19
20
  />
20
21
  )
package/src/utils.tsx CHANGED
@@ -64,3 +64,24 @@ export function buildIcon(icon?: string) {
64
64
  const Icon = findIcon(icon)
65
65
  if (Icon) return <Icon />
66
66
  }
67
+
68
+ function isObject(item: any) {
69
+ return item && typeof item === "object" && !Array.isArray(item)
70
+ }
71
+
72
+ export function deepMerge(target: any, ...sources: any[]): any {
73
+ if (!sources.length) return target
74
+ const source = sources.shift()
75
+
76
+ if (isObject(target) && isObject(source)) {
77
+ for (const key in source) {
78
+ if (isObject(source[key])) {
79
+ if (!target[key]) Object.assign(target, { [key]: {} })
80
+ deepMerge(target[key], source[key])
81
+ } else {
82
+ Object.assign(target, { [key]: source[key] })
83
+ }
84
+ }
85
+ }
86
+ return deepMerge(target, ...sources)
87
+ }