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.
package/dist/types.d.ts CHANGED
@@ -57,6 +57,7 @@ export type AdminResourceProps = {
57
57
  list: {
58
58
  limit: number;
59
59
  limitMax: number;
60
+ limitTotal: boolean;
60
61
  create: boolean;
61
62
  filters: AdminInput[];
62
63
  fields: AdminField[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "muffin-admin",
3
- "version": "5.0.0",
3
+ "version": "6.0.1",
4
4
  "description": "NPM package for https://github.com/klen/muffin-admin",
5
5
  "files": [
6
6
  "src",
@@ -9,6 +9,7 @@ import {
9
9
  EditButton,
10
10
  ExportButton,
11
11
  FilterButton,
12
+ InfiniteList,
12
13
  List,
13
14
  Pagination,
14
15
  SelectColumnsButton,
@@ -22,12 +23,12 @@ import { buildAdmin, findBuilder, setupAdmin } from "./utils"
22
23
 
23
24
  export function MuffinList({ children }: PropsWithChildren) {
24
25
  const { name, list } = useMuffinResourceOpts()
25
- const { limit, limitMax, filters, sort } = list
26
+ const { limit, limitMax, limitTotal, filters, sort } = list
26
27
 
27
28
  const DataGrid = findBuilder(["list-grid", name])
28
29
  const Toolbar = findBuilder(["list-toolbar", name])
29
30
 
30
- return (
31
+ return limitTotal ? (
31
32
  <List
32
33
  sort={sort}
33
34
  perPage={limit}
@@ -40,6 +41,16 @@ export function MuffinList({ children }: PropsWithChildren) {
40
41
  {children}
41
42
  <DataGrid />
42
43
  </List>
44
+ ) : (
45
+ <InfiniteList
46
+ sort={sort}
47
+ perPage={limit}
48
+ actions={<Toolbar />}
49
+ filters={buildAdmin(["list-filters", name], filters)}
50
+ >
51
+ {children}
52
+ <DataGrid />
53
+ </InfiniteList>
43
54
  )
44
55
  }
45
56
 
@@ -96,7 +107,7 @@ function MuffinListToolbar() {
96
107
  }
97
108
  setupAdmin(["list-toolbar"], MuffinListToolbar)
98
109
 
99
- function MuffinListBulkActions() {
110
+ function MuffinListActions() {
100
111
  const {
101
112
  actions: baseActions = [],
102
113
  list: { remove },
@@ -113,4 +124,8 @@ function MuffinListBulkActions() {
113
124
  )
114
125
  }
115
126
 
116
- setupAdmin(["list-actions"], MuffinListBulkActions)
127
+ setupAdmin(["list-actions"], MuffinListActions)
128
+
129
+ function MuffinPagination() {
130
+ return null
131
+ }
@@ -24,7 +24,17 @@ export function MuffinDataprovider(apiUrl: string) {
24
24
  query.sort = order == "ASC" ? field : `-${field}`
25
25
  }
26
26
  const { headers, data } = await request(resource, { query })
27
- return { data, total: parseInt(headers.get("x-total"), 10) }
27
+ if (pagination)
28
+ return {
29
+ data,
30
+ total: parseInt(headers.get("x-total"), 10),
31
+ pageInfo: {
32
+ hasPreviousPage: pagination.page > 1,
33
+ hasNextPage: data.length === pagination.perPage,
34
+ },
35
+ }
36
+
37
+ return { data }
28
38
  },
29
39
 
30
40
  getOne: async (resource: string, { id }: { id: TID }) => {
package/src/types.ts CHANGED
@@ -93,6 +93,7 @@ export type AdminResourceProps = {
93
93
  list: {
94
94
  limit: number
95
95
  limitMax: number
96
+ limitTotal: boolean
96
97
  create: boolean
97
98
  filters: AdminInput[]
98
99
  fields: AdminField[]