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.
@@ -10,4 +10,4 @@ export function MuffinResourceShow(props) {
10
10
  }
11
11
  setupAdmin(["show"], (props) => _jsx(MuffinResourceShow, Object.assign({}, props)));
12
12
  setupAdmin(["show-fields"], ({ fields }) => buildRA(fields));
13
- setupAdmin(["show-actions"], ({ actions, links }) => (_jsxs(TopToolbar, { children: [_jsx("div", { style: { marginRight: "auto" }, children: Object.keys(links).map((key) => (_jsx(LinkAction, Object.assign({ resource: key }, links[key]), key))) }), actions.map((props, idx) => (_jsx(ActionButton, Object.assign({}, props), idx))), _jsx(ListButton, {}), _jsx(EditButton, {})] })));
13
+ setupAdmin(["show-actions"], ({ actions, links }) => (_jsxs(TopToolbar, { children: [_jsx("div", { style: { marginRight: "auto" }, children: links.map(([key, props]) => (_jsx(LinkAction, Object.assign({ resource: key }, props), key))) }), actions.map((props, idx) => (_jsx(ActionButton, Object.assign({}, props), idx))), _jsx(ListButton, {}), _jsx(EditButton, {})] })));
@@ -38,9 +38,7 @@ export declare function MuffinDataprovider({ apiUrl }: AdminOpts): {
38
38
  }) => Promise<{
39
39
  data: any;
40
40
  }>;
41
- getMany: (resource: any, { ids }: {
42
- ids: any;
43
- }) => Promise<{
41
+ getMany: (resource: any, props: any) => Promise<{
44
42
  data: any;
45
43
  total: number;
46
44
  }>;
@@ -78,8 +78,10 @@ export function MuffinDataprovider({ apiUrl }) {
78
78
  });
79
79
  return { data: ids };
80
80
  }),
81
- getMany: (resource, { ids }) => {
82
- return methods.getList(resource, { filter: { id: { $in: ids } } });
81
+ getMany: (resource, props) => {
82
+ const { ids, meta } = props;
83
+ const key = (meta === null || meta === void 0 ? void 0 : meta.key) || "id";
84
+ return methods.getList(resource, { filter: { [key]: { $in: ids } } });
83
85
  },
84
86
  getManyReference: (resource, _a) => __awaiter(this, void 0, void 0, function* () {
85
87
  var { target, id, filter } = _a, opts = __rest(_a, ["target", "id", "filter"]);
@@ -1,9 +1,9 @@
1
- export declare function FKField({ refSource, refID, link, reference, source, ...props }: {
1
+ export declare function FKField({ reference, refSource, refKey, link, source, ...props }: {
2
2
  [x: string]: any;
3
+ reference: any;
3
4
  refSource: any;
4
- refID: any;
5
+ refKey: any;
5
6
  link: any;
6
- reference: any;
7
7
  source: any;
8
8
  }): import("react/jsx-runtime").JSX.Element;
9
9
  export declare namespace FKField {
@@ -12,8 +12,8 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { ReferenceField, TextField } from "react-admin";
14
14
  export function FKField(_a) {
15
- var { refSource, refID, link, reference, source } = _a, props = __rest(_a, ["refSource", "refID", "link", "reference", "source"]);
16
- return (_jsx(ReferenceField, Object.assign({ link: link || "show", reference: reference, source: source }, props, { children: _jsxs(_Fragment, { children: [_jsx(TextField, { source: refSource }), " (#", _jsx(TextField, { source: refID || "id" }), ")"] }) })));
15
+ var { reference, refSource, refKey, link, source } = _a, props = __rest(_a, ["reference", "refSource", "refKey", "link", "source"]);
16
+ return (_jsx(ReferenceField, Object.assign({ link: link || "show", reference: reference, source: source, queryOptions: { meta: { key: refKey } } }, props, { children: _jsxs(_Fragment, { children: [_jsx(TextField, { source: refSource }), " (#", _jsx(TextField, { source: refKey || "id" }), ")"] }) })));
17
17
  }
18
18
  FKField.displayName = "FKField";
19
19
  FKField.defaultProps = {
@@ -1,6 +1,6 @@
1
- export declare function FKInput({ refProp, refSource, fullWidth, reference, source, ...props }: {
1
+ export declare function FKInput({ refKey, refSource, fullWidth, reference, source, ...props }: {
2
2
  [x: string]: any;
3
- refProp: any;
3
+ refKey: any;
4
4
  refSource: any;
5
5
  fullWidth: any;
6
6
  reference: any;
@@ -12,16 +12,13 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { AutocompleteInput, ReferenceInput } from "react-admin";
14
14
  export function FKInput(_a) {
15
- var { refProp, refSource, fullWidth, reference, source } = _a, props = __rest(_a, ["refProp", "refSource", "fullWidth", "reference", "source"]);
16
- const filterToQuery = (search) => {
17
- const filters = {};
18
- filters[refProp] = search;
19
- return filters;
20
- };
21
- refSource = refSource || "id";
15
+ var { refKey, refSource, fullWidth, reference, source } = _a, props = __rest(_a, ["refKey", "refSource", "fullWidth", "reference", "source"]);
16
+ refKey = refKey || "id";
22
17
  const renderText = (record) => {
23
- const pk = record[refSource];
24
- return (pk && `${record[refProp]} (#${pk})`) || "";
18
+ const pk = record[refKey];
19
+ if (refKey == refSource)
20
+ return `#${pk}`;
21
+ return (pk && `${record[refSource]} (#${pk})`) || "";
25
22
  };
26
- return (_jsx(ReferenceInput, Object.assign({ reference: reference, source: source, filterToQuery: filterToQuery }, props, { children: _jsx(AutocompleteInput, Object.assign({ source: refSource, optionText: renderText, fullWidth: fullWidth }, props)) })));
23
+ return (_jsx(ReferenceInput, Object.assign({ reference: reference, source: source }, props, { children: _jsx(AutocompleteInput, Object.assign({ source: refKey, optionText: renderText, fullWidth: fullWidth }, props)) })));
27
24
  }