@kaspernj/api-maker 1.0.380 → 1.0.381
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
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {digg, digs} from "diggerize"
|
|
2
2
|
import * as inflection from "inflection"
|
|
3
|
+
import Link from "../../link"
|
|
3
4
|
import MoneyFormatter from "../../money-formatter"
|
|
4
5
|
import PropTypes from "prop-types"
|
|
5
6
|
|
|
6
|
-
import Link from "../../link"
|
|
7
|
-
|
|
8
7
|
export default class ApiMakerBootStrapLiveTableModelRow extends React.PureComponent {
|
|
9
8
|
static propTypes = {
|
|
10
9
|
model: PropTypes.object.isRequired,
|
|
@@ -20,8 +20,14 @@ export default memo(shapeComponent(class ApiMakerBootstrapPaginate extends BaseC
|
|
|
20
20
|
setup() {
|
|
21
21
|
const {result} = this.p
|
|
22
22
|
|
|
23
|
-
this.totalPages = useMemo(
|
|
24
|
-
|
|
23
|
+
this.totalPages = useMemo(
|
|
24
|
+
() => Math.ceil(this.p.result.count() / this.p.result.perPage()),
|
|
25
|
+
[result.currentPage(), result.totalCount(), result.totalPages()]
|
|
26
|
+
)
|
|
27
|
+
this.pages = useMemo(
|
|
28
|
+
() => this.calculatePages(),
|
|
29
|
+
[result.currentPage(), result.totalCount(), result.totalPages()]
|
|
30
|
+
)
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
calculatePages () {
|
|
@@ -131,7 +137,12 @@ export default memo(shapeComponent(class ApiMakerBootstrapPaginate extends BaseC
|
|
|
131
137
|
</li>
|
|
132
138
|
}
|
|
133
139
|
{pages.map((page) =>
|
|
134
|
-
<li
|
|
140
|
+
<li
|
|
141
|
+
className={`page-item ${this.isPageActiveClass(page)}`}
|
|
142
|
+
data-active={this.isPageActiveClass(page) == "active"}
|
|
143
|
+
data-page={page}
|
|
144
|
+
key={`page-${page}`}
|
|
145
|
+
>
|
|
135
146
|
{this.isPageActiveClass(page) == "active" &&
|
|
136
147
|
page
|
|
137
148
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import BaseComponent from "../base-component"
|
|
2
|
-
import {digg, digs} from "diggerize"
|
|
3
2
|
import * as inflection from "inflection"
|
|
4
3
|
import PropTypes from "prop-types"
|
|
5
4
|
import qs from "qs"
|
|
6
|
-
import {memo
|
|
5
|
+
import {memo} from "react"
|
|
7
6
|
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
8
7
|
import urlEncode from "../url-encode.mjs"
|
|
9
8
|
|
|
@@ -31,12 +30,13 @@ export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseC
|
|
|
31
30
|
href () {
|
|
32
31
|
const qParams = this.qParams()
|
|
33
32
|
const {queryParams, searchKey} = this.tt
|
|
33
|
+
const newQueryParams = {...queryParams}
|
|
34
34
|
|
|
35
35
|
qParams.s = `${this.attribute()} ${this.sortMode()}` // eslint-disable-line id-length
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
newQueryParams[searchKey] = JSON.stringify(qParams)
|
|
38
38
|
|
|
39
|
-
const newParams = qs.stringify(
|
|
39
|
+
const newParams = qs.stringify(newQueryParams, {encoder: urlEncode})
|
|
40
40
|
const newPath = `${location.pathname}?${newParams}`
|
|
41
41
|
|
|
42
42
|
return newPath
|
|
@@ -56,17 +56,15 @@ export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseC
|
|
|
56
56
|
const {attribute, className, defaultParams, linkComponent, onChanged, query, title, ...restProps} = this.props
|
|
57
57
|
|
|
58
58
|
return (
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
</LinkComponent>
|
|
69
|
-
</>
|
|
59
|
+
<LinkComponent
|
|
60
|
+
className={this.className()}
|
|
61
|
+
data-attribute={attribute}
|
|
62
|
+
data-sort-mode={this.sortMode()}
|
|
63
|
+
to={this.href()}
|
|
64
|
+
{...restProps}
|
|
65
|
+
>
|
|
66
|
+
{this.title()}
|
|
67
|
+
</LinkComponent>
|
|
70
68
|
)
|
|
71
69
|
}
|
|
72
70
|
|
|
@@ -78,16 +76,11 @@ export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseC
|
|
|
78
76
|
return classNames.join(" ")
|
|
79
77
|
}
|
|
80
78
|
|
|
81
|
-
linkComponent ()
|
|
82
|
-
if (this.props.linkComponent) return this.props.linkComponent
|
|
83
|
-
|
|
84
|
-
return Link
|
|
85
|
-
}
|
|
79
|
+
linkComponent = () => this.props.linkComponent || Link
|
|
86
80
|
|
|
87
81
|
qParams() {
|
|
88
82
|
const {defaultParams} = this.props
|
|
89
|
-
const {queryParams} = this.tt
|
|
90
|
-
const {searchKey} = digs(this, "searchKey")
|
|
83
|
+
const {queryParams, searchKey} = this.tt
|
|
91
84
|
|
|
92
85
|
if (searchKey in queryParams) {
|
|
93
86
|
return JSON.parse(queryParams[searchKey])
|
|
@@ -105,7 +98,7 @@ export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseC
|
|
|
105
98
|
}
|
|
106
99
|
|
|
107
100
|
title () {
|
|
108
|
-
const {attribute, query} =
|
|
101
|
+
const {attribute, query} = this.p
|
|
109
102
|
const {title} = this.props
|
|
110
103
|
|
|
111
104
|
if (title) return title
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import AttributeElement from "./attribute-element"
|
|
2
|
+
import BaseComponent from "../../base-component"
|
|
2
3
|
import {digg, digs} from "diggerize"
|
|
3
4
|
import * as inflection from "inflection"
|
|
4
5
|
import Input from "../../inputs/input"
|
|
@@ -9,9 +10,9 @@ import ReflectionElement from "./reflection-element"
|
|
|
9
10
|
import ScopeElement from "./scope-element"
|
|
10
11
|
import Select from "../../inputs/select"
|
|
11
12
|
import Services from "../../services.mjs"
|
|
12
|
-
import {shapeComponent
|
|
13
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
13
14
|
|
|
14
|
-
export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
15
|
+
export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends BaseComponent {
|
|
15
16
|
static propTypes = PropTypesExact({
|
|
16
17
|
filter: PropTypes.object,
|
|
17
18
|
modelClass: PropTypes.func.isRequired,
|
|
@@ -55,7 +56,7 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
|
55
56
|
render() {
|
|
56
57
|
const {valueInputRef} = digs(this, "valueInputRef")
|
|
57
58
|
const currentModelClass = this.currentModelClass()
|
|
58
|
-
const {attribute, predicate, predicates, scope, value} =
|
|
59
|
+
const {attribute, predicate, predicates, scope, value} = this.s
|
|
59
60
|
let submitEnabled = false
|
|
60
61
|
|
|
61
62
|
if (attribute && predicate) {
|
|
@@ -66,7 +67,7 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
|
66
67
|
|
|
67
68
|
return (
|
|
68
69
|
<div className="api-maker--table--filters--filter-form">
|
|
69
|
-
<form onSubmit={
|
|
70
|
+
<form onSubmit={this.tt.onSubmit}>
|
|
70
71
|
<div>
|
|
71
72
|
{this.currentPathParts().map(({translation}, pathPartIndex) =>
|
|
72
73
|
<span key={`${pathPartIndex}-${translation}`}>
|
|
@@ -85,7 +86,7 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
|
85
86
|
<ReflectionElement
|
|
86
87
|
currentModelClass={currentModelClass}
|
|
87
88
|
key={reflection.name()}
|
|
88
|
-
onClick={
|
|
89
|
+
onClick={this.tt.onReflectionClicked}
|
|
89
90
|
reflection={reflection}
|
|
90
91
|
/>
|
|
91
92
|
)}
|
|
@@ -97,7 +98,7 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
|
97
98
|
attribute={attribute}
|
|
98
99
|
currentModelClass={currentModelClass}
|
|
99
100
|
key={attribute.name()}
|
|
100
|
-
onClick={
|
|
101
|
+
onClick={this.tt.onAttributeClicked}
|
|
101
102
|
/>
|
|
102
103
|
)}
|
|
103
104
|
{currentModelClass.ransackableScopes().map((scope) =>
|
|
@@ -105,7 +106,7 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
|
105
106
|
active={scope.name() == this.state.scope?.name()}
|
|
106
107
|
key={scope.name()}
|
|
107
108
|
scope={scope}
|
|
108
|
-
onScopeClicked={
|
|
109
|
+
onScopeClicked={this.tt.onScopeClicked}
|
|
109
110
|
/>
|
|
110
111
|
)}
|
|
111
112
|
</div>
|
|
@@ -115,7 +116,7 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
|
115
116
|
className="predicate-select"
|
|
116
117
|
defaultValue={predicate?.name}
|
|
117
118
|
includeBlank
|
|
118
|
-
onChange={
|
|
119
|
+
onChange={this.tt.onPredicateChanged}
|
|
119
120
|
options={predicates.map((predicate) => digg(predicate, "name"))}
|
|
120
121
|
/>
|
|
121
122
|
}
|
|
@@ -136,14 +137,10 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
|
136
137
|
)
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
currentModelClass()
|
|
140
|
-
const {path} = digs(this.state, "path")
|
|
141
|
-
|
|
142
|
-
return this.currentModelClassFromPath(path)
|
|
143
|
-
}
|
|
140
|
+
currentModelClass = () => this.currentModelClassFromPath(this.s.path)
|
|
144
141
|
|
|
145
142
|
currentModelClassFromPath(path) {
|
|
146
|
-
const {modelClass} =
|
|
143
|
+
const {modelClass} = this.p
|
|
147
144
|
let currentModelClass = modelClass
|
|
148
145
|
|
|
149
146
|
for (const pathPart of path) {
|
|
@@ -163,8 +160,8 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
|
163
160
|
}
|
|
164
161
|
|
|
165
162
|
currentPathParts() {
|
|
166
|
-
const {modelClass} =
|
|
167
|
-
const {path} =
|
|
163
|
+
const {modelClass} = this.p
|
|
164
|
+
const {path} = this.s
|
|
168
165
|
const result = []
|
|
169
166
|
let currentModelClass = modelClass
|
|
170
167
|
|
|
@@ -225,11 +222,11 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
|
|
|
225
222
|
onSubmit = (e) => {
|
|
226
223
|
e.preventDefault()
|
|
227
224
|
|
|
228
|
-
const {filter, querySearchName} =
|
|
229
|
-
const {attribute, path, predicate, scope} =
|
|
225
|
+
const {filter, querySearchName} = this.p
|
|
226
|
+
const {attribute, path, predicate, scope} = this.s
|
|
230
227
|
const {filterIndex} = digs(filter, "filterIndex")
|
|
231
228
|
const searchParams = Params.parse()[querySearchName] || {}
|
|
232
|
-
const value = digg(this
|
|
229
|
+
const value = digg(this.tt.valueInputRef, "current", "value")
|
|
233
230
|
const newSearchParams = {
|
|
234
231
|
p: path,
|
|
235
232
|
v: value
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import BaseComponent from "../../base-component"
|
|
1
2
|
import {digg, digs} from "diggerize"
|
|
2
3
|
import Filter from "./filter"
|
|
3
4
|
import FilterForm from "./filter-form"
|
|
@@ -5,13 +6,13 @@ import LoadSearchModal from "./load-search-modal"
|
|
|
5
6
|
import SaveSearchModal from "./save-search-modal"
|
|
6
7
|
import PropTypes from "prop-types"
|
|
7
8
|
import {memo} from "react"
|
|
8
|
-
import {shapeComponent
|
|
9
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
9
10
|
import {TableSearch} from "../../models.mjs.erb"
|
|
10
11
|
import useI18n from "i18n-on-steroids/src/use-i18n.mjs"
|
|
11
12
|
import useQueryParams from "on-location-changed/src/use-query-params"
|
|
12
13
|
import {View} from "react-native"
|
|
13
14
|
|
|
14
|
-
export default memo(shapeComponent(class ApiMakerTableFilters extends
|
|
15
|
+
export default memo(shapeComponent(class ApiMakerTableFilters extends BaseComponent {
|
|
15
16
|
static propTypes = {
|
|
16
17
|
currentUser: PropTypes.object,
|
|
17
18
|
modelClass: PropTypes.func.isRequired,
|
|
@@ -38,7 +39,7 @@ export default memo(shapeComponent(class ApiMakerTableFilters extends ShapeCompo
|
|
|
38
39
|
const currentFilters = this.currentFilters()
|
|
39
40
|
|
|
40
41
|
return (
|
|
41
|
-
<View dataSet={{class: "api-maker--table--filters"}}>
|
|
42
|
+
<View dataSet={{class: "api-maker--table--filters"}} style={{alignItems: "flex-start"}}>
|
|
42
43
|
{filter &&
|
|
43
44
|
<FilterForm
|
|
44
45
|
filter={filter}
|
|
@@ -74,21 +75,21 @@ export default memo(shapeComponent(class ApiMakerTableFilters extends ShapeCompo
|
|
|
74
75
|
{...filterData}
|
|
75
76
|
/>
|
|
76
77
|
)}
|
|
77
|
-
<
|
|
78
|
-
<button className="add-new-filter-button" onClick={
|
|
78
|
+
<View className="filter-actions" style={{flexDirection: "row", marginTop: 10}}>
|
|
79
|
+
<button className="add-new-filter-button" onClick={this.tt.onAddFilterClicked}>
|
|
79
80
|
{this.t(".add_new_filter", {defaultValue: "Add new filter"})}
|
|
80
81
|
</button>
|
|
81
82
|
{currentUser &&
|
|
82
83
|
<>
|
|
83
|
-
<button className="save-search-button" onClick={
|
|
84
|
+
<button className="save-search-button" onClick={this.tt.onSaveSearchClicked} style={{marginLeft: 10}}>
|
|
84
85
|
{this.t(".save_search", {defaultValue: "Save search"})}
|
|
85
86
|
</button>
|
|
86
|
-
<button className="load-search-button" onClick={
|
|
87
|
+
<button className="load-search-button" onClick={this.tt.onLoadSearchClicked} style={{marginLeft: 10}}>
|
|
87
88
|
{this.t(".load_search", {defaultValue: "Load search"})}
|
|
88
89
|
</button>
|
|
89
90
|
</>
|
|
90
91
|
}
|
|
91
|
-
</
|
|
92
|
+
</View>
|
|
92
93
|
</View>
|
|
93
94
|
)
|
|
94
95
|
}
|