@kaspernj/api-maker 1.0.418 → 1.0.420

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaspernj/api-maker",
3
- "version": "1.0.418",
3
+ "version": "1.0.420",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -9,12 +9,12 @@ import Result from "./result.mjs"
9
9
  export default class ApiMakerCollection {
10
10
  static apiMakerType = "Collection"
11
11
 
12
- constructor (args, queryArgs = {}) {
12
+ constructor(args, queryArgs = {}) {
13
13
  this.queryArgs = queryArgs
14
14
  this.args = args
15
15
  }
16
16
 
17
- abilities (originalAbilities) {
17
+ abilities(originalAbilities) {
18
18
  const newAbilities = {}
19
19
 
20
20
  for (const originalAbilityName in originalAbilities) {
@@ -33,21 +33,21 @@ export default class ApiMakerCollection {
33
33
  return this._merge({abilities: newAbilities})
34
34
  }
35
35
 
36
- accessibleBy (abilityName) {
36
+ accessibleBy(abilityName) {
37
37
  return this._merge({accessibleBy: inflection.underscore(abilityName)})
38
38
  }
39
39
 
40
- async count () {
40
+ async count() {
41
41
  const response = await this.clone()._merge({count: true})._response()
42
42
 
43
43
  return digg(response, "count")
44
44
  }
45
45
 
46
- distinct () {
46
+ distinct() {
47
47
  return this._merge({distinct: true})
48
48
  }
49
49
 
50
- async each (callback) {
50
+ async each(callback) {
51
51
  const array = await this.toArray()
52
52
 
53
53
  for (const model in array) {
@@ -55,12 +55,24 @@ export default class ApiMakerCollection {
55
55
  }
56
56
  }
57
57
 
58
- async first () {
58
+ except(...keys) {
59
+ for (const key of keys) {
60
+ if (key == "page") {
61
+ delete this.queryArgs[key]
62
+ } else {
63
+ throw new Error(`Unhandled key: ${key}`)
64
+ }
65
+ }
66
+
67
+ return this
68
+ }
69
+
70
+ async first() {
59
71
  const models = await this.toArray()
60
72
  return models[0]
61
73
  }
62
74
 
63
- groupBy (...arrayOfTablesAndColumns) {
75
+ groupBy(...arrayOfTablesAndColumns) {
64
76
  const arrayOfTablesAndColumnsWithLowercaseColumns = arrayOfTablesAndColumns.map((tableAndColumn) => {
65
77
  if (Array.isArray(tableAndColumn)) {
66
78
  return [tableAndColumn[0], tableAndColumn[1].toLowerCase()]
@@ -76,18 +88,18 @@ export default class ApiMakerCollection {
76
88
  })
77
89
  }
78
90
 
79
- isLoaded () {
91
+ isLoaded() {
80
92
  if (this.args.reflectionName in this.args.model.relationshipsCache)
81
93
  return true
82
94
 
83
95
  return false
84
96
  }
85
97
 
86
- limit (amount) {
98
+ limit(amount) {
87
99
  return this._merge({limit: amount})
88
100
  }
89
101
 
90
- preloaded () {
102
+ preloaded() {
91
103
  if (!(this.args.reflectionName in this.args.model.relationshipsCache)) {
92
104
  throw new Error(`${this.args.reflectionName} hasnt been loaded yet`)
93
105
  }
@@ -95,7 +107,7 @@ export default class ApiMakerCollection {
95
107
  return this.args.model.relationshipsCache[this.args.reflectionName]
96
108
  }
97
109
 
98
- loaded () {
110
+ loaded() {
99
111
  const {model, reflectionName} = this.args
100
112
 
101
113
  if (reflectionName in model.relationships) {
@@ -135,22 +147,22 @@ export default class ApiMakerCollection {
135
147
  forEach = (...args) => this.loaded().forEach(...args)
136
148
  map = (...args) => this.loaded().map(...args)
137
149
 
138
- preload (preloadValue) {
150
+ preload(preloadValue) {
139
151
  return this._merge({preload: preloadValue})
140
152
  }
141
153
 
142
- page (page) {
154
+ page(page) {
143
155
  if (!page)
144
156
  page = 1
145
157
 
146
158
  return this._merge({page})
147
159
  }
148
160
 
149
- pageKey (pageKey) {
161
+ pageKey(pageKey) {
150
162
  return this._merge({pageKey})
151
163
  }
152
164
 
153
- params () {
165
+ params() {
154
166
  let params = {}
155
167
 
156
168
  if (this.queryArgs.params) params = incorporate(params, this.queryArgs.params)
@@ -171,20 +183,20 @@ export default class ApiMakerCollection {
171
183
  return params
172
184
  }
173
185
 
174
- per (per) {
186
+ per(per) {
175
187
  return this._merge({per})
176
188
  }
177
189
 
178
- perKey (perKey) {
190
+ perKey(perKey) {
179
191
  return this._merge({perKey})
180
192
  }
181
193
 
182
- ransack (params) {
194
+ ransack(params) {
183
195
  if (params) this._merge({ransack: params})
184
196
  return this
185
197
  }
186
198
 
187
- async result () {
199
+ async result() {
188
200
  const response = await this._response()
189
201
  const models = digg(response, "collection")
190
202
 
@@ -242,11 +254,11 @@ export default class ApiMakerCollection {
242
254
  return this._merge({selectColumns: newSelect})
243
255
  }
244
256
 
245
- sort (sortBy) {
257
+ sort(sortBy) {
246
258
  return this._merge({ransack: {s: sortBy}})
247
259
  }
248
260
 
249
- async toArray () {
261
+ async toArray() {
250
262
  const response = await this._response()
251
263
  const models = digg(response, "collection")
252
264
 
@@ -255,13 +267,13 @@ export default class ApiMakerCollection {
255
267
  return models
256
268
  }
257
269
 
258
- modelClass () {
270
+ modelClass() {
259
271
  const modelName = digg(this.args.modelClass.modelClassData(), "name")
260
272
 
261
273
  return modelClassRequire(modelName)
262
274
  }
263
275
 
264
- clone () {
276
+ clone() {
265
277
  const clonedQueryArgs = cloneDeep(this.queryArgs)
266
278
 
267
279
  return new ApiMakerCollection(this.args, clonedQueryArgs)
@@ -274,13 +286,13 @@ export default class ApiMakerCollection {
274
286
  }
275
287
  }
276
288
 
277
- _merge (newQueryArgs) {
289
+ _merge(newQueryArgs) {
278
290
  incorporate(this.queryArgs, newQueryArgs)
279
291
 
280
292
  return this
281
293
  }
282
294
 
283
- _response () {
295
+ _response() {
284
296
  const modelClassData = this.args.modelClass.modelClassData()
285
297
 
286
298
  return CommandsPool.addCommand(
@@ -42,7 +42,7 @@ export default memo(shapeComponent(class ApiMakerTableHeaderColumn extends BaseC
42
42
  const actualStyle = Object.assign(
43
43
  {
44
44
  cursor: resizing ? "col-resize" : undefined,
45
- width: `${width}%`
45
+ width
46
46
  },
47
47
  style
48
48
  )
@@ -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
+ }))
@@ -1,14 +1,13 @@
1
- import {Pressable, Text, View} from "react-native"
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
- {table.headerLabelForColumn(column)}
46
+ <Text>
47
+ {table.headerLabelForColumn(column)}
48
+ </Text>
47
49
  </label>
48
50
  </View>
49
51
  )
@@ -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
 
@@ -169,6 +183,10 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
169
183
  select,
170
184
  selectColumns: this.props.selectColumns
171
185
  })
186
+ this.queryWithoutPagination = useMemo(
187
+ () => this.collection?.query?.clone()?.except("page"),
188
+ [this.collection.query]
189
+ )
172
190
  }
173
191
 
174
192
  async loadCurrentWorkplace() {
@@ -196,13 +214,14 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
196
214
 
197
215
  const tableSetting = await this.tableSettings.loadExistingOrCreateTableSettings()
198
216
  const {columns, preload} = this.tableSettings.preparedColumns(tableSetting)
199
- const {flatListWidth} = this.s
200
- const widths = new Widths({columns, flatListWidth, table: this})
217
+ const {width} = this.s
218
+ const widths = new Widths({columns, table: this, width})
201
219
 
202
220
  this.setState({
203
221
  preparedColumns: columns,
204
222
  preload: this.mergedPreloads(preload),
205
223
  tableSetting,
224
+ tableSettingLoaded: true,
206
225
  tableSettingFullCacheKey: tableSetting.fullCacheKey(),
207
226
  widths
208
227
  })
@@ -259,7 +278,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
259
278
  }
260
279
 
261
280
  return (
262
- <div className={this.className()} style={this.props.styles?.container}>
281
+ <View dataSet={{class: this.className()}} onLayout={this.tt.onContainerLayout} style={this.props.styles?.container}>
263
282
  {showNoRecordsAvailableContent &&
264
283
  <div className="live-table--no-records-available-content">
265
284
  {noRecordsAvailableContent({models, qParams, overallCount})}
@@ -276,7 +295,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
276
295
  {qParams && query && result && models && !showNoRecordsAvailableContent && !showNoRecordsFoundContent &&
277
296
  this.cardOrTable()
278
297
  }
279
- </div>
298
+ </View>
280
299
  )
281
300
  }
282
301
 
@@ -376,10 +395,9 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
376
395
  extraData={this.s.lastUpdate}
377
396
  keyExtractor={this.tt.keyExtrator}
378
397
  ListHeaderComponent={this.tt.listHeaderComponent}
379
- onLayout={this.tt.onFlatListLayout}
380
398
  renderItem={this.tt.renderItem}
381
399
  showsHorizontalScrollIndicator
382
- style={{border: "1px solid #dbdbdb", borderRadius: 5, overflowX: "auto"}}
400
+ style={styleSheet.flatList}
383
401
  {...restProps}
384
402
  />
385
403
  )
@@ -416,12 +434,12 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
416
434
  )
417
435
  }
418
436
 
419
- onFlatListLayout = (e) => {
437
+ onContainerLayout = (e) => {
420
438
  const {width} = e.nativeEvent.layout
421
439
  const {widths} = this.s
422
440
 
423
- this.setState({flatListWidth: width})
424
- widths.flatListWidth = width
441
+ this.setState({width})
442
+ if (widths) widths.tableWidth = width
425
443
  }
426
444
 
427
445
  onLinksCreated = ({args}) => {
@@ -495,7 +513,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
495
513
  }
496
514
 
497
515
  listHeaderComponent = () => {
498
- const {query} = digs(this.collection, "query")
516
+ const {queryWithoutPagination} = this.tt
499
517
 
500
518
  return (
501
519
  <Row dataSet={{class: "live-table-header-row"}} style={this.styleForRow()}>
@@ -503,7 +521,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
503
521
  <Header style={this.styleForHeader({style: {width: 41}})}>
504
522
  <WorkerPluginsCheckAllCheckbox
505
523
  currentWorkplace={this.s.currentWorkplace}
506
- query={query}
524
+ query={queryWithoutPagination}
507
525
  style={{marginHorizontal: "auto"}}
508
526
  />
509
527
  </Header>
@@ -517,6 +535,16 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
517
535
  renderItem = ({index, item: model}) => {
518
536
  const {preparedColumns, tableSettingFullCacheKey} = this.s
519
537
 
538
+ if (!this.s.tableSettingLoaded) {
539
+ return (
540
+ <View>
541
+ <Text>
542
+ Loading...
543
+ </Text>
544
+ </View>
545
+ )
546
+ }
547
+
520
548
  return (
521
549
  <ModelRow
522
550
  cacheKey={model.cacheKey()}
@@ -536,7 +564,8 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
536
564
  const defaultStyle = {
537
565
  justifyContent: "center",
538
566
  padding: 8,
539
- backgroundColor: even ? "#f5f5f5" : undefined
567
+ backgroundColor: even ? "#f5f5f5" : undefined,
568
+ overflow: "hidden"
540
569
  }
541
570
 
542
571
  if (type == "actions") {
@@ -1,28 +1,28 @@
1
1
  import {digg} from "diggerize"
2
2
 
3
3
  export default class TableWidths {
4
- constructor({columns, flatListWidth, table}) {
4
+ constructor({columns, table, width}) {
5
5
  this.columns = columns
6
- this.flatListWidth = flatListWidth
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].tableSettingColumn
19
+ const column = this.columns[columnIndex]
20
+ const tableSettingColumn = column.tableSettingColumn
21
21
 
22
- if (column.hasWidth()) {
23
- this.columns[columnIndex].width = column.width()
22
+ if (tableSettingColumn.hasWidth()) {
23
+ column.width = tableSettingColumn.width()
24
24
 
25
- widthLeft -= column.width()
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].tableSettingColumn
39
+ const column = this.columns[columnIndex]
40
+ const tableSettingColumn = column.tableSettingColumn
41
+
42
+ if (!tableSettingColumn.hasWidth()) {
43
+ let newWidth = widthLeft / amountOfColumns
40
44
 
41
- if (!column.hasWidth()) {
42
- const newWidth = widthLeft / amountOfColumns
45
+ if (newWidth < 200) newWidth = 200
43
46
 
44
- this.columns[columnIndex].width = newWidth
47
+ column.width = newWidth
45
48
 
46
49
  updateData << {
47
- id: column.id(),
50
+ id: tableSettingColumn.id(),
48
51
  width: newWidth
49
52
  }
50
53
  }
51
54
  }
52
55
 
53
- // FIXME: Should update the columns on the backend if anything changed
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
- const widthPercent = (width / this.flatListWidth) * 100
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,39 +1,47 @@
1
+ import {memo, useEffect, useMemo, useRef} from "react"
2
+ import BaseComponent from "../base-component"
1
3
  import classNames from "classnames"
2
4
  import Collection from "../collection.mjs"
3
- import EventConnection from "../event-connection"
4
5
  import PropTypes from "prop-types"
5
6
  import propTypesExact from "prop-types-exact"
6
- import React from "react"
7
+ import {shapeComponent} from "set-state-compare/src/shape-component"
7
8
  import {simpleObjectDifferent} from "set-state-compare/src/diff-utils"
8
- import {useEffect, useRef} from "react"
9
+ import useModelEvent from "../use-model-event.js"
9
10
 
10
- const Checkbox = (props) => {
11
- const {indeterminate, ...restProps} = props
12
- const checkboxRef = useRef()
11
+ const Checkbox = memo(shapeComponent(class Checkbox extends BaseComponent {
12
+ render() {
13
+ const {indeterminate, ...restProps} = this.props
14
+ const checkboxRef = useRef()
13
15
 
14
- useEffect(() => {
15
- checkboxRef.current.indeterminate = indeterminate
16
- })
16
+ useEffect(() => {
17
+ checkboxRef.current.indeterminate = indeterminate
18
+ })
17
19
 
18
- return (
19
- <input ref={checkboxRef} type="checkbox" {...restProps} />
20
- )
21
- }
20
+ return (
21
+ <input ref={checkboxRef} type="checkbox" {...restProps} />
22
+ )
23
+ }
24
+ }))
22
25
 
23
- export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends React.PureComponent {
26
+ export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckAllCheckbox extends BaseComponent {
24
27
  static propTypes = propTypesExact({
25
28
  currentWorkplace: PropTypes.object,
26
29
  query: PropTypes.instanceOf(Collection),
27
30
  style: PropTypes.object
28
31
  })
29
32
 
30
- state = {
31
- checked: false,
32
- indeterminate: false
33
- }
33
+ setup() {
34
+ this.useStates({
35
+ checked: false,
36
+ indeterminate: false
37
+ })
38
+
39
+ useMemo(() => {
40
+ this.updateAllChecked()
41
+ }, [])
34
42
 
35
- componentDidMount() {
36
- this.updateAllChecked()
43
+ useModelEvent(this.props.currentWorkplace, "workplace_links_created", this.tt.onLinksCreated)
44
+ useModelEvent(this.props.currentWorkplace, "workplace_links_destroyed", this.tt.onLinksDestroyed)
37
45
  }
38
46
 
39
47
  componentDidUpdate(prevProps) {
@@ -58,21 +66,17 @@ export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends React.Pu
58
66
  }
59
67
 
60
68
  render() {
61
- const {className, currentWorkplace, style} = this.props
69
+ const {className, style} = this.props
62
70
  const {checked, indeterminate} = this.state
63
71
 
64
72
  return (
65
- <>
66
- <EventConnection event="workplace_links_created" model={currentWorkplace} onCall={this.onLinksCreated} />
67
- <EventConnection event="workplace_links_destroyed" model={currentWorkplace} onCall={this.onLinksDestroyed} />
68
- <Checkbox
69
- checked={checked}
70
- className={classNames("api-maker--table--worker-plugins-check-all-checkbox", className)}
71
- indeterminate={indeterminate}
72
- onChange={this.onCheckedChanged}
73
- style={style}
74
- />
75
- </>
73
+ <Checkbox
74
+ checked={checked}
75
+ className={classNames("api-maker--table--worker-plugins-check-all-checkbox", className)}
76
+ indeterminate={indeterminate}
77
+ onChange={this.onCheckedChanged}
78
+ style={style}
79
+ />
76
80
  )
77
81
  }
78
82
 
@@ -104,4 +108,4 @@ export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends React.Pu
104
108
  this.updateAllChecked()
105
109
  }
106
110
  }
107
- }
111
+ }))
@@ -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"