@kaspernj/api-maker 1.0.418 → 1.0.419
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/table/header-column.jsx +1 -1
- package/src/table/model-column.jsx +64 -0
- package/src/table/model-row.jsx +2 -57
- package/src/table/settings/column-row.jsx +4 -2
- package/src/table/table.jsx +39 -14
- package/src/table/widths.mjs +20 -19
- package/src/table/worker-plugins-checkbox.jsx +0 -1
package/package.json
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {Text, View} from "react-native"
|
|
2
|
+
import BaseComponent from "../base-component"
|
|
3
|
+
import classNames from "classnames"
|
|
4
|
+
import Column from "./components/column"
|
|
5
|
+
import ColumnContent from "./column-content"
|
|
6
|
+
import columnIdentifier from "./column-identifier.mjs"
|
|
7
|
+
import PropTypes from "prop-types"
|
|
8
|
+
import propTypesExact from "prop-types-exact"
|
|
9
|
+
import {memo} from "react"
|
|
10
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
11
|
+
|
|
12
|
+
export default memo(shapeComponent(class ApiMakerTableModelColumn extends BaseComponent {
|
|
13
|
+
static propTypes = propTypesExact({
|
|
14
|
+
column: PropTypes.object.isRequired,
|
|
15
|
+
columnIndex: PropTypes.number.isRequired,
|
|
16
|
+
even: PropTypes.bool.isRequired,
|
|
17
|
+
isSmallScreen: PropTypes.bool.isRequired,
|
|
18
|
+
model: PropTypes.object.isRequired,
|
|
19
|
+
table: PropTypes.object.isRequired,
|
|
20
|
+
tableSettingColumn: PropTypes.object.isRequired,
|
|
21
|
+
width: PropTypes.number.isRequired
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
render() {
|
|
25
|
+
const {column, columnIndex, even, isSmallScreen, model, table, width} = this.props
|
|
26
|
+
const columnProps = table.columnProps(column)
|
|
27
|
+
const {style, ...restColumnProps} = columnProps
|
|
28
|
+
const actualStyle = Object.assign(
|
|
29
|
+
table.styleForColumn({column, columnIndex, even, style: {width}}),
|
|
30
|
+
style
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Column
|
|
35
|
+
dataSet={{
|
|
36
|
+
class: classNames(this.columnClassNamesForColumn(column)),
|
|
37
|
+
identifier: columnIdentifier(column)
|
|
38
|
+
}}
|
|
39
|
+
style={actualStyle}
|
|
40
|
+
{...restColumnProps}
|
|
41
|
+
>
|
|
42
|
+
{isSmallScreen &&
|
|
43
|
+
<View dataSet={{class: "table--column-label"}}>
|
|
44
|
+
<Text>
|
|
45
|
+
{table.headerLabelForColumn(column)}
|
|
46
|
+
</Text>
|
|
47
|
+
</View>
|
|
48
|
+
}
|
|
49
|
+
<View dataSet={{class: "table--column-value"}}>
|
|
50
|
+
{new ColumnContent({column, model, table}).content()}
|
|
51
|
+
</View>
|
|
52
|
+
</Column>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
columnClassNamesForColumn(column) {
|
|
57
|
+
const classNames = ["table--column"]
|
|
58
|
+
|
|
59
|
+
if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
|
|
60
|
+
if (column.columnProps && column.columnProps.className) classNames.push(column.columnProps.className)
|
|
61
|
+
|
|
62
|
+
return classNames
|
|
63
|
+
}
|
|
64
|
+
}))
|
package/src/table/model-row.jsx
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import {Pressable
|
|
1
|
+
import {Pressable} from "react-native"
|
|
2
2
|
import BaseComponent from "../base-component"
|
|
3
|
-
import classNames from "classnames"
|
|
4
3
|
import Column from "./components/column"
|
|
5
|
-
import ColumnContent from "./column-content"
|
|
6
4
|
import columnIdentifier from "./column-identifier.mjs"
|
|
7
5
|
import columnVisible from "./column-visible.mjs"
|
|
8
6
|
import FontAwesomeIcon from "react-native-vector-icons/FontAwesome"
|
|
9
7
|
import * as inflection from "inflection"
|
|
10
8
|
import modelCallbackArgs from "./model-callback-args.mjs"
|
|
11
9
|
import Link from "../link"
|
|
10
|
+
import ModelColumn from "./model-column"
|
|
12
11
|
import PropTypes from "prop-types"
|
|
13
12
|
import propTypesExact from "prop-types-exact"
|
|
14
13
|
import Row from "./components/row"
|
|
@@ -17,60 +16,6 @@ import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
|
17
16
|
|
|
18
17
|
const WorkerPluginsCheckbox = React.lazy(() => import("./worker-plugins-checkbox"))
|
|
19
18
|
|
|
20
|
-
const ModelColumn = memo(shapeComponent(class ApiMakerTableModelColumn extends BaseComponent {
|
|
21
|
-
static propTypes = propTypesExact({
|
|
22
|
-
column: PropTypes.object.isRequired,
|
|
23
|
-
columnIndex: PropTypes.number.isRequired,
|
|
24
|
-
even: PropTypes.bool.isRequired,
|
|
25
|
-
isSmallScreen: PropTypes.bool.isRequired,
|
|
26
|
-
model: PropTypes.object.isRequired,
|
|
27
|
-
table: PropTypes.object.isRequired,
|
|
28
|
-
tableSettingColumn: PropTypes.object.isRequired,
|
|
29
|
-
width: PropTypes.number.isRequired
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
render() {
|
|
33
|
-
const {column, columnIndex, even, isSmallScreen, model, table, width} = this.props
|
|
34
|
-
const columnProps = table.columnProps(column)
|
|
35
|
-
const {style, ...restColumnProps} = columnProps
|
|
36
|
-
const actualStyle = Object.assign(
|
|
37
|
-
table.styleForColumn({column, columnIndex, even, style: {width: `${width}%`}}),
|
|
38
|
-
style
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
return (
|
|
42
|
-
<Column
|
|
43
|
-
dataSet={{
|
|
44
|
-
class: classNames(this.columnClassNamesForColumn(column)),
|
|
45
|
-
identifier: columnIdentifier(column)
|
|
46
|
-
}}
|
|
47
|
-
style={actualStyle}
|
|
48
|
-
{...restColumnProps}
|
|
49
|
-
>
|
|
50
|
-
{isSmallScreen &&
|
|
51
|
-
<View dataSet={{class: "table--column-label"}}>
|
|
52
|
-
<Text>
|
|
53
|
-
{table.headerLabelForColumn(column)}
|
|
54
|
-
</Text>
|
|
55
|
-
</View>
|
|
56
|
-
}
|
|
57
|
-
<View dataSet={{class: "table--column-value"}}>
|
|
58
|
-
{new ColumnContent({column, model, table}).content()}
|
|
59
|
-
</View>
|
|
60
|
-
</Column>
|
|
61
|
-
)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
columnClassNamesForColumn(column) {
|
|
65
|
-
const classNames = ["table--column"]
|
|
66
|
-
|
|
67
|
-
if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
|
|
68
|
-
if (column.columnProps && column.columnProps.className) classNames.push(column.columnProps.className)
|
|
69
|
-
|
|
70
|
-
return classNames
|
|
71
|
-
}
|
|
72
|
-
}))
|
|
73
|
-
|
|
74
19
|
export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow extends BaseComponent {
|
|
75
20
|
static propTypes = propTypesExact({
|
|
76
21
|
cacheKey: PropTypes.string.isRequired,
|
|
@@ -4,7 +4,7 @@ import PropTypes from "prop-types"
|
|
|
4
4
|
import propTypesExact from "prop-types-exact"
|
|
5
5
|
import {memo, useEffect, useRef} from "react"
|
|
6
6
|
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
7
|
-
import {View} from "react-native"
|
|
7
|
+
import {Text, View} from "react-native"
|
|
8
8
|
|
|
9
9
|
export default memo(shapeComponent(class ColumnRow extends BaseComponent {
|
|
10
10
|
static propTypes = propTypesExact({
|
|
@@ -43,7 +43,9 @@ export default memo(shapeComponent(class ColumnRow extends BaseComponent {
|
|
|
43
43
|
type="checkbox"
|
|
44
44
|
{...checkboxProps}
|
|
45
45
|
/>
|
|
46
|
-
|
|
46
|
+
<Text>
|
|
47
|
+
{table.headerLabelForColumn(column)}
|
|
48
|
+
</Text>
|
|
47
49
|
</label>
|
|
48
50
|
</View>
|
|
49
51
|
)
|
package/src/table/table.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {digg, digs} from "diggerize"
|
|
2
|
-
import {Pressable, Text, View} from "react-native"
|
|
2
|
+
import {Pressable, StyleSheet, Text, View} from "react-native"
|
|
3
3
|
import BaseComponent from "../base-component"
|
|
4
4
|
import Card from "../bootstrap/card"
|
|
5
5
|
import classNames from "classnames"
|
|
@@ -34,6 +34,13 @@ import Widths from "./widths"
|
|
|
34
34
|
|
|
35
35
|
const paginationOptions = [30, 60, 90, ["All", "all"]]
|
|
36
36
|
const WorkerPluginsCheckAllCheckbox = React.lazy(() => import("./worker-plugins-check-all-checkbox"))
|
|
37
|
+
const styleSheet = StyleSheet.create({
|
|
38
|
+
flatList: {
|
|
39
|
+
border: "1px solid #dbdbdb",
|
|
40
|
+
borderRadius: 5,
|
|
41
|
+
overflowX: "auto"
|
|
42
|
+
}
|
|
43
|
+
})
|
|
37
44
|
|
|
38
45
|
export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
39
46
|
static defaultProps = {
|
|
@@ -87,6 +94,8 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
87
94
|
workplace: PropTypes.bool.isRequired
|
|
88
95
|
}
|
|
89
96
|
|
|
97
|
+
tableSetting = null
|
|
98
|
+
|
|
90
99
|
setup() {
|
|
91
100
|
const {t} = useI18n({namespace: "js.api_maker.table"})
|
|
92
101
|
const {breakpoint} = useBreakpoint()
|
|
@@ -111,7 +120,6 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
111
120
|
columns: columnsAsArray,
|
|
112
121
|
currentWorkplace: undefined,
|
|
113
122
|
currentWorkplaceCount: null,
|
|
114
|
-
flatListWidth: undefined,
|
|
115
123
|
identifier: () => this.props.identifier || `${collectionKey}-default`,
|
|
116
124
|
lastUpdate: () => new Date(),
|
|
117
125
|
preload: undefined,
|
|
@@ -124,13 +132,13 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
124
132
|
showFilters: () => Boolean(queryParams[querySName]),
|
|
125
133
|
showSettings: false,
|
|
126
134
|
tableSetting: undefined,
|
|
135
|
+
tableSettingLoaded: false,
|
|
127
136
|
tableSettingFullCacheKey: undefined,
|
|
137
|
+
width: undefined,
|
|
128
138
|
widths: null
|
|
129
139
|
})
|
|
130
140
|
|
|
131
141
|
useMemo(() => {
|
|
132
|
-
this.loadTableSetting()
|
|
133
|
-
|
|
134
142
|
if (this.props.workplace) {
|
|
135
143
|
this.loadCurrentWorkplace().then(() => {
|
|
136
144
|
this.loadCurrentWorkplaceCount()
|
|
@@ -138,6 +146,12 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
138
146
|
}
|
|
139
147
|
}, [this.p.currentUser?.id()])
|
|
140
148
|
|
|
149
|
+
useMemo(() => {
|
|
150
|
+
if (!this.tt.tableSetting && this.s.width) {
|
|
151
|
+
this.loadTableSetting()
|
|
152
|
+
}
|
|
153
|
+
}, [this.p.currentUser?.id(), this.s.width])
|
|
154
|
+
|
|
141
155
|
useModelEvent(this.s.currentWorkplace, "workplace_links_created", this.tt.onLinksCreated)
|
|
142
156
|
useModelEvent(this.s.currentWorkplace, "workplace_links_destroyed", this.tt.onLinksDestroyed)
|
|
143
157
|
|
|
@@ -196,13 +210,14 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
196
210
|
|
|
197
211
|
const tableSetting = await this.tableSettings.loadExistingOrCreateTableSettings()
|
|
198
212
|
const {columns, preload} = this.tableSettings.preparedColumns(tableSetting)
|
|
199
|
-
const {
|
|
200
|
-
const widths = new Widths({columns,
|
|
213
|
+
const {width} = this.s
|
|
214
|
+
const widths = new Widths({columns, table: this, width})
|
|
201
215
|
|
|
202
216
|
this.setState({
|
|
203
217
|
preparedColumns: columns,
|
|
204
218
|
preload: this.mergedPreloads(preload),
|
|
205
219
|
tableSetting,
|
|
220
|
+
tableSettingLoaded: true,
|
|
206
221
|
tableSettingFullCacheKey: tableSetting.fullCacheKey(),
|
|
207
222
|
widths
|
|
208
223
|
})
|
|
@@ -259,7 +274,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
259
274
|
}
|
|
260
275
|
|
|
261
276
|
return (
|
|
262
|
-
<
|
|
277
|
+
<View dataSet={{class: this.className()}} onLayout={this.tt.onContainerLayout} style={this.props.styles?.container}>
|
|
263
278
|
{showNoRecordsAvailableContent &&
|
|
264
279
|
<div className="live-table--no-records-available-content">
|
|
265
280
|
{noRecordsAvailableContent({models, qParams, overallCount})}
|
|
@@ -276,7 +291,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
276
291
|
{qParams && query && result && models && !showNoRecordsAvailableContent && !showNoRecordsFoundContent &&
|
|
277
292
|
this.cardOrTable()
|
|
278
293
|
}
|
|
279
|
-
</
|
|
294
|
+
</View>
|
|
280
295
|
)
|
|
281
296
|
}
|
|
282
297
|
|
|
@@ -376,10 +391,9 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
376
391
|
extraData={this.s.lastUpdate}
|
|
377
392
|
keyExtractor={this.tt.keyExtrator}
|
|
378
393
|
ListHeaderComponent={this.tt.listHeaderComponent}
|
|
379
|
-
onLayout={this.tt.onFlatListLayout}
|
|
380
394
|
renderItem={this.tt.renderItem}
|
|
381
395
|
showsHorizontalScrollIndicator
|
|
382
|
-
style={
|
|
396
|
+
style={styleSheet.flatList}
|
|
383
397
|
{...restProps}
|
|
384
398
|
/>
|
|
385
399
|
)
|
|
@@ -416,12 +430,12 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
416
430
|
)
|
|
417
431
|
}
|
|
418
432
|
|
|
419
|
-
|
|
433
|
+
onContainerLayout = (e) => {
|
|
420
434
|
const {width} = e.nativeEvent.layout
|
|
421
435
|
const {widths} = this.s
|
|
422
436
|
|
|
423
|
-
this.setState({
|
|
424
|
-
widths.
|
|
437
|
+
this.setState({width})
|
|
438
|
+
if (widths) widths.tableWidth = width
|
|
425
439
|
}
|
|
426
440
|
|
|
427
441
|
onLinksCreated = ({args}) => {
|
|
@@ -517,6 +531,16 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
517
531
|
renderItem = ({index, item: model}) => {
|
|
518
532
|
const {preparedColumns, tableSettingFullCacheKey} = this.s
|
|
519
533
|
|
|
534
|
+
if (!this.s.tableSettingLoaded) {
|
|
535
|
+
return (
|
|
536
|
+
<View>
|
|
537
|
+
<Text>
|
|
538
|
+
Loading...
|
|
539
|
+
</Text>
|
|
540
|
+
</View>
|
|
541
|
+
)
|
|
542
|
+
}
|
|
543
|
+
|
|
520
544
|
return (
|
|
521
545
|
<ModelRow
|
|
522
546
|
cacheKey={model.cacheKey()}
|
|
@@ -536,7 +560,8 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
536
560
|
const defaultStyle = {
|
|
537
561
|
justifyContent: "center",
|
|
538
562
|
padding: 8,
|
|
539
|
-
backgroundColor: even ? "#f5f5f5" : undefined
|
|
563
|
+
backgroundColor: even ? "#f5f5f5" : undefined,
|
|
564
|
+
overflow: "hidden"
|
|
540
565
|
}
|
|
541
566
|
|
|
542
567
|
if (type == "actions") {
|
package/src/table/widths.mjs
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import {digg} from "diggerize"
|
|
2
2
|
|
|
3
3
|
export default class TableWidths {
|
|
4
|
-
constructor({columns,
|
|
4
|
+
constructor({columns, table, width}) {
|
|
5
5
|
this.columns = columns
|
|
6
|
-
this.
|
|
6
|
+
this.tableWidth = width
|
|
7
7
|
this.table = table
|
|
8
8
|
this.setWidths()
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
setWidths() {
|
|
12
|
-
let widthLeft = 100.0
|
|
13
|
-
|
|
14
12
|
this.columnsWidths = {}
|
|
15
13
|
|
|
14
|
+
let widthLeft = this.tableWidth
|
|
16
15
|
const updateData = []
|
|
17
16
|
|
|
18
17
|
// Set widths that are defined
|
|
19
18
|
for (const columnIndex in this.columns) {
|
|
20
|
-
const column = this.columns[columnIndex]
|
|
19
|
+
const column = this.columns[columnIndex]
|
|
20
|
+
const tableSettingColumn = column.tableSettingColumn
|
|
21
21
|
|
|
22
|
-
if (
|
|
23
|
-
|
|
22
|
+
if (tableSettingColumn.hasWidth()) {
|
|
23
|
+
column.width = tableSettingColumn.width()
|
|
24
24
|
|
|
25
|
-
widthLeft -=
|
|
25
|
+
widthLeft -= tableSettingColumn.width()
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -36,21 +36,26 @@ export default class TableWidths {
|
|
|
36
36
|
|
|
37
37
|
// Set widths of columns without
|
|
38
38
|
for (const columnIndex in this.columns) {
|
|
39
|
-
const column = this.columns[columnIndex]
|
|
39
|
+
const column = this.columns[columnIndex]
|
|
40
|
+
const tableSettingColumn = column.tableSettingColumn
|
|
41
|
+
|
|
42
|
+
if (!tableSettingColumn.hasWidth()) {
|
|
43
|
+
let newWidth = widthLeft / amountOfColumns
|
|
40
44
|
|
|
41
|
-
|
|
42
|
-
const newWidth = widthLeft / amountOfColumns
|
|
45
|
+
if (newWidth < 200) newWidth = 200
|
|
43
46
|
|
|
44
|
-
|
|
47
|
+
column.width = newWidth
|
|
45
48
|
|
|
46
49
|
updateData << {
|
|
47
|
-
id:
|
|
50
|
+
id: tableSettingColumn.id(),
|
|
48
51
|
width: newWidth
|
|
49
52
|
}
|
|
50
53
|
}
|
|
51
54
|
}
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
if (updateData.length > 0) {
|
|
57
|
+
// FIXME: Should update the columns on the backend if anything changed
|
|
58
|
+
}
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
getWidthOfColumn(identifier) {
|
|
@@ -66,12 +71,8 @@ export default class TableWidths {
|
|
|
66
71
|
|
|
67
72
|
if (!column) throw new Error(`No such column: ${identifier}`)
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
column.width = widthPercent
|
|
74
|
+
column.width = width
|
|
72
75
|
|
|
73
76
|
this.table.setState({lastUpdate: new Date()})
|
|
74
|
-
|
|
75
|
-
// FIXME: Should reduce / enlarge sibling columns to keep a 100% fit
|
|
76
77
|
}
|
|
77
78
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import BaseComponent from "../base-component"
|
|
2
2
|
import classNames from "classnames"
|
|
3
3
|
import {digg} from "diggerize"
|
|
4
|
-
import EventConnection from "../event-connection"
|
|
5
4
|
import modelClassRequire from "../model-class-require.mjs"
|
|
6
5
|
import PropTypes from "prop-types"
|
|
7
6
|
import PropTypesExact from "prop-types-exact"
|