@kaspernj/api-maker 1.0.379 → 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 +2 -2
- package/src/bootstrap/attribute-rows.jsx +7 -6
- package/src/bootstrap/card.jsx +10 -9
- package/src/bootstrap/live-table/model-row.jsx +1 -2
- package/src/bootstrap/live-table.jsx +3 -2
- package/src/bootstrap/paginate.jsx +95 -68
- package/src/bootstrap/sort-link.jsx +28 -37
- package/src/link.jsx +2 -2
- package/src/result.mjs +7 -23
- package/src/super-admin/show-reflection-link.jsx +2 -0
- package/src/table/filters/filter-form.jsx +16 -19
- package/src/table/filters/index.jsx +9 -8
- package/src/table/header-column.jsx +107 -0
- package/src/table/model-row.jsx +14 -13
- package/src/table/style.scss +4 -0
- package/src/table/table.jsx +27 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaspernj/api-maker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.381",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"js-money": ">= 0.6.3",
|
|
33
33
|
"numberable": ">= 1.0.0",
|
|
34
34
|
"object-to-formdata": ">= 4.1.0",
|
|
35
|
-
"on-location-changed": ">= 1.0.
|
|
35
|
+
"on-location-changed": ">= 1.0.13",
|
|
36
36
|
"qs": ">= 6.9.3",
|
|
37
37
|
"replaceall": ">= 0.1.6",
|
|
38
38
|
"set-state-compare": "^1.0.45",
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import AttributeRow from "./attribute-row"
|
|
2
|
-
import
|
|
2
|
+
import BaseComponent from "../base-component"
|
|
3
|
+
import {memo} from "react"
|
|
3
4
|
import PropTypes from "prop-types"
|
|
4
5
|
import propTypesExact from "prop-types-exact"
|
|
5
|
-
import
|
|
6
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
6
7
|
|
|
7
|
-
export default class ApiMakerBootstrapAttributeRows extends
|
|
8
|
+
export default memo(shapeComponent(class ApiMakerBootstrapAttributeRows extends BaseComponent {
|
|
8
9
|
static defaultProps = {
|
|
9
10
|
checkIfAttributeLoaded: false
|
|
10
11
|
}
|
|
@@ -15,13 +16,13 @@ export default class ApiMakerBootstrapAttributeRows extends React.PureComponent
|
|
|
15
16
|
model: PropTypes.object.isRequired
|
|
16
17
|
})
|
|
17
18
|
|
|
18
|
-
classObject = this.
|
|
19
|
+
classObject = this.p.model.modelClass()
|
|
19
20
|
|
|
20
21
|
render () {
|
|
21
|
-
const {attributes, checkIfAttributeLoaded, model} =
|
|
22
|
+
const {attributes, checkIfAttributeLoaded, model} = this.p
|
|
22
23
|
|
|
23
24
|
return attributes.map((attribute) =>
|
|
24
25
|
<AttributeRow attribute={attribute} checkIfAttributeLoaded={checkIfAttributeLoaded} key={`attribute-${attribute}`} model={model} />
|
|
25
26
|
)
|
|
26
27
|
}
|
|
27
|
-
}
|
|
28
|
+
}))
|
package/src/bootstrap/card.jsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
1
2
|
import classNames from "classnames"
|
|
2
3
|
import {digg, digs} from "diggerize"
|
|
3
4
|
import PropTypes from "prop-types"
|
|
4
|
-
import
|
|
5
|
+
import {memo, useRef} from "react"
|
|
6
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
5
7
|
|
|
6
|
-
export default class ApiMakerBootstrapCard extends
|
|
8
|
+
export default memo(shapeComponent(class ApiMakerBootstrapCard extends BaseComponent {
|
|
7
9
|
static defaultProps = {
|
|
8
10
|
defaultExpanded: true,
|
|
9
11
|
expandable: false,
|
|
@@ -27,13 +29,12 @@ export default class ApiMakerBootstrapCard extends React.PureComponent {
|
|
|
27
29
|
table: PropTypes.bool.isRequired
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
setup() {
|
|
33
|
+
this.cardRef = useRef()
|
|
31
34
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
expanded: props.defaultExpanded
|
|
36
|
-
}
|
|
35
|
+
this.useStates({
|
|
36
|
+
expanded: this.props.defaultExpanded
|
|
37
|
+
})
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
render () {
|
|
@@ -144,4 +145,4 @@ export default class ApiMakerBootstrapCard extends React.PureComponent {
|
|
|
144
145
|
|
|
145
146
|
return classNames.join(" ")
|
|
146
147
|
}
|
|
147
|
-
}
|
|
148
|
+
}))
|
|
@@ -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,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
1
2
|
import Card from "./card"
|
|
2
3
|
import classNames from "classnames"
|
|
3
4
|
import Collection from "../collection"
|
|
@@ -10,10 +11,10 @@ import Paginate from "./paginate"
|
|
|
10
11
|
import Params from "../params"
|
|
11
12
|
import PropTypes from "prop-types"
|
|
12
13
|
import {memo} from "react"
|
|
13
|
-
import {shapeComponent
|
|
14
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
14
15
|
import SortLink from "./sort-link"
|
|
15
16
|
|
|
16
|
-
export default memo(shapeComponent(class ApiMakerBootstrapLiveTable extends
|
|
17
|
+
export default memo(shapeComponent(class ApiMakerBootstrapLiveTable extends BaseComponent {
|
|
17
18
|
static defaultProps = {
|
|
18
19
|
card: true,
|
|
19
20
|
destroyEnabled: true,
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
1
2
|
import instanceOfClassName from "../instance-of-class-name"
|
|
2
3
|
import Link from "../link"
|
|
3
4
|
import PropTypes from "prop-types"
|
|
4
5
|
import propTypesExact from "prop-types-exact"
|
|
5
6
|
import qs from "qs"
|
|
6
|
-
import {memo} from "react"
|
|
7
|
+
import {memo, useMemo} from "react"
|
|
7
8
|
import Result from "../result"
|
|
8
|
-
import {shapeComponent
|
|
9
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
9
10
|
import urlEncode from "../url-encode.mjs"
|
|
10
11
|
|
|
11
|
-
export default memo(shapeComponent(class ApiMakerBootstrapPaginate extends
|
|
12
|
+
export default memo(shapeComponent(class ApiMakerBootstrapPaginate extends BaseComponent {
|
|
12
13
|
static propTypes = propTypesExact({
|
|
13
14
|
result: PropTypes.oneOfType([
|
|
14
15
|
instanceOfClassName("ApiMakerResult"),
|
|
@@ -17,34 +18,34 @@ export default memo(shapeComponent(class ApiMakerBootstrapPaginate extends Shape
|
|
|
17
18
|
})
|
|
18
19
|
|
|
19
20
|
setup() {
|
|
20
|
-
this.
|
|
21
|
-
pages: () => this.pages()
|
|
22
|
-
})
|
|
23
|
-
}
|
|
21
|
+
const {result} = this.p
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return "active"
|
|
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
|
+
)
|
|
34
31
|
}
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
const
|
|
33
|
+
calculatePages () {
|
|
34
|
+
const {result} = this.p
|
|
35
|
+
const {totalPages} = this.tt
|
|
36
|
+
const currentPage = result.currentPage()
|
|
38
37
|
const pages = []
|
|
39
|
-
|
|
38
|
+
|
|
40
39
|
let pagesFrom = currentPage - 5
|
|
41
40
|
let pagesTo = currentPage + 5
|
|
42
41
|
|
|
43
|
-
if (pagesFrom < 1)
|
|
42
|
+
if (pagesFrom < 1) {
|
|
44
43
|
pagesFrom = 1
|
|
44
|
+
}
|
|
45
45
|
|
|
46
|
-
if (pagesTo > totalPages)
|
|
46
|
+
if (pagesTo > totalPages) {
|
|
47
47
|
pagesTo = totalPages
|
|
48
|
+
}
|
|
48
49
|
|
|
49
50
|
for (let i = pagesFrom; i <= pagesTo; i++) {
|
|
50
51
|
pages.push(i)
|
|
@@ -53,8 +54,10 @@ export default memo(shapeComponent(class ApiMakerBootstrapPaginate extends Shape
|
|
|
53
54
|
return pages
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
isPageActiveClass = (pageNumber) => this.p.result.currentPage() == pageNumber ? "active" : "not-active"
|
|
58
|
+
|
|
56
59
|
pagePath (pageNumber) {
|
|
57
|
-
let pageKey = this.
|
|
60
|
+
let pageKey = this.p.result.data.collection.queryArgs.pageKey
|
|
58
61
|
|
|
59
62
|
if (!pageKey) {
|
|
60
63
|
pageKey = "page"
|
|
@@ -69,87 +72,111 @@ export default memo(shapeComponent(class ApiMakerBootstrapPaginate extends Shape
|
|
|
69
72
|
}
|
|
70
73
|
|
|
71
74
|
previousPagePath () {
|
|
75
|
+
const {result} = this.p
|
|
72
76
|
let previousPage
|
|
73
77
|
|
|
74
|
-
if (
|
|
75
|
-
previousPage =
|
|
78
|
+
if (result.currentPage() > 1) {
|
|
79
|
+
previousPage = result.currentPage() - 1
|
|
76
80
|
} else {
|
|
77
|
-
previousPage =
|
|
81
|
+
previousPage = result.currentPage()
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
return this.pagePath(previousPage)
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
nextPagePath () {
|
|
88
|
+
const {result} = this.p
|
|
84
89
|
let nextPage
|
|
85
90
|
|
|
86
|
-
if (
|
|
87
|
-
nextPage =
|
|
91
|
+
if (result.currentPage() < this.tt.totalPages) {
|
|
92
|
+
nextPage = result.currentPage() + 1
|
|
88
93
|
} else {
|
|
89
|
-
nextPage =
|
|
94
|
+
nextPage = result.currentPage()
|
|
90
95
|
}
|
|
91
96
|
|
|
92
97
|
return this.pagePath(nextPage)
|
|
93
98
|
}
|
|
94
99
|
|
|
95
|
-
showBackwardsDots ()
|
|
96
|
-
|
|
97
|
-
return (currentPage - 5 > 1)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
showForwardsDots () {
|
|
101
|
-
const currentPage = this.props.result.currentPage()
|
|
102
|
-
const totalPages = this.props.result.totalPages()
|
|
103
|
-
return (currentPage + 5 < totalPages)
|
|
104
|
-
}
|
|
100
|
+
showBackwardsDots = () => (this.p.result.currentPage() - 5 > 1)
|
|
101
|
+
showForwardsDots = () => (this.p.result.currentPage() + 5 < this.tt.totalPages)
|
|
105
102
|
|
|
106
103
|
render () {
|
|
107
|
-
const {result} = this.
|
|
108
|
-
const {pages} = this.
|
|
104
|
+
const {result} = this.p
|
|
105
|
+
const {pages, totalPages} = this.tt
|
|
106
|
+
const showNextPage = result.currentPage() < totalPages
|
|
107
|
+
const showLastPage = result.currentPage() < totalPages
|
|
108
|
+
const showPreviousPage = result.currentPage() > 1
|
|
109
|
+
const showFirstPage = result.currentPage() > 1
|
|
109
110
|
|
|
110
111
|
return (
|
|
111
112
|
<>
|
|
112
113
|
<ul className="pagination" data-pages-length={pages.length}>
|
|
113
|
-
<li className={`page-item ${
|
|
114
|
-
|
|
115
|
-
⇤
|
|
116
|
-
|
|
114
|
+
<li className={`page-item ${!showPreviousPage ? "disabled" : ""}`} key="page-first">
|
|
115
|
+
{!showPreviousPage &&
|
|
116
|
+
"⇤"
|
|
117
|
+
}
|
|
118
|
+
{showPreviousPage &&
|
|
119
|
+
<Link className="page-link" to={this.pagePath(1)}>
|
|
120
|
+
⇤
|
|
121
|
+
</Link>
|
|
122
|
+
}
|
|
117
123
|
</li>
|
|
118
|
-
<li className={`page-item ${
|
|
119
|
-
|
|
120
|
-
←
|
|
121
|
-
|
|
124
|
+
<li className={`page-item ${!showFirstPage ? "disabled" : ""}`} key="page-previous">
|
|
125
|
+
{!showFirstPage &&
|
|
126
|
+
"←"
|
|
127
|
+
}
|
|
128
|
+
{showFirstPage &&
|
|
129
|
+
<Link className="page-link" to={this.previousPagePath()}>
|
|
130
|
+
←
|
|
131
|
+
</Link>
|
|
132
|
+
}
|
|
122
133
|
</li>
|
|
123
134
|
{this.showBackwardsDots() &&
|
|
124
|
-
<li className="page-item">
|
|
125
|
-
|
|
126
|
-
…
|
|
127
|
-
</a>
|
|
135
|
+
<li className="page-item disabled">
|
|
136
|
+
…
|
|
128
137
|
</li>
|
|
129
138
|
}
|
|
130
139
|
{pages.map((page) =>
|
|
131
|
-
<li
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
>
|
|
146
|
+
{this.isPageActiveClass(page) == "active" &&
|
|
147
|
+
page
|
|
148
|
+
}
|
|
149
|
+
{this.isPageActiveClass(page) == "not-active" &&
|
|
150
|
+
<Link className="page-link" to={this.pagePath(page)}>
|
|
151
|
+
{page}
|
|
152
|
+
</Link>
|
|
153
|
+
}
|
|
135
154
|
</li>
|
|
136
155
|
)}
|
|
137
156
|
{this.showForwardsDots() &&
|
|
138
|
-
<li className="page-item">
|
|
139
|
-
|
|
140
|
-
…
|
|
141
|
-
</a>
|
|
157
|
+
<li className="page-item disabled">
|
|
158
|
+
…
|
|
142
159
|
</li>
|
|
143
160
|
}
|
|
144
|
-
<li className={`page-item ${
|
|
145
|
-
|
|
146
|
-
→
|
|
147
|
-
|
|
161
|
+
<li className={`page-item ${!showNextPage ? "disabled" : ""}`} key="page-next">
|
|
162
|
+
{!showNextPage &&
|
|
163
|
+
"→"
|
|
164
|
+
}
|
|
165
|
+
{showNextPage &&
|
|
166
|
+
<Link className="page-link" to={this.nextPagePath()}>
|
|
167
|
+
→
|
|
168
|
+
</Link>
|
|
169
|
+
}
|
|
148
170
|
</li>
|
|
149
|
-
<li className={`page-item ${
|
|
150
|
-
|
|
151
|
-
⇥
|
|
152
|
-
|
|
171
|
+
<li className={`page-item ${!showLastPage ? "disabled" : ""}`} key="page-last">
|
|
172
|
+
{!showLastPage &&
|
|
173
|
+
"⇥"
|
|
174
|
+
}
|
|
175
|
+
{showLastPage &&
|
|
176
|
+
<Link className="page-link" to={this.pagePath(totalPages)}>
|
|
177
|
+
⇥
|
|
178
|
+
</Link>
|
|
179
|
+
}
|
|
153
180
|
</li>
|
|
154
181
|
</ul>
|
|
155
182
|
</>
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
2
2
|
import * as inflection from "inflection"
|
|
3
3
|
import PropTypes from "prop-types"
|
|
4
4
|
import qs from "qs"
|
|
5
|
-
import
|
|
5
|
+
import {memo} from "react"
|
|
6
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
6
7
|
import urlEncode from "../url-encode.mjs"
|
|
7
8
|
|
|
8
9
|
import Link from "../link"
|
|
9
|
-
import
|
|
10
|
-
import withQueryParams from "on-location-changed/src/with-query-params"
|
|
10
|
+
import useQueryParams from "on-location-changed/src/use-query-params"
|
|
11
11
|
|
|
12
|
-
class ApiMakerBootstrapSortLink extends
|
|
12
|
+
export default memo(shapeComponent(class ApiMakerBootstrapSortLink extends BaseComponent {
|
|
13
13
|
static propTypes = {
|
|
14
14
|
attribute: PropTypes.string.isRequired,
|
|
15
15
|
className: PropTypes.string,
|
|
@@ -17,26 +17,26 @@ class ApiMakerBootstrapSortLink extends PureComponent {
|
|
|
17
17
|
linkComponent: PropTypes.object,
|
|
18
18
|
onChanged: PropTypes.func,
|
|
19
19
|
query: PropTypes.object.isRequired,
|
|
20
|
-
queryParams: PropTypes.object.isRequired,
|
|
21
20
|
title: PropTypes.node
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return inflection.underscore(this.props.attribute)
|
|
23
|
+
setup() {
|
|
24
|
+
this.queryParams = useQueryParams()
|
|
25
|
+
this.searchKey = this.p.query.queryArgs.searchKey || "q"
|
|
28
26
|
}
|
|
29
27
|
|
|
28
|
+
attribute = () => inflection.underscore(this.p.attribute)
|
|
29
|
+
|
|
30
30
|
href () {
|
|
31
31
|
const qParams = this.qParams()
|
|
32
|
-
const {queryParams} =
|
|
33
|
-
const
|
|
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
|
|
@@ -53,20 +53,18 @@ class ApiMakerBootstrapSortLink extends PureComponent {
|
|
|
53
53
|
|
|
54
54
|
render () {
|
|
55
55
|
const LinkComponent = this.linkComponent()
|
|
56
|
-
const {attribute, className, defaultParams, linkComponent, onChanged, query,
|
|
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 @@ class ApiMakerBootstrapSortLink extends PureComponent {
|
|
|
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} =
|
|
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,13 +98,11 @@ class ApiMakerBootstrapSortLink extends PureComponent {
|
|
|
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
|
|
112
105
|
|
|
113
106
|
return query.modelClass().humanAttributeName(attribute)
|
|
114
107
|
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export default withQueryParams(ApiMakerBootstrapSortLink)
|
|
108
|
+
}))
|
package/src/link.jsx
CHANGED
package/src/result.mjs
CHANGED
|
@@ -3,27 +3,11 @@ export default class ApiMakerResult {
|
|
|
3
3
|
this.data = data
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
modelClass () {
|
|
15
|
-
return this.data.collection.modelClass()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
perPage () {
|
|
19
|
-
return this.data.response.meta.perPage
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
totalCount () {
|
|
23
|
-
return this.data.response.meta.totalCount
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
totalPages () {
|
|
27
|
-
return this.data.response.meta.totalPages
|
|
28
|
-
}
|
|
6
|
+
count = () => this.data.response.meta.count
|
|
7
|
+
currentPage = () => this.data.response.meta.currentPage
|
|
8
|
+
models = () => this.data.models
|
|
9
|
+
modelClass = () => this.data.collection.modelClass()
|
|
10
|
+
perPage = () => this.data.response.meta.perPage
|
|
11
|
+
totalCount = () => this.data.response.meta.totalCount
|
|
12
|
+
totalPages = () => this.data.response.meta.totalPages
|
|
29
13
|
}
|
|
@@ -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
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
2
|
+
import classNames from "classnames"
|
|
3
|
+
import {digs} from "diggerize"
|
|
4
|
+
import {memo} from "react"
|
|
5
|
+
import {Pressable, Text, View} from "react-native"
|
|
6
|
+
import PropTypes from "prop-types"
|
|
7
|
+
import propTypesExact from "prop-types-exact"
|
|
8
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
9
|
+
import SortLink from "../bootstrap/sort-link"
|
|
10
|
+
import useEventListener from "../use-event-listener.mjs"
|
|
11
|
+
import {useRef} from "react"
|
|
12
|
+
|
|
13
|
+
export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseComponent {
|
|
14
|
+
static propTypes = propTypesExact({
|
|
15
|
+
column: PropTypes.object.isRequired,
|
|
16
|
+
table: PropTypes.object.isRequired,
|
|
17
|
+
tableSettingColumn: PropTypes.object.isRequired
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
setup() {
|
|
21
|
+
this.columnRef = useRef()
|
|
22
|
+
|
|
23
|
+
useEventListener(window, "mousemove", this.tt.onWindowMouseMove)
|
|
24
|
+
useEventListener(window, "mouseup", this.tt.onWindowMouseUp)
|
|
25
|
+
|
|
26
|
+
this.useStates({
|
|
27
|
+
cursorX: undefined,
|
|
28
|
+
originalWidth: undefined,
|
|
29
|
+
resizing: false,
|
|
30
|
+
width: this.p.tableSettingColumn.width()
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
render() {
|
|
35
|
+
const {column, table, tableSettingColumn} = this.p
|
|
36
|
+
const {width} = this.s
|
|
37
|
+
const {defaultParams} = table.props
|
|
38
|
+
const {query} = digs(table.collection, "query")
|
|
39
|
+
const ColumnInHeadComponent = table.columnInHeadComponent()
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<ColumnInHeadComponent
|
|
43
|
+
className={classNames(...table.headerClassNameForColumn(column))}
|
|
44
|
+
data-identifier={tableSettingColumn.identifier()}
|
|
45
|
+
ref={this.tt.columnRef}
|
|
46
|
+
style={{width}}
|
|
47
|
+
{...table.columnProps(column)}
|
|
48
|
+
>
|
|
49
|
+
<View style={{display: "flex", flexDirection: "row", alignItems: "center"}}>
|
|
50
|
+
{tableSettingColumn.hasSortKey() && query &&
|
|
51
|
+
<SortLink attribute={tableSettingColumn.sortKey()} defaultParams={defaultParams} query={query} title={table.headerLabelForColumn(column)} />
|
|
52
|
+
}
|
|
53
|
+
{(!tableSettingColumn.hasSortKey() || !query) &&
|
|
54
|
+
<Text>
|
|
55
|
+
{table.headerLabelForColumn(column)}
|
|
56
|
+
</Text>
|
|
57
|
+
}
|
|
58
|
+
<Pressable onPressIn={this.tt.onResizePressIn} style={{marginLeft: "auto", cursor: "col-resize"}}>
|
|
59
|
+
<Text>
|
|
60
|
+
|
|
|
61
|
+
</Text>
|
|
62
|
+
</Pressable>
|
|
63
|
+
</View>
|
|
64
|
+
</ColumnInHeadComponent>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
onResizeEnd = async () => {
|
|
69
|
+
this.setState({cursorX: undefined, resizing: false})
|
|
70
|
+
|
|
71
|
+
await this.p.tableSettingColumn.update({
|
|
72
|
+
width: this.s.width
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onResizePressIn = (e) => {
|
|
77
|
+
e.preventDefault()
|
|
78
|
+
e.stopPropagation()
|
|
79
|
+
|
|
80
|
+
const originalWidth = this.s.width || this.tt.columnRef.current.offsetWidth
|
|
81
|
+
const cursorX = e.nativeEvent.pageX
|
|
82
|
+
|
|
83
|
+
this.setState({
|
|
84
|
+
cursorX,
|
|
85
|
+
originalWidth,
|
|
86
|
+
resizing: true
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
onWindowMouseMove = (e) => {
|
|
91
|
+
const {cursorX, resizing, originalWidth} = this.s
|
|
92
|
+
|
|
93
|
+
if (resizing) {
|
|
94
|
+
const newCursorX = e.pageX
|
|
95
|
+
const diffX = newCursorX - cursorX
|
|
96
|
+
const newWidth = originalWidth + diffX
|
|
97
|
+
|
|
98
|
+
this.setState({width: newWidth})
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
onWindowMouseUp = () => {
|
|
103
|
+
if (this.s.resizing) {
|
|
104
|
+
this.onResizeEnd()
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}))
|
package/src/table/model-row.jsx
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
1
2
|
import classNames from "classnames"
|
|
2
3
|
import columnIdentifier from "./column-identifier.mjs"
|
|
3
4
|
import columnVisible from "./column-visible.mjs"
|
|
4
|
-
import {
|
|
5
|
+
import {digs} from "diggerize"
|
|
5
6
|
import * as inflection from "inflection"
|
|
6
7
|
import Link from "../link"
|
|
7
8
|
import MoneyFormatter from "../money-formatter"
|
|
8
9
|
import PropTypes from "prop-types"
|
|
9
10
|
import {memo} from "react"
|
|
10
|
-
import {shapeComponent
|
|
11
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
11
12
|
|
|
12
13
|
const WorkerPluginsCheckbox = React.lazy(() => import("./worker-plugins-checkbox"))
|
|
13
14
|
|
|
14
|
-
export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow extends
|
|
15
|
+
export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow extends BaseComponent {
|
|
15
16
|
static propTypes = {
|
|
16
17
|
cacheKey: PropTypes.string.isRequired,
|
|
17
18
|
model: PropTypes.object.isRequired,
|
|
@@ -21,10 +22,10 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
render() {
|
|
24
|
-
const {model} =
|
|
25
|
-
const {modelClass, workplace} =
|
|
26
|
-
const {actionsContent, columnsContent, destroyEnabled, editModelPath, viewModelPath} =
|
|
27
|
-
const {columns, currentWorkplace} =
|
|
25
|
+
const {model} = this.p
|
|
26
|
+
const {modelClass, workplace} = this.p.liveTable.p
|
|
27
|
+
const {actionsContent, columnsContent, destroyEnabled, editModelPath, viewModelPath} = this.p.liveTable.props
|
|
28
|
+
const {columns, currentWorkplace} = this.p.liveTable.state
|
|
28
29
|
|
|
29
30
|
this.modelCallbackArgs = this._modelCallbackArgs() // 'model' can change so this needs to be re-cached for every render
|
|
30
31
|
|
|
@@ -39,7 +40,7 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
39
40
|
return (
|
|
40
41
|
<RowComponent className={`live-table-row ${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`} data-model-id={model.id()}>
|
|
41
42
|
{workplace &&
|
|
42
|
-
<ColumnComponent className="workplace-column">
|
|
43
|
+
<ColumnComponent className="workplace-column" style={{width: 25, textAlign: "center"}}>
|
|
43
44
|
<WorkerPluginsCheckbox currentWorkplace={currentWorkplace} model={model} />
|
|
44
45
|
</ColumnComponent>
|
|
45
46
|
}
|
|
@@ -77,7 +78,7 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
columnsContentFromColumns (model) {
|
|
80
|
-
const {preparedColumns} =
|
|
81
|
+
const {preparedColumns} = this.p
|
|
81
82
|
const ColumnComponent = this.props.columnComponent
|
|
82
83
|
|
|
83
84
|
return preparedColumns?.map(({column, tableSettingColumn}) => columnVisible(column, tableSettingColumn) &&
|
|
@@ -98,7 +99,7 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
98
99
|
)
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
columnContentFromContentArg (column,
|
|
102
|
+
columnContentFromContentArg (column, _model) {
|
|
102
103
|
const value = column.content(this.modelCallbackArgs)
|
|
103
104
|
|
|
104
105
|
return this.presentColumnValue(value)
|
|
@@ -135,7 +136,7 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
_modelCallbackArgs () {
|
|
138
|
-
const {model} =
|
|
139
|
+
const {model} = this.p
|
|
139
140
|
const modelArgName = inflection.camelize(this.props.liveTable.props.modelClass.modelClassData().name, true)
|
|
140
141
|
const modelCallbackArgs = {model}
|
|
141
142
|
|
|
@@ -147,8 +148,8 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
147
148
|
onDestroyClicked = async (e) => {
|
|
148
149
|
e.preventDefault()
|
|
149
150
|
|
|
150
|
-
const {destroyMessage} =
|
|
151
|
-
const {model} =
|
|
151
|
+
const {destroyMessage} = this.p.liveTable.props
|
|
152
|
+
const {model} = this.p
|
|
152
153
|
|
|
153
154
|
if (!confirm(I18n.t("js.shared.are_you_sure"))) {
|
|
154
155
|
return
|
package/src/table/style.scss
CHANGED
package/src/table/table.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import "./style"
|
|
2
|
+
import BaseComponent from "../base-component"
|
|
2
3
|
import Card from "../bootstrap/card"
|
|
3
4
|
import classNames from "classnames"
|
|
4
5
|
import Collection from "../collection"
|
|
@@ -6,6 +7,7 @@ import columnVisible from "./column-visible.mjs"
|
|
|
6
7
|
import debounce from "debounce"
|
|
7
8
|
import {digg, digs} from "diggerize"
|
|
8
9
|
import Filters from "./filters"
|
|
10
|
+
import HeaderColumn from "./header-column"
|
|
9
11
|
import * as inflection from "inflection"
|
|
10
12
|
import modelClassRequire from "../model-class-require.mjs"
|
|
11
13
|
import ModelRow from "./model-row"
|
|
@@ -16,8 +18,7 @@ import React, {memo, useEffect, useRef} from "react"
|
|
|
16
18
|
import selectCalculator from "./select-calculator"
|
|
17
19
|
import Select from "../inputs/select"
|
|
18
20
|
import Settings from "./settings"
|
|
19
|
-
import {shapeComponent
|
|
20
|
-
import SortLink from "../bootstrap/sort-link"
|
|
21
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
21
22
|
import TableSettings from "./table-settings"
|
|
22
23
|
import uniqunize from "uniqunize"
|
|
23
24
|
import useBreakpoint from "./use-breakpoint"
|
|
@@ -27,7 +28,7 @@ import useQueryParams from "on-location-changed/src/use-query-params.js"
|
|
|
27
28
|
const paginationOptions = [30, 60, 90, ["All", "all"]]
|
|
28
29
|
const WorkerPluginsCheckAllCheckbox = React.lazy(() => import("./worker-plugins-check-all-checkbox"))
|
|
29
30
|
|
|
30
|
-
export default memo(shapeComponent(class ApiMakerTable extends
|
|
31
|
+
export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
31
32
|
static defaultProps = {
|
|
32
33
|
card: true,
|
|
33
34
|
destroyEnabled: true,
|
|
@@ -87,7 +88,7 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
87
88
|
filterFormRef: useRef()
|
|
88
89
|
})
|
|
89
90
|
|
|
90
|
-
const collectionKey = digg(this.
|
|
91
|
+
const collectionKey = digg(this.p.modelClass.modelClassData(), "collectionKey")
|
|
91
92
|
let queryName = this.props.queryName
|
|
92
93
|
|
|
93
94
|
if (!queryName) queryName = collectionKey
|
|
@@ -188,9 +189,9 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
188
189
|
}
|
|
189
190
|
|
|
190
191
|
render () {
|
|
191
|
-
const {modelClass, noRecordsAvailableContent, noRecordsFoundContent} =
|
|
192
|
+
const {modelClass, noRecordsAvailableContent, noRecordsFoundContent} = this.p
|
|
192
193
|
const {collection, currentUser} = this.props
|
|
193
|
-
const {queryName, querySName, showFilters} =
|
|
194
|
+
const {queryName, querySName, showFilters} = this.s
|
|
194
195
|
const {
|
|
195
196
|
models,
|
|
196
197
|
overallCount,
|
|
@@ -362,8 +363,8 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
362
363
|
}
|
|
363
364
|
|
|
364
365
|
filterForm = () => {
|
|
365
|
-
const {filterFormRef, submitFilter, submitFilterDebounce} =
|
|
366
|
-
const {filterContent, filterSubmitButton} =
|
|
366
|
+
const {filterFormRef, submitFilter, submitFilterDebounce} = this.tt
|
|
367
|
+
const {filterContent, filterSubmitButton} = this.p
|
|
367
368
|
const {filterSubmitLabel} = this.props
|
|
368
369
|
const {qParams} = digs(this.collection, "qParams")
|
|
369
370
|
|
|
@@ -395,7 +396,7 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
395
396
|
}
|
|
396
397
|
|
|
397
398
|
onPerPageChanged = (e) => {
|
|
398
|
-
const {queryName} =
|
|
399
|
+
const {queryName} = this.s
|
|
399
400
|
const newPerPageValue = digg(e, "target", "value")
|
|
400
401
|
const perKey = `${queryName}_per`
|
|
401
402
|
const paramsChange = {}
|
|
@@ -407,20 +408,20 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
407
408
|
|
|
408
409
|
tableControls() {
|
|
409
410
|
const {controls} = this.props
|
|
410
|
-
const {showSettings} =
|
|
411
|
+
const {showSettings} = this.s
|
|
411
412
|
const {models, qParams, query, result} = digs(this.collection, "models", "qParams", "query", "result")
|
|
412
413
|
|
|
413
414
|
return (
|
|
414
415
|
<>
|
|
415
416
|
{controls && controls({models, qParams, query, result})}
|
|
416
|
-
<a className="filter-button" href="#" onClick={
|
|
417
|
+
<a className="filter-button" href="#" onClick={this.tt.onFilterClicked}>
|
|
417
418
|
<i className="fa fa-fw fa-magnifying-glass la la-fw la-search" />
|
|
418
419
|
</a>
|
|
419
420
|
<span style={{position: "relative"}}>
|
|
420
421
|
{showSettings &&
|
|
421
|
-
<Settings onRequestClose={this.onRequestCloseSettings} table={this} />
|
|
422
|
+
<Settings onRequestClose={this.tt.onRequestCloseSettings} table={this} />
|
|
422
423
|
}
|
|
423
|
-
<a className="settings-button" href="#" onClick={
|
|
424
|
+
<a className="settings-button" href="#" onClick={this.tt.onSettingsClicked}>
|
|
424
425
|
<i className="fa fa-fw fa-gear la la-fw la-gear" />
|
|
425
426
|
</a>
|
|
426
427
|
</span>
|
|
@@ -429,9 +430,9 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
429
430
|
}
|
|
430
431
|
|
|
431
432
|
tableContent () {
|
|
432
|
-
const {workplace} =
|
|
433
|
-
const {breakpoint} =
|
|
434
|
-
const {currentWorkplace, preparedColumns, tableSettingFullCacheKey} =
|
|
433
|
+
const {workplace} = this.p
|
|
434
|
+
const {breakpoint} = this.tt
|
|
435
|
+
const {currentWorkplace, preparedColumns, tableSettingFullCacheKey} = this.s
|
|
435
436
|
const {models, query} = digs(this.collection, "models", "query")
|
|
436
437
|
const ColumnInHeadComponent = this.columnInHeadComponent()
|
|
437
438
|
const RowComponent = this.rowComponent()
|
|
@@ -451,7 +452,7 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
451
452
|
<HeadComponent>
|
|
452
453
|
<RowComponent className="live-table-header-row">
|
|
453
454
|
{workplace && currentWorkplace &&
|
|
454
|
-
<ColumnInHeadComponent>
|
|
455
|
+
<ColumnInHeadComponent style={{width: 25, textAlign: "center"}}>
|
|
455
456
|
<WorkerPluginsCheckAllCheckbox currentWorkplace={currentWorkplace} query={query} />
|
|
456
457
|
</ColumnInHeadComponent>
|
|
457
458
|
}
|
|
@@ -498,7 +499,7 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
498
499
|
<Select
|
|
499
500
|
className="per-page-select"
|
|
500
501
|
defaultValue={perPage}
|
|
501
|
-
onChange={
|
|
502
|
+
onChange={this.tt.onPerPageChanged}
|
|
502
503
|
options={paginationOptions}
|
|
503
504
|
/>
|
|
504
505
|
</div>
|
|
@@ -535,28 +536,9 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
535
536
|
responsiveComponent = (largeComponent) => this.isSmallScreen() ? "div" : largeComponent
|
|
536
537
|
rowComponent = () => this.responsiveComponent("tr")
|
|
537
538
|
|
|
538
|
-
headersContentFromColumns () {
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
const {query} = digs(this.collection, "query")
|
|
542
|
-
const ColumnInHeadComponent = this.columnInHeadComponent()
|
|
543
|
-
|
|
544
|
-
return preparedColumns?.map(({column, tableSettingColumn}) => columnVisible(column, tableSettingColumn) &&
|
|
545
|
-
<ColumnInHeadComponent
|
|
546
|
-
className={classNames(...this.headerClassNameForColumn(column))}
|
|
547
|
-
data-identifier={tableSettingColumn.identifier()}
|
|
548
|
-
key={tableSettingColumn.identifier()}
|
|
549
|
-
{...this.columnProps(column)}
|
|
550
|
-
>
|
|
551
|
-
{tableSettingColumn.hasSortKey() && query &&
|
|
552
|
-
<SortLink attribute={tableSettingColumn.sortKey()} defaultParams={defaultParams} query={query} title={this.headerLabelForColumn(column)} />
|
|
553
|
-
}
|
|
554
|
-
{(!tableSettingColumn.hasSortKey() || !query) &&
|
|
555
|
-
this.headerLabelForColumn(column)
|
|
556
|
-
}
|
|
557
|
-
</ColumnInHeadComponent>
|
|
558
|
-
)
|
|
559
|
-
}
|
|
539
|
+
headersContentFromColumns = () => this.s.preparedColumns?.map(({column, tableSettingColumn}) => columnVisible(column, tableSettingColumn) &&
|
|
540
|
+
<HeaderColumn column={column} key={tableSettingColumn.identifier()} table={this} tableSettingColumn={tableSettingColumn} />
|
|
541
|
+
)
|
|
560
542
|
|
|
561
543
|
headerClassNameForColumn (column) {
|
|
562
544
|
const classNames = ["live-table-header"]
|
|
@@ -568,7 +550,7 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
568
550
|
}
|
|
569
551
|
|
|
570
552
|
headerLabelForColumn (column) {
|
|
571
|
-
const {modelClass} =
|
|
553
|
+
const {modelClass} = this.p
|
|
572
554
|
|
|
573
555
|
if ("label" in column) {
|
|
574
556
|
if (typeof column.label == "function") {
|
|
@@ -605,17 +587,16 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
605
587
|
onSettingsClicked = (e) => {
|
|
606
588
|
e.preventDefault()
|
|
607
589
|
|
|
608
|
-
const {showSettings} =
|
|
590
|
+
const {showSettings} = this.s
|
|
609
591
|
|
|
610
592
|
this.setState({showSettings: !showSettings})
|
|
611
593
|
}
|
|
612
594
|
|
|
613
595
|
submitFilter = () => {
|
|
614
|
-
const
|
|
615
|
-
const filterForm = digg(filterFormRef, "current")
|
|
596
|
+
const filterForm = digg(this.tt.filterFormRef, "current")
|
|
616
597
|
const {appHistory} = this.props
|
|
617
598
|
const qParams = Params.serializeForm(filterForm)
|
|
618
|
-
const {queryQName} =
|
|
599
|
+
const {queryQName} = this.s
|
|
619
600
|
const changeParamsParams = {}
|
|
620
601
|
|
|
621
602
|
changeParamsParams[queryQName] = JSON.stringify(qParams)
|
|
@@ -623,5 +604,5 @@ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
|
|
|
623
604
|
Params.changeParams(changeParamsParams, {appHistory})
|
|
624
605
|
}
|
|
625
606
|
|
|
626
|
-
submitFilterDebounce = debounce(
|
|
607
|
+
submitFilterDebounce = debounce(this.tt.submitFilter)
|
|
627
608
|
}))
|