muffin-admin 1.45.8 → 2.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.
package/dist/types.d.ts CHANGED
@@ -24,7 +24,7 @@ export type AdminShowLink = {
24
24
  export type AdminShowProps = {
25
25
  actions: AdminAction[];
26
26
  fields: AdminField[];
27
- links: Record<string, AdminShowLink>;
27
+ links: [string, AdminShowLink][];
28
28
  };
29
29
  export type AdminResourceProps = {
30
30
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "1.45.8",
3
+ "version": "2.1.0",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -26,8 +26,8 @@ setupAdmin(["show-fields"], ({ fields }) => buildRA(fields))
26
26
  setupAdmin(["show-actions"], ({ actions, links }) => (
27
27
  <TopToolbar>
28
28
  <div style={{ marginRight: "auto" }}>
29
- {Object.keys(links).map((key) => (
30
- <LinkAction key={key} resource={key} {...links[key]} />
29
+ {links.map(([key, props]) => (
30
+ <LinkAction key={key} resource={key} {...props} />
31
31
  ))}
32
32
  </div>
33
33
  {actions.map((props, idx) => (
@@ -66,8 +66,10 @@ export function MuffinDataprovider({ apiUrl }: AdminOpts) {
66
66
  return { data: ids }
67
67
  },
68
68
 
69
- getMany: (resource, { ids }) => {
70
- return methods.getList(resource, { filter: { id: { $in: ids } } })
69
+ getMany: (resource, props) => {
70
+ const { ids, meta } = props
71
+ const key = meta?.key || "id"
72
+ return methods.getList(resource, { filter: { [key]: { $in: ids } } })
71
73
  },
72
74
 
73
75
  getManyReference: async (resource, { target, id, filter, ...opts }) => {
@@ -1,12 +1,18 @@
1
1
  import { ReferenceField, TextField } from "react-admin"
2
2
 
3
- export function FKField({ refSource, refID, link, reference, source, ...props }) {
3
+ export function FKField({ reference, refSource, refKey, link, source, ...props }) {
4
4
  return (
5
- <ReferenceField link={link || "show"} reference={reference} source={source} {...props}>
5
+ <ReferenceField
6
+ link={link || "show"}
7
+ reference={reference}
8
+ source={source}
9
+ queryOptions={{ meta: { key: refKey } }}
10
+ {...props}
11
+ >
6
12
  <>
7
13
  <TextField source={refSource} />
8
14
  {" (#"}
9
- <TextField source={refID || "id"} />
15
+ <TextField source={refKey || "id"} />
10
16
  {")"}
11
17
  </>
12
18
  </ReferenceField>
@@ -1,27 +1,16 @@
1
1
  import { AutocompleteInput, ReferenceInput } from "react-admin"
2
2
 
3
- export function FKInput({ refProp, refSource, fullWidth, reference, source, ...props }) {
4
- const filterToQuery = (search) => {
5
- const filters = {}
6
- filters[refProp] = search
7
- return filters
8
- }
9
-
10
- refSource = refSource || "id"
11
-
3
+ export function FKInput({ refKey, refSource, fullWidth, reference, source, ...props }) {
4
+ refKey = refKey || "id"
12
5
  const renderText = (record) => {
13
- const pk = record[refSource]
14
- return (pk && `${record[refProp]} (#${pk})`) || ""
6
+ const pk = record[refKey]
7
+ if (refKey == refSource) return `#${pk}`
8
+ return (pk && `${record[refSource]} (#${pk})`) || ""
15
9
  }
16
10
 
17
11
  return (
18
- <ReferenceInput reference={reference} source={source} filterToQuery={filterToQuery} {...props}>
19
- <AutocompleteInput
20
- source={refSource}
21
- optionText={renderText}
22
- fullWidth={fullWidth}
23
- {...props}
24
- />
12
+ <ReferenceInput reference={reference} source={source} {...props}>
13
+ <AutocompleteInput source={refKey} optionText={renderText} fullWidth={fullWidth} {...props} />
25
14
  </ReferenceInput>
26
15
  )
27
16
  }
package/src/types.ts CHANGED
@@ -22,7 +22,7 @@ export type AdminShowLink = {
22
22
  export type AdminShowProps = {
23
23
  actions: AdminAction[]
24
24
  fields: AdminField[]
25
- links: Record<string, AdminShowLink>
25
+ links: [string, AdminShowLink][]
26
26
  }
27
27
 
28
28
  export type AdminResourceProps = {