@kaspernj/api-maker 1.0.261 → 1.0.263

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.261",
19
+ "version": "1.0.263",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -20,16 +20,16 @@ const inputWrapper = (WrapperComponentClass, wrapperOptions = {}) => {
20
20
  this.setForm()
21
21
  }
22
22
 
23
- render() {
24
- const {errors, form} = digs(this.state, "errors", "form")
25
- const type = this.inputType()
26
- const inputProps = {
27
- id: idForComponent(this),
28
- name: nameForComponent(this),
29
- ref: this.inputRef()
30
- }
31
-
32
- if (!inputProps.ref) throw new Error("No input ref?")
23
+ inputProps() {
24
+ const givenInputProps = this.props.inputProps || {}
25
+ const inputProps = Object.assign(
26
+ {
27
+ id: idForComponent(this),
28
+ name: nameForComponent(this),
29
+ ref: this.inputRef()
30
+ },
31
+ givenInputProps
32
+ )
33
33
 
34
34
  if (this.handleAsCheckbox()) {
35
35
  inputProps.defaultChecked = this.inputDefaultChecked()
@@ -37,6 +37,16 @@ const inputWrapper = (WrapperComponentClass, wrapperOptions = {}) => {
37
37
  inputProps.defaultValue = this.inputDefaultValue()
38
38
  }
39
39
 
40
+ return inputProps
41
+ }
42
+
43
+ render() {
44
+ const {inputProps: oldInputProps, ...restProps} = this.props
45
+ const {errors, form} = digs(this.state, "errors", "form")
46
+ const type = this.inputType()
47
+ const inputProps = this.inputProps()
48
+
49
+ if (!inputProps.ref) throw new Error("No input ref?")
40
50
  if (!this.handleAsSelect()) inputProps.type = type
41
51
 
42
52
  const wrapperOpts = {
@@ -53,7 +63,7 @@ const inputWrapper = (WrapperComponentClass, wrapperOptions = {}) => {
53
63
  <WrapperComponentClass
54
64
  inputProps={inputProps}
55
65
  wrapperOpts={wrapperOpts}
56
- {...this.props}
66
+ {...restProps}
57
67
  />
58
68
  </>
59
69
  )
@@ -7,6 +7,8 @@ import Link from "../link"
7
7
  import MoneyFormatter from "../money-formatter"
8
8
  import PropTypes from "prop-types"
9
9
 
10
+ const WorkerPluginsCheckbox = React.lazy(() => import("./worker-plugins-checkbox"))
11
+
10
12
  export default class ApiMakerBootStrapLiveTableModelRow extends React.PureComponent {
11
13
  static propTypes = {
12
14
  cacheKey: PropTypes.string.isRequired,
@@ -16,10 +18,10 @@ export default class ApiMakerBootStrapLiveTableModelRow extends React.PureCompon
16
18
  }
17
19
 
18
20
  render() {
19
- const {cacheKey, model} = digs(this.props, "cacheKey", "model")
20
- const {modelClass} = digs(this.props.liveTable.props, "modelClass")
21
+ const {model} = digs(this.props, "model")
22
+ const {modelClass, workplace} = digs(this.props.liveTable.props, "modelClass", "workplace")
21
23
  const {actionsContent, columnsContent, destroyEnabled, editModelPath, viewModelPath} = digg(this, "props", "liveTable", "props")
22
- const {columns} = digg(this, "props", "liveTable", "shape")
24
+ const {columns, currentWorkplace} = digg(this, "props", "liveTable", "shape")
23
25
 
24
26
  this.modelCallbackArgs = this._modelCallbackArgs() // 'model' can change so this needs to be re-cached for every render
25
27
 
@@ -33,6 +35,11 @@ export default class ApiMakerBootStrapLiveTableModelRow extends React.PureCompon
33
35
 
34
36
  return (
35
37
  <RowComponent className={`live-table-row ${inflection.dasherize(modelClass.modelClassData().paramKey)}-row`} data-model-id={model.id()}>
38
+ {workplace &&
39
+ <ColumnComponent className="workplace-column">
40
+ <WorkerPluginsCheckbox currentWorkplace={currentWorkplace} model={model} />
41
+ </ColumnComponent>
42
+ }
36
43
  {columns && this.columnsContentFromColumns(model)}
37
44
  {!columns && columnsContent && columnsContent(this.modelCallbackArgs)}
38
45
  <ColumnComponent className="actions-column">
@@ -33,7 +33,8 @@ class ApiMakerTable extends React.PureComponent {
33
33
  noRecordsAvailableContent: undefined,
34
34
  noRecordsFoundContent: undefined,
35
35
  preloads: [],
36
- select: {}
36
+ select: {},
37
+ workplace: false
37
38
  }
38
39
 
39
40
  static propTypes = {
@@ -69,7 +70,8 @@ class ApiMakerTable extends React.PureComponent {
69
70
  queryName: PropTypes.string,
70
71
  select: PropTypes.object,
71
72
  selectColumns: PropTypes.object,
72
- viewModelPath: PropTypes.func
73
+ viewModelPath: PropTypes.func,
74
+ workplace: PropTypes.bool.isRequired
73
75
  }
74
76
 
75
77
  filterFormRef = React.createRef()
@@ -86,6 +88,7 @@ class ApiMakerTable extends React.PureComponent {
86
88
 
87
89
  this.shape = new Shape(this, {
88
90
  columns: columnsAsArray,
91
+ currentWorkplace: undefined,
89
92
  identifier: this.props.identifier || `${collectionKey}-default`,
90
93
  models: undefined,
91
94
  overallCount: undefined,
@@ -105,6 +108,16 @@ class ApiMakerTable extends React.PureComponent {
105
108
  })
106
109
 
107
110
  this.loadTableSetting()
111
+
112
+ if (this.props.workplace) this.loadCurrentWorkplace()
113
+ }
114
+
115
+ async loadCurrentWorkplace() {
116
+ const Workplace = modelClassRequire("Workplace")
117
+ const result = await Workplace.current()
118
+ const currentWorkplace = digg(result, "current", 0)
119
+
120
+ this.shape.set({currentWorkplace})
108
121
  }
109
122
 
110
123
  async loadTableSetting() {
@@ -270,6 +283,7 @@ class ApiMakerTable extends React.PureComponent {
270
283
  select,
271
284
  selectColumns,
272
285
  viewModelPath,
286
+ workplace,
273
287
  ...restProps
274
288
  } = this.props
275
289
  const {models, qParams, query, result} = digs(this.shape, "models", "qParams", "query", "result")
@@ -382,7 +396,7 @@ class ApiMakerTable extends React.PureComponent {
382
396
  }
383
397
 
384
398
  tableContent () {
385
- const {breakPoint} = digs(this.props, "breakPoint")
399
+ const {breakPoint, workplace} = digs(this.props, "breakPoint", "workplace")
386
400
  const {models, preparedColumns} = digs(this.shape, "models", "preparedColumns")
387
401
  const ColumnInHeadComponent = this.columnInHeadComponent()
388
402
  const RowComponent = this.rowComponent()
@@ -401,6 +415,9 @@ class ApiMakerTable extends React.PureComponent {
401
415
  <>
402
416
  <HeadComponent>
403
417
  <RowComponent className="live-table-header-row">
418
+ {workplace &&
419
+ <ColumnInHeadComponent />
420
+ }
404
421
  {this.headersContentFromColumns()}
405
422
  <ColumnInHeadComponent />
406
423
  </RowComponent>
@@ -0,0 +1,96 @@
1
+ import EventConnection from "../event-connection"
2
+ import modelClassRequire from "../model-class-require.mjs"
3
+
4
+ const Workplace = modelClassRequire("Workplace")
5
+
6
+ export default class ApiMakerTableWorkerPluginsCheckbox extends BaseComponent {
7
+ static propTypes = PropTypesExact({
8
+ currentWorkplace: PropTypes.object,
9
+ model: PropTypes.object.isRequired
10
+ })
11
+
12
+ shape = new Shape(this, {
13
+ checked: false
14
+ })
15
+
16
+ componentDidMount() {
17
+ this.loadCurrentLink()
18
+ }
19
+
20
+ async loadCurrentLink() {
21
+ const {model} = this.props
22
+ const response = await Workplace.linkFor({model_class: model.modelClassData().name, model_id: model.id()})
23
+ const link = digg(response, "link")
24
+
25
+ this.shape.set({
26
+ checked: Boolean(link),
27
+ linkLoaded: true
28
+ })
29
+ }
30
+
31
+ render() {
32
+ const {className, currentWorkplace, model} = this.props
33
+ const {checked, linkLoaded} = this.shape
34
+
35
+ if (!linkLoaded) {
36
+ return null
37
+ }
38
+
39
+ return (
40
+ <>
41
+ {currentWorkplace &&
42
+ <>
43
+ <EventConnection event="workplace_links_created" model={currentWorkplace} onCall={this.onLinksCreated} />
44
+ <EventConnection event="workplace_links_destroyed" model={currentWorkplace} onCall={this.onLinksDestroyed} />
45
+ </>
46
+ }
47
+ <input
48
+ checked={checked}
49
+ className={classNames("api-maker--table--worker-plugins-checkbox", className)}
50
+ data-checked={checked}
51
+ data-model-id={model.id()}
52
+ onChange={this.onCheckedChanged}
53
+ type="checkbox"
54
+ />
55
+ </>
56
+ )
57
+ }
58
+
59
+ onCheckedChanged = (e) => {
60
+ e.preventDefault()
61
+
62
+ const {model} = this.props
63
+ const checked = e.target.checked
64
+
65
+ if (checked) {
66
+ Workplace.createLink({model_class: model.modelClassData().name, model_id: model.id()})
67
+ } else {
68
+ const modelClassName = model.modelClassData().name
69
+ const params = {models: {}}
70
+
71
+ params.models[modelClassName] = [model.id()]
72
+
73
+ Workplace.destroyLinks(params)
74
+ }
75
+ }
76
+
77
+ onLinksCreated = ({args}) => {
78
+ const {model} = digs(this.props, "model")
79
+ const id = model.id()
80
+ const modelClassName = model.modelClassData().name
81
+
82
+ if (args.created[modelClassName] && args.created[modelClassName].includes(id)) {
83
+ this.shape.set({checked: true})
84
+ }
85
+ }
86
+
87
+ onLinksDestroyed = ({args}) => {
88
+ const {model} = digs(this.props, "model")
89
+ const id = model.id()
90
+ const modelClassName = model.modelClassData().name
91
+
92
+ if (args.destroyed[modelClassName] && args.destroyed[modelClassName].includes(id)) {
93
+ this.shape.set({checked: false})
94
+ }
95
+ }
96
+ }