muffin-admin 2.0.0 → 2.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "2.0.0",
3
+ "version": "2.2.0",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
package/src/buildRA.tsx CHANGED
@@ -37,7 +37,7 @@ import {
37
37
  import { AvatarField, EditableBooleanField, FKField, JsonField } from "./fields"
38
38
  import { FKInput, JsonInput } from "./inputs"
39
39
 
40
- const UI = {
40
+ export const UI = {
41
41
  // Fields
42
42
  BooleanField,
43
43
  ChipField,
@@ -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,23 @@
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"
3
+ export function FKInput({ refKey, refSource, fullWidth, reference, source, ...props }) {
4
+ // Bind to AutoCompleteInput if we want to customize the search
5
+ // const filterToQuery = (search) => {
6
+ // const filters = {}
7
+ // filters[refKey] = search
8
+ // return filters
9
+ // }
11
10
 
11
+ refKey = refKey || "id"
12
12
  const renderText = (record) => {
13
- const pk = record[refSource]
14
- return (pk && `${record[refProp]} (#${pk})`) || ""
13
+ const pk = record[refKey]
14
+ if (refKey == refSource) return `#${pk}`
15
+ return (pk && `${record[refSource]} (#${pk})`) || ""
15
16
  }
16
17
 
17
18
  return (
18
- <ReferenceInput reference={reference} source={source} filterToQuery={filterToQuery} {...props}>
19
- <AutocompleteInput
20
- source={refSource}
21
- optionText={renderText}
22
- fullWidth={fullWidth}
23
- {...props}
24
- />
19
+ <ReferenceInput reference={reference} source={source} {...props}>
20
+ <AutocompleteInput source={refKey} optionText={renderText} fullWidth={fullWidth} {...props} />
25
21
  </ReferenceInput>
26
22
  )
27
23
  }