@kaspernj/api-maker 1.0.380 → 1.0.382
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/bootstrap/live-table/model-row.jsx +1 -2
- package/src/bootstrap/paginate.jsx +14 -3
- package/src/bootstrap/sort-link.jsx +16 -23
- package/src/table/filters/filter-form.jsx +16 -19
- package/src/table/filters/index.jsx +9 -8
- package/src/table/header-column.jsx +9 -6
- package/src/table/model-row.jsx +12 -6
- package/src/table/settings/column-row.jsx +88 -0
- package/src/table/settings/index.jsx +48 -96
- package/src/table/style.scss +4 -2
- package/src/table/table.jsx +15 -5
- package/src/utils/checkbox.jsx +33 -0
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
|
}
|
|
@@ -13,6 +13,7 @@ import {useRef} from "react"
|
|
|
13
13
|
export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseComponent {
|
|
14
14
|
static propTypes = propTypesExact({
|
|
15
15
|
column: PropTypes.object.isRequired,
|
|
16
|
+
fixedTableLayout: PropTypes.bool.isRequired,
|
|
16
17
|
table: PropTypes.object.isRequired,
|
|
17
18
|
tableSettingColumn: PropTypes.object.isRequired
|
|
18
19
|
})
|
|
@@ -32,7 +33,7 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
render() {
|
|
35
|
-
const {column, table, tableSettingColumn} = this.p
|
|
36
|
+
const {column, fixedTableLayout, table, tableSettingColumn} = this.p
|
|
36
37
|
const {width} = this.s
|
|
37
38
|
const {defaultParams} = table.props
|
|
38
39
|
const {query} = digs(table.collection, "query")
|
|
@@ -55,11 +56,13 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
55
56
|
{table.headerLabelForColumn(column)}
|
|
56
57
|
</Text>
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
-
<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
{fixedTableLayout &&
|
|
60
|
+
<Pressable onPressIn={this.tt.onResizePressIn} style={{marginLeft: "auto", cursor: "col-resize"}}>
|
|
61
|
+
<Text>
|
|
62
|
+
|
|
|
63
|
+
</Text>
|
|
64
|
+
</Pressable>
|
|
65
|
+
}
|
|
63
66
|
</View>
|
|
64
67
|
</ColumnInHeadComponent>
|
|
65
68
|
)
|
package/src/table/model-row.jsx
CHANGED
|
@@ -7,22 +7,31 @@ import * as inflection from "inflection"
|
|
|
7
7
|
import Link from "../link"
|
|
8
8
|
import MoneyFormatter from "../money-formatter"
|
|
9
9
|
import PropTypes from "prop-types"
|
|
10
|
+
import propTypesExact from "prop-types-exact"
|
|
10
11
|
import {memo} from "react"
|
|
11
12
|
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
12
13
|
|
|
13
14
|
const WorkerPluginsCheckbox = React.lazy(() => import("./worker-plugins-checkbox"))
|
|
14
15
|
|
|
15
16
|
export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow extends BaseComponent {
|
|
16
|
-
static propTypes = {
|
|
17
|
+
static propTypes = propTypesExact({
|
|
17
18
|
cacheKey: PropTypes.string.isRequired,
|
|
19
|
+
columnComponent: PropTypes.oneOfType([
|
|
20
|
+
PropTypes.func,
|
|
21
|
+
PropTypes.string
|
|
22
|
+
]).isRequired,
|
|
18
23
|
model: PropTypes.object.isRequired,
|
|
19
24
|
liveTable: PropTypes.object.isRequired,
|
|
20
25
|
preparedColumns: PropTypes.array,
|
|
26
|
+
rowComponent: PropTypes.oneOfType([
|
|
27
|
+
PropTypes.func,
|
|
28
|
+
PropTypes.string
|
|
29
|
+
]).isRequired,
|
|
21
30
|
tableSettingFullCacheKey: PropTypes.string.isRequired
|
|
22
|
-
}
|
|
31
|
+
})
|
|
23
32
|
|
|
24
33
|
render() {
|
|
25
|
-
const {model} = this.p
|
|
34
|
+
const {columnComponent: ColumnComponent, model, rowComponent: RowComponent} = this.p
|
|
26
35
|
const {modelClass, workplace} = this.p.liveTable.p
|
|
27
36
|
const {actionsContent, columnsContent, destroyEnabled, editModelPath, viewModelPath} = this.p.liveTable.props
|
|
28
37
|
const {columns, currentWorkplace} = this.p.liveTable.state
|
|
@@ -34,9 +43,6 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
34
43
|
if (editModelPath && model.can("edit")) editPath = editModelPath(this.modelCallbackArgs)
|
|
35
44
|
if (viewModelPath && model.can("show")) viewPath = viewModelPath(this.modelCallbackArgs)
|
|
36
45
|
|
|
37
|
-
const RowComponent = this.props.rowComponent
|
|
38
|
-
const ColumnComponent = this.props.columnComponent
|
|
39
|
-
|
|
40
46
|
return (
|
|
41
47
|
<RowComponent className={`live-table-row ${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`} data-model-id={model.id()}>
|
|
42
48
|
{workplace &&
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import BaseComponent from "../../base-component"
|
|
2
|
+
import columnIdentifier from "../column-identifier.mjs"
|
|
3
|
+
import PropTypes from "prop-types"
|
|
4
|
+
import propTypesExact from "prop-types-exact"
|
|
5
|
+
import {memo, useEffect, useRef} from "react"
|
|
6
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
7
|
+
import {View} from "react-native"
|
|
8
|
+
|
|
9
|
+
export default memo(shapeComponent(class ColumnRow extends BaseComponent {
|
|
10
|
+
static propTypes = propTypesExact({
|
|
11
|
+
column: PropTypes.object.isRequired,
|
|
12
|
+
table: PropTypes.object.isRequired,
|
|
13
|
+
tableSettingColumn: PropTypes.object.isRequired
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
setup() {
|
|
17
|
+
this.checked = this.p.tableSettingColumn.visible()
|
|
18
|
+
this.checkboxRef = useRef()
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
this.updateCheckboxChecked()
|
|
22
|
+
}, [this.checked])
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
render() {
|
|
26
|
+
const {column, table, tableSettingColumn} = this.p
|
|
27
|
+
const checkboxProps = {}
|
|
28
|
+
|
|
29
|
+
if (tableSettingColumn.visible() === true) {
|
|
30
|
+
checkboxProps.checked = "checked"
|
|
31
|
+
} else if (tableSettingColumn.visible() === null) {
|
|
32
|
+
checkboxProps.indeterminate = "indeterminate"
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<View dataSet={{component: "api-maker--table--settings--column-row"}} style={{justifyContent: "center"}}>
|
|
37
|
+
<label style={{whiteSpace: "nowrap"}}>
|
|
38
|
+
<input
|
|
39
|
+
className="api-maker--table--setings--column-checkbox"
|
|
40
|
+
data-identifier={columnIdentifier(column)}
|
|
41
|
+
onChange={this.onCheckboxChange}
|
|
42
|
+
ref={this.checkboxRef}
|
|
43
|
+
type="checkbox"
|
|
44
|
+
{...checkboxProps}
|
|
45
|
+
/>
|
|
46
|
+
{table.headerLabelForColumn(column)}
|
|
47
|
+
</label>
|
|
48
|
+
</View>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
onCheckboxChange = () => {
|
|
53
|
+
const {checked} = this
|
|
54
|
+
|
|
55
|
+
if (checked === true) {
|
|
56
|
+
this.checked = null
|
|
57
|
+
} else if (checked === null) {
|
|
58
|
+
this.checked = false
|
|
59
|
+
} else {
|
|
60
|
+
this.checked = true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
this.updateCheckboxChecked()
|
|
64
|
+
this.updateTableSettingColumn()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
updateCheckboxChecked() {
|
|
68
|
+
const {checked} = this.tt
|
|
69
|
+
|
|
70
|
+
if (checked === true) {
|
|
71
|
+
this.checkboxRef.current.checked = true
|
|
72
|
+
this.checkboxRef.current.indeterminate = undefined
|
|
73
|
+
} else if (checked === null) {
|
|
74
|
+
this.checkboxRef.current.checked = undefined
|
|
75
|
+
this.checkboxRef.current.indeterminate = true
|
|
76
|
+
} else {
|
|
77
|
+
this.checkboxRef.current.checked = undefined
|
|
78
|
+
this.checkboxRef.current.indeterminate = undefined
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async updateTableSettingColumn() {
|
|
83
|
+
const {table, tableSettingColumn} = this.p
|
|
84
|
+
|
|
85
|
+
await tableSettingColumn.update({visible: this.checked})
|
|
86
|
+
table.updateSettingsFullCacheKey()
|
|
87
|
+
}
|
|
88
|
+
}))
|
|
@@ -1,107 +1,53 @@
|
|
|
1
1
|
import "./style"
|
|
2
|
+
import BaseComponent from "../../base-component"
|
|
3
|
+
import Checkbox from "../../utils/checkbox"
|
|
2
4
|
import columnIdentifier from "../column-identifier.mjs"
|
|
3
|
-
import
|
|
5
|
+
import ColumnRow from "./column-row"
|
|
6
|
+
import {memo, useRef} from "react"
|
|
4
7
|
import PropTypes from "prop-types"
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
checked = this.props.tableSettingColumn.visible()
|
|
15
|
-
checkboxRef = React.createRef()
|
|
16
|
-
|
|
17
|
-
componentDidMount() {
|
|
18
|
-
this.updateCheckboxChecked()
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
componentDidUpdate() {
|
|
22
|
-
this.updateCheckboxChecked()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
render() {
|
|
26
|
-
const {column, table, tableSettingColumn} = this.props
|
|
27
|
-
const checkboxProps = {}
|
|
28
|
-
|
|
29
|
-
if (tableSettingColumn.visible() === true) {
|
|
30
|
-
checkboxProps.checked = "checked"
|
|
31
|
-
} else if (tableSettingColumn.visible() === null) {
|
|
32
|
-
checkboxProps.indeterminate = "indeterminate"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<div className="api-maker--table--settings--column-row">
|
|
37
|
-
<label style={{whiteSpace: "nowrap"}}>
|
|
38
|
-
<input
|
|
39
|
-
className="api-maker--table--setings--column-checkbox"
|
|
40
|
-
data-identifier={columnIdentifier(column)}
|
|
41
|
-
onChange={this.onCheckboxChange}
|
|
42
|
-
ref={this.checkboxRef}
|
|
43
|
-
type="checkbox"
|
|
44
|
-
{...checkboxProps}
|
|
45
|
-
/>
|
|
46
|
-
{table.headerLabelForColumn(column)}
|
|
47
|
-
</label>
|
|
48
|
-
</div>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
onCheckboxChange = () => {
|
|
53
|
-
const {checked} = this
|
|
54
|
-
|
|
55
|
-
if (checked === true) {
|
|
56
|
-
this.checked = null
|
|
57
|
-
} else if (checked === null) {
|
|
58
|
-
this.checked = false
|
|
59
|
-
} else {
|
|
60
|
-
this.checked = true
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
this.updateCheckboxChecked()
|
|
64
|
-
this.updateTableSettingColumn()
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
updateCheckboxChecked() {
|
|
68
|
-
const {checked} = this
|
|
69
|
-
|
|
70
|
-
if (checked === true) {
|
|
71
|
-
this.checkboxRef.current.checked = true
|
|
72
|
-
this.checkboxRef.current.indeterminate = undefined
|
|
73
|
-
} else if (checked === null) {
|
|
74
|
-
this.checkboxRef.current.checked = undefined
|
|
75
|
-
this.checkboxRef.current.indeterminate = true
|
|
76
|
-
} else {
|
|
77
|
-
this.checkboxRef.current.checked = undefined
|
|
78
|
-
this.checkboxRef.current.indeterminate = undefined
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async updateTableSettingColumn() {
|
|
83
|
-
const {table, tableSettingColumn} = this.props
|
|
84
|
-
|
|
85
|
-
await tableSettingColumn.update({visible: this.checked})
|
|
86
|
-
table.updateSettingsFullCacheKey()
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export default class ApiMakerTableSettings extends React.PureComponent {
|
|
91
|
-
static propTypes = {
|
|
8
|
+
import propTypesExact from "prop-types-exact"
|
|
9
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
10
|
+
import useEventListener from "../../use-event-listener"
|
|
11
|
+
import {Text, View} from "react-native"
|
|
12
|
+
|
|
13
|
+
export default memo(shapeComponent(class ApiMakerTableSettings extends BaseComponent {
|
|
14
|
+
static propTypes = propTypesExact({
|
|
15
|
+
onFixedTableLayoutChanged: PropTypes.func.isRequired,
|
|
92
16
|
onRequestClose: PropTypes.func.isRequired,
|
|
93
17
|
table: PropTypes.object.isRequired
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
setup() {
|
|
21
|
+
this.rootRef = useRef()
|
|
22
|
+
|
|
23
|
+
useEventListener(window, "mouseup", this.tt.onWindowMouseUp)
|
|
24
|
+
this.useStates({
|
|
25
|
+
fixedTableLayout: this.tableSetting().fixedTableLayout()
|
|
26
|
+
})
|
|
94
27
|
}
|
|
95
28
|
|
|
96
|
-
|
|
29
|
+
tableSetting = () => this.p.table.s.tableSetting
|
|
97
30
|
|
|
98
31
|
render() {
|
|
99
|
-
const {table} = this.
|
|
100
|
-
const {
|
|
32
|
+
const {table} = this.p
|
|
33
|
+
const {fixedTableLayout} = this.s
|
|
34
|
+
const {preparedColumns} = table.s
|
|
101
35
|
|
|
102
36
|
return (
|
|
103
|
-
<div className="api-maker--table--settings" ref={this.rootRef}>
|
|
104
|
-
<
|
|
37
|
+
<div className="api-maker--table--settings" ref={this.tt.rootRef}>
|
|
38
|
+
<View style={{marginBottom: 5}}>
|
|
39
|
+
<Text style={{fontSize: 16, fontWeight: "bold"}}>
|
|
40
|
+
Settings
|
|
41
|
+
</Text>
|
|
42
|
+
</View>
|
|
43
|
+
<View>
|
|
44
|
+
<Checkbox checked={fixedTableLayout} label="Fixed table" onValueChange={this.tt.onFixedTableChecked} />
|
|
45
|
+
</View>
|
|
46
|
+
<View style={{marginBottom: 5}}>
|
|
47
|
+
<Text style={{fontSize: 16, fontWeight: "bold"}}>
|
|
48
|
+
Columns
|
|
49
|
+
</Text>
|
|
50
|
+
</View>
|
|
105
51
|
{preparedColumns?.map(({column, tableSettingColumn}) =>
|
|
106
52
|
<ColumnRow column={column} key={columnIdentifier(column)} table={table} tableSettingColumn={tableSettingColumn} />
|
|
107
53
|
)}
|
|
@@ -109,9 +55,15 @@ export default class ApiMakerTableSettings extends React.PureComponent {
|
|
|
109
55
|
)
|
|
110
56
|
}
|
|
111
57
|
|
|
58
|
+
onFixedTableChecked = async (checked) => {
|
|
59
|
+
await this.tableSetting().update({fixedTableLayout: true})
|
|
60
|
+
this.setState({fixedTableLayout: checked})
|
|
61
|
+
this.p.onFixedTableLayoutChanged(checked)
|
|
62
|
+
}
|
|
63
|
+
|
|
112
64
|
onWindowMouseUp = (e) => {
|
|
113
|
-
if (this.rootRef.current && !this.rootRef.current.contains(e.target)) {
|
|
114
|
-
this.
|
|
65
|
+
if (this.tt.rootRef.current && !this.tt.rootRef.current.contains(e.target)) {
|
|
66
|
+
this.p.onRequestClose()
|
|
115
67
|
}
|
|
116
68
|
}
|
|
117
|
-
}
|
|
69
|
+
}))
|
package/src/table/style.scss
CHANGED
package/src/table/table.jsx
CHANGED
|
@@ -99,6 +99,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
99
99
|
this.useStates({
|
|
100
100
|
columns: columnsAsArray,
|
|
101
101
|
currentWorkplace: undefined,
|
|
102
|
+
fixedTableLayout: undefined,
|
|
102
103
|
identifier: () => this.props.identifier || `${collectionKey}-default`,
|
|
103
104
|
preload: undefined,
|
|
104
105
|
preparedColumns: undefined,
|
|
@@ -163,6 +164,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
163
164
|
const {columns, preload} = this.tableSettings.preparedColumns(tableSetting)
|
|
164
165
|
|
|
165
166
|
this.setState({
|
|
167
|
+
fixedTableLayout: tableSetting.fixedTableLayout(),
|
|
166
168
|
preparedColumns: columns,
|
|
167
169
|
preload: this.mergedPreloads(preload),
|
|
168
170
|
tableSetting,
|
|
@@ -219,7 +221,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
219
221
|
}
|
|
220
222
|
|
|
221
223
|
return (
|
|
222
|
-
<div className={this.className()}>
|
|
224
|
+
<div className={this.className()} data-fixed-table-layout={this.s.fixedTableLayout}>
|
|
223
225
|
{showNoRecordsAvailableContent &&
|
|
224
226
|
<div className="live-table--no-records-available-content">
|
|
225
227
|
{noRecordsAvailableContent({models, qParams, overallCount})}
|
|
@@ -395,6 +397,10 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
395
397
|
this.setState({showFilters: !this.state.showFilters})
|
|
396
398
|
}
|
|
397
399
|
|
|
400
|
+
onFixedTableLayoutChanged = (fixedTableLayout) => {
|
|
401
|
+
this.setState({fixedTableLayout})
|
|
402
|
+
}
|
|
403
|
+
|
|
398
404
|
onPerPageChanged = (e) => {
|
|
399
405
|
const {queryName} = this.s
|
|
400
406
|
const newPerPageValue = digg(e, "target", "value")
|
|
@@ -419,7 +425,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
419
425
|
</a>
|
|
420
426
|
<span style={{position: "relative"}}>
|
|
421
427
|
{showSettings &&
|
|
422
|
-
<Settings onRequestClose={this.tt.onRequestCloseSettings} table={this} />
|
|
428
|
+
<Settings onFixedTableLayoutChanged={this.tt.onFixedTableLayoutChanged} onRequestClose={this.tt.onRequestCloseSettings} table={this} />
|
|
423
429
|
}
|
|
424
430
|
<a className="settings-button" href="#" onClick={this.tt.onSettingsClicked}>
|
|
425
431
|
<i className="fa fa-fw fa-gear la la-fw la-gear" />
|
|
@@ -431,7 +437,6 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
431
437
|
|
|
432
438
|
tableContent () {
|
|
433
439
|
const {workplace} = this.p
|
|
434
|
-
const {breakpoint} = this.tt
|
|
435
440
|
const {currentWorkplace, preparedColumns, tableSettingFullCacheKey} = this.s
|
|
436
441
|
const {models, query} = digs(this.collection, "models", "query")
|
|
437
442
|
const ColumnInHeadComponent = this.columnInHeadComponent()
|
|
@@ -463,7 +468,6 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
463
468
|
<BodyComponent>
|
|
464
469
|
{models.map((model) =>
|
|
465
470
|
<ModelRow
|
|
466
|
-
breakPoint={breakpoint}
|
|
467
471
|
cacheKey={model.cacheKey()}
|
|
468
472
|
columnComponent={this.columnComponent()}
|
|
469
473
|
key={model.id()}
|
|
@@ -537,7 +541,13 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
537
541
|
rowComponent = () => this.responsiveComponent("tr")
|
|
538
542
|
|
|
539
543
|
headersContentFromColumns = () => this.s.preparedColumns?.map(({column, tableSettingColumn}) => columnVisible(column, tableSettingColumn) &&
|
|
540
|
-
<HeaderColumn
|
|
544
|
+
<HeaderColumn
|
|
545
|
+
column={column}
|
|
546
|
+
fixedTableLayout={this.s.fixedTableLayout}
|
|
547
|
+
key={tableSettingColumn.identifier()}
|
|
548
|
+
table={this}
|
|
549
|
+
tableSettingColumn={tableSettingColumn}
|
|
550
|
+
/>
|
|
541
551
|
)
|
|
542
552
|
|
|
543
553
|
headerClassNameForColumn (column) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
2
|
+
import {CheckBox, Text, View} from "react-native"
|
|
3
|
+
import {memo} from "react"
|
|
4
|
+
import PropTypes from "prop-types"
|
|
5
|
+
import propTypesExact from "prop-types-exact"
|
|
6
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
7
|
+
|
|
8
|
+
export default memo(shapeComponent(class ApiMakerUtilsCheckbox extends BaseComponent {
|
|
9
|
+
static defaultProps = {
|
|
10
|
+
label: undefined
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static propTypes = propTypesExact({
|
|
14
|
+
checked: PropTypes.bool.isRequired,
|
|
15
|
+
label: PropTypes.string,
|
|
16
|
+
onValueChange: PropTypes.func.isRequired
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
render() {
|
|
20
|
+
const {checked, label, onValueChange} = this.p
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<View dataSet={{component: "api-maker--utils--checkbox"}} style={{flexDirection: "row", alignItems: "center"}}>
|
|
24
|
+
<CheckBox onValueChange={onValueChange} value={checked} />
|
|
25
|
+
{label &&
|
|
26
|
+
<Text style={{marginLeft: 3}}>
|
|
27
|
+
{label}
|
|
28
|
+
</Text>
|
|
29
|
+
}
|
|
30
|
+
</View>
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
|
+
}))
|