@kaspernj/api-maker 1.0.263 → 1.0.265
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.
|
|
19
|
+
"version": "1.0.265",
|
|
20
20
|
"type": "module",
|
|
21
21
|
"description": "",
|
|
22
22
|
"main": "index.js",
|
|
@@ -75,6 +75,6 @@
|
|
|
75
75
|
"eslint-plugin-react": "^7.23.2",
|
|
76
76
|
"i18n-on-steroids": "^1.0.5",
|
|
77
77
|
"jest": "^29.0.1",
|
|
78
|
-
"jsdom": "^
|
|
78
|
+
"jsdom": "^22.0.0"
|
|
79
79
|
}
|
|
80
80
|
}
|
package/src/collection.mjs
CHANGED
|
@@ -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.
|
|
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.
|
|
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
|
-
|
|
231
|
+
_addQueryToModels(models) {
|
|
232
232
|
for(const model of models) {
|
|
233
233
|
model.collection = this
|
|
234
234
|
}
|
package/src/error-logger.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import SourceMapsLoader from "./source-maps-loader.mjs"
|
|
|
3
3
|
|
|
4
4
|
export default class ErrorLogger {
|
|
5
5
|
constructor () {
|
|
6
|
-
this.debugging =
|
|
6
|
+
this.debugging = false
|
|
7
7
|
this.errorOccurred = false
|
|
8
8
|
this.errors = []
|
|
9
9
|
this.isHandlingError = false
|
|
@@ -18,7 +18,12 @@ export default class ErrorLogger {
|
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
debug(...output) {
|
|
22
|
+
if (this.debugging) console.error(`ApiMaker ErrorLogger:`, ...output)
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
enable () {
|
|
26
|
+
this.debug("Enable called")
|
|
22
27
|
this.connectOnError()
|
|
23
28
|
this.connectUnhandledRejection()
|
|
24
29
|
}
|
|
@@ -40,7 +45,8 @@ export default class ErrorLogger {
|
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
connectOnError () {
|
|
43
|
-
|
|
48
|
+
window.addEventListener("error", (event) => {
|
|
49
|
+
if (this.debugging) this.debug(`Error:`, event.message)
|
|
44
50
|
this.errorOccurred = true
|
|
45
51
|
|
|
46
52
|
if (!this.isHandlingError) {
|
|
@@ -53,7 +59,8 @@ export default class ErrorLogger {
|
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
connectUnhandledRejection () {
|
|
56
|
-
|
|
62
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
63
|
+
if (this.debugging) this.debug(`Unhandled rejection:`, event.reason.message)
|
|
57
64
|
this.errorOccurred = true
|
|
58
65
|
|
|
59
66
|
if (!this.isHandlingError) {
|
|
@@ -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.
|
|
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
|
-
|
|
64
|
+
addQueryCommandsToModelClass (ModelClass, collectionCommands) {
|
|
65
65
|
for (const collectionCommandName in collectionCommands) {
|
|
66
66
|
const methodName = inflection.camelize(collectionCommandName, true)
|
|
67
67
|
|
package/src/table/style.scss
CHANGED
package/src/table/table.jsx
CHANGED
|
@@ -23,6 +23,7 @@ import uniqunize from "uniqunize"
|
|
|
23
23
|
import withBreakpoint from "./with-breakpoint"
|
|
24
24
|
|
|
25
25
|
const paginationOptions = [30, 60, 90, ["All", "all"]]
|
|
26
|
+
const WorkerPluginsCheckAllCheckbox = React.lazy(() => import("./worker-plugins-check-all-checkbox"))
|
|
26
27
|
|
|
27
28
|
class ApiMakerTable extends React.PureComponent {
|
|
28
29
|
static defaultProps = {
|
|
@@ -397,7 +398,7 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
397
398
|
|
|
398
399
|
tableContent () {
|
|
399
400
|
const {breakPoint, workplace} = digs(this.props, "breakPoint", "workplace")
|
|
400
|
-
const {models, preparedColumns} = digs(this.shape, "models", "preparedColumns")
|
|
401
|
+
const {currentWorkplace, models, preparedColumns, query} = digs(this.shape, "currentWorkplace", "models", "preparedColumns", "query")
|
|
401
402
|
const ColumnInHeadComponent = this.columnInHeadComponent()
|
|
402
403
|
const RowComponent = this.rowComponent()
|
|
403
404
|
|
|
@@ -415,8 +416,10 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
415
416
|
<>
|
|
416
417
|
<HeadComponent>
|
|
417
418
|
<RowComponent className="live-table-header-row">
|
|
418
|
-
{workplace &&
|
|
419
|
-
<ColumnInHeadComponent
|
|
419
|
+
{workplace && currentWorkplace &&
|
|
420
|
+
<ColumnInHeadComponent>
|
|
421
|
+
<WorkerPluginsCheckAllCheckbox currentWorkplace={currentWorkplace} query={query} />
|
|
422
|
+
</ColumnInHeadComponent>
|
|
420
423
|
}
|
|
421
424
|
{this.headersContentFromColumns()}
|
|
422
425
|
<ColumnInHeadComponent />
|
|
@@ -469,7 +472,7 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
469
472
|
}
|
|
470
473
|
|
|
471
474
|
className() {
|
|
472
|
-
const classNames = ["
|
|
475
|
+
const classNames = ["api-maker--table"]
|
|
473
476
|
|
|
474
477
|
if (this.props.className)
|
|
475
478
|
classNames.push(this.props.className)
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
}
|
|
18
|
+
|
|
19
|
+
export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends BaseComponent {
|
|
20
|
+
static propTypes = PropTypesExact({
|
|
21
|
+
currentWorkplace: PropTypes.object,
|
|
22
|
+
query: PropTypes.instanceOf(Collection)
|
|
23
|
+
})
|
|
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
|
+
|
|
55
|
+
render() {
|
|
56
|
+
const {className, currentWorkplace} = this.props
|
|
57
|
+
const {checked, indeterminate} = this.state
|
|
58
|
+
|
|
59
|
+
return (
|
|
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
|
+
</>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
modelClassName = () => this.props.query.modelClass().modelClassData().name
|
|
74
|
+
|
|
75
|
+
onCheckedChanged = async (e) => {
|
|
76
|
+
e.preventDefault()
|
|
77
|
+
|
|
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
|
+
}
|
|
95
|
+
|
|
96
|
+
onLinksDestroyed = ({args}) => {
|
|
97
|
+
if (args.destroyed[this.modelClassName()]) {
|
|
98
|
+
this.updateAllChecked()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|