@kaspernj/api-maker 1.0.401 → 1.0.403
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/paginate.jsx +15 -14
- package/src/bootstrap/sort-link.jsx +10 -12
- package/src/data-set-to-attributes.mjs +13 -0
- package/src/link.jsx +44 -10
- package/src/model-class-require.mjs +7 -2
- package/src/super-admin/index.jsx +15 -10
- package/src/super-admin/layout/menu/index.jsx +5 -3
- package/src/super-admin/layout/menu/menu-item/index.jsx +42 -5
- package/src/super-admin/layout/menu/menu-item/style.scss +1 -21
- package/src/super-admin/show-nav.jsx +4 -2
- package/src/super-admin/show-page/belongs-to-attribute-row.jsx +5 -2
- package/src/super-admin/show-reflection-actions.jsx +1 -1
- package/src/super-admin/show-reflection-link.jsx +4 -1
- package/src/table/components/column.jsx +12 -0
- package/src/table/components/flat-list.jsx +18 -0
- package/src/table/components/header.jsx +12 -0
- package/src/table/components/row.jsx +20 -0
- package/src/table/header-column.jsx +36 -38
- package/src/table/model-row.jsx +76 -51
- package/src/table/settings/column-row.jsx +1 -1
- package/src/table/settings/index.jsx +0 -12
- package/src/table/style.scss +0 -4
- package/src/table/table.jsx +99 -82
- package/src/table/widths.mjs +77 -0
- package/src/table/worker-plugins-check-all-checkbox.jsx +6 -4
- package/src/table/worker-plugins-checkbox.jsx +5 -3
- package/src/use-screen-layout.mjs +2 -2
- package/src/bootstrap/live-table/model-row.jsx +0 -149
- package/src/bootstrap/live-table.jsx +0 -399
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BaseComponent from "../base-component"
|
|
2
2
|
import classNames from "classnames"
|
|
3
3
|
import {digs} from "diggerize"
|
|
4
|
+
import Header from "./components/header"
|
|
4
5
|
import {memo} from "react"
|
|
5
6
|
import {Pressable, Text, View} from "react-native"
|
|
6
7
|
import PropTypes from "prop-types"
|
|
@@ -8,51 +9,41 @@ import propTypesExact from "prop-types-exact"
|
|
|
8
9
|
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
9
10
|
import SortLink from "../bootstrap/sort-link"
|
|
10
11
|
import useEventListener from "../use-event-listener.mjs"
|
|
11
|
-
import
|
|
12
|
+
import Widths from "./widths"
|
|
12
13
|
|
|
13
14
|
export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseComponent {
|
|
14
15
|
static propTypes = propTypesExact({
|
|
15
16
|
column: PropTypes.object.isRequired,
|
|
16
|
-
fixedTableLayout: PropTypes.bool.isRequired,
|
|
17
17
|
table: PropTypes.object.isRequired,
|
|
18
|
-
tableSettingColumn: PropTypes.object.isRequired
|
|
18
|
+
tableSettingColumn: PropTypes.object.isRequired,
|
|
19
|
+
width: PropTypes.number.isRequired,
|
|
20
|
+
widths: PropTypes.instanceOf(Widths).isRequired
|
|
19
21
|
})
|
|
20
22
|
|
|
21
23
|
setup() {
|
|
22
|
-
this.columnRef = useRef()
|
|
23
|
-
|
|
24
24
|
useEventListener(window, "mousemove", this.tt.onWindowMouseMove)
|
|
25
25
|
useEventListener(window, "mouseup", this.tt.onWindowMouseUp)
|
|
26
26
|
|
|
27
27
|
this.useStates({
|
|
28
28
|
cursorX: undefined,
|
|
29
29
|
originalWidth: undefined,
|
|
30
|
-
resizing: false
|
|
31
|
-
width: this.p.tableSettingColumn.width()
|
|
30
|
+
resizing: false
|
|
32
31
|
})
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
render() {
|
|
36
|
-
const {column,
|
|
37
|
-
const {width} = this.s
|
|
35
|
+
const {column, table, tableSettingColumn, width} = this.p
|
|
38
36
|
const {defaultParams} = table.props
|
|
39
37
|
const {query} = digs(table.collection, "query")
|
|
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
|
-
}
|
|
49
38
|
|
|
50
39
|
return (
|
|
51
|
-
<
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
40
|
+
<Header
|
|
41
|
+
dataSet={{
|
|
42
|
+
className: classNames(...table.headerClassNameForColumn(column)),
|
|
43
|
+
identifier: tableSettingColumn.identifier()
|
|
44
|
+
}}
|
|
45
|
+
onLayout={this.tt.onLayout}
|
|
46
|
+
style={{width: `${width}%`}}
|
|
56
47
|
{...table.columnProps(column)}
|
|
57
48
|
>
|
|
58
49
|
<View style={{display: "flex", flexDirection: "row", alignItems: "center"}}>
|
|
@@ -61,40 +52,44 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
61
52
|
attribute={tableSettingColumn.sortKey()}
|
|
62
53
|
defaultParams={defaultParams}
|
|
63
54
|
query={query}
|
|
64
|
-
style={
|
|
55
|
+
style={{whiteSpace: "nowrap", overflow: "hidden"}}
|
|
65
56
|
title={table.headerLabelForColumn(column)}
|
|
66
57
|
/>
|
|
67
58
|
}
|
|
68
59
|
{(!tableSettingColumn.hasSortKey() || !query) &&
|
|
69
|
-
<Text {
|
|
60
|
+
<Text ellipsizeMode="clip" numberOfLines={1}>
|
|
70
61
|
{table.headerLabelForColumn(column)}
|
|
71
62
|
</Text>
|
|
72
63
|
}
|
|
73
|
-
{
|
|
74
|
-
<
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
</Pressable>
|
|
79
|
-
}
|
|
64
|
+
<Pressable onPressIn={this.tt.onResizePressIn} style={{marginLeft: "auto", cursor: "col-resize"}}>
|
|
65
|
+
<Text>
|
|
66
|
+
|
|
|
67
|
+
</Text>
|
|
68
|
+
</Pressable>
|
|
80
69
|
</View>
|
|
81
|
-
</
|
|
70
|
+
</Header>
|
|
82
71
|
)
|
|
83
72
|
}
|
|
84
73
|
|
|
74
|
+
onLayout = (e) => {
|
|
75
|
+
const {width} = e.nativeEvent.layout
|
|
76
|
+
|
|
77
|
+
this.currentWidth = width
|
|
78
|
+
}
|
|
79
|
+
|
|
85
80
|
onResizeEnd = async () => {
|
|
86
81
|
this.setState({cursorX: undefined, resizing: false})
|
|
87
82
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
83
|
+
const width = this.p.widths.getWidthOfColumn(this.p.tableSettingColumn.identifier())
|
|
84
|
+
|
|
85
|
+
await this.p.tableSettingColumn.update({width})
|
|
91
86
|
}
|
|
92
87
|
|
|
93
88
|
onResizePressIn = (e) => {
|
|
94
89
|
e.preventDefault()
|
|
95
90
|
e.stopPropagation()
|
|
96
91
|
|
|
97
|
-
const originalWidth = this.
|
|
92
|
+
const originalWidth = this.currentWidth
|
|
98
93
|
const cursorX = e.nativeEvent.pageX
|
|
99
94
|
|
|
100
95
|
this.setState({
|
|
@@ -112,7 +107,10 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
112
107
|
const diffX = newCursorX - cursorX
|
|
113
108
|
const newWidth = originalWidth + diffX
|
|
114
109
|
|
|
115
|
-
this.
|
|
110
|
+
this.p.widths.setWidthOfColumn({
|
|
111
|
+
identifier: this.p.tableSettingColumn.identifier(),
|
|
112
|
+
width: newWidth
|
|
113
|
+
})
|
|
116
114
|
}
|
|
117
115
|
}
|
|
118
116
|
|
package/src/table/model-row.jsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import {Pressable, Text, View} from "react-native"
|
|
1
2
|
import BaseComponent from "../base-component"
|
|
2
3
|
import classNames from "classnames"
|
|
4
|
+
import Column from "./components/column"
|
|
3
5
|
import columnIdentifier from "./column-identifier.mjs"
|
|
4
6
|
import columnVisible from "./column-visible.mjs"
|
|
5
7
|
import {digs} from "diggerize"
|
|
@@ -8,6 +10,7 @@ import Link from "../link"
|
|
|
8
10
|
import MoneyFormatter from "../money-formatter"
|
|
9
11
|
import PropTypes from "prop-types"
|
|
10
12
|
import propTypesExact from "prop-types-exact"
|
|
13
|
+
import Row from "./components/row"
|
|
11
14
|
import {memo} from "react"
|
|
12
15
|
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
13
16
|
|
|
@@ -16,22 +19,16 @@ const WorkerPluginsCheckbox = React.lazy(() => import("./worker-plugins-checkbox
|
|
|
16
19
|
export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow extends BaseComponent {
|
|
17
20
|
static propTypes = propTypesExact({
|
|
18
21
|
cacheKey: PropTypes.string.isRequired,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
PropTypes.string
|
|
22
|
-
]).isRequired,
|
|
22
|
+
columnWidths: PropTypes.object.isRequired,
|
|
23
|
+
isSmallScreen: PropTypes.bool.isRequired,
|
|
23
24
|
model: PropTypes.object.isRequired,
|
|
24
25
|
liveTable: PropTypes.object.isRequired,
|
|
25
26
|
preparedColumns: PropTypes.array,
|
|
26
|
-
rowComponent: PropTypes.oneOfType([
|
|
27
|
-
PropTypes.func,
|
|
28
|
-
PropTypes.string
|
|
29
|
-
]).isRequired,
|
|
30
27
|
tableSettingFullCacheKey: PropTypes.string.isRequired
|
|
31
28
|
})
|
|
32
29
|
|
|
33
30
|
render() {
|
|
34
|
-
const {
|
|
31
|
+
const {model} = this.p
|
|
35
32
|
const {modelClass, workplace} = this.p.liveTable.p
|
|
36
33
|
const {actionsContent, columnsContent, destroyEnabled, editModelPath, viewModelPath} = this.p.liveTable.props
|
|
37
34
|
const {columns, currentWorkplace} = this.p.liveTable.state
|
|
@@ -40,42 +37,57 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
40
37
|
|
|
41
38
|
let editPath, viewPath
|
|
42
39
|
|
|
43
|
-
if (editModelPath && model.can("edit"))
|
|
44
|
-
|
|
40
|
+
if (editModelPath && model.can("edit")) {
|
|
41
|
+
editPath = editModelPath(this.modelCallbackArgs)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (viewModelPath && model.can("show")) {
|
|
45
|
+
viewPath = viewModelPath(this.modelCallbackArgs)
|
|
46
|
+
}
|
|
45
47
|
|
|
46
48
|
return (
|
|
47
|
-
<
|
|
49
|
+
<Row dataSet={{class: `${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`, modelId: model.id()}}>
|
|
48
50
|
{workplace &&
|
|
49
|
-
<
|
|
50
|
-
<WorkerPluginsCheckbox
|
|
51
|
-
|
|
51
|
+
<Column dataSet={{class: "workplace-column"}} style={{width: 25}}>
|
|
52
|
+
<WorkerPluginsCheckbox
|
|
53
|
+
currentWorkplace={currentWorkplace}
|
|
54
|
+
model={model}
|
|
55
|
+
style={{marginHorizontal: "auto"}}
|
|
56
|
+
/>
|
|
57
|
+
</Column>
|
|
52
58
|
}
|
|
53
59
|
{columns && this.columnsContentFromColumns(model)}
|
|
54
60
|
{!columns && columnsContent && columnsContent(this.modelCallbackArgs)}
|
|
55
|
-
<
|
|
61
|
+
<Column dataSet={{class: "actions-column"}} style={{flexDirection: "row"}}>
|
|
56
62
|
{actionsContent && actionsContent(this.modelCallbackArgs)}
|
|
57
63
|
{viewPath &&
|
|
58
|
-
<Link
|
|
59
|
-
<
|
|
64
|
+
<Link dataSet={{class: "view-button"}} to={viewPath}>
|
|
65
|
+
<Text>
|
|
66
|
+
🔍
|
|
67
|
+
</Text>
|
|
60
68
|
</Link>
|
|
61
69
|
}
|
|
62
70
|
{editPath &&
|
|
63
|
-
<Link
|
|
64
|
-
<
|
|
71
|
+
<Link dataSet={{class: "edit-button"}} to={editPath}>
|
|
72
|
+
<Text>
|
|
73
|
+
✎
|
|
74
|
+
</Text>
|
|
65
75
|
</Link>
|
|
66
76
|
}
|
|
67
77
|
{destroyEnabled && model.can("destroy") &&
|
|
68
|
-
<
|
|
69
|
-
<
|
|
70
|
-
|
|
78
|
+
<Pressable dataSet={{class: "destroy-button"}} onPress={this.tt.onDestroyClicked}>
|
|
79
|
+
<Text>
|
|
80
|
+
✕
|
|
81
|
+
</Text>
|
|
82
|
+
</Pressable>
|
|
71
83
|
}
|
|
72
|
-
</
|
|
73
|
-
</
|
|
84
|
+
</Column>
|
|
85
|
+
</Row>
|
|
74
86
|
)
|
|
75
87
|
}
|
|
76
88
|
|
|
77
89
|
columnClassNamesForColumn (column) {
|
|
78
|
-
const classNames = ["
|
|
90
|
+
const classNames = ["table--column"]
|
|
79
91
|
|
|
80
92
|
if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
|
|
81
93
|
if (column.columnProps && column.columnProps.className) classNames.push(column.columnProps.className)
|
|
@@ -84,24 +96,30 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
84
96
|
}
|
|
85
97
|
|
|
86
98
|
columnsContentFromColumns (model) {
|
|
87
|
-
const {preparedColumns} = this.p
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
const {isSmallScreen, preparedColumns} = this.p
|
|
100
|
+
|
|
101
|
+
return preparedColumns?.map(({column, tableSettingColumn, width}) => columnVisible(column, tableSettingColumn) &&
|
|
102
|
+
<Column
|
|
103
|
+
dataSet={{
|
|
104
|
+
class: classNames(this.columnClassNamesForColumn(column)),
|
|
105
|
+
identifier: columnIdentifier(column)
|
|
106
|
+
}}
|
|
94
107
|
key={columnIdentifier(column)}
|
|
108
|
+
style={{width: `${width}%`}}
|
|
95
109
|
{...this.props.liveTable.columnProps(column)}
|
|
96
110
|
>
|
|
97
|
-
|
|
98
|
-
{
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
{isSmallScreen &&
|
|
112
|
+
<View dataSet={{class: "table--column-label"}}>
|
|
113
|
+
<Text>
|
|
114
|
+
{this.props.liveTable.headerLabelForColumn(column)}
|
|
115
|
+
</Text>
|
|
116
|
+
</View>
|
|
117
|
+
}
|
|
118
|
+
<View dataSet={{class: "table--column-value"}}>
|
|
101
119
|
{column.content && this.columnContentFromContentArg(column, model)}
|
|
102
120
|
{!column.content && column.attribute && this.columnsContentFromAttributeAndPath(column, model)}
|
|
103
|
-
</
|
|
104
|
-
</
|
|
121
|
+
</View>
|
|
122
|
+
</Column>
|
|
105
123
|
)
|
|
106
124
|
}
|
|
107
125
|
|
|
@@ -135,7 +153,9 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
135
153
|
const modelColumn = attribute?.getColumn()
|
|
136
154
|
|
|
137
155
|
if (modelColumn?.getType() == "date") {
|
|
138
|
-
return
|
|
156
|
+
return (
|
|
157
|
+
<Text>{this.presentDateTime({apiMakerType: "date", value})}</Text>
|
|
158
|
+
)
|
|
139
159
|
}
|
|
140
160
|
|
|
141
161
|
return this.presentColumnValue(value)
|
|
@@ -151,9 +171,7 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
151
171
|
return modelCallbackArgs
|
|
152
172
|
}
|
|
153
173
|
|
|
154
|
-
onDestroyClicked = async (
|
|
155
|
-
e.preventDefault()
|
|
156
|
-
|
|
174
|
+
onDestroyClicked = async () => {
|
|
157
175
|
const {destroyMessage} = this.p.liveTable.props
|
|
158
176
|
const {model} = this.p
|
|
159
177
|
|
|
@@ -174,21 +192,28 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
174
192
|
|
|
175
193
|
presentColumnValue(value) {
|
|
176
194
|
if (value instanceof Date) {
|
|
177
|
-
return this.presentDateTime({value})
|
|
195
|
+
return <Text>{this.presentDateTime({value})}</Text>
|
|
178
196
|
} else if (MoneyFormatter.isMoney(value)) {
|
|
179
|
-
return MoneyFormatter.format(value)
|
|
197
|
+
return <Text>{MoneyFormatter.format(value)}</Text>
|
|
180
198
|
} else if (typeof value == "boolean") {
|
|
181
199
|
if (value) return I18n.t("js.shared.yes", {defaultValue: "Yes"})
|
|
182
200
|
|
|
183
|
-
return I18n.t("js.shared.no", {defaultValue: "No"})
|
|
201
|
+
return <Text>{I18n.t("js.shared.no", {defaultValue: "No"})}</Text>
|
|
184
202
|
} else if (Array.isArray(value)) {
|
|
185
|
-
return
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
203
|
+
return (
|
|
204
|
+
<Text>
|
|
205
|
+
{value
|
|
206
|
+
.map((valuePart) => this.presentColumnValue(valuePart))
|
|
207
|
+
.filter((valuePart) => Boolean(valuePart))
|
|
208
|
+
.join(", ")
|
|
209
|
+
}
|
|
210
|
+
</Text>
|
|
211
|
+
)
|
|
212
|
+
} else if (typeof value == "string") {
|
|
213
|
+
return <Text>{value}</Text>
|
|
189
214
|
}
|
|
190
215
|
|
|
191
|
-
return value
|
|
216
|
+
return <Text>{value}</Text>
|
|
192
217
|
}
|
|
193
218
|
|
|
194
219
|
presentDateTime({apiMakerType, value}) {
|
|
@@ -33,7 +33,7 @@ export default memo(shapeComponent(class ColumnRow extends BaseComponent {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
return (
|
|
36
|
-
<View dataSet={{component: "api-maker--table--settings--column-row"}} style={{justifyContent: "center"}}>
|
|
36
|
+
<View dataSet={{component: "api-maker--table--settings--column-row"}} style={{zIndex: 1, justifyContent: "center"}}>
|
|
37
37
|
<label style={{whiteSpace: "nowrap"}}>
|
|
38
38
|
<input
|
|
39
39
|
className="api-maker--table--setings--column-checkbox"
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "./style"
|
|
2
2
|
import BaseComponent from "../../base-component"
|
|
3
|
-
import Checkbox from "../../utils/checkbox"
|
|
4
3
|
import columnIdentifier from "../column-identifier.mjs"
|
|
5
4
|
import ColumnRow from "./column-row"
|
|
6
5
|
import {memo, useRef} from "react"
|
|
@@ -12,7 +11,6 @@ import {Text, View} from "react-native"
|
|
|
12
11
|
|
|
13
12
|
export default memo(shapeComponent(class ApiMakerTableSettings extends BaseComponent {
|
|
14
13
|
static propTypes = propTypesExact({
|
|
15
|
-
onFixedTableLayoutChanged: PropTypes.func.isRequired,
|
|
16
14
|
onRequestClose: PropTypes.func.isRequired,
|
|
17
15
|
table: PropTypes.object.isRequired
|
|
18
16
|
})
|
|
@@ -30,7 +28,6 @@ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseCompo
|
|
|
30
28
|
|
|
31
29
|
render() {
|
|
32
30
|
const {table} = this.p
|
|
33
|
-
const {fixedTableLayout} = this.s
|
|
34
31
|
const {preparedColumns} = table.s
|
|
35
32
|
|
|
36
33
|
return (
|
|
@@ -40,9 +37,6 @@ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseCompo
|
|
|
40
37
|
Settings
|
|
41
38
|
</Text>
|
|
42
39
|
</View>
|
|
43
|
-
<View>
|
|
44
|
-
<Checkbox checked={fixedTableLayout} label="Fixed table" onValueChange={this.tt.onFixedTableChecked} />
|
|
45
|
-
</View>
|
|
46
40
|
<View style={{marginBottom: 5}}>
|
|
47
41
|
<Text style={{fontSize: 16, fontWeight: "bold"}}>
|
|
48
42
|
Columns
|
|
@@ -55,12 +49,6 @@ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseCompo
|
|
|
55
49
|
)
|
|
56
50
|
}
|
|
57
51
|
|
|
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
|
-
|
|
64
52
|
onWindowMouseUp = (e) => {
|
|
65
53
|
if (this.tt.rootRef.current && !this.tt.rootRef.current.contains(e.target)) {
|
|
66
54
|
this.p.onRequestClose()
|