@kaspernj/api-maker 1.0.277 → 1.0.279

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
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.277",
19
+ "version": "1.0.279",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -149,6 +149,12 @@ class ApiMakerBootstrapInput extends React.PureComponent {
149
149
  if (forwardedProp in this.props) moneyProps[forwardedProp] = this.props[forwardedProp]
150
150
  }
151
151
 
152
+ const forwardedInputProps = ["defaultValue"]
153
+
154
+ for (const forwardedInputProp of forwardedInputProps) {
155
+ if (forwardedInputProp in this.props.inputProps) moneyProps[forwardedInputProp] = this.props.inputProps[forwardedInputProp]
156
+ }
157
+
152
158
  return moneyProps
153
159
  }
154
160
 
@@ -14,7 +14,8 @@ export default class ApiMakerBootStrapLiveTableModelRow extends React.PureCompon
14
14
  cacheKey: PropTypes.string.isRequired,
15
15
  model: PropTypes.object.isRequired,
16
16
  liveTable: PropTypes.object.isRequired,
17
- preparedColumns: PropTypes.array
17
+ preparedColumns: PropTypes.array,
18
+ tableSettingFullCacheKey: PropTypes.string.isRequired
18
19
  }
19
20
 
20
21
  render() {
@@ -0,0 +1,117 @@
1
+ import "./style"
2
+ import columnIdentifier from "../column-identifier.mjs"
3
+ import EventListener from "../../event-listener.jsx"
4
+ import PropTypes from "prop-types"
5
+ import React from "react"
6
+
7
+ class ColumnRow extends React.PureComponent {
8
+ static propTypes = {
9
+ column: PropTypes.object.isRequired,
10
+ table: PropTypes.object.isRequired,
11
+ tableSettingColumn: PropTypes.object.isRequired
12
+ }
13
+
14
+ checked = this.props.tableSettingColumn.visible()
15
+ checkboxRef = React.createRef()
16
+
17
+ componentDidMount() {
18
+ this.updateCheckboxChecked()
19
+ }
20
+
21
+ componentDidUpdate() {
22
+ this.updateCheckboxChecked()
23
+ }
24
+
25
+ render() {
26
+ const {column, table, tableSettingColumn} = this.props
27
+ const checkboxProps = {}
28
+
29
+ if (tableSettingColumn.visible() === true) {
30
+ checkboxProps.checked = "checked"
31
+ } else if (tableSettingColumn.visible() === null) {
32
+ checkboxProps.indeterminate = "indeterminate"
33
+ }
34
+
35
+ return (
36
+ <div className="api-maker--table--settings--column-row">
37
+ <label>
38
+ <input
39
+ className="api-maker--table--setings--column-checkbox"
40
+ data-identifier={columnIdentifier(column)}
41
+ onChange={this.onCheckboxChange}
42
+ ref={this.checkboxRef}
43
+ type="checkbox"
44
+ {...checkboxProps}
45
+ />
46
+ {table.headerLabelForColumn(column)}
47
+ </label>
48
+ </div>
49
+ )
50
+ }
51
+
52
+ onCheckboxChange = () => {
53
+ const {checked} = this
54
+
55
+ if (checked === true) {
56
+ this.checked = null
57
+ } else if (checked === null) {
58
+ this.checked = false
59
+ } else {
60
+ this.checked = true
61
+ }
62
+
63
+ this.updateCheckboxChecked()
64
+ this.updateTableSettingColumn()
65
+ }
66
+
67
+ updateCheckboxChecked() {
68
+ const {checked} = this
69
+
70
+ if (checked === true) {
71
+ this.checkboxRef.current.checked = true
72
+ this.checkboxRef.current.indeterminate = undefined
73
+ } else if (checked === null) {
74
+ this.checkboxRef.current.checked = undefined
75
+ this.checkboxRef.current.indeterminate = true
76
+ } else {
77
+ this.checkboxRef.current.checked = undefined
78
+ this.checkboxRef.current.indeterminate = undefined
79
+ }
80
+ }
81
+
82
+ async updateTableSettingColumn() {
83
+ const {table, tableSettingColumn} = this.props
84
+
85
+ await tableSettingColumn.update({visible: this.checked})
86
+ table.updateSettingsFullCacheKey()
87
+ }
88
+ }
89
+
90
+ export default class ApiMakerTableSettings extends React.PureComponent {
91
+ static propTypes = {
92
+ onRequestClose: PropTypes.func.isRequired,
93
+ table: PropTypes.object.isRequired
94
+ }
95
+
96
+ rootRef = React.createRef()
97
+
98
+ render() {
99
+ const {table} = this.props
100
+ const {preparedColumns} = table.shape
101
+
102
+ return (
103
+ <div className="api-maker--table--settings" ref={this.rootRef}>
104
+ <EventListener event="mouseup" onCalled={this.onWindowMouseUp} target={window} />
105
+ {preparedColumns?.map(({column, tableSettingColumn}) =>
106
+ <ColumnRow column={column} key={columnIdentifier(column)} table={table} tableSettingColumn={tableSettingColumn} />
107
+ )}
108
+ </div>
109
+ )
110
+ }
111
+
112
+ onWindowMouseUp = (e) => {
113
+ if (this.rootRef.current && !this.rootRef.current.contains(e.target)) {
114
+ this.props.onRequestClose()
115
+ }
116
+ }
117
+ }
@@ -0,0 +1,8 @@
1
+ .api-maker--table--settings {
2
+ position: absolute;
3
+ right: 0px;
4
+ padding: 12px;
5
+ background-color: #fff;
6
+ border: 1px solid black;
7
+ font-size: 12px;
8
+ }
@@ -16,6 +16,7 @@ import PropTypes from "prop-types"
16
16
  import React from "react"
17
17
  import selectCalculator from "./select-calculator"
18
18
  import Select from "../inputs/select"
19
+ import Settings from "./settings"
19
20
  import Shape from "set-state-compare/src/shape"
20
21
  import SortLink from "../bootstrap/sort-link"
21
22
  import TableSettings from "./table-settings"
@@ -105,7 +106,8 @@ class ApiMakerTable extends React.PureComponent {
105
106
  result: undefined,
106
107
  showFilters: false,
107
108
  showNoRecordsAvailableContent: false,
108
- showNoRecordsFoundContent: false
109
+ showNoRecordsFoundContent: false,
110
+ showSettings: false
109
111
  })
110
112
 
111
113
  this.loadTableSetting()
@@ -129,10 +131,14 @@ class ApiMakerTable extends React.PureComponent {
129
131
 
130
132
  this.shape.set({
131
133
  preparedColumns: columns,
132
- preload: this.mergedPreloads(preload)
134
+ preload: this.mergedPreloads(preload),
135
+ tableSetting,
136
+ tableSettingFullCacheKey: tableSetting.fullCacheKey()
133
137
  })
134
138
  }
135
139
 
140
+ updateSettingsFullCacheKey = () => this.shape.set({tableSettingFullCacheKey: this.shape.tableSetting.fullCacheKey()})
141
+
136
142
  columnsAsArray = () => {
137
143
  if (typeof this.props.columns == "function") return this.props.columns()
138
144
 
@@ -384,7 +390,7 @@ class ApiMakerTable extends React.PureComponent {
384
390
 
385
391
  tableControls() {
386
392
  const {controls} = this.props
387
- const {models, qParams, query, result} = digs(this.shape, "models", "qParams", "query", "result")
393
+ const {models, qParams, query, result, showSettings} = digs(this.shape, "models", "qParams", "query", "result", "showSettings")
388
394
 
389
395
  return (
390
396
  <>
@@ -392,13 +398,34 @@ class ApiMakerTable extends React.PureComponent {
392
398
  <a className="filter-button" href="#" onClick={digg(this, "onFilterClicked")}>
393
399
  <i className="fa fa-fw fa-magnifying-glass la la-fw la-search" />
394
400
  </a>
401
+ <span style={{position: "relative"}}>
402
+ {showSettings &&
403
+ <Settings onRequestClose={this.onRequestCloseSettings} table={this} />
404
+ }
405
+ <a className="settings-button" href="#" onClick={digg(this, "onSettingsClicked")}>
406
+ <i className="fa fa-fw fa-gear la la-fw la-gear" />
407
+ </a>
408
+ </span>
395
409
  </>
396
410
  )
397
411
  }
398
412
 
399
413
  tableContent () {
400
414
  const {breakPoint, workplace} = digs(this.props, "breakPoint", "workplace")
401
- const {currentWorkplace, models, preparedColumns, query} = digs(this.shape, "currentWorkplace", "models", "preparedColumns", "query")
415
+ const {
416
+ currentWorkplace,
417
+ models,
418
+ preparedColumns,
419
+ query,
420
+ tableSettingFullCacheKey
421
+ } = digs(
422
+ this.shape,
423
+ "currentWorkplace",
424
+ "models",
425
+ "preparedColumns",
426
+ "query",
427
+ "tableSettingFullCacheKey"
428
+ )
402
429
  const ColumnInHeadComponent = this.columnInHeadComponent()
403
430
  const RowComponent = this.rowComponent()
404
431
 
@@ -436,6 +463,7 @@ class ApiMakerTable extends React.PureComponent {
436
463
  model={model}
437
464
  preparedColumns={preparedColumns}
438
465
  rowComponent={this.rowComponent()}
466
+ tableSettingFullCacheKey={tableSettingFullCacheKey}
439
467
  />
440
468
  )}
441
469
  </BodyComponent>
@@ -563,6 +591,16 @@ class ApiMakerTable extends React.PureComponent {
563
591
  this.submitFilter()
564
592
  }
565
593
 
594
+ onRequestCloseSettings = () => this.shape.set({showSettings: false})
595
+
596
+ onSettingsClicked = (e) => {
597
+ e.preventDefault()
598
+
599
+ const {showSettings} = digs(this.shape, "showSettings")
600
+
601
+ this.shape.set({showSettings: !showSettings})
602
+ }
603
+
566
604
  submitFilter = () => {
567
605
  const {filterFormRef} = digs(this, "filterFormRef")
568
606
  const filterForm = digg(filterFormRef, "current")