muffin-admin 5.0.0 → 6.0.1

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.
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import sortBy from "lodash/sortBy";
3
3
  import uniq from "lodash/uniq";
4
- import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, List, Pagination, SelectColumnsButton, TopToolbar, } from "react-admin";
4
+ import { BulkDeleteButton, BulkExportButton, CreateButton, DatagridConfigurable, EditButton, ExportButton, FilterButton, InfiniteList, List, Pagination, SelectColumnsButton, TopToolbar, } from "react-admin";
5
5
  import { buildRA } from "./buildRA";
6
6
  import { BulkActionButton, ListActionButton } from "./buttons";
7
7
  import { HelpLink } from "./common/HelpLink";
@@ -9,10 +9,10 @@ import { useMuffinResourceOpts } from "./hooks";
9
9
  import { buildAdmin, findBuilder, setupAdmin } from "./utils";
10
10
  export function MuffinList({ children }) {
11
11
  const { name, list } = useMuffinResourceOpts();
12
- const { limit, limitMax, filters, sort } = list;
12
+ const { limit, limitMax, limitTotal, filters, sort } = list;
13
13
  const DataGrid = findBuilder(["list-grid", name]);
14
14
  const Toolbar = findBuilder(["list-toolbar", name]);
15
- return (_jsxs(List, { sort: sort, perPage: limit, actions: _jsx(Toolbar, {}), filters: buildAdmin(["list-filters", name], filters), pagination: _jsx(Pagination, { rowsPerPageOptions: sortBy(uniq([10, 25, 50, 100, limit, limitMax])) }), children: [children, _jsx(DataGrid, {})] }));
15
+ return limitTotal ? (_jsxs(List, { sort: sort, perPage: limit, actions: _jsx(Toolbar, {}), filters: buildAdmin(["list-filters", name], filters), 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: buildAdmin(["list-filters", name], filters), children: [children, _jsx(DataGrid, {})] }));
16
16
  }
17
17
  setupAdmin(["list"], MuffinList);
18
18
  setupAdmin(["list-fields"], buildRA);
@@ -41,9 +41,12 @@ function MuffinListToolbar() {
41
41
  : null, !hasExport && _jsx(ExportButton, {})] }));
42
42
  }
43
43
  setupAdmin(["list-toolbar"], MuffinListToolbar);
44
- function MuffinListBulkActions() {
44
+ function MuffinListActions() {
45
45
  const { actions: baseActions = [], list: { remove }, } = useMuffinResourceOpts();
46
46
  const actions = baseActions.filter((a) => { var _a; return (_a = a.view) === null || _a === void 0 ? void 0 : _a.includes("bulk"); });
47
47
  return (_jsxs(_Fragment, { children: [actions.map((props) => (_jsx(BulkActionButton, Object.assign({}, props), props.id))), _jsx(BulkExportButton, {}), remove && _jsx(BulkDeleteButton, {})] }));
48
48
  }
49
- setupAdmin(["list-actions"], MuffinListBulkActions);
49
+ setupAdmin(["list-actions"], MuffinListActions);
50
+ function MuffinPagination() {
51
+ return null;
52
+ }
@@ -8,6 +8,14 @@ export declare function MuffinDataprovider(apiUrl: string): {
8
8
  getList: (resource: string, params: any) => Promise<{
9
9
  data: any;
10
10
  total: number;
11
+ pageInfo: {
12
+ hasPreviousPage: boolean;
13
+ hasNextPage: boolean;
14
+ };
15
+ } | {
16
+ data: any;
17
+ total?: undefined;
18
+ pageInfo?: undefined;
11
19
  }>;
12
20
  getOne: (resource: string, { id }: {
13
21
  id: TID;
@@ -51,6 +59,14 @@ export declare function MuffinDataprovider(apiUrl: string): {
51
59
  }) => Promise<{
52
60
  data: any;
53
61
  total: number;
62
+ pageInfo: {
63
+ hasPreviousPage: boolean;
64
+ hasNextPage: boolean;
65
+ };
66
+ } | {
67
+ data: any;
68
+ total?: undefined;
69
+ pageInfo?: undefined;
54
70
  }>;
55
71
  getManyReference: (resource: string, { target, id, filter, ...opts }: {
56
72
  [x: string]: any;
@@ -60,6 +76,14 @@ export declare function MuffinDataprovider(apiUrl: string): {
60
76
  }) => Promise<{
61
77
  data: any;
62
78
  total: number;
79
+ pageInfo: {
80
+ hasPreviousPage: boolean;
81
+ hasNextPage: boolean;
82
+ };
83
+ } | {
84
+ data: any;
85
+ total?: undefined;
86
+ pageInfo?: undefined;
63
87
  }>;
64
88
  runAction: (resource: string, action: string, props: TActionProps) => Promise<{
65
89
  data: any;
@@ -45,7 +45,16 @@ export function MuffinDataprovider(apiUrl) {
45
45
  query.sort = order == "ASC" ? field : `-${field}`;
46
46
  }
47
47
  const { headers, data } = yield request(resource, { query });
48
- return { data, total: parseInt(headers.get("x-total"), 10) };
48
+ if (pagination)
49
+ return {
50
+ data,
51
+ total: parseInt(headers.get("x-total"), 10),
52
+ pageInfo: {
53
+ hasPreviousPage: pagination.page > 1,
54
+ hasNextPage: data.length === pagination.perPage,
55
+ },
56
+ };
57
+ return { data };
49
58
  }),
50
59
  getOne: (resource_1, _a) => __awaiter(this, [resource_1, _a], void 0, function* (resource, { id }) {
51
60
  return yield request(`${resource}/${id}`);