@kaspernj/api-maker 1.0.232 → 1.0.234

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.234",
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
 
@@ -75,10 +75,11 @@ class ReflectionElement extends React.PureComponent {
75
75
  }
76
76
  }
77
77
 
78
- export default class ApiMakerTableFiltersRelationshipSelect extends React.PureComponent {
78
+ export default class ApiMakerTableFiltersFilterForm extends React.PureComponent {
79
79
  static propTypes = PropTypesExact({
80
80
  filter: PropTypes.object,
81
81
  modelClass: PropTypes.func.isRequired,
82
+ onApplyClicked: PropTypes.func.isRequired,
82
83
  querySearchName: PropTypes.string.isRequired
83
84
  })
84
85
 
@@ -269,6 +270,8 @@ export default class ApiMakerTableFiltersRelationshipSelect extends React.PureCo
269
270
  newParams[querySearchName] = searchParams
270
271
 
271
272
  Params.changeParams(newParams)
273
+
274
+ this.props.onApplyClicked()
272
275
  }
273
276
 
274
277
  reflectionsWithModelClass(reflections) {
@@ -10,6 +10,7 @@ class ApiMakerTableFilter extends React.PureComponent {
10
10
  a: PropTypes.string.isRequired,
11
11
  filterIndex: PropTypes.number.isRequired,
12
12
  onClick: PropTypes.func.isRequired,
13
+ onRemoveClicked: PropTypes.func.isRequired,
13
14
  p: PropTypes.array.isRequired,
14
15
  pre: PropTypes.string.isRequired,
15
16
  v: PropTypes.string.isRequired
@@ -19,8 +20,18 @@ class ApiMakerTableFilter extends React.PureComponent {
19
20
  const {a, p, pre, v} = digs(this.props, "a", "p", "pre", "v")
20
21
 
21
22
  return (
22
- <div onClick={digg(this, "onFilterClicked")} style={{display: "inline-block", backgroundColor: "grey", padding: "10px 6px"}}>
23
- {p.join(".")}.{a} {pre} {v}
23
+ <div style={{display: "inline-block", backgroundColor: "grey", padding: "10px 6px"}}>
24
+ <span className="filter-label" onClick={digg(this, "onFilterClicked")} style={{cursor: "pointer"}}>
25
+ {p.length > 0 &&
26
+ `${p.join(".")}.`
27
+ }
28
+ {a} {pre} {v}
29
+ </span>
30
+ <span>
31
+ <a className="remove-filter-button" href="#" onClick={digg(this, "onRemoveFilterClicked")}>
32
+ <i className="fa fa-remove la la-remove" />
33
+ </a>
34
+ </span>
24
35
  </div>
25
36
  )
26
37
  }
@@ -32,6 +43,14 @@ class ApiMakerTableFilter extends React.PureComponent {
32
43
 
33
44
  this.props.onClick({a, filterIndex, p, pre, v})
34
45
  }
46
+
47
+ onRemoveFilterClicked = (e) => {
48
+ e.preventDefault()
49
+
50
+ const {filterIndex} = digs(this.props, "filterIndex")
51
+
52
+ this.props.onRemoveClicked({filterIndex})
53
+ }
35
54
  }
36
55
 
37
56
  class ApiMakerTableFilters extends React.PureComponent {
@@ -60,11 +79,18 @@ class ApiMakerTableFilters extends React.PureComponent {
60
79
  filter={filter}
61
80
  key={`filter-${filter.filterIndex}`}
62
81
  modelClass={modelClass}
82
+ onApplyClicked={digg(this, "onApplyClicked")}
63
83
  querySearchName={this.querySearchName()}
64
84
  />
65
85
  }
66
86
  {currentFilters?.map((filterData, filterIndex) =>
67
- <ApiMakerTableFilter key={filterIndex} filterIndex={filterIndex} onClick={digg(this, "onFilterClicked")} {...JSON.parse(filterData)} />
87
+ <ApiMakerTableFilter
88
+ key={filterIndex}
89
+ filterIndex={filterIndex}
90
+ onClick={digg(this, "onFilterClicked")}
91
+ onRemoveClicked={digg(this, "onRemoveClicked")}
92
+ {...JSON.parse(filterData)}
93
+ />
68
94
  )}
69
95
  </div>
70
96
  )
@@ -89,6 +115,24 @@ class ApiMakerTableFilters extends React.PureComponent {
89
115
  })
90
116
  }
91
117
 
118
+ onApplyClicked = () => this.shape.set({filter: undefined})
119
+
120
+ onRemoveClicked = ({filterIndex}) => {
121
+ const searchParams = Params.parse()[this.querySearchName()] || {}
122
+
123
+ delete searchParams[filterIndex]
124
+
125
+ const newParams = {}
126
+
127
+ newParams[this.querySearchName()] = searchParams
128
+
129
+ Params.changeParams(newParams)
130
+
131
+ this.shape.set({
132
+ filter: undefined
133
+ })
134
+ }
135
+
92
136
  onFilterClicked = (args) => this.shape.set({filter: args})
93
137
  querySearchName = () => `${this.props.queryName}_s`
94
138
  }
@@ -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
  }