muffin-admin 2.0.0 → 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/dataprovider.d.ts +1 -3
- package/dist/dataprovider.js +4 -2
- package/dist/fields/FKField.d.ts +3 -3
- package/dist/fields/FKField.js +2 -2
- package/dist/inputs/FKInput.d.ts +2 -2
- package/dist/inputs/FKInput.js +7 -10
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/dataprovider.ts +4 -2
- package/src/fields/FKField.tsx +9 -3
- package/src/inputs/FKInput.tsx +7 -18
package/package.json
CHANGED
package/src/dataprovider.ts
CHANGED
|
@@ -66,8 +66,10 @@ export function MuffinDataprovider({ apiUrl }: AdminOpts) {
|
|
|
66
66
|
return { data: ids }
|
|
67
67
|
},
|
|
68
68
|
|
|
69
|
-
getMany: (resource,
|
|
70
|
-
|
|
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 }) => {
|
package/src/fields/FKField.tsx
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { ReferenceField, TextField } from "react-admin"
|
|
2
2
|
|
|
3
|
-
export function FKField({ refSource,
|
|
3
|
+
export function FKField({ reference, refSource, refKey, link, source, ...props }) {
|
|
4
4
|
return (
|
|
5
|
-
<ReferenceField
|
|
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={
|
|
15
|
+
<TextField source={refKey || "id"} />
|
|
10
16
|
{")"}
|
|
11
17
|
</>
|
|
12
18
|
</ReferenceField>
|
package/src/inputs/FKInput.tsx
CHANGED
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import { AutocompleteInput, ReferenceInput } from "react-admin"
|
|
2
2
|
|
|
3
|
-
export function FKInput({
|
|
4
|
-
|
|
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[
|
|
14
|
-
|
|
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}
|
|
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
|
}
|