@kaspernj/api-maker 1.0.231 → 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 +1 -1
- package/src/collection-loader.jsx +24 -1
- package/src/params.mjs +2 -2
- package/src/table/filters/filter-form.jsx +25 -11
- package/src/table/filters/index.jsx +3 -2
- package/src/table/table.jsx +35 -16
package/package.json
CHANGED
|
@@ -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 {
|
|
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
|
|
package/src/params.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import config from "./config.mjs"
|
|
1
2
|
import formSerialize from "form-serialize"
|
|
2
3
|
import Incorporator from "incorporator"
|
|
3
4
|
import qs from "qs"
|
|
@@ -26,8 +27,7 @@ export default class Params {
|
|
|
26
27
|
const params = Params.change(given)
|
|
27
28
|
const newParams = qs.stringify(params)
|
|
28
29
|
const newPath = `${location.pathname}?${newParams}`
|
|
29
|
-
|
|
30
|
-
let appHistory = opts.appHistory || AppHistory
|
|
30
|
+
const appHistory = opts.appHistory || config.getHistory() || AppHistory
|
|
31
31
|
|
|
32
32
|
appHistory.push(newPath)
|
|
33
33
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Attribute from "../../base-model/attribute"
|
|
2
|
-
import {digs} from "diggerize"
|
|
2
|
+
import {digg, digs} from "diggerize"
|
|
3
|
+
import inflection from "inflection"
|
|
3
4
|
import Input from "../../inputs/input"
|
|
4
5
|
import PropTypes from "prop-types"
|
|
5
6
|
import PropTypesExact from "prop-types-exact"
|
|
@@ -10,13 +11,13 @@ import Services from "../../services.mjs"
|
|
|
10
11
|
import Shape from "set-state-compare/src/shape"
|
|
11
12
|
|
|
12
13
|
class AttributeElement extends React.PureComponent {
|
|
13
|
-
static propTypes = {
|
|
14
|
+
static propTypes = PropTypesExact({
|
|
14
15
|
active: PropTypes.bool.isRequired,
|
|
15
16
|
attribute: PropTypes.instanceOf(Attribute).isRequired,
|
|
16
17
|
currentModelClass: PropTypes.func.isRequired,
|
|
17
18
|
fikter: PropTypes.object,
|
|
18
19
|
onClick: PropTypes.func.isRequired
|
|
19
|
-
}
|
|
20
|
+
})
|
|
20
21
|
|
|
21
22
|
render() {
|
|
22
23
|
const {active, attribute, currentModelClass} = digs(this.props, "active", "attribute", "currentModelClass")
|
|
@@ -25,7 +26,13 @@ class AttributeElement extends React.PureComponent {
|
|
|
25
26
|
if (active) style.fontWeight = "bold"
|
|
26
27
|
|
|
27
28
|
return (
|
|
28
|
-
<div
|
|
29
|
+
<div
|
|
30
|
+
className="attribute-element"
|
|
31
|
+
data-attribute-name={attribute.name()}
|
|
32
|
+
data-model-class={currentModelClass.modelClassData().name}
|
|
33
|
+
onClick={digg(this, "onAttributeClicked")}
|
|
34
|
+
style={style}
|
|
35
|
+
>
|
|
29
36
|
{currentModelClass.humanAttributeName(inflection.camelize(attribute.name(), true))}
|
|
30
37
|
</div>
|
|
31
38
|
)
|
|
@@ -39,17 +46,23 @@ class AttributeElement extends React.PureComponent {
|
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
class ReflectionElement extends React.PureComponent {
|
|
42
|
-
static propTypes = {
|
|
49
|
+
static propTypes = PropTypesExact({
|
|
43
50
|
currentModelClass: PropTypes.func.isRequired,
|
|
44
51
|
onClick: PropTypes.func.isRequired,
|
|
45
52
|
reflection: PropTypes.instanceOf(Reflection).isRequired
|
|
46
|
-
}
|
|
53
|
+
})
|
|
47
54
|
|
|
48
55
|
render() {
|
|
49
56
|
const {currentModelClass, reflection} = digs(this.props, "currentModelClass", "reflection")
|
|
50
57
|
|
|
51
58
|
return (
|
|
52
|
-
<div
|
|
59
|
+
<div
|
|
60
|
+
className="reflection-element"
|
|
61
|
+
data-model-class={currentModelClass.modelClassData().name}
|
|
62
|
+
data-reflection-name={reflection.name()}
|
|
63
|
+
key={reflection.name()}
|
|
64
|
+
onClick={digg(this, "onReflectionClicked")}
|
|
65
|
+
>
|
|
53
66
|
{currentModelClass.humanAttributeName(reflection.name())}
|
|
54
67
|
</div>
|
|
55
68
|
)
|
|
@@ -103,7 +116,7 @@ export default class ApiMakerTableFiltersRelationshipSelect extends React.PureCo
|
|
|
103
116
|
const {attribute, predicate, predicates, value} = digs(this.shape, "attribute", "predicate", "predicates", "value")
|
|
104
117
|
|
|
105
118
|
return (
|
|
106
|
-
<div className="api-maker--table--filters--
|
|
119
|
+
<div className="api-maker--table--filters--filter-form">
|
|
107
120
|
<form onSubmit={digg(this, "onSubmit")}>
|
|
108
121
|
<div>
|
|
109
122
|
{this.currentPathParts().map(({translation}, pathPartIndex) =>
|
|
@@ -147,6 +160,7 @@ export default class ApiMakerTableFiltersRelationshipSelect extends React.PureCo
|
|
|
147
160
|
<div>
|
|
148
161
|
{predicates &&
|
|
149
162
|
<Select
|
|
163
|
+
className="predicate-select"
|
|
150
164
|
defaultValue={predicate?.name}
|
|
151
165
|
includeBlank
|
|
152
166
|
onChange={digg(this, "onPredicateChanged")}
|
|
@@ -156,14 +170,14 @@ export default class ApiMakerTableFiltersRelationshipSelect extends React.PureCo
|
|
|
156
170
|
</div>
|
|
157
171
|
<div>
|
|
158
172
|
{attribute && predicate &&
|
|
159
|
-
<Input defaultValue={value} inputRef={valueInputRef} />
|
|
173
|
+
<Input className="value-input" defaultValue={value} inputRef={valueInputRef} />
|
|
160
174
|
}
|
|
161
175
|
</div>
|
|
162
176
|
</div>
|
|
163
177
|
<div>
|
|
164
|
-
<
|
|
178
|
+
<button className="apply-filter-button" disabled={!attribute || !predicate}>
|
|
165
179
|
{I18n.t("js.api_maker.table.filters.relationship_select.apply", {defaultValue: "Apply"})}
|
|
166
|
-
</
|
|
180
|
+
</button>
|
|
167
181
|
</div>
|
|
168
182
|
</form>
|
|
169
183
|
</div>
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {digg, digs} from "diggerize"
|
|
1
2
|
import PropTypes from "prop-types"
|
|
2
3
|
import React from "react"
|
|
3
4
|
import FilterForm from "./filter-form"
|
|
@@ -50,8 +51,8 @@ class ApiMakerTableFilters extends React.PureComponent {
|
|
|
50
51
|
const currentFilters = this.currentFilters()
|
|
51
52
|
|
|
52
53
|
return (
|
|
53
|
-
<div className="api-maker--table--filters
|
|
54
|
-
<button onClick={digg(this, "onAddFilterClicked")}>
|
|
54
|
+
<div className="api-maker--table--filters">
|
|
55
|
+
<button className="add-new-filter-button" onClick={digg(this, "onAddFilterClicked")}>
|
|
55
56
|
{I18n.t("js.api_maker.table.filters.add_new_filter", {defaultValue: "Add new filter"})}
|
|
56
57
|
</button>
|
|
57
58
|
{filter &&
|
package/src/table/table.jsx
CHANGED
|
@@ -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,
|
|
@@ -273,13 +277,7 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
273
277
|
} = this.props
|
|
274
278
|
const {models, qParams, query, result} = digs(this.shape, "models", "qParams", "query", "result")
|
|
275
279
|
|
|
276
|
-
let
|
|
277
|
-
|
|
278
|
-
if (controls) {
|
|
279
|
-
controlsContent = controls({models, qParams, query, result})
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
controlsContent += this.tableControls()
|
|
280
|
+
let headerContent, PaginationComponent
|
|
283
281
|
|
|
284
282
|
if (typeof header == "function") {
|
|
285
283
|
headerContent = header({models, qParams, query, result})
|
|
@@ -353,24 +351,35 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
353
351
|
)
|
|
354
352
|
}
|
|
355
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
|
+
|
|
356
370
|
tableControls() {
|
|
357
371
|
const {controls} = this.props
|
|
358
372
|
|
|
359
373
|
return (
|
|
360
374
|
<>
|
|
361
375
|
{controls && controls({models, qParams, query, result})}
|
|
362
|
-
<a href="#" onClick={digg(this, "
|
|
363
|
-
<i className="fa fa-fw fa-magnifying-glass" />
|
|
376
|
+
<a className="filter-button" href="#" onClick={digg(this, "onFilterClicked")}>
|
|
377
|
+
<i className="fa fa-fw fa-magnifying-glass la la-fw la-search" />
|
|
364
378
|
</a>
|
|
365
379
|
</>
|
|
366
380
|
)
|
|
367
381
|
}
|
|
368
382
|
|
|
369
|
-
onNewFilterClick = (e) => {
|
|
370
|
-
e.preventDefault()
|
|
371
|
-
this.shape.set({showFilters: !this.shape.showFilters})
|
|
372
|
-
}
|
|
373
|
-
|
|
374
383
|
tableContent () {
|
|
375
384
|
const {breakPoint} = digs(this.props, "breakPoint")
|
|
376
385
|
const {models, preparedColumns} = digs(this.shape, "models", "preparedColumns")
|
|
@@ -424,8 +433,18 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
424
433
|
if (to === 0) from = 0
|
|
425
434
|
|
|
426
435
|
return (
|
|
427
|
-
<div style={{marginTop: "10px"}}>
|
|
428
|
-
|
|
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>
|
|
429
448
|
</div>
|
|
430
449
|
)
|
|
431
450
|
}
|