@kaspernj/api-maker 1.0.232 → 1.0.233

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/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.232",
19
+ "version": "1.0.233",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -103,7 +103,28 @@ export default class CollectionLoader extends React.PureComponent {
103
103
  loadModels = async () => {
104
104
  const params = Params.parse()
105
105
  const {abilities, collection, groupBy, modelClass, onModelsLoaded, preloads, select, selectColumns} = this.props
106
- const {qParams, queryPageName, queryQName, searchParams} = digs(this.shape, "qParams", "queryPageName", "queryQName", "searchParams")
106
+ const {
107
+ qParams,
108
+ queryName,
109
+ queryPageName,
110
+ queryQName,
111
+ searchParams
112
+ } = digs(
113
+ this.shape,
114
+ "qParams",
115
+ "queryName",
116
+ "queryPageName",
117
+ "queryQName",
118
+ "searchParams"
119
+ )
120
+ const perKey = `${queryName}_per`
121
+ let per = params[perKey] || 30
122
+
123
+ if (per == "all") {
124
+ per = 999_999_999
125
+ } else {
126
+ per = Number(per)
127
+ }
107
128
 
108
129
  let query = collection?.clone() || modelClass.ransack()
109
130
 
@@ -115,6 +136,8 @@ export default class CollectionLoader extends React.PureComponent {
115
136
  .searchKey(queryQName)
116
137
  .page(params[queryPageName])
117
138
  .pageKey(queryPageName)
139
+ .per(per)
140
+ .perKey(perKey)
118
141
  .preload(preloads)
119
142
  .select(select)
120
143
 
@@ -15,12 +15,15 @@ import Params from "../params"
15
15
  import PropTypes from "prop-types"
16
16
  import React from "react"
17
17
  import selectCalculator from "./select-calculator"
18
+ import Select from "../inputs/select"
18
19
  import Shape from "set-state-compare/src/shape"
19
20
  import SortLink from "../bootstrap/sort-link"
20
21
  import TableSettings from "./table-settings"
21
22
  import uniqunize from "uniqunize"
22
23
  import withBreakpoint from "./with-breakpoint"
23
24
 
25
+ const paginationOptions = [30, 60, 90, ["All", "all"]]
26
+
24
27
  class ApiMakerTable extends React.PureComponent {
25
28
  static defaultProps = {
26
29
  card: true,
@@ -86,6 +89,7 @@ class ApiMakerTable extends React.PureComponent {
86
89
  identifier: this.props.identifier || `${collectionKey}-default`,
87
90
  models: undefined,
88
91
  overallCount: undefined,
92
+ perPage: 30,
89
93
  preload: undefined,
90
94
  preparedColumns: undefined,
91
95
  query: undefined,
@@ -347,6 +351,22 @@ class ApiMakerTable extends React.PureComponent {
347
351
  )
348
352
  }
349
353
 
354
+ onFilterClicked = (e) => {
355
+ e.preventDefault()
356
+ this.shape.set({showFilters: !this.shape.showFilters})
357
+ }
358
+
359
+ onPerPageChanged = (e) => {
360
+ const {queryName} = digs(this.shape, "queryName")
361
+ const newPerPageValue = digg(e, "target", "value")
362
+ const perKey = `${queryName}_per`
363
+ const paramsChange = {}
364
+
365
+ paramsChange[perKey] = newPerPageValue
366
+
367
+ Params.changeParams(paramsChange)
368
+ }
369
+
350
370
  tableControls() {
351
371
  const {controls} = this.props
352
372
 
@@ -360,11 +380,6 @@ class ApiMakerTable extends React.PureComponent {
360
380
  )
361
381
  }
362
382
 
363
- onFilterClicked = (e) => {
364
- e.preventDefault()
365
- this.shape.set({showFilters: !this.shape.showFilters})
366
- }
367
-
368
383
  tableContent () {
369
384
  const {breakPoint} = digs(this.props, "breakPoint")
370
385
  const {models, preparedColumns} = digs(this.shape, "models", "preparedColumns")
@@ -418,8 +433,18 @@ class ApiMakerTable extends React.PureComponent {
418
433
  if (to === 0) from = 0
419
434
 
420
435
  return (
421
- <div style={{marginTop: "10px"}}>
422
- {I18n.t("js.api_maker.table.showing_from_to_out_of_total", {defaultValue, from, to, total_count: totalCount})}
436
+ <div style={{display: "flex", justifyContent: "space-between", marginTop: "10px"}}>
437
+ <div>
438
+ {I18n.t("js.api_maker.table.showing_from_to_out_of_total", {defaultValue, from, to, total_count: totalCount})}
439
+ </div>
440
+ <div>
441
+ <Select
442
+ className="per-page-select"
443
+ defaultValue={perPage}
444
+ onChange={digg(this, "onPerPageChanged")}
445
+ options={paginationOptions}
446
+ />
447
+ </div>
423
448
  </div>
424
449
  )
425
450
  }