muffin-admin 9.5.4 → 11.0.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.
@@ -23,10 +23,10 @@ setupAdmin(["dashboard-actions"], () => null);
23
23
  setupAdmin(["dashboard-content"], () => null);
24
24
  function AdminCards({ src }) {
25
25
  if (Array.isArray(src))
26
- return (_jsx(Grid, { container: true, item: true, spacing: 2, children: src.map((card, idx) => (_jsx(AdminCards, { src: card }, idx))) }));
26
+ return (_jsx(Grid, { container: true, spacing: 2, children: src.map((card, idx) => (_jsx(AdminCards, { src: card }, idx))) }));
27
27
  return _jsx(DashboardCard, Object.assign({}, src));
28
28
  }
29
29
  function DashboardCard({ title, value }) {
30
- return (_jsx(Grid, { item: true, xs: true, children: _jsx(Card, { children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h5", component: "h2", m: 2, style: { textAlign: "center" }, children: title }), (Array.isArray(value) && _jsx(AdminTableView, { src: value })) || (_jsx("pre", { children: JSON.stringify(value, null, 2) }))] }) }) }));
30
+ return (_jsx(Card, { children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h5", component: "h2", m: 2, style: { textAlign: "center" }, children: title }), (Array.isArray(value) && _jsx(AdminTableView, { src: value })) || (_jsx("pre", { children: JSON.stringify(value, null, 2) }))] }) }));
31
31
  }
32
- const AdminTableView = ({ src }) => (_jsx(Table, { children: _jsx(TableBody, { children: src.map((row, idx) => (_jsx(TableRow, { hover: true, children: row.map((cell, idx) => (_jsx(TableCell, { children: cell }, idx))) }, idx))) }) }));
32
+ const AdminTableView = ({ src }) => (_jsx(Table, { width: "100%", sx: { tableLayout: "fixed" }, children: _jsx(TableBody, { children: src.map((row, idx) => (_jsx(TableRow, { hover: true, children: row.map((cell, idx) => (_jsx(TableCell, { children: cell }, idx))) }, idx))) }) }));
@@ -6,13 +6,13 @@ import { useMuffinAdminOpts, useMuffinResourceOpts } from "./hooks";
6
6
  import { findBuilder, setupAdmin } from "./utils";
7
7
  export function MuffinEdit({ children }) {
8
8
  const { adminProps: { mutationMode = "optimistic" }, } = useMuffinAdminOpts();
9
- const { edit, name } = useMuffinResourceOpts();
9
+ const { edit, name, key } = useMuffinResourceOpts();
10
10
  if (!edit)
11
11
  return null;
12
12
  const Actions = findBuilder(["edit-toolbar", name]);
13
13
  const Inputs = findBuilder(["edit-inputs", name]);
14
14
  const FormToolbar = findBuilder(["edit-form-toolbar", name]);
15
- return (_jsxs(Edit, { actions: _jsx(Actions, {}), mutationMode: mutationMode, children: [children, _jsx(SimpleForm, { toolbar: _jsx(FormToolbar, {}), children: _jsx(Inputs, {}) })] }));
15
+ return (_jsxs(Edit, { actions: _jsx(Actions, {}), mutationMode: mutationMode, queryOptions: { meta: { key } }, children: [children, _jsx(SimpleForm, { toolbar: _jsx(FormToolbar, {}), children: _jsx(Inputs, {}) })] }));
16
16
  }
17
17
  setupAdmin(["edit"], MuffinEdit);
18
18
  export function MuffinEditFormToolbar() {
@@ -8,12 +8,12 @@ import { HelpLink } from "./common/HelpLink";
8
8
  import { useMuffinResourceOpts } from "./hooks";
9
9
  import { buildAdmin, findBuilder, setupAdmin } from "./utils";
10
10
  export function MuffinList({ children }) {
11
- const { name, list } = useMuffinResourceOpts();
11
+ const { name, list, key } = useMuffinResourceOpts();
12
12
  const { limit, limitMax, limitTotal, sort, filters } = list;
13
13
  const DataGrid = findBuilder(["list-grid", name]);
14
14
  const Toolbar = findBuilder(["list-toolbar", name]);
15
15
  const raFilters = buildAdmin(["list-filters", name], filters);
16
- return limitTotal ? (_jsxs(List, { sort: sort, perPage: limit, filters: raFilters, actions: _jsx(Toolbar, {}), pagination: _jsx(Pagination, { rowsPerPageOptions: sortBy(uniq([10, 25, 50, 100, limit, limitMax])) }), children: [children, _jsx(DataGrid, {})] })) : (_jsxs(InfiniteList, { sort: sort, perPage: limit, actions: _jsx(Toolbar, {}), filters: raFilters, children: [children, _jsx(DataGrid, {})] }));
16
+ return limitTotal ? (_jsxs(List, { sort: sort, perPage: limit, filters: raFilters, actions: _jsx(Toolbar, {}), queryOptions: { meta: { key } }, pagination: _jsx(Pagination, { rowsPerPageOptions: sortBy(uniq([10, 25, 50, 100, limit, limitMax])) }), children: [children, _jsx(DataGrid, {})] })) : (_jsxs(InfiniteList, { sort: sort, perPage: limit, filters: raFilters, actions: _jsx(Toolbar, {}), queryOptions: { meta: { key } }, children: [children, _jsx(DataGrid, {})] }));
17
17
  }
18
18
  setupAdmin(["list"], MuffinList);
19
19
  setupAdmin(["list-fields"], buildRA);
@@ -6,9 +6,9 @@ import { ActionButton } from "./buttons";
6
6
  import { useMuffinResourceOpts } from "./hooks";
7
7
  import { buildAdmin, findBuilder, setupAdmin } from "./utils";
8
8
  export function MuffinShow({ children }) {
9
- const { show, name } = useMuffinResourceOpts();
9
+ const { show, name, key } = useMuffinResourceOpts();
10
10
  const ShowToolbar = findBuilder(["show-toolbar", name]);
11
- return (_jsxs(Show, { actions: _jsx(ShowToolbar, {}), children: [_jsx(SimpleShowLayout, { children: buildAdmin(["show-fields", name], show) }), children] }));
11
+ return (_jsxs(Show, { actions: _jsx(ShowToolbar, {}), queryOptions: { meta: { key } }, children: [_jsx(SimpleShowLayout, { children: buildAdmin(["show-fields", name], show) }), children] }));
12
12
  }
13
13
  setupAdmin(["show"], MuffinShow);
14
14
  setupAdmin(["show-fields"], ({ fields }) => buildRA(fields));
@@ -1,11 +1,14 @@
1
1
  import { TID } from "./types";
2
2
  import { APIParams } from "./utils";
3
+ type TQueryMeta = {
4
+ key?: string;
5
+ };
3
6
  export declare function MuffinDataprovider(apiUrl: string): {
4
7
  request: (url: string, options?: APIParams) => Promise<{
5
8
  data: any;
6
9
  headers: Headers;
7
10
  }>;
8
- getList: (resource: string, params: any) => Promise<{
11
+ getList: (resource: string, { meta, ...params }: any) => Promise<{
9
12
  data: any;
10
13
  total: number;
11
14
  pageInfo: {
@@ -17,8 +20,9 @@ export declare function MuffinDataprovider(apiUrl: string): {
17
20
  total?: undefined;
18
21
  pageInfo?: undefined;
19
22
  }>;
20
- getOne: (resource: string, { id }: {
23
+ getOne: (resource: string, { id, meta }: {
21
24
  id: TID;
25
+ meta?: TQueryMeta;
22
26
  }) => Promise<{
23
27
  data: any;
24
28
  headers: Headers;
@@ -94,3 +98,4 @@ export type TActionProps<T = any> = {
94
98
  ids?: string[];
95
99
  record?: T;
96
100
  };
101
+ export {};
@@ -30,7 +30,9 @@ export function MuffinDataprovider(apiUrl) {
30
30
  }
31
31
  const methods = {
32
32
  request,
33
- getList: (resource, params) => __awaiter(this, void 0, void 0, function* () {
33
+ getList: (resource, _a) => __awaiter(this, void 0, void 0, function* () {
34
+ var _b;
35
+ var { meta } = _a, params = __rest(_a, ["meta"]);
34
36
  const { filter, pagination, sort } = params;
35
37
  const query = {};
36
38
  if (filter)
@@ -45,6 +47,12 @@ export function MuffinDataprovider(apiUrl) {
45
47
  query.sort = order == "ASC" ? field : `-${field}`;
46
48
  }
47
49
  const { headers, data } = yield request(resource, { query });
50
+ // React-admin requires item to have an `id` field
51
+ if (meta === null || meta === void 0 ? void 0 : meta.key) {
52
+ for (const item of data) {
53
+ item.id = (_b = item.id) !== null && _b !== void 0 ? _b : item[meta.key];
54
+ }
55
+ }
48
56
  if (pagination)
49
57
  return {
50
58
  data,
@@ -56,8 +64,14 @@ export function MuffinDataprovider(apiUrl) {
56
64
  };
57
65
  return { data };
58
66
  }),
59
- getOne: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { id }) {
60
- return yield request(`${resource}/${id}`);
67
+ getOne: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { id, meta }) {
68
+ var _b;
69
+ const response = yield request(`${resource}/${id}`);
70
+ const { data } = response;
71
+ if (meta === null || meta === void 0 ? void 0 : meta.key) {
72
+ data.id = (_b = data.id) !== null && _b !== void 0 ? _b : data[meta.key];
73
+ }
74
+ return response;
61
75
  }),
62
76
  create: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { data }) {
63
77
  return yield request(resource, {
@@ -89,7 +103,7 @@ export function MuffinDataprovider(apiUrl) {
89
103
  getMany: (resource, props) => {
90
104
  const { ids, meta } = props;
91
105
  const key = (meta === null || meta === void 0 ? void 0 : meta.key) || "id";
92
- return methods.getList(resource, { filter: { [key]: { $in: ids } } });
106
+ return methods.getList(resource, { filter: { [key]: { $in: ids } }, meta });
93
107
  },
94
108
  getManyReference: (resource, _a) => __awaiter(this, void 0, void 0, function* () {
95
109
  var { target, id, filter } = _a, opts = __rest(_a, ["target", "id", "filter"]);
@@ -13,6 +13,7 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
13
13
  import { ReferenceField, TextField } from "react-admin";
14
14
  export function FKField(_a) {
15
15
  var { reference, refSource, refKey, link, source } = _a, props = __rest(_a, ["reference", "refSource", "refKey", "link", "source"]);
16
- return (_jsx(ReferenceField, Object.assign({ source: source, link: link || "show", reference: reference, queryOptions: { meta: { key: refKey } } }, props, { children: _jsxs(_Fragment, { children: [_jsx(TextField, { source: refSource }), " (#", _jsx(TextField, { source: refKey || "id" }), ")"] }) })));
16
+ refKey = refKey || "id";
17
+ return (_jsx(ReferenceField, Object.assign({ source: source, link: link || "show", reference: reference, queryOptions: { meta: { key: refKey } } }, props, { children: _jsxs(_Fragment, { children: [_jsx(TextField, { source: refSource }), refSource !== refKey && (_jsxs(_Fragment, { children: [" (#", _jsx(TextField, { source: refKey }), ")"] }))] }) })));
17
18
  }
18
19
  FKField.displayName = "FKField";
package/dist/index.d.ts CHANGED
@@ -19,4 +19,4 @@ export * from "./fields";
19
19
  export * from "./hooks";
20
20
  export * from "./types";
21
21
  export declare function initAdmin(prefix?: string, containerId?: string): Promise<void>;
22
- export declare const VERSION = "9.5.4";
22
+ export declare const VERSION = "11.0.0";
package/dist/index.js CHANGED
@@ -42,4 +42,4 @@ export function initAdmin() {
42
42
  root.render(_jsx(MuffinAdminContext.Provider, { value: adminOpts, children: _jsx(MuffinAdmin, {}) }));
43
43
  });
44
44
  }
45
- export const VERSION = "9.5.4";
45
+ export const VERSION = "11.0.0";
@@ -21,10 +21,12 @@ export function FKInput(_a) {
21
21
  var { refKey, refSource, fullWidth, reference, source } = _a, props = __rest(_a, ["refKey", "refSource", "fullWidth", "reference", "source"]);
22
22
  refKey = refKey || "id";
23
23
  const renderText = (record) => {
24
- const pk = record[refKey];
24
+ const key = record[refKey];
25
25
  if (refKey == refSource)
26
- return `#${pk}`;
27
- return (pk && `${record[refSource]} (#${pk})`) || "";
26
+ return `#${key}`;
27
+ return (key && `${record[refSource]} (#${key})`) || "";
28
28
  };
29
- return (_jsx(ReferenceInput, { reference: reference, source: source, children: _jsx(AutocompleteInput, Object.assign({ source: refKey, optionText: renderText, fullWidth: fullWidth, sx: { minWidth: 300 } }, props)) }));
29
+ return (_jsx(ReferenceInput, { reference: reference, source: source, queryOptions: {
30
+ meta: { key: refKey },
31
+ }, children: _jsx(AutocompleteInput, Object.assign({ source: refKey, optionText: renderText, fullWidth: fullWidth, sx: { minWidth: 300 } }, props)) }));
30
32
  }