@kaspernj/api-maker 1.0.401 → 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.
@@ -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
- fixedTableLayout: undefined,
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) this.loadCurrentWorkplace()
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.state.preparedColumns) {
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()} data-fixed-table-layout={this.s.fixedTableLayout}>
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 TableComponent = this.responsiveComponent("table")
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()} table={!this.isSmallScreen()} {...restProps}>
351
- {this.tableContent()}
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 onFixedTableLayoutChanged={this.tt.onFixedTableLayoutChanged} onRequestClose={this.tt.onRequestCloseSettings} table={this} />
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
- <div style={{display: "flex", justifyContent: "space-between", marginTop: "10px"}}>
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
- </div>
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
- isSmallScreen() {
535
- if (this.breakpoint == "xs" || this.breakpoint == "sm") return true
551
+ columnWidths() {
552
+ const columnWidths = {}
536
553
 
537
- return false
538
- }
554
+ for (const column of this.s.preparedColumns) {
555
+ columnWidths[column.tableSettingColumn.identifier()] = column.width
556
+ }
539
557
 
540
- columnComponent = () => this.responsiveComponent("td")
541
- columnInHeadComponent = () => this.responsiveComponent("th")
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 PropTypesExact from "prop-types-exact"
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 = PropTypesExact({
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
  </>
@@ -18,7 +18,7 @@ const getWindowLayout = (width) => {
18
18
  }
19
19
  }
20
20
 
21
- const useScreenSize = () => {
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 useScreenSize
49
+ export default useScreenLayout
@@ -1,149 +0,0 @@
1
- import {digg, digs} from "diggerize"
2
- import * as inflection from "inflection"
3
- import Link from "../../link"
4
- import MoneyFormatter from "../../money-formatter"
5
- import PropTypes from "prop-types"
6
-
7
- export default class ApiMakerBootStrapLiveTableModelRow extends React.PureComponent {
8
- static propTypes = {
9
- model: PropTypes.object.isRequired,
10
- liveTable: PropTypes.object.isRequired
11
- }
12
-
13
- modelCallbackArgs = this._modelCallbackArgs()
14
-
15
- render() {
16
- const {model} = digs(this.props, "model")
17
- const {modelClass} = digs(this.props.liveTable.props, "modelClass")
18
- const {actionsContent, columnsContent, destroyEnabled, editModelPath, viewModelPath} = digg(this, "props", "liveTable", "props")
19
- const {columns} = digg(this, "props", "liveTable", "shape")
20
-
21
- let editPath, viewPath
22
-
23
- if (editModelPath && model.can("edit")) editPath = editModelPath(this.modelCallbackArgs)
24
- if (viewModelPath && model.can("show")) viewPath = viewModelPath(this.modelCallbackArgs)
25
-
26
- return (
27
- <tr className={`${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`} data-model-id={model.id()}>
28
- {columns && this.columnsContentFromColumns(model)}
29
- {!columns && columnsContent && columnsContent(this.modelCallbackArgs)}
30
- <td className="actions-column text-end text-nowrap text-right">
31
- {actionsContent && actionsContent(this.modelCallbackArgs)}
32
- {viewPath &&
33
- <Link className="view-button" to={viewPath}>
34
- <i className="fa fa-search la la-search" />
35
- </Link>
36
- }
37
- {editPath &&
38
- <Link className="edit-button" to={editPath}>
39
- <i className="fa fa-edit la la-edit" />
40
- </Link>
41
- }
42
- {destroyEnabled && model.can("destroy") &&
43
- <a className="destroy-button" href="#" onClick={this.onDestroyClicked}>
44
- <i className="fa fa-trash la la-trash" />
45
- </a>
46
- }
47
- </td>
48
- </tr>
49
- )
50
- }
51
-
52
- columnClassNamesForColumn (column) {
53
- const classNames = ["live-table-column"]
54
-
55
- if (column.commonProps && column.commonProps.className) classNames.push(column.commonProps.className)
56
- if (column.columnProps && column.columnProps.className) classNames.push(column.columnProps.className)
57
- if (column.textCenter) classNames.push("text-center")
58
- if (column.textRight) classNames.push("text-end text-right")
59
-
60
- return classNames
61
- }
62
-
63
- columnsContentFromColumns (model) {
64
- const {columns} = digs(this.props.liveTable.shape, "columns")
65
-
66
- return columns.map((column) =>
67
- <td
68
- className={classNames(this.columnClassNamesForColumn(column))}
69
- data-identifier={this.props.liveTable.identifierForColumn(column)}
70
- key={this.props.liveTable.identifierForColumn(column)}
71
- >
72
- {column.content && this.columnContentFromContentArg(column, model)}
73
- {!column.content && column.attribute && this.columnsContentFromAttributeAndPath(column, model)}
74
- </td>
75
- )
76
- }
77
-
78
- columnContentFromContentArg (column, model) {
79
- const value = column.content(this.modelCallbackArgs)
80
-
81
- return this.presentColumnValue(value)
82
- }
83
-
84
- columnsContentFromAttributeAndPath (column, model) {
85
- const {attribute} = digs(column, "attribute")
86
- const currentModelClass = this.props.modelClass
87
- const path = column.path || []
88
-
89
- if (path.length > 0) throw new Error("'path' support not implemented")
90
-
91
- if (!(attribute in model)) throw new Error(`${currentModelClass.modelName().name} doesn't respond to ${attribute}`)
92
-
93
- const value = model[attribute]()
94
-
95
- return this.presentColumnValue(value)
96
- }
97
-
98
- _modelCallbackArgs () {
99
- const {model} = digs(this.props, "model")
100
- const modelArgName = inflection.camelize(this.props.liveTable.props.modelClass.modelClassData().name, true)
101
- const modelCallbackArgs = {}
102
-
103
- modelCallbackArgs[modelArgName] = model
104
-
105
- return modelCallbackArgs
106
- }
107
-
108
- onDestroyClicked = async (e) => {
109
- e.preventDefault()
110
-
111
- const {destroyMessage} = digg(this, "props", "liveTable", "props")
112
- const {model} = digs(this.props, "model")
113
-
114
- if (!confirm(I18n.t("js.shared.are_you_sure"))) {
115
- return
116
- }
117
-
118
- try {
119
- await model.destroy()
120
-
121
- if (destroyMessage) {
122
- FlashMessage.success(destroyMessage)
123
- }
124
- } catch (error) {
125
- FlashMessage.errorResponse(error)
126
- }
127
- }
128
-
129
- presentColumnValue (value) {
130
- if (value instanceof Date) {
131
- return I18n.l("time.formats.default", value)
132
- } else if (MoneyFormatter.isMoney(value)) {
133
- return MoneyFormatter.format(value)
134
- } else if (typeof value == "boolean") {
135
- if (value) {
136
- return I18n.t("js.shared.yes")
137
- }
138
-
139
- return I18n.t("js.shared.no")
140
- } else if (Array.isArray(value)) {
141
- return value
142
- .map((valuePart) => this.presentColumnValue(valuePart))
143
- .filter((valuePart) => Boolean(valuePart))
144
- .join(", ")
145
- }
146
-
147
- return value
148
- }
149
- }