@kaspernj/api-maker 1.0.381 → 1.0.383
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/base-model.mjs +56 -63
- package/src/bootstrap/paginate.jsx +3 -3
- package/src/collection-loader.jsx +2 -2
- package/src/super-admin/edit-page.jsx +3 -3
- package/src/super-admin/index.jsx +1 -2
- package/src/super-admin/layout/index.jsx +2 -2
- package/src/table/filters/attribute-element.jsx +5 -4
- package/src/table/filters/filter.jsx +7 -6
- package/src/table/filters/load-search-modal.jsx +6 -5
- package/src/table/filters/reflection-element.jsx +5 -4
- package/src/table/filters/save-search-modal.jsx +5 -4
- package/src/table/filters/scope-element.jsx +6 -4
- package/src/table/header-column.jsx +25 -8
- 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 +17 -7
- package/src/table/use-breakpoint.mjs +2 -2
- package/src/table/worker-plugins-checkbox.jsx +2 -2
- package/src/use-can-can.mjs +3 -3
- package/src/use-collection.mjs +14 -17
- package/src/use-created-event.mjs +2 -2
- package/src/use-current-user.mjs +2 -2
- package/src/use-destroyed-event.mjs +2 -2
- package/src/use-event-emitter.mjs +2 -2
- package/src/use-event-listener.mjs +2 -2
- package/src/use-model.mjs +6 -6
- package/src/use-resize-observer.mjs +1 -1
- package/src/use-updated-event.mjs +2 -2
- package/src/utils/checkbox.jsx +33 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import apiMakerConfig from "@kaspernj/api-maker/src/config.mjs"
|
|
2
|
-
import
|
|
2
|
+
import BaseComponent from "../../base-component"
|
|
3
|
+
import Checkbox from "../../bootstrap/checkbox"
|
|
3
4
|
import {digg, digs} from "diggerize"
|
|
4
5
|
import Input from "../../bootstrap/input"
|
|
5
|
-
import {shapeComponent
|
|
6
|
+
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
6
7
|
import {memo} from "react"
|
|
7
8
|
import useI18n from "i18n-on-steroids/src/use-i18n.mjs"
|
|
8
9
|
|
|
9
|
-
export default memo(shapeComponent(class ApiMakerTableFiltersSaveSearchModal extends
|
|
10
|
+
export default memo(shapeComponent(class ApiMakerTableFiltersSaveSearchModal extends BaseComponent {
|
|
10
11
|
setup() {
|
|
11
12
|
const {t} = useI18n({namespace: "js.api_maker.table.filters.save_search_modal"})
|
|
12
13
|
|
|
@@ -45,7 +46,7 @@ export default memo(shapeComponent(class ApiMakerTableFiltersSaveSearchModal ext
|
|
|
45
46
|
|
|
46
47
|
const form = digg(e, "target")
|
|
47
48
|
const formData = new FormData(form)
|
|
48
|
-
const {currentFilters, currentUser, onRequestClose, search} =
|
|
49
|
+
const {currentFilters, currentUser, onRequestClose, search} = this.p
|
|
49
50
|
|
|
50
51
|
if (search.isNewRecord()) {
|
|
51
52
|
formData.append("table_search[query_params]", JSON.stringify(currentFilters()))
|
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
import BaseComponent from "../../base-component"
|
|
1
2
|
import {digg} from "diggerize"
|
|
2
3
|
import PropTypes from "prop-types"
|
|
3
4
|
import {memo} from "react"
|
|
4
|
-
import {shapeComponent
|
|
5
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
5
6
|
|
|
6
|
-
export default memo(shapeComponent(class ScopeElement extends
|
|
7
|
+
export default memo(shapeComponent(class ScopeElement extends BaseComponent {
|
|
7
8
|
static defaultProps = {
|
|
8
9
|
active: false
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
static propTypes = {
|
|
12
13
|
active: PropTypes.bool.isRequired,
|
|
14
|
+
onScopeClicked: PropTypes.func.isRequired,
|
|
13
15
|
scope: PropTypes.object.isRequired
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
render() {
|
|
17
|
-
const {active, scope} = this.
|
|
19
|
+
const {active, scope} = this.p
|
|
18
20
|
const style = {}
|
|
19
21
|
|
|
20
22
|
if (active) style.fontWeight = "bold"
|
|
@@ -34,6 +36,6 @@ export default memo(shapeComponent(class ScopeElement extends ShapeComponent {
|
|
|
34
36
|
onScopeClicked = (e) => {
|
|
35
37
|
e.preventDefault()
|
|
36
38
|
|
|
37
|
-
this.
|
|
39
|
+
this.p.onScopeClicked({scope: this.p.scope})
|
|
38
40
|
}
|
|
39
41
|
}))
|
|
@@ -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,11 +33,19 @@ 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")
|
|
39
40
|
const ColumnInHeadComponent = table.columnInHeadComponent()
|
|
41
|
+
let sortLinkStyle
|
|
42
|
+
let textProps = {}
|
|
43
|
+
|
|
44
|
+
if (fixedTableLayout) {
|
|
45
|
+
sortLinkStyle = {whiteSpace: "nowrap", overflow: "hidden"}
|
|
46
|
+
textProps.ellipsizeMode="clip"
|
|
47
|
+
textProps.numberOfLines = 1
|
|
48
|
+
}
|
|
40
49
|
|
|
41
50
|
return (
|
|
42
51
|
<ColumnInHeadComponent
|
|
@@ -48,18 +57,26 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
48
57
|
>
|
|
49
58
|
<View style={{display: "flex", flexDirection: "row", alignItems: "center"}}>
|
|
50
59
|
{tableSettingColumn.hasSortKey() && query &&
|
|
51
|
-
<SortLink
|
|
60
|
+
<SortLink
|
|
61
|
+
attribute={tableSettingColumn.sortKey()}
|
|
62
|
+
defaultParams={defaultParams}
|
|
63
|
+
query={query}
|
|
64
|
+
style={sortLinkStyle}
|
|
65
|
+
title={table.headerLabelForColumn(column)}
|
|
66
|
+
/>
|
|
52
67
|
}
|
|
53
68
|
{(!tableSettingColumn.hasSortKey() || !query) &&
|
|
54
|
-
<Text>
|
|
69
|
+
<Text {...textProps}>
|
|
55
70
|
{table.headerLabelForColumn(column)}
|
|
56
71
|
</Text>
|
|
57
72
|
}
|
|
58
|
-
|
|
59
|
-
<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
{fixedTableLayout &&
|
|
74
|
+
<Pressable onPressIn={this.tt.onResizePressIn} style={{marginLeft: "auto", cursor: "col-resize"}}>
|
|
75
|
+
<Text>
|
|
76
|
+
|
|
|
77
|
+
</Text>
|
|
78
|
+
</Pressable>
|
|
79
|
+
}
|
|
63
80
|
</View>
|
|
64
81
|
</ColumnInHeadComponent>
|
|
65
82
|
)
|
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({fixed_table_layout: checked})
|
|
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
|
@@ -14,7 +14,7 @@ import ModelRow from "./model-row"
|
|
|
14
14
|
import Paginate from "../bootstrap/paginate"
|
|
15
15
|
import Params from "../params"
|
|
16
16
|
import PropTypes from "prop-types"
|
|
17
|
-
import React, {memo,
|
|
17
|
+
import React, {memo, useMemo, useRef} from "react"
|
|
18
18
|
import selectCalculator from "./select-calculator"
|
|
19
19
|
import Select from "../inputs/select"
|
|
20
20
|
import Settings from "./settings"
|
|
@@ -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,
|
|
@@ -112,7 +113,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
112
113
|
tableSettingFullCacheKey: undefined
|
|
113
114
|
})
|
|
114
115
|
|
|
115
|
-
|
|
116
|
+
useMemo(() => {
|
|
116
117
|
this.loadTableSetting()
|
|
117
118
|
|
|
118
119
|
if (this.props.workplace) this.loadCurrentWorkplace()
|
|
@@ -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) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useCallback,
|
|
1
|
+
import {useCallback, useMemo} from "react"
|
|
2
2
|
import apiMakerConfig from "@kaspernj/api-maker/src/config.mjs"
|
|
3
3
|
import useShape from "set-state-compare/src/use-shape.js"
|
|
4
4
|
|
|
@@ -30,7 +30,7 @@ const useBreakpoint = () => {
|
|
|
30
30
|
breakpoint: () => calculateBreakPoint()
|
|
31
31
|
})
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
useMemo(() => {
|
|
34
34
|
window.addEventListener("resize", onCalled)
|
|
35
35
|
|
|
36
36
|
return () => {
|
|
@@ -4,7 +4,7 @@ import EventConnection from "../event-connection"
|
|
|
4
4
|
import modelClassRequire from "../model-class-require.mjs"
|
|
5
5
|
import PropTypes from "prop-types"
|
|
6
6
|
import PropTypesExact from "prop-types-exact"
|
|
7
|
-
import {memo,
|
|
7
|
+
import {memo, useMemo} from "react"
|
|
8
8
|
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component"
|
|
9
9
|
|
|
10
10
|
const Workplace = modelClassRequire("Workplace")
|
|
@@ -21,7 +21,7 @@ export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckbox exte
|
|
|
21
21
|
linkLoaded: false
|
|
22
22
|
})
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
useMemo(() => {
|
|
25
25
|
this.loadCurrentLink()
|
|
26
26
|
}, [])
|
|
27
27
|
}
|
package/src/use-can-can.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import CanCan from "./can-can.mjs"
|
|
2
|
-
import {useCallback,
|
|
2
|
+
import {useCallback, useMemo, useState} from "react"
|
|
3
3
|
import useCurrentUser from "./use-current-user.mjs"
|
|
4
4
|
import useShape from "set-state-compare/src/use-shape.js"
|
|
5
5
|
|
|
@@ -26,12 +26,12 @@ const useCanCan = (abilitiesCallback, dependencies) => {
|
|
|
26
26
|
loadAbilities()
|
|
27
27
|
}, [])
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
useMemo(() => {
|
|
30
30
|
setCanCan(undefined)
|
|
31
31
|
loadAbilities()
|
|
32
32
|
}, dependencies)
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
useMemo(() => {
|
|
35
35
|
CanCan.current().events.addListener("onResetAbilities", onResetAbilities)
|
|
36
36
|
|
|
37
37
|
return () => {
|
package/src/use-collection.mjs
CHANGED
|
@@ -2,7 +2,8 @@ import debounce from "debounce"
|
|
|
2
2
|
import {digg} from "diggerize"
|
|
3
3
|
import * as inflection from "inflection"
|
|
4
4
|
import ModelEvents from "./model-events.mjs"
|
|
5
|
-
import {useCallback,
|
|
5
|
+
import {useCallback, useMemo} from "react"
|
|
6
|
+
import useCreatedEvent from "./use-created-event.mjs"
|
|
6
7
|
import useShape from "set-state-compare/src/use-shape.js"
|
|
7
8
|
import useQueryParams from "on-location-changed/src/use-query-params.js"
|
|
8
9
|
|
|
@@ -64,7 +65,7 @@ const useCollection = (props, cacheKeys = []) => {
|
|
|
64
65
|
showNoRecordsFoundContent: false
|
|
65
66
|
})
|
|
66
67
|
s.useStates({
|
|
67
|
-
qParams: qParams()
|
|
68
|
+
qParams: () => qParams()
|
|
68
69
|
})
|
|
69
70
|
|
|
70
71
|
let modelIdsCacheString
|
|
@@ -221,7 +222,11 @@ const useCollection = (props, cacheKeys = []) => {
|
|
|
221
222
|
if (models.length === 0 && s.props.noRecordsFoundContent) return true
|
|
222
223
|
}, [])
|
|
223
224
|
|
|
224
|
-
|
|
225
|
+
const onCreated = useCallback(() => {
|
|
226
|
+
loadModels()
|
|
227
|
+
}, [])
|
|
228
|
+
|
|
229
|
+
useMemo(
|
|
225
230
|
() => {
|
|
226
231
|
if (!("ifCondition" in s.props) || s.props.ifCondition) {
|
|
227
232
|
loadQParams()
|
|
@@ -238,23 +243,15 @@ const useCollection = (props, cacheKeys = []) => {
|
|
|
238
243
|
].concat(cacheKeys)
|
|
239
244
|
)
|
|
240
245
|
|
|
241
|
-
|
|
242
|
-
if (s.props.noRecordsAvailableContent)
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const onCreated = useCallback(() => {
|
|
246
|
-
loadModels()
|
|
247
|
-
}, [])
|
|
248
|
-
|
|
249
|
-
useEffect(() => {
|
|
250
|
-
const connectCreated = ModelEvents.connectCreated(s.p.modelClass, onCreated)
|
|
251
|
-
|
|
252
|
-
return () => {
|
|
253
|
-
connectCreated.unsubscribe()
|
|
246
|
+
useMemo(() => {
|
|
247
|
+
if (s.props.noRecordsAvailableContent) {
|
|
248
|
+
loadOverallCount()
|
|
254
249
|
}
|
|
255
250
|
}, [])
|
|
256
251
|
|
|
257
|
-
|
|
252
|
+
useCreatedEvent(s.p.modelClass, onCreated)
|
|
253
|
+
|
|
254
|
+
useMemo(() => {
|
|
258
255
|
const connections = []
|
|
259
256
|
|
|
260
257
|
if (s.s.models) {
|
|
@@ -2,7 +2,7 @@ import debounceFunction from "debounce"
|
|
|
2
2
|
import ModelEvents from "./model-events.mjs"
|
|
3
3
|
import PropTypes from "prop-types"
|
|
4
4
|
import propTypesExact from "prop-types-exact"
|
|
5
|
-
import {useCallback,
|
|
5
|
+
import {useCallback, useMemo} from "react"
|
|
6
6
|
import useShape from "set-state-compare/src/use-shape.js"
|
|
7
7
|
|
|
8
8
|
const ApiMakerUseCreatedEvent = (modelClass, onCreated, args = {}) => {
|
|
@@ -33,7 +33,7 @@ const ApiMakerUseCreatedEvent = (modelClass, onCreated, args = {}) => {
|
|
|
33
33
|
}
|
|
34
34
|
}, [])
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
useMemo(() => {
|
|
37
37
|
const connectCreated = ModelEvents.connectCreated(s.p.modelClass, (...args) => onCreatedCallback(...args))
|
|
38
38
|
|
|
39
39
|
return () => {
|
package/src/use-current-user.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useCallback,
|
|
1
|
+
import {useCallback, useMemo} from "react"
|
|
2
2
|
import {camelize} from "inflection"
|
|
3
3
|
import Devise from "./devise.mjs"
|
|
4
4
|
import Logger from "./logger.mjs"
|
|
@@ -69,7 +69,7 @@ const useCurrentUser = (args) => {
|
|
|
69
69
|
s.set(setStatesArgument)
|
|
70
70
|
}, [])
|
|
71
71
|
|
|
72
|
-
|
|
72
|
+
useMemo(() => {
|
|
73
73
|
if (!Devise.current().hasGlobalCurrentScope(s.m.scope) && !Devise.current().hasCurrentScope(s.m.scope)) {
|
|
74
74
|
logger.debug(() => `Devise hasn't got current scope ${s.m.scope} so loading from request`)
|
|
75
75
|
loadCurrentUserFromRequest()
|