@kaspernj/api-maker 1.0.264 → 1.0.266

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.264",
19
+ "version": "1.0.266",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -148,7 +148,7 @@ export default class ApiMakerCollection {
148
148
  const response = await this._response()
149
149
  const models = digg(response, "collection")
150
150
 
151
- this._addCollectionToModels(models)
151
+ this._addQueryToModels(models)
152
152
 
153
153
  const result = new Result({collection: this, models, response})
154
154
 
@@ -210,7 +210,7 @@ export default class ApiMakerCollection {
210
210
  const response = await this._response()
211
211
  const models = digg(response, "collection")
212
212
 
213
- this._addCollectionToModels(models)
213
+ this._addQueryToModels(models)
214
214
 
215
215
  return models
216
216
  }
@@ -228,7 +228,7 @@ export default class ApiMakerCollection {
228
228
  }
229
229
 
230
230
  // This is needed when reloading a version of the model with the same selected attributes and preloads
231
- _addCollectionToModels(models) {
231
+ _addQueryToModels(models) {
232
232
  for(const model of models) {
233
233
  model.collection = this
234
234
  }
@@ -36,7 +36,7 @@ export default class ApiMakerModelRecipesModelLoader {
36
36
 
37
37
  this.addAttributeMethodsToModelClass(ModelClass, attributes)
38
38
  this.addRelationshipsToModelClass(ModelClass, modelClassData, relationships)
39
- this.addCollectionCommandsToModelClass(ModelClass, collectionCommands)
39
+ this.addQueryCommandsToModelClass(ModelClass, collectionCommands)
40
40
  this.addMemberCommandsToModelClass(ModelClass, memberCommands)
41
41
 
42
42
  return ModelClass
@@ -61,7 +61,7 @@ export default class ApiMakerModelRecipesModelLoader {
61
61
  }
62
62
  }
63
63
 
64
- addCollectionCommandsToModelClass (ModelClass, collectionCommands) {
64
+ addQueryCommandsToModelClass (ModelClass, collectionCommands) {
65
65
  for (const collectionCommandName in collectionCommands) {
66
66
  const methodName = inflection.camelize(collectionCommandName, true)
67
67
 
@@ -456,7 +456,7 @@ class ApiMakerTable extends React.PureComponent {
456
456
 
457
457
  return (
458
458
  <div style={{display: "flex", justifyContent: "space-between", marginTop: "10px"}}>
459
- <div>
459
+ <div className="showing-counts">
460
460
  {I18n.t("js.api_maker.table.showing_from_to_out_of_total", {defaultValue, from, to, total_count: totalCount})}
461
461
  </div>
462
462
  <div>
@@ -1,4 +1,20 @@
1
1
  import Collection from "../collection.mjs"
2
+ import EventConnection from "../event-connection"
3
+ import {simpleObjectDifferent} from "set-state-compare/src/diff-utils"
4
+ import {useEffect, useRef} from "react"
5
+
6
+ const Checkbox = (props) => {
7
+ const {indeterminate, ...restProps} = props
8
+ const checkboxRef = useRef()
9
+
10
+ useEffect(() => {
11
+ checkboxRef.current.indeterminate = indeterminate
12
+ })
13
+
14
+ return (
15
+ <input ref={checkboxRef} type="checkbox" {...restProps} />
16
+ )
17
+ }
2
18
 
3
19
  export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends BaseComponent {
4
20
  static propTypes = PropTypesExact({
@@ -6,24 +22,80 @@ export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends BaseComp
6
22
  query: PropTypes.instanceOf(Collection)
7
23
  })
8
24
 
25
+ state = {
26
+ checked: false,
27
+ indeterminate: false
28
+ }
29
+
30
+ componentDidMount() {
31
+ this.updateAllChecked()
32
+ }
33
+
34
+ componentDidUpdate(prevProps) {
35
+ const previousParams = prevProps.query.params()
36
+ const currentParams = this.props.query.params()
37
+
38
+ if (simpleObjectDifferent(previousParams, currentParams)) {
39
+ this.updateAllChecked()
40
+ }
41
+ }
42
+
43
+ async updateAllChecked() {
44
+ const {query, currentWorkplace} = this.props
45
+ const queryLinksStatusResult = await currentWorkplace.queryLinksStatus({query})
46
+ const allChecked = queryLinksStatusResult.all_checked
47
+ const someChecked = queryLinksStatusResult.some_checked
48
+
49
+ this.setState({
50
+ checked: allChecked,
51
+ indeterminate: someChecked
52
+ })
53
+ }
54
+
9
55
  render() {
10
- const {className} = this.props
56
+ const {className, currentWorkplace} = this.props
57
+ const {checked, indeterminate} = this.state
11
58
 
12
59
  return (
13
- <input
14
- className={classNames("api-maker--table--worker-plugins-check-all-checkbox", className)}
15
- onChange={this.onCheckedChanged}
16
- type="checkbox"
17
- />
60
+ <>
61
+ <EventConnection event="workplace_links_created" model={currentWorkplace} onCall={this.onLinksCreated} />
62
+ <EventConnection event="workplace_links_destroyed" model={currentWorkplace} onCall={this.onLinksDestroyed} />
63
+ <Checkbox
64
+ checked={checked}
65
+ className={classNames("api-maker--table--worker-plugins-check-all-checkbox", className)}
66
+ indeterminate={indeterminate}
67
+ onChange={this.onCheckedChanged}
68
+ />
69
+ </>
18
70
  )
19
71
  }
20
72
 
73
+ modelClassName = () => this.props.query.modelClass().modelClassData().name
74
+
21
75
  onCheckedChanged = async (e) => {
22
76
  e.preventDefault()
23
77
 
24
78
  const {currentWorkplace, query} = this.props
79
+ const checkbox = e.target
80
+
81
+ if (checkbox.checked) {
82
+ await currentWorkplace.addQuery({query})
83
+ this.setState({checked: true, indeterminate: false})
84
+ } else {
85
+ await currentWorkplace.removeQuery({query})
86
+ this.setState({checked: false, indeterminate: false})
87
+ }
88
+ }
89
+
90
+ onLinksCreated = ({args}) => {
91
+ if (args.created[this.modelClassName()]) {
92
+ this.updateAllChecked()
93
+ }
94
+ }
25
95
 
26
- await currentWorkplace.addCollection({query})
27
- e.target.checked = true
96
+ onLinksDestroyed = ({args}) => {
97
+ if (args.destroyed[this.modelClassName()]) {
98
+ this.updateAllChecked()
99
+ }
28
100
  }
29
101
  }