@kaspernj/api-maker 1.0.262 → 1.0.264
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.264",
|
|
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/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) {
|
package/src/table/model-row.jsx
CHANGED
|
@@ -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 {
|
|
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">
|
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 = {
|
|
@@ -33,7 +34,8 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
33
34
|
noRecordsAvailableContent: undefined,
|
|
34
35
|
noRecordsFoundContent: undefined,
|
|
35
36
|
preloads: [],
|
|
36
|
-
select: {}
|
|
37
|
+
select: {},
|
|
38
|
+
workplace: false
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
static propTypes = {
|
|
@@ -69,7 +71,8 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
69
71
|
queryName: PropTypes.string,
|
|
70
72
|
select: PropTypes.object,
|
|
71
73
|
selectColumns: PropTypes.object,
|
|
72
|
-
viewModelPath: PropTypes.func
|
|
74
|
+
viewModelPath: PropTypes.func,
|
|
75
|
+
workplace: PropTypes.bool.isRequired
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
filterFormRef = React.createRef()
|
|
@@ -86,6 +89,7 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
86
89
|
|
|
87
90
|
this.shape = new Shape(this, {
|
|
88
91
|
columns: columnsAsArray,
|
|
92
|
+
currentWorkplace: undefined,
|
|
89
93
|
identifier: this.props.identifier || `${collectionKey}-default`,
|
|
90
94
|
models: undefined,
|
|
91
95
|
overallCount: undefined,
|
|
@@ -105,6 +109,16 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
105
109
|
})
|
|
106
110
|
|
|
107
111
|
this.loadTableSetting()
|
|
112
|
+
|
|
113
|
+
if (this.props.workplace) this.loadCurrentWorkplace()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async loadCurrentWorkplace() {
|
|
117
|
+
const Workplace = modelClassRequire("Workplace")
|
|
118
|
+
const result = await Workplace.current()
|
|
119
|
+
const currentWorkplace = digg(result, "current", 0)
|
|
120
|
+
|
|
121
|
+
this.shape.set({currentWorkplace})
|
|
108
122
|
}
|
|
109
123
|
|
|
110
124
|
async loadTableSetting() {
|
|
@@ -270,6 +284,7 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
270
284
|
select,
|
|
271
285
|
selectColumns,
|
|
272
286
|
viewModelPath,
|
|
287
|
+
workplace,
|
|
273
288
|
...restProps
|
|
274
289
|
} = this.props
|
|
275
290
|
const {models, qParams, query, result} = digs(this.shape, "models", "qParams", "query", "result")
|
|
@@ -382,8 +397,8 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
382
397
|
}
|
|
383
398
|
|
|
384
399
|
tableContent () {
|
|
385
|
-
const {breakPoint} = digs(this.props, "breakPoint")
|
|
386
|
-
const {models, preparedColumns} = digs(this.shape, "models", "preparedColumns")
|
|
400
|
+
const {breakPoint, workplace} = digs(this.props, "breakPoint", "workplace")
|
|
401
|
+
const {currentWorkplace, models, preparedColumns, query} = digs(this.shape, "currentWorkplace", "models", "preparedColumns", "query")
|
|
387
402
|
const ColumnInHeadComponent = this.columnInHeadComponent()
|
|
388
403
|
const RowComponent = this.rowComponent()
|
|
389
404
|
|
|
@@ -401,6 +416,11 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
401
416
|
<>
|
|
402
417
|
<HeadComponent>
|
|
403
418
|
<RowComponent className="live-table-header-row">
|
|
419
|
+
{workplace && currentWorkplace &&
|
|
420
|
+
<ColumnInHeadComponent>
|
|
421
|
+
<WorkerPluginsCheckAllCheckbox currentWorkplace={currentWorkplace} query={query} />
|
|
422
|
+
</ColumnInHeadComponent>
|
|
423
|
+
}
|
|
404
424
|
{this.headersContentFromColumns()}
|
|
405
425
|
<ColumnInHeadComponent />
|
|
406
426
|
</RowComponent>
|
|
@@ -452,7 +472,7 @@ class ApiMakerTable extends React.PureComponent {
|
|
|
452
472
|
}
|
|
453
473
|
|
|
454
474
|
className() {
|
|
455
|
-
const classNames = ["
|
|
475
|
+
const classNames = ["api-maker--table"]
|
|
456
476
|
|
|
457
477
|
if (this.props.className)
|
|
458
478
|
classNames.push(this.props.className)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import Collection from "../collection.mjs"
|
|
2
|
+
|
|
3
|
+
export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends BaseComponent {
|
|
4
|
+
static propTypes = PropTypesExact({
|
|
5
|
+
currentWorkplace: PropTypes.object,
|
|
6
|
+
query: PropTypes.instanceOf(Collection)
|
|
7
|
+
})
|
|
8
|
+
|
|
9
|
+
render() {
|
|
10
|
+
const {className} = this.props
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<input
|
|
14
|
+
className={classNames("api-maker--table--worker-plugins-check-all-checkbox", className)}
|
|
15
|
+
onChange={this.onCheckedChanged}
|
|
16
|
+
type="checkbox"
|
|
17
|
+
/>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
onCheckedChanged = async (e) => {
|
|
22
|
+
e.preventDefault()
|
|
23
|
+
|
|
24
|
+
const {currentWorkplace, query} = this.props
|
|
25
|
+
|
|
26
|
+
await currentWorkplace.addCollection({query})
|
|
27
|
+
e.target.checked = true
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -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
|
+
}
|