@kaspernj/api-maker 1.0.417 → 1.0.418
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/attribute-row/index.jsx +6 -2
- package/src/table/header-column.jsx +11 -5
- package/src/table/model-row.jsx +64 -28
- package/src/table/settings/index.jsx +0 -4
- package/src/table/table.jsx +79 -21
- package/src/table/worker-plugins-checkbox.jsx +17 -20
- package/src/use-model-event.js +60 -0
- package/src/table/style.scss +0 -76
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ import PropTypes from "prop-types"
|
|
|
6
6
|
import {memo, useMemo} from "react"
|
|
7
7
|
import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
|
|
8
8
|
import strftime from "strftime"
|
|
9
|
+
import useI18n from "i18n-on-steroids/src/use-i18n.mjs"
|
|
9
10
|
|
|
10
11
|
export default memo(shapeComponent(class ApiMakerBootstrapAttributeRow extends ShapeComponent {
|
|
11
12
|
static defaultProps = {
|
|
@@ -23,6 +24,9 @@ export default memo(shapeComponent(class ApiMakerBootstrapAttributeRow extends S
|
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
setup() {
|
|
27
|
+
const {t} = useI18n({namespace: "js.api_maker.attribute_row"})
|
|
28
|
+
|
|
29
|
+
this.t = t
|
|
26
30
|
this.attribute = useMemo(
|
|
27
31
|
() => {
|
|
28
32
|
if (this.props.attribute) {
|
|
@@ -88,9 +92,9 @@ export default memo(shapeComponent(class ApiMakerBootstrapAttributeRow extends S
|
|
|
88
92
|
} else if (value instanceof Date) {
|
|
89
93
|
return strftime("%Y-%m-%d %H:%M", value)
|
|
90
94
|
} else if (typeof value === "boolean") {
|
|
91
|
-
if (value) return
|
|
95
|
+
if (value) return this.t("js.shared.yes", {defaultValue: "Yes"})
|
|
92
96
|
|
|
93
|
-
return
|
|
97
|
+
return this.t("js.shared.no", {defaultValue: "No"})
|
|
94
98
|
} else if (MoneyFormatter.isMoney(value)) {
|
|
95
99
|
return MoneyFormatter.format(value)
|
|
96
100
|
} else {
|
|
@@ -37,6 +37,15 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
37
37
|
const {defaultParams} = table.props
|
|
38
38
|
const {styleForHeader, styleForHeaderText} = table.tt
|
|
39
39
|
const {query} = digs(table.collection, "query")
|
|
40
|
+
const columnProps = table.columnProps(column)
|
|
41
|
+
const {style, ...restColumnProps} = columnProps
|
|
42
|
+
const actualStyle = Object.assign(
|
|
43
|
+
{
|
|
44
|
+
cursor: resizing ? "col-resize" : undefined,
|
|
45
|
+
width: `${width}%`
|
|
46
|
+
},
|
|
47
|
+
style
|
|
48
|
+
)
|
|
40
49
|
|
|
41
50
|
return (
|
|
42
51
|
<Header
|
|
@@ -45,11 +54,8 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
|
|
|
45
54
|
identifier: tableSettingColumn.identifier()
|
|
46
55
|
}}
|
|
47
56
|
onLayout={this.tt.onLayout}
|
|
48
|
-
style={styleForHeader({style:
|
|
49
|
-
|
|
50
|
-
width: `${width}%`
|
|
51
|
-
}})}
|
|
52
|
-
{...table.columnProps(column)}
|
|
57
|
+
style={styleForHeader({style: actualStyle})}
|
|
58
|
+
{...restColumnProps}
|
|
53
59
|
>
|
|
54
60
|
<View style={{display: "flex", flexDirection: "row", alignItems: "center"}}>
|
|
55
61
|
{tableSettingColumn.hasSortKey() && query &&
|
package/src/table/model-row.jsx
CHANGED
|
@@ -17,6 +17,60 @@ import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
|
17
17
|
|
|
18
18
|
const WorkerPluginsCheckbox = React.lazy(() => import("./worker-plugins-checkbox"))
|
|
19
19
|
|
|
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
|
+
|
|
20
74
|
export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow extends BaseComponent {
|
|
21
75
|
static propTypes = propTypesExact({
|
|
22
76
|
cacheKey: PropTypes.string.isRequired,
|
|
@@ -86,39 +140,21 @@ export default memo(shapeComponent(class ApiMakerBootStrapLiveTableModelRow exte
|
|
|
86
140
|
)
|
|
87
141
|
}
|
|
88
142
|
|
|
89
|
-
columnClassNamesForColumn(column) {
|
|
90
|
-
const classNames = ["table--column"]
|
|
91
|
-
|
|
92
|
-
if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
|
|
93
|
-
if (column.columnProps && column.columnProps.className) classNames.push(column.columnProps.className)
|
|
94
|
-
|
|
95
|
-
return classNames
|
|
96
|
-
}
|
|
97
|
-
|
|
98
143
|
columnsContentFromColumns(model, even) {
|
|
99
144
|
const {isSmallScreen, table, preparedColumns} = this.p
|
|
100
145
|
|
|
101
146
|
return preparedColumns?.map(({column, tableSettingColumn, width}, columnIndex) => columnVisible(column, tableSettingColumn) &&
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
147
|
+
<ModelColumn
|
|
148
|
+
column={column}
|
|
149
|
+
columnIndex={columnIndex}
|
|
150
|
+
even={even}
|
|
151
|
+
isSmallScreen={isSmallScreen}
|
|
107
152
|
key={columnIdentifier(column)}
|
|
108
|
-
|
|
109
|
-
{
|
|
110
|
-
|
|
111
|
-
{
|
|
112
|
-
|
|
113
|
-
<Text>
|
|
114
|
-
{table.headerLabelForColumn(column)}
|
|
115
|
-
</Text>
|
|
116
|
-
</View>
|
|
117
|
-
}
|
|
118
|
-
<View dataSet={{class: "table--column-value"}}>
|
|
119
|
-
{new ColumnContent({column, model, table}).content()}
|
|
120
|
-
</View>
|
|
121
|
-
</Column>
|
|
153
|
+
model={model}
|
|
154
|
+
table={table}
|
|
155
|
+
tableSettingColumn={tableSettingColumn}
|
|
156
|
+
width={width}
|
|
157
|
+
/>
|
|
122
158
|
)
|
|
123
159
|
}
|
|
124
160
|
|
|
@@ -16,10 +16,6 @@ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseCompo
|
|
|
16
16
|
|
|
17
17
|
setup() {
|
|
18
18
|
this.rootRef = useRef()
|
|
19
|
-
|
|
20
|
-
this.useStates({
|
|
21
|
-
fixedTableLayout: this.tableSetting().fixedTableLayout()
|
|
22
|
-
})
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
tableSetting = () => this.p.table.s.tableSetting
|
package/src/table/table.jsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import "./style"
|
|
2
1
|
import {digg, digs} from "diggerize"
|
|
3
|
-
import {Pressable, View} from "react-native"
|
|
2
|
+
import {Pressable, Text, View} from "react-native"
|
|
4
3
|
import BaseComponent from "../base-component"
|
|
5
4
|
import Card from "../bootstrap/card"
|
|
6
5
|
import classNames from "classnames"
|
|
@@ -28,6 +27,8 @@ import TableSettings from "./table-settings"
|
|
|
28
27
|
import uniqunize from "uniqunize"
|
|
29
28
|
import useBreakpoint from "../use-breakpoint"
|
|
30
29
|
import useCollection from "../use-collection"
|
|
30
|
+
import useI18n from "i18n-on-steroids/src/use-i18n.mjs"
|
|
31
|
+
import useModelEvent from "../use-model-event.js"
|
|
31
32
|
import useQueryParams from "on-location-changed/src/use-query-params.js"
|
|
32
33
|
import Widths from "./widths"
|
|
33
34
|
|
|
@@ -37,6 +38,7 @@ const WorkerPluginsCheckAllCheckbox = React.lazy(() => import("./worker-plugins-
|
|
|
37
38
|
export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
38
39
|
static defaultProps = {
|
|
39
40
|
card: true,
|
|
41
|
+
currentUser: null,
|
|
40
42
|
destroyEnabled: true,
|
|
41
43
|
filterCard: true,
|
|
42
44
|
filterSubmitButton: true,
|
|
@@ -86,13 +88,15 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
setup() {
|
|
91
|
+
const {t} = useI18n({namespace: "js.api_maker.table"})
|
|
89
92
|
const {breakpoint} = useBreakpoint()
|
|
90
93
|
const queryParams = useQueryParams()
|
|
91
94
|
|
|
92
95
|
this.setInstance({
|
|
93
96
|
breakpoint,
|
|
94
97
|
filterFormRef: useRef(),
|
|
95
|
-
isSmallScreen: breakpoint == "xs" || breakpoint == "sm"
|
|
98
|
+
isSmallScreen: breakpoint == "xs" || breakpoint == "sm",
|
|
99
|
+
t
|
|
96
100
|
})
|
|
97
101
|
|
|
98
102
|
const collectionKey = digg(this.p.modelClass.modelClassData(), "collectionKey")
|
|
@@ -106,6 +110,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
106
110
|
this.useStates({
|
|
107
111
|
columns: columnsAsArray,
|
|
108
112
|
currentWorkplace: undefined,
|
|
113
|
+
currentWorkplaceCount: null,
|
|
109
114
|
flatListWidth: undefined,
|
|
110
115
|
identifier: () => this.props.identifier || `${collectionKey}-default`,
|
|
111
116
|
lastUpdate: () => new Date(),
|
|
@@ -127,9 +132,14 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
127
132
|
this.loadTableSetting()
|
|
128
133
|
|
|
129
134
|
if (this.props.workplace) {
|
|
130
|
-
this.loadCurrentWorkplace()
|
|
135
|
+
this.loadCurrentWorkplace().then(() => {
|
|
136
|
+
this.loadCurrentWorkplaceCount()
|
|
137
|
+
})
|
|
131
138
|
}
|
|
132
|
-
}, [])
|
|
139
|
+
}, [this.p.currentUser?.id()])
|
|
140
|
+
|
|
141
|
+
useModelEvent(this.s.currentWorkplace, "workplace_links_created", this.tt.onLinksCreated)
|
|
142
|
+
useModelEvent(this.s.currentWorkplace, "workplace_links_destroyed", this.tt.onLinksDestroyed)
|
|
133
143
|
|
|
134
144
|
let collectionReady = true
|
|
135
145
|
let select
|
|
@@ -169,6 +179,18 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
169
179
|
this.setState({currentWorkplace})
|
|
170
180
|
}
|
|
171
181
|
|
|
182
|
+
async loadCurrentWorkplaceCount() {
|
|
183
|
+
const WorkplaceLink = modelClassRequire("WorkplaceLink")
|
|
184
|
+
const currentWorkplaceCount = await WorkplaceLink
|
|
185
|
+
.ransack({
|
|
186
|
+
resource_type_eq: this.p.modelClass.modelClassData().name,
|
|
187
|
+
workplace_id_eq: this.s.currentWorkplace.id()
|
|
188
|
+
})
|
|
189
|
+
.count()
|
|
190
|
+
|
|
191
|
+
this.setState({currentWorkplaceCount})
|
|
192
|
+
}
|
|
193
|
+
|
|
172
194
|
async loadTableSetting() {
|
|
173
195
|
this.tableSettings = new TableSettings({table: this})
|
|
174
196
|
|
|
@@ -402,6 +424,30 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
402
424
|
widths.flatListWidth = width
|
|
403
425
|
}
|
|
404
426
|
|
|
427
|
+
onLinksCreated = ({args}) => {
|
|
428
|
+
const modelClassName = this.p.modelClass.modelClassData().name
|
|
429
|
+
|
|
430
|
+
if (args.created[modelClassName]) {
|
|
431
|
+
const amountCreated = args.created[modelClassName].length
|
|
432
|
+
|
|
433
|
+
this.setState((prevState) => ({
|
|
434
|
+
currentWorkplaceCount: prevState.currentWorkplaceCount + amountCreated
|
|
435
|
+
}))
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
onLinksDestroyed = ({args}) => {
|
|
440
|
+
const modelClassName = this.p.modelClass.modelClassData().name
|
|
441
|
+
|
|
442
|
+
if (args.destroyed[modelClassName]) {
|
|
443
|
+
const amountDestroyed = args.destroyed[modelClassName].length
|
|
444
|
+
|
|
445
|
+
this.setState((prevState) => ({
|
|
446
|
+
currentWorkplaceCount: prevState.currentWorkplaceCount - amountDestroyed
|
|
447
|
+
}))
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
405
451
|
keyExtrator = (model) => model.id()
|
|
406
452
|
|
|
407
453
|
filterForm = () => {
|
|
@@ -425,7 +471,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
425
471
|
className="btn btn-primary live-table--submit-filter-button"
|
|
426
472
|
type="submit"
|
|
427
473
|
style={{marginTop: "8px"}}
|
|
428
|
-
value={filterSubmitLabel ||
|
|
474
|
+
value={filterSubmitLabel || this.t(".filter", {defaultValue: "Filter"})}
|
|
429
475
|
/>
|
|
430
476
|
}
|
|
431
477
|
</form>
|
|
@@ -449,16 +495,14 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
449
495
|
}
|
|
450
496
|
|
|
451
497
|
listHeaderComponent = () => {
|
|
452
|
-
const {workplace} = this.p
|
|
453
|
-
const {currentWorkplace} = this.s
|
|
454
498
|
const {query} = digs(this.collection, "query")
|
|
455
499
|
|
|
456
500
|
return (
|
|
457
501
|
<Row dataSet={{class: "live-table-header-row"}} style={this.styleForRow()}>
|
|
458
|
-
{workplace && currentWorkplace &&
|
|
502
|
+
{this.p.workplace && this.s.currentWorkplace &&
|
|
459
503
|
<Header style={this.styleForHeader({style: {width: 41}})}>
|
|
460
504
|
<WorkerPluginsCheckAllCheckbox
|
|
461
|
-
currentWorkplace={currentWorkplace}
|
|
505
|
+
currentWorkplace={this.s.currentWorkplace}
|
|
462
506
|
query={query}
|
|
463
507
|
style={{marginHorizontal: "auto"}}
|
|
464
508
|
/>
|
|
@@ -576,24 +620,31 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
576
620
|
const totalCount = result.totalCount()
|
|
577
621
|
const perPage = result.perPage()
|
|
578
622
|
const to = Math.min(currentPage * perPage, totalCount)
|
|
579
|
-
const defaultValue = "Showing %{from} to %{to} out of %{total_count} total"
|
|
623
|
+
const defaultValue = "Showing %{from} to %{to} out of %{total_count} total."
|
|
580
624
|
let from = ((currentPage - 1) * perPage) + 1
|
|
581
625
|
|
|
582
626
|
if (to === 0) from = 0
|
|
583
627
|
|
|
584
628
|
return (
|
|
585
|
-
<View style={{flexDirection: "row", justifyContent: "space-between", marginTop:
|
|
586
|
-
<
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
629
|
+
<View style={{flexDirection: "row", justifyContent: "space-between", marginTop: 10}}>
|
|
630
|
+
<View dataSet={{class: "showing-counts"}} style={{flexDirection: "row"}}>
|
|
631
|
+
<Text>
|
|
632
|
+
{this.t(".showing_from_to_out_of_total", {defaultValue, from, to, total_count: totalCount})}
|
|
633
|
+
</Text>
|
|
634
|
+
{this.p.workplace && this.s.currentWorkplaceCount !== null &&
|
|
635
|
+
<Text style={{marginLeft: 3}}>
|
|
636
|
+
{this.t(".x_selected", {defaultValue: "%{selected} selected.", selected: this.s.currentWorkplaceCount})}
|
|
637
|
+
</Text>
|
|
638
|
+
}
|
|
639
|
+
</View>
|
|
640
|
+
<View>
|
|
590
641
|
<Select
|
|
591
642
|
className="per-page-select"
|
|
592
643
|
defaultValue={perPage}
|
|
593
644
|
onChange={this.tt.onPerPageChanged}
|
|
594
645
|
options={paginationOptions}
|
|
595
646
|
/>
|
|
596
|
-
</
|
|
647
|
+
</View>
|
|
597
648
|
</View>
|
|
598
649
|
)
|
|
599
650
|
}
|
|
@@ -611,8 +662,15 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
611
662
|
columnProps(column) {
|
|
612
663
|
const props = {}
|
|
613
664
|
|
|
614
|
-
if (column.textCenter)
|
|
615
|
-
|
|
665
|
+
if (column.textCenter) {
|
|
666
|
+
props.style ||= {}
|
|
667
|
+
props.style.textAlign = "center"
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
if (column.textRight) {
|
|
671
|
+
props.style ||= {}
|
|
672
|
+
props.style.textAlign = "right"
|
|
673
|
+
}
|
|
616
674
|
|
|
617
675
|
return props
|
|
618
676
|
}
|
|
@@ -639,7 +697,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
639
697
|
/>
|
|
640
698
|
)
|
|
641
699
|
|
|
642
|
-
headerClassNameForColumn
|
|
700
|
+
headerClassNameForColumn(column) {
|
|
643
701
|
const classNames = ["live-table-header"]
|
|
644
702
|
|
|
645
703
|
if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
|
|
@@ -648,7 +706,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
648
706
|
return classNames
|
|
649
707
|
}
|
|
650
708
|
|
|
651
|
-
headerLabelForColumn
|
|
709
|
+
headerLabelForColumn(column) {
|
|
652
710
|
const {modelClass} = this.p
|
|
653
711
|
|
|
654
712
|
if ("label" in column) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import BaseComponent from "../base-component"
|
|
1
2
|
import classNames from "classnames"
|
|
2
3
|
import {digg} from "diggerize"
|
|
3
4
|
import EventConnection from "../event-connection"
|
|
@@ -5,11 +6,12 @@ import modelClassRequire from "../model-class-require.mjs"
|
|
|
5
6
|
import PropTypes from "prop-types"
|
|
6
7
|
import PropTypesExact from "prop-types-exact"
|
|
7
8
|
import {memo, useMemo} from "react"
|
|
8
|
-
import {shapeComponent
|
|
9
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
10
|
+
import useModelEvent from "../use-model-event.js"
|
|
9
11
|
|
|
10
12
|
const Workplace = modelClassRequire("Workplace")
|
|
11
13
|
|
|
12
|
-
export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckbox extends
|
|
14
|
+
export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckbox extends BaseComponent {
|
|
13
15
|
static propTypes = PropTypesExact({
|
|
14
16
|
currentWorkplace: PropTypes.object,
|
|
15
17
|
model: PropTypes.object.isRequired,
|
|
@@ -25,6 +27,9 @@ export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckbox exte
|
|
|
25
27
|
useMemo(() => {
|
|
26
28
|
this.loadCurrentLink()
|
|
27
29
|
}, [])
|
|
30
|
+
|
|
31
|
+
useModelEvent(this.p.currentWorkplace, "workplace_links_created", this.tt.onLinksCreated)
|
|
32
|
+
useModelEvent(this.p.currentWorkplace, "workplace_links_destroyed", this.tt.onLinksDestroyed)
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
async loadCurrentLink() {
|
|
@@ -39,7 +44,7 @@ export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckbox exte
|
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
render() {
|
|
42
|
-
const {className,
|
|
47
|
+
const {className, model, style} = this.props
|
|
43
48
|
const {checked, linkLoaded} = this.state
|
|
44
49
|
|
|
45
50
|
if (!linkLoaded) {
|
|
@@ -47,23 +52,15 @@ export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckbox exte
|
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
return (
|
|
50
|
-
|
|
51
|
-
{
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
className={classNames("api-maker--table--worker-plugins-checkbox", className)}
|
|
60
|
-
data-checked={checked}
|
|
61
|
-
data-model-id={model.id()}
|
|
62
|
-
onChange={this.tt.onCheckedChanged}
|
|
63
|
-
style={style}
|
|
64
|
-
type="checkbox"
|
|
65
|
-
/>
|
|
66
|
-
</>
|
|
55
|
+
<input
|
|
56
|
+
checked={checked}
|
|
57
|
+
className={classNames("api-maker--table--worker-plugins-checkbox", className)}
|
|
58
|
+
data-checked={checked}
|
|
59
|
+
data-model-id={model.id()}
|
|
60
|
+
onChange={this.tt.onCheckedChanged}
|
|
61
|
+
style={style}
|
|
62
|
+
type="checkbox"
|
|
63
|
+
/>
|
|
67
64
|
)
|
|
68
65
|
}
|
|
69
66
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {useCallback, useLayoutEffect, useMemo} from "react"
|
|
2
|
+
import debounceFunction from "debounce"
|
|
3
|
+
import ModelEvents from "./model-events.mjs"
|
|
4
|
+
import useShape from "set-state-compare/src/use-shape.js"
|
|
5
|
+
|
|
6
|
+
const apiMakerUseModelEvent = (model, event, onCallback, props) => {
|
|
7
|
+
const {active = true, debounce, onConnected, ...restProps} = props || {}
|
|
8
|
+
|
|
9
|
+
if (Object.keys(restProps).length > 0) {
|
|
10
|
+
throw new Error(`Unknown props given to apiMakerUseModelEvent: ${Object.keys(restProps).join(", ")}`)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const s = useShape({active, debounce, model, onCallback})
|
|
14
|
+
|
|
15
|
+
const debounceCallback = useMemo(() => {
|
|
16
|
+
if (typeof debounce == "number") {
|
|
17
|
+
return debounceFunction(s.p.onCallback, debounce)
|
|
18
|
+
} else {
|
|
19
|
+
return debounceFunction(s.p.onCallback)
|
|
20
|
+
}
|
|
21
|
+
}, [debounce])
|
|
22
|
+
|
|
23
|
+
s.updateMeta({debounceCallback})
|
|
24
|
+
|
|
25
|
+
const onCallbackCallback = useCallback((...args) => {
|
|
26
|
+
if (!s.p.active) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (s.p.debounce) {
|
|
31
|
+
s.m.debounceCallback(...args)
|
|
32
|
+
} else {
|
|
33
|
+
s.p.onCallback(...args)
|
|
34
|
+
}
|
|
35
|
+
}, [])
|
|
36
|
+
|
|
37
|
+
useLayoutEffect(() => {
|
|
38
|
+
let connectEvent, onConnectedListener
|
|
39
|
+
|
|
40
|
+
if (model) {
|
|
41
|
+
connectEvent = ModelEvents.connect(model, event, onCallbackCallback)
|
|
42
|
+
|
|
43
|
+
if (onConnected) {
|
|
44
|
+
onConnectedListener = connectEvent.events.addListener("connected", onConnected)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return () => {
|
|
49
|
+
if (onConnectedListener) {
|
|
50
|
+
connectEvent.events.removeListener("connected", onConnected)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (connectEvent) {
|
|
54
|
+
connectEvent.unsubscribe()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, [model?.id()])
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default apiMakerUseModelEvent
|
package/src/table/style.scss
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
@import "./variables";
|
|
2
|
-
|
|
3
|
-
.api-maker--table {
|
|
4
|
-
&[data-fixed-table-layout="true"] {
|
|
5
|
-
table {
|
|
6
|
-
table-layout: fixed;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
.live-table-header {
|
|
11
|
-
text-align: left;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@media (max-width: $sm-to) {
|
|
15
|
-
.live-table-column {
|
|
16
|
-
display: flex;
|
|
17
|
-
justify-content: space-between;
|
|
18
|
-
|
|
19
|
-
.live-table-column-value {
|
|
20
|
-
text-align: right;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.live-table-header-row {
|
|
25
|
-
margin-bottom: 15px;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.live-table-row {
|
|
29
|
-
+ .live-table-row {
|
|
30
|
-
margin-top: 15px;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
@media (min-width: $md-from) {
|
|
36
|
-
.actions-column {
|
|
37
|
-
display: flex;
|
|
38
|
-
align-items: center;
|
|
39
|
-
justify-content: end;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
.live-table-header:not(:first-child),
|
|
43
|
-
.live-table-column:not(:first-child) {
|
|
44
|
-
padding-left: 10px;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.live-table-header:not(:last-child),
|
|
48
|
-
.live-table-column:not(:last-child) {
|
|
49
|
-
padding-right: 10px;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.live-table-column {
|
|
53
|
-
&[data-text-align="center"] {
|
|
54
|
-
.live-table-column-value {
|
|
55
|
-
text-align: center;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
&[data-text-align="right"] {
|
|
60
|
-
.live-table-column-value {
|
|
61
|
-
text-align: right;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
.live-table-header {
|
|
67
|
-
&[data-text-align="center"] {
|
|
68
|
-
text-align: center;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
&[data-text-align="right"] {
|
|
72
|
-
text-align: right;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|