@kaspernj/api-maker 1.0.400 → 1.0.402
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/router/route.jsx +32 -13
- 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-model.mjs +25 -23
- 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
package/src/table/table.jsx
CHANGED
|
@@ -7,6 +7,8 @@ import columnVisible from "./column-visible.mjs"
|
|
|
7
7
|
import debounce from "debounce"
|
|
8
8
|
import {digg, digs} from "diggerize"
|
|
9
9
|
import Filters from "./filters"
|
|
10
|
+
import FlatList from "./components/flat-list"
|
|
11
|
+
import Header from "./components/header"
|
|
10
12
|
import HeaderColumn from "./header-column"
|
|
11
13
|
import * as inflection from "inflection"
|
|
12
14
|
import modelClassRequire from "../model-class-require.mjs"
|
|
@@ -15,6 +17,7 @@ import Paginate from "../bootstrap/paginate"
|
|
|
15
17
|
import Params from "../params"
|
|
16
18
|
import PropTypes from "prop-types"
|
|
17
19
|
import React, {memo, useMemo, useRef} from "react"
|
|
20
|
+
import Row from "./components/row"
|
|
18
21
|
import selectCalculator from "./select-calculator"
|
|
19
22
|
import Select from "../inputs/select"
|
|
20
23
|
import Settings from "./settings"
|
|
@@ -24,6 +27,8 @@ import uniqunize from "uniqunize"
|
|
|
24
27
|
import useBreakpoint from "../use-breakpoint"
|
|
25
28
|
import useCollection from "../use-collection"
|
|
26
29
|
import useQueryParams from "on-location-changed/src/use-query-params.js"
|
|
30
|
+
import {View} from "react-native"
|
|
31
|
+
import Widths from "./widths"
|
|
27
32
|
|
|
28
33
|
const paginationOptions = [30, 60, 90, ["All", "all"]]
|
|
29
34
|
const WorkerPluginsCheckAllCheckbox = React.lazy(() => import("./worker-plugins-check-all-checkbox"))
|
|
@@ -85,7 +90,8 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
85
90
|
|
|
86
91
|
this.setInstance({
|
|
87
92
|
breakpoint,
|
|
88
|
-
filterFormRef: useRef()
|
|
93
|
+
filterFormRef: useRef(),
|
|
94
|
+
isSmallScreen: breakpoint == "xs" || breakpoint == "sm"
|
|
89
95
|
})
|
|
90
96
|
|
|
91
97
|
const collectionKey = digg(this.p.modelClass.modelClassData(), "collectionKey")
|
|
@@ -99,8 +105,9 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
99
105
|
this.useStates({
|
|
100
106
|
columns: columnsAsArray,
|
|
101
107
|
currentWorkplace: undefined,
|
|
102
|
-
|
|
108
|
+
flatListWidth: undefined,
|
|
103
109
|
identifier: () => this.props.identifier || `${collectionKey}-default`,
|
|
110
|
+
lastUpdate: () => new Date(),
|
|
104
111
|
preload: undefined,
|
|
105
112
|
preparedColumns: undefined,
|
|
106
113
|
queryName,
|
|
@@ -110,19 +117,22 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
110
117
|
showFilters: () => Boolean(queryParams[querySName]),
|
|
111
118
|
showSettings: false,
|
|
112
119
|
tableSetting: undefined,
|
|
113
|
-
tableSettingFullCacheKey: undefined
|
|
120
|
+
tableSettingFullCacheKey: undefined,
|
|
121
|
+
widths: null
|
|
114
122
|
})
|
|
115
123
|
|
|
116
124
|
useMemo(() => {
|
|
117
125
|
this.loadTableSetting()
|
|
118
126
|
|
|
119
|
-
if (this.props.workplace)
|
|
127
|
+
if (this.props.workplace) {
|
|
128
|
+
this.loadCurrentWorkplace()
|
|
129
|
+
}
|
|
120
130
|
}, [])
|
|
121
131
|
|
|
122
132
|
let collectionReady = true
|
|
123
133
|
let select
|
|
124
134
|
|
|
125
|
-
if (!this.
|
|
135
|
+
if (!this.s.preparedColumns) {
|
|
126
136
|
collectionReady = false
|
|
127
137
|
}
|
|
128
138
|
|
|
@@ -162,13 +172,15 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
162
172
|
|
|
163
173
|
const tableSetting = await this.tableSettings.loadExistingOrCreateTableSettings()
|
|
164
174
|
const {columns, preload} = this.tableSettings.preparedColumns(tableSetting)
|
|
175
|
+
const {flatListWidth} = this.s
|
|
176
|
+
const widths = new Widths({columns, flatListWidth, table: this})
|
|
165
177
|
|
|
166
178
|
this.setState({
|
|
167
|
-
fixedTableLayout: tableSetting.fixedTableLayout(),
|
|
168
179
|
preparedColumns: columns,
|
|
169
180
|
preload: this.mergedPreloads(preload),
|
|
170
181
|
tableSetting,
|
|
171
|
-
tableSettingFullCacheKey: tableSetting.fullCacheKey()
|
|
182
|
+
tableSettingFullCacheKey: tableSetting.fullCacheKey(),
|
|
183
|
+
widths
|
|
172
184
|
})
|
|
173
185
|
}
|
|
174
186
|
|
|
@@ -223,7 +235,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
223
235
|
}
|
|
224
236
|
|
|
225
237
|
return (
|
|
226
|
-
<div className={this.className()}
|
|
238
|
+
<div className={this.className()}>
|
|
227
239
|
{showNoRecordsAvailableContent &&
|
|
228
240
|
<div className="live-table--no-records-available-content">
|
|
229
241
|
{noRecordsAvailableContent({models, qParams, overallCount})}
|
|
@@ -334,7 +346,18 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
334
346
|
}
|
|
335
347
|
}
|
|
336
348
|
|
|
337
|
-
const
|
|
349
|
+
const flatList = (
|
|
350
|
+
<FlatList
|
|
351
|
+
data={models}
|
|
352
|
+
dataSet={{class: className}}
|
|
353
|
+
extraData={this.s.lastUpdate}
|
|
354
|
+
keyExtractor={this.tt.keyExtrator}
|
|
355
|
+
ListHeaderComponent={this.tt.listHeaderComponent}
|
|
356
|
+
onLayout={this.tt.onFlatListLayout}
|
|
357
|
+
renderItem={this.tt.renderItem}
|
|
358
|
+
{...restProps}
|
|
359
|
+
/>
|
|
360
|
+
)
|
|
338
361
|
|
|
339
362
|
return (
|
|
340
363
|
<>
|
|
@@ -347,15 +370,11 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
347
370
|
this.filterForm()
|
|
348
371
|
}
|
|
349
372
|
{card &&
|
|
350
|
-
<Card className={classNames("live-table--table-card", "mb-4", className)} controls={this.tableControls()} header={headerContent} footer={this.tableFooter()}
|
|
351
|
-
{
|
|
373
|
+
<Card className={classNames("live-table--table-card", "mb-4", className)} controls={this.tableControls()} header={headerContent} footer={this.tableFooter()} {...restProps}>
|
|
374
|
+
{flatList}
|
|
352
375
|
</Card>
|
|
353
376
|
}
|
|
354
|
-
{!card &&
|
|
355
|
-
<TableComponent className={className} {...restProps}>
|
|
356
|
-
{this.tableContent()}
|
|
357
|
-
</TableComponent>
|
|
358
|
-
}
|
|
377
|
+
{!card && flatList}
|
|
359
378
|
{result && PaginationComponent &&
|
|
360
379
|
<PaginationComponent result={result} />
|
|
361
380
|
}
|
|
@@ -366,6 +385,16 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
366
385
|
)
|
|
367
386
|
}
|
|
368
387
|
|
|
388
|
+
onFlatListLayout = (e) => {
|
|
389
|
+
const {width} = e.nativeEvent.layout
|
|
390
|
+
const {widths} = this.s
|
|
391
|
+
|
|
392
|
+
this.setState({flatListWidth: width})
|
|
393
|
+
widths.flatListWidth = width
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
keyExtrator = (model) => model.id()
|
|
397
|
+
|
|
369
398
|
filterForm = () => {
|
|
370
399
|
const {filterFormRef, submitFilter, submitFilterDebounce} = this.tt
|
|
371
400
|
const {filterContent, filterSubmitButton} = this.p
|
|
@@ -399,10 +428,6 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
399
428
|
this.setState({showFilters: !this.state.showFilters})
|
|
400
429
|
}
|
|
401
430
|
|
|
402
|
-
onFixedTableLayoutChanged = (fixedTableLayout) => {
|
|
403
|
-
this.setState({fixedTableLayout})
|
|
404
|
-
}
|
|
405
|
-
|
|
406
431
|
onPerPageChanged = (e) => {
|
|
407
432
|
const {queryName} = this.s
|
|
408
433
|
const newPerPageValue = digg(e, "target", "value")
|
|
@@ -414,6 +439,45 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
414
439
|
Params.changeParams(paramsChange)
|
|
415
440
|
}
|
|
416
441
|
|
|
442
|
+
listHeaderComponent = () => {
|
|
443
|
+
const {workplace} = this.p
|
|
444
|
+
const {currentWorkplace} = this.s
|
|
445
|
+
const {query} = digs(this.collection, "query")
|
|
446
|
+
|
|
447
|
+
return (
|
|
448
|
+
<Row dataSet={{class: "live-table-header-row"}}>
|
|
449
|
+
{workplace && currentWorkplace &&
|
|
450
|
+
<Header style={{width: 25}}>
|
|
451
|
+
<WorkerPluginsCheckAllCheckbox
|
|
452
|
+
currentWorkplace={currentWorkplace}
|
|
453
|
+
query={query}
|
|
454
|
+
style={{marginHorizontal: "auto"}}
|
|
455
|
+
/>
|
|
456
|
+
</Header>
|
|
457
|
+
}
|
|
458
|
+
{this.headersContentFromColumns()}
|
|
459
|
+
<Header />
|
|
460
|
+
</Row>
|
|
461
|
+
)
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
renderItem = ({item: model}) => {
|
|
465
|
+
const {preparedColumns, tableSettingFullCacheKey} = this.s
|
|
466
|
+
|
|
467
|
+
return (
|
|
468
|
+
<ModelRow
|
|
469
|
+
cacheKey={model.cacheKey()}
|
|
470
|
+
columnWidths={this.columnWidths()}
|
|
471
|
+
isSmallScreen={this.tt.isSmallScreen}
|
|
472
|
+
key={model.id()}
|
|
473
|
+
liveTable={this}
|
|
474
|
+
model={model}
|
|
475
|
+
preparedColumns={preparedColumns}
|
|
476
|
+
tableSettingFullCacheKey={tableSettingFullCacheKey}
|
|
477
|
+
/>
|
|
478
|
+
)
|
|
479
|
+
}
|
|
480
|
+
|
|
417
481
|
tableControls() {
|
|
418
482
|
const {controls} = this.props
|
|
419
483
|
const {showSettings} = this.s
|
|
@@ -427,7 +491,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
427
491
|
</a>
|
|
428
492
|
<span style={{position: "relative"}}>
|
|
429
493
|
{showSettings &&
|
|
430
|
-
<Settings
|
|
494
|
+
<Settings onRequestClose={this.tt.onRequestCloseSettings} table={this} />
|
|
431
495
|
}
|
|
432
496
|
<a className="settings-button" href="#" onClick={this.tt.onSettingsClicked}>
|
|
433
497
|
<i className="fa fa-fw fa-gear la la-fw la-gear" />
|
|
@@ -437,54 +501,6 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
437
501
|
)
|
|
438
502
|
}
|
|
439
503
|
|
|
440
|
-
tableContent () {
|
|
441
|
-
const {workplace} = this.p
|
|
442
|
-
const {currentWorkplace, preparedColumns, tableSettingFullCacheKey} = this.s
|
|
443
|
-
const {models, query} = digs(this.collection, "models", "query")
|
|
444
|
-
const ColumnInHeadComponent = this.columnInHeadComponent()
|
|
445
|
-
const RowComponent = this.rowComponent()
|
|
446
|
-
|
|
447
|
-
let BodyComponent, HeadComponent
|
|
448
|
-
|
|
449
|
-
if (this.isSmallScreen()) {
|
|
450
|
-
BodyComponent = "div"
|
|
451
|
-
HeadComponent = "div"
|
|
452
|
-
} else {
|
|
453
|
-
BodyComponent = "tbody"
|
|
454
|
-
HeadComponent = "thead"
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
return (
|
|
458
|
-
<>
|
|
459
|
-
<HeadComponent>
|
|
460
|
-
<RowComponent className="live-table-header-row">
|
|
461
|
-
{workplace && currentWorkplace &&
|
|
462
|
-
<ColumnInHeadComponent style={{width: 25, textAlign: "center"}}>
|
|
463
|
-
<WorkerPluginsCheckAllCheckbox currentWorkplace={currentWorkplace} query={query} />
|
|
464
|
-
</ColumnInHeadComponent>
|
|
465
|
-
}
|
|
466
|
-
{this.headersContentFromColumns()}
|
|
467
|
-
<ColumnInHeadComponent />
|
|
468
|
-
</RowComponent>
|
|
469
|
-
</HeadComponent>
|
|
470
|
-
<BodyComponent>
|
|
471
|
-
{models.map((model) =>
|
|
472
|
-
<ModelRow
|
|
473
|
-
cacheKey={model.cacheKey()}
|
|
474
|
-
columnComponent={this.columnComponent()}
|
|
475
|
-
key={model.id()}
|
|
476
|
-
liveTable={this}
|
|
477
|
-
model={model}
|
|
478
|
-
preparedColumns={preparedColumns}
|
|
479
|
-
rowComponent={this.rowComponent()}
|
|
480
|
-
tableSettingFullCacheKey={tableSettingFullCacheKey}
|
|
481
|
-
/>
|
|
482
|
-
)}
|
|
483
|
-
</BodyComponent>
|
|
484
|
-
</>
|
|
485
|
-
)
|
|
486
|
-
}
|
|
487
|
-
|
|
488
504
|
tableFooter() {
|
|
489
505
|
const {result} = digs(this.collection, "result")
|
|
490
506
|
const currentPage = result.currentPage()
|
|
@@ -497,7 +513,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
497
513
|
if (to === 0) from = 0
|
|
498
514
|
|
|
499
515
|
return (
|
|
500
|
-
<
|
|
516
|
+
<View style={{flexDirection: "row", justifyContent: "space-between", marginTop: "10px"}}>
|
|
501
517
|
<div className="showing-counts">
|
|
502
518
|
{I18n.t("js.api_maker.table.showing_from_to_out_of_total", {defaultValue, from, to, total_count: totalCount})}
|
|
503
519
|
</div>
|
|
@@ -509,15 +525,16 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
509
525
|
options={paginationOptions}
|
|
510
526
|
/>
|
|
511
527
|
</div>
|
|
512
|
-
</
|
|
528
|
+
</View>
|
|
513
529
|
)
|
|
514
530
|
}
|
|
515
531
|
|
|
516
532
|
className() {
|
|
517
533
|
const classNames = ["api-maker--table"]
|
|
518
534
|
|
|
519
|
-
if (this.props.className)
|
|
535
|
+
if (this.props.className) {
|
|
520
536
|
classNames.push(this.props.className)
|
|
537
|
+
}
|
|
521
538
|
|
|
522
539
|
return classNames.join(" ")
|
|
523
540
|
}
|
|
@@ -531,24 +548,24 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
531
548
|
return props
|
|
532
549
|
}
|
|
533
550
|
|
|
534
|
-
|
|
535
|
-
|
|
551
|
+
columnWidths() {
|
|
552
|
+
const columnWidths = {}
|
|
536
553
|
|
|
537
|
-
|
|
538
|
-
|
|
554
|
+
for (const column of this.s.preparedColumns) {
|
|
555
|
+
columnWidths[column.tableSettingColumn.identifier()] = column.width
|
|
556
|
+
}
|
|
539
557
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
responsiveComponent = (largeComponent) => this.isSmallScreen() ? "div" : largeComponent
|
|
543
|
-
rowComponent = () => this.responsiveComponent("tr")
|
|
558
|
+
return columnWidths
|
|
559
|
+
}
|
|
544
560
|
|
|
545
|
-
headersContentFromColumns = () => this.s.preparedColumns?.map(({column, tableSettingColumn}) => columnVisible(column, tableSettingColumn) &&
|
|
561
|
+
headersContentFromColumns = () => this.s.preparedColumns?.map(({column, tableSettingColumn, width}) => columnVisible(column, tableSettingColumn) &&
|
|
546
562
|
<HeaderColumn
|
|
547
563
|
column={column}
|
|
548
|
-
fixedTableLayout={this.s.fixedTableLayout}
|
|
549
564
|
key={tableSettingColumn.identifier()}
|
|
550
565
|
table={this}
|
|
551
566
|
tableSettingColumn={tableSettingColumn}
|
|
567
|
+
width={width}
|
|
568
|
+
widths={this.s.widths}
|
|
552
569
|
/>
|
|
553
570
|
)
|
|
554
571
|
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import {digg} from "diggerize"
|
|
2
|
+
|
|
3
|
+
export default class TableWidths {
|
|
4
|
+
constructor({columns, flatListWidth, table}) {
|
|
5
|
+
this.columns = columns
|
|
6
|
+
this.flatListWidth = flatListWidth
|
|
7
|
+
this.table = table
|
|
8
|
+
this.setWidths()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
setWidths() {
|
|
12
|
+
let widthLeft = 100.0
|
|
13
|
+
|
|
14
|
+
this.columnsWidths = {}
|
|
15
|
+
|
|
16
|
+
const updateData = []
|
|
17
|
+
|
|
18
|
+
// Set widths that are defined
|
|
19
|
+
for (const columnIndex in this.columns) {
|
|
20
|
+
const column = this.columns[columnIndex].tableSettingColumn
|
|
21
|
+
|
|
22
|
+
if (column.hasWidth()) {
|
|
23
|
+
this.columns[columnIndex].width = column.width()
|
|
24
|
+
|
|
25
|
+
widthLeft -= column.width()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Calculate how many columns are shown
|
|
30
|
+
const columnsWithoutWidth = this.columns.filter((column) => !column.tableSettingColumn.hasWidth())
|
|
31
|
+
let amountOfColumns = columnsWithoutWidth.length
|
|
32
|
+
|
|
33
|
+
amountOfColumns++ // Actions column
|
|
34
|
+
|
|
35
|
+
if (this.table.p.workplace) amountOfColumns++
|
|
36
|
+
|
|
37
|
+
// Set widths of columns without
|
|
38
|
+
for (const columnIndex in this.columns) {
|
|
39
|
+
const column = this.columns[columnIndex].tableSettingColumn
|
|
40
|
+
|
|
41
|
+
if (!column.hasWidth()) {
|
|
42
|
+
const newWidth = widthLeft / amountOfColumns
|
|
43
|
+
|
|
44
|
+
this.columns[columnIndex].width = newWidth
|
|
45
|
+
|
|
46
|
+
updateData << {
|
|
47
|
+
id: column.id(),
|
|
48
|
+
width: newWidth
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// FIXME: Should update the columns on the backend if anything changed
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getWidthOfColumn(identifier) {
|
|
57
|
+
const column = this.columns.find((column) => column.tableSettingColumn.identifier() == identifier)
|
|
58
|
+
|
|
59
|
+
if (!column) throw new Error(`No such column: ${identifier}`)
|
|
60
|
+
|
|
61
|
+
return digg(column, "width")
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
setWidthOfColumn({identifier, width}) {
|
|
65
|
+
const column = this.columns.find((column) => column.tableSettingColumn.identifier() == identifier)
|
|
66
|
+
|
|
67
|
+
if (!column) throw new Error(`No such column: ${identifier}`)
|
|
68
|
+
|
|
69
|
+
const widthPercent = (width / this.flatListWidth) * 100
|
|
70
|
+
|
|
71
|
+
column.width = widthPercent
|
|
72
|
+
|
|
73
|
+
this.table.setState({lastUpdate: new Date()})
|
|
74
|
+
|
|
75
|
+
// FIXME: Should reduce / enlarge sibling columns to keep a 100% fit
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -2,7 +2,7 @@ import classNames from "classnames"
|
|
|
2
2
|
import Collection from "../collection.mjs"
|
|
3
3
|
import EventConnection from "../event-connection"
|
|
4
4
|
import PropTypes from "prop-types"
|
|
5
|
-
import
|
|
5
|
+
import propTypesExact from "prop-types-exact"
|
|
6
6
|
import React from "react"
|
|
7
7
|
import {simpleObjectDifferent} from "set-state-compare/src/diff-utils"
|
|
8
8
|
import {useEffect, useRef} from "react"
|
|
@@ -21,9 +21,10 @@ const Checkbox = (props) => {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends React.PureComponent {
|
|
24
|
-
static propTypes =
|
|
24
|
+
static propTypes = propTypesExact({
|
|
25
25
|
currentWorkplace: PropTypes.object,
|
|
26
|
-
query: PropTypes.instanceOf(Collection)
|
|
26
|
+
query: PropTypes.instanceOf(Collection),
|
|
27
|
+
style: PropTypes.object
|
|
27
28
|
})
|
|
28
29
|
|
|
29
30
|
state = {
|
|
@@ -57,7 +58,7 @@ export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends React.Pu
|
|
|
57
58
|
}
|
|
58
59
|
|
|
59
60
|
render() {
|
|
60
|
-
const {className, currentWorkplace} = this.props
|
|
61
|
+
const {className, currentWorkplace, style} = this.props
|
|
61
62
|
const {checked, indeterminate} = this.state
|
|
62
63
|
|
|
63
64
|
return (
|
|
@@ -69,6 +70,7 @@ export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends React.Pu
|
|
|
69
70
|
className={classNames("api-maker--table--worker-plugins-check-all-checkbox", className)}
|
|
70
71
|
indeterminate={indeterminate}
|
|
71
72
|
onChange={this.onCheckedChanged}
|
|
73
|
+
style={style}
|
|
72
74
|
/>
|
|
73
75
|
</>
|
|
74
76
|
)
|
|
@@ -12,7 +12,8 @@ const Workplace = modelClassRequire("Workplace")
|
|
|
12
12
|
export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckbox extends ShapeComponent {
|
|
13
13
|
static propTypes = PropTypesExact({
|
|
14
14
|
currentWorkplace: PropTypes.object,
|
|
15
|
-
model: PropTypes.object.isRequired
|
|
15
|
+
model: PropTypes.object.isRequired,
|
|
16
|
+
style: PropTypes.object
|
|
16
17
|
})
|
|
17
18
|
|
|
18
19
|
setup() {
|
|
@@ -38,7 +39,7 @@ export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckbox exte
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
render() {
|
|
41
|
-
const {className, currentWorkplace, model} = this.props
|
|
42
|
+
const {className, currentWorkplace, model, style} = this.props
|
|
42
43
|
const {checked, linkLoaded} = this.state
|
|
43
44
|
|
|
44
45
|
if (!linkLoaded) {
|
|
@@ -58,7 +59,8 @@ export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckbox exte
|
|
|
58
59
|
className={classNames("api-maker--table--worker-plugins-checkbox", className)}
|
|
59
60
|
data-checked={checked}
|
|
60
61
|
data-model-id={model.id()}
|
|
61
|
-
onChange={this.onCheckedChanged}
|
|
62
|
+
onChange={this.tt.onCheckedChanged}
|
|
63
|
+
style={style}
|
|
62
64
|
type="checkbox"
|
|
63
65
|
/>
|
|
64
66
|
</>
|
package/src/use-model.mjs
CHANGED
|
@@ -42,12 +42,6 @@ const useModel = (modelClassArg, argsArg = {}) => {
|
|
|
42
42
|
const modelVariableName = inflection.camelize(modelClass.modelClassData().name, true)
|
|
43
43
|
const cacheArgs = [modelId]
|
|
44
44
|
|
|
45
|
-
if (args.cacheArgs) {
|
|
46
|
-
cacheArgs.push(...args.cacheArgs)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
s.updateMeta({args, modelId, modelVariableName, queryParams})
|
|
50
|
-
|
|
51
45
|
const loadExistingModel = useCallback(async () => {
|
|
52
46
|
let query
|
|
53
47
|
|
|
@@ -89,13 +83,37 @@ const useModel = (modelClassArg, argsArg = {}) => {
|
|
|
89
83
|
}, [])
|
|
90
84
|
|
|
91
85
|
const loadModel = useCallback(async () => {
|
|
92
|
-
if (s.props
|
|
86
|
+
if ("active" in s.props && !s.props.active) {
|
|
87
|
+
// Not active - don't do anything
|
|
88
|
+
} else if (s.props.newIfNoId && !s.m.modelId) {
|
|
93
89
|
return await loadNewModel()
|
|
94
90
|
} else if (!s.props.optional || s.m.modelId | s.m.args.query) {
|
|
95
91
|
return await loadExistingModel()
|
|
96
92
|
}
|
|
97
93
|
}, [])
|
|
98
94
|
|
|
95
|
+
const onDestroyed = useCallback(({model}) => {
|
|
96
|
+
const forwardArgs = {model}
|
|
97
|
+
|
|
98
|
+
forwardArgs[s.m.modelVariableName] = model
|
|
99
|
+
|
|
100
|
+
s.p.onDestroyed(forwardArgs)
|
|
101
|
+
}, [])
|
|
102
|
+
|
|
103
|
+
const onSignedIn = useCallback(() => {
|
|
104
|
+
loadModel()
|
|
105
|
+
}, [])
|
|
106
|
+
|
|
107
|
+
const onSignedOut = useCallback(() => {
|
|
108
|
+
loadModel()
|
|
109
|
+
}, [])
|
|
110
|
+
|
|
111
|
+
if (args.cacheArgs) {
|
|
112
|
+
cacheArgs.push(...args.cacheArgs)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
s.updateMeta({args, modelId, modelVariableName, queryParams})
|
|
116
|
+
|
|
99
117
|
useMemo(
|
|
100
118
|
() => { loadModel() },
|
|
101
119
|
cacheArgs
|
|
@@ -127,14 +145,6 @@ const useModel = (modelClassArg, argsArg = {}) => {
|
|
|
127
145
|
}
|
|
128
146
|
}, [args.eventUpdated, s.s.model?.id()])
|
|
129
147
|
|
|
130
|
-
const onSignedIn = useCallback(() => {
|
|
131
|
-
loadModel()
|
|
132
|
-
}, [])
|
|
133
|
-
|
|
134
|
-
const onSignedOut = useCallback(() => {
|
|
135
|
-
loadModel()
|
|
136
|
-
}, [])
|
|
137
|
-
|
|
138
148
|
useLayoutEffect(() => {
|
|
139
149
|
Devise.events().addListener("onDeviseSignIn", onSignedIn)
|
|
140
150
|
Devise.events().addListener("onDeviseSignOut", onSignedOut)
|
|
@@ -145,14 +155,6 @@ const useModel = (modelClassArg, argsArg = {}) => {
|
|
|
145
155
|
}
|
|
146
156
|
})
|
|
147
157
|
|
|
148
|
-
const onDestroyed = useCallback(({model}) => {
|
|
149
|
-
const forwardArgs = {model}
|
|
150
|
-
|
|
151
|
-
forwardArgs[s.m.modelVariableName] = model
|
|
152
|
-
|
|
153
|
-
s.p.onDestroyed(forwardArgs)
|
|
154
|
-
}, [])
|
|
155
|
-
|
|
156
158
|
useLayoutEffect(() => {
|
|
157
159
|
let connectDestroyed
|
|
158
160
|
|
|
@@ -18,7 +18,7 @@ const getWindowLayout = (width) => {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
const
|
|
21
|
+
const useScreenLayout = () => {
|
|
22
22
|
if (Platform.OS == "web") {
|
|
23
23
|
const shared = useMemo(() => ({}))
|
|
24
24
|
|
|
@@ -46,4 +46,4 @@ const useScreenSize = () => {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export default
|
|
49
|
+
export default useScreenLayout
|