@kaspernj/api-maker 1.0.262 → 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
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/table.jsx
CHANGED
|
@@ -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
|
+
}
|