@kaspernj/api-maker 1.0.419 → 1.0.421
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/collection.mjs
CHANGED
|
@@ -9,12 +9,12 @@ import Result from "./result.mjs"
|
|
|
9
9
|
export default class ApiMakerCollection {
|
|
10
10
|
static apiMakerType = "Collection"
|
|
11
11
|
|
|
12
|
-
constructor
|
|
12
|
+
constructor(args, queryArgs = {}) {
|
|
13
13
|
this.queryArgs = queryArgs
|
|
14
14
|
this.args = args
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
abilities
|
|
17
|
+
abilities(originalAbilities) {
|
|
18
18
|
const newAbilities = {}
|
|
19
19
|
|
|
20
20
|
for (const originalAbilityName in originalAbilities) {
|
|
@@ -33,21 +33,21 @@ export default class ApiMakerCollection {
|
|
|
33
33
|
return this._merge({abilities: newAbilities})
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
accessibleBy
|
|
36
|
+
accessibleBy(abilityName) {
|
|
37
37
|
return this._merge({accessibleBy: inflection.underscore(abilityName)})
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
async count
|
|
40
|
+
async count() {
|
|
41
41
|
const response = await this.clone()._merge({count: true})._response()
|
|
42
42
|
|
|
43
43
|
return digg(response, "count")
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
distinct
|
|
46
|
+
distinct() {
|
|
47
47
|
return this._merge({distinct: true})
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
async each
|
|
50
|
+
async each(callback) {
|
|
51
51
|
const array = await this.toArray()
|
|
52
52
|
|
|
53
53
|
for (const model in array) {
|
|
@@ -55,12 +55,24 @@ export default class ApiMakerCollection {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
|
|
58
|
+
except(...keys) {
|
|
59
|
+
for (const key of keys) {
|
|
60
|
+
if (key == "page") {
|
|
61
|
+
delete this.queryArgs[key]
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error(`Unhandled key: ${key}`)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return this
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async first() {
|
|
59
71
|
const models = await this.toArray()
|
|
60
72
|
return models[0]
|
|
61
73
|
}
|
|
62
74
|
|
|
63
|
-
groupBy
|
|
75
|
+
groupBy(...arrayOfTablesAndColumns) {
|
|
64
76
|
const arrayOfTablesAndColumnsWithLowercaseColumns = arrayOfTablesAndColumns.map((tableAndColumn) => {
|
|
65
77
|
if (Array.isArray(tableAndColumn)) {
|
|
66
78
|
return [tableAndColumn[0], tableAndColumn[1].toLowerCase()]
|
|
@@ -76,18 +88,18 @@ export default class ApiMakerCollection {
|
|
|
76
88
|
})
|
|
77
89
|
}
|
|
78
90
|
|
|
79
|
-
isLoaded
|
|
91
|
+
isLoaded() {
|
|
80
92
|
if (this.args.reflectionName in this.args.model.relationshipsCache)
|
|
81
93
|
return true
|
|
82
94
|
|
|
83
95
|
return false
|
|
84
96
|
}
|
|
85
97
|
|
|
86
|
-
limit
|
|
98
|
+
limit(amount) {
|
|
87
99
|
return this._merge({limit: amount})
|
|
88
100
|
}
|
|
89
101
|
|
|
90
|
-
preloaded
|
|
102
|
+
preloaded() {
|
|
91
103
|
if (!(this.args.reflectionName in this.args.model.relationshipsCache)) {
|
|
92
104
|
throw new Error(`${this.args.reflectionName} hasnt been loaded yet`)
|
|
93
105
|
}
|
|
@@ -95,7 +107,7 @@ export default class ApiMakerCollection {
|
|
|
95
107
|
return this.args.model.relationshipsCache[this.args.reflectionName]
|
|
96
108
|
}
|
|
97
109
|
|
|
98
|
-
loaded
|
|
110
|
+
loaded() {
|
|
99
111
|
const {model, reflectionName} = this.args
|
|
100
112
|
|
|
101
113
|
if (reflectionName in model.relationships) {
|
|
@@ -135,22 +147,22 @@ export default class ApiMakerCollection {
|
|
|
135
147
|
forEach = (...args) => this.loaded().forEach(...args)
|
|
136
148
|
map = (...args) => this.loaded().map(...args)
|
|
137
149
|
|
|
138
|
-
preload
|
|
150
|
+
preload(preloadValue) {
|
|
139
151
|
return this._merge({preload: preloadValue})
|
|
140
152
|
}
|
|
141
153
|
|
|
142
|
-
page
|
|
154
|
+
page(page) {
|
|
143
155
|
if (!page)
|
|
144
156
|
page = 1
|
|
145
157
|
|
|
146
158
|
return this._merge({page})
|
|
147
159
|
}
|
|
148
160
|
|
|
149
|
-
pageKey
|
|
161
|
+
pageKey(pageKey) {
|
|
150
162
|
return this._merge({pageKey})
|
|
151
163
|
}
|
|
152
164
|
|
|
153
|
-
params
|
|
165
|
+
params() {
|
|
154
166
|
let params = {}
|
|
155
167
|
|
|
156
168
|
if (this.queryArgs.params) params = incorporate(params, this.queryArgs.params)
|
|
@@ -171,20 +183,20 @@ export default class ApiMakerCollection {
|
|
|
171
183
|
return params
|
|
172
184
|
}
|
|
173
185
|
|
|
174
|
-
per
|
|
186
|
+
per(per) {
|
|
175
187
|
return this._merge({per})
|
|
176
188
|
}
|
|
177
189
|
|
|
178
|
-
perKey
|
|
190
|
+
perKey(perKey) {
|
|
179
191
|
return this._merge({perKey})
|
|
180
192
|
}
|
|
181
193
|
|
|
182
|
-
ransack
|
|
194
|
+
ransack(params) {
|
|
183
195
|
if (params) this._merge({ransack: params})
|
|
184
196
|
return this
|
|
185
197
|
}
|
|
186
198
|
|
|
187
|
-
async result
|
|
199
|
+
async result() {
|
|
188
200
|
const response = await this._response()
|
|
189
201
|
const models = digg(response, "collection")
|
|
190
202
|
|
|
@@ -242,11 +254,11 @@ export default class ApiMakerCollection {
|
|
|
242
254
|
return this._merge({selectColumns: newSelect})
|
|
243
255
|
}
|
|
244
256
|
|
|
245
|
-
sort
|
|
257
|
+
sort(sortBy) {
|
|
246
258
|
return this._merge({ransack: {s: sortBy}})
|
|
247
259
|
}
|
|
248
260
|
|
|
249
|
-
async toArray
|
|
261
|
+
async toArray() {
|
|
250
262
|
const response = await this._response()
|
|
251
263
|
const models = digg(response, "collection")
|
|
252
264
|
|
|
@@ -255,13 +267,13 @@ export default class ApiMakerCollection {
|
|
|
255
267
|
return models
|
|
256
268
|
}
|
|
257
269
|
|
|
258
|
-
modelClass
|
|
270
|
+
modelClass() {
|
|
259
271
|
const modelName = digg(this.args.modelClass.modelClassData(), "name")
|
|
260
272
|
|
|
261
273
|
return modelClassRequire(modelName)
|
|
262
274
|
}
|
|
263
275
|
|
|
264
|
-
clone
|
|
276
|
+
clone() {
|
|
265
277
|
const clonedQueryArgs = cloneDeep(this.queryArgs)
|
|
266
278
|
|
|
267
279
|
return new ApiMakerCollection(this.args, clonedQueryArgs)
|
|
@@ -274,13 +286,13 @@ export default class ApiMakerCollection {
|
|
|
274
286
|
}
|
|
275
287
|
}
|
|
276
288
|
|
|
277
|
-
_merge
|
|
289
|
+
_merge(newQueryArgs) {
|
|
278
290
|
incorporate(this.queryArgs, newQueryArgs)
|
|
279
291
|
|
|
280
292
|
return this
|
|
281
293
|
}
|
|
282
294
|
|
|
283
|
-
_response
|
|
295
|
+
_response() {
|
|
284
296
|
const modelClassData = this.args.modelClass.modelClassData()
|
|
285
297
|
|
|
286
298
|
return CommandsPool.addCommand(
|
|
@@ -17,7 +17,7 @@ export default memo(shapeComponent(class ApiMakerSuperAdminLayoutHeader extends
|
|
|
17
17
|
})
|
|
18
18
|
|
|
19
19
|
setup() {
|
|
20
|
-
const {breakpoint} = useBreakpoint()
|
|
20
|
+
const {name: breakpoint} = useBreakpoint()
|
|
21
21
|
|
|
22
22
|
this.headerActionsRef = useRef()
|
|
23
23
|
this.setInstance({breakpoint})
|
package/src/table/table.jsx
CHANGED
|
@@ -98,7 +98,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
98
98
|
|
|
99
99
|
setup() {
|
|
100
100
|
const {t} = useI18n({namespace: "js.api_maker.table"})
|
|
101
|
-
const {breakpoint} = useBreakpoint()
|
|
101
|
+
const {name: breakpoint} = useBreakpoint()
|
|
102
102
|
const queryParams = useQueryParams()
|
|
103
103
|
|
|
104
104
|
this.setInstance({
|
|
@@ -183,6 +183,10 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
183
183
|
select,
|
|
184
184
|
selectColumns: this.props.selectColumns
|
|
185
185
|
})
|
|
186
|
+
this.queryWithoutPagination = useMemo(
|
|
187
|
+
() => this.collection?.query?.clone()?.except("page"),
|
|
188
|
+
[this.collection.query]
|
|
189
|
+
)
|
|
186
190
|
}
|
|
187
191
|
|
|
188
192
|
async loadCurrentWorkplace() {
|
|
@@ -509,7 +513,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
509
513
|
}
|
|
510
514
|
|
|
511
515
|
listHeaderComponent = () => {
|
|
512
|
-
const {
|
|
516
|
+
const {queryWithoutPagination} = this.tt
|
|
513
517
|
|
|
514
518
|
return (
|
|
515
519
|
<Row dataSet={{class: "live-table-header-row"}} style={this.styleForRow()}>
|
|
@@ -517,7 +521,7 @@ export default memo(shapeComponent(class ApiMakerTable extends BaseComponent {
|
|
|
517
521
|
<Header style={this.styleForHeader({style: {width: 41}})}>
|
|
518
522
|
<WorkerPluginsCheckAllCheckbox
|
|
519
523
|
currentWorkplace={this.s.currentWorkplace}
|
|
520
|
-
query={
|
|
524
|
+
query={queryWithoutPagination}
|
|
521
525
|
style={{marginHorizontal: "auto"}}
|
|
522
526
|
/>
|
|
523
527
|
</Header>
|
|
@@ -1,39 +1,47 @@
|
|
|
1
|
+
import {memo, useEffect, useMemo, useRef} from "react"
|
|
2
|
+
import BaseComponent from "../base-component"
|
|
1
3
|
import classNames from "classnames"
|
|
2
4
|
import Collection from "../collection.mjs"
|
|
3
|
-
import EventConnection from "../event-connection"
|
|
4
5
|
import PropTypes from "prop-types"
|
|
5
6
|
import propTypesExact from "prop-types-exact"
|
|
6
|
-
import
|
|
7
|
+
import {shapeComponent} from "set-state-compare/src/shape-component"
|
|
7
8
|
import {simpleObjectDifferent} from "set-state-compare/src/diff-utils"
|
|
8
|
-
import
|
|
9
|
+
import useModelEvent from "../use-model-event.js"
|
|
9
10
|
|
|
10
|
-
const Checkbox = (
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const Checkbox = memo(shapeComponent(class Checkbox extends BaseComponent {
|
|
12
|
+
render() {
|
|
13
|
+
const {indeterminate, ...restProps} = this.props
|
|
14
|
+
const checkboxRef = useRef()
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
checkboxRef.current.indeterminate = indeterminate
|
|
18
|
+
})
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
20
|
+
return (
|
|
21
|
+
<input ref={checkboxRef} type="checkbox" {...restProps} />
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
}))
|
|
22
25
|
|
|
23
|
-
export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends
|
|
26
|
+
export default memo(shapeComponent(class ApiMakerTableWorkerPluginsCheckAllCheckbox extends BaseComponent {
|
|
24
27
|
static propTypes = propTypesExact({
|
|
25
28
|
currentWorkplace: PropTypes.object,
|
|
26
29
|
query: PropTypes.instanceOf(Collection),
|
|
27
30
|
style: PropTypes.object
|
|
28
31
|
})
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
setup() {
|
|
34
|
+
this.useStates({
|
|
35
|
+
checked: false,
|
|
36
|
+
indeterminate: false
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
useMemo(() => {
|
|
40
|
+
this.updateAllChecked()
|
|
41
|
+
}, [])
|
|
34
42
|
|
|
35
|
-
|
|
36
|
-
this.
|
|
43
|
+
useModelEvent(this.props.currentWorkplace, "workplace_links_created", this.tt.onLinksCreated)
|
|
44
|
+
useModelEvent(this.props.currentWorkplace, "workplace_links_destroyed", this.tt.onLinksDestroyed)
|
|
37
45
|
}
|
|
38
46
|
|
|
39
47
|
componentDidUpdate(prevProps) {
|
|
@@ -58,21 +66,17 @@ export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends React.Pu
|
|
|
58
66
|
}
|
|
59
67
|
|
|
60
68
|
render() {
|
|
61
|
-
const {className,
|
|
69
|
+
const {className, style} = this.props
|
|
62
70
|
const {checked, indeterminate} = this.state
|
|
63
71
|
|
|
64
72
|
return (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
onChange={this.onCheckedChanged}
|
|
73
|
-
style={style}
|
|
74
|
-
/>
|
|
75
|
-
</>
|
|
73
|
+
<Checkbox
|
|
74
|
+
checked={checked}
|
|
75
|
+
className={classNames("api-maker--table--worker-plugins-check-all-checkbox", className)}
|
|
76
|
+
indeterminate={indeterminate}
|
|
77
|
+
onChange={this.onCheckedChanged}
|
|
78
|
+
style={style}
|
|
79
|
+
/>
|
|
76
80
|
)
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -104,4 +108,4 @@ export default class ApiMakerTableWorkerPluginsCheckAllCheckbox extends React.Pu
|
|
|
104
108
|
this.updateAllChecked()
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
|
-
}
|
|
111
|
+
}))
|
package/src/use-breakpoint.mjs
CHANGED
|
@@ -1,44 +1,52 @@
|
|
|
1
1
|
import {useCallback, useLayoutEffect} from "react"
|
|
2
2
|
import apiMakerConfig from "@kaspernj/api-maker/src/config.mjs"
|
|
3
|
+
import {Dimensions} from "react-native"
|
|
3
4
|
import useShape from "set-state-compare/src/use-shape.js"
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const calculateBreakPoint = useCallback(() => {
|
|
9
|
-
const windowWidth = window.innerWidth
|
|
6
|
+
const calculateBreakPoint = (window) => {
|
|
7
|
+
const windowWidth = window.width
|
|
8
|
+
const result = {}
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
for (const breakpointData of apiMakerConfig.getBreakPoints()) {
|
|
11
|
+
const breakpoint = breakpointData[0]
|
|
12
|
+
const width = breakpointData[1]
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
if (!result.name && windowWidth >= width) {
|
|
15
|
+
result.name = breakpoint
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
result[`${breakpoint}Down`] = !result.name
|
|
19
|
+
result[`${breakpoint}Up`] = Boolean(result.name)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (result.name) {
|
|
23
|
+
return result
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
throw new Error(`Couldn't not find breakpoint from window width: ${windowWidth}`)
|
|
27
|
+
}
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
const useBreakpoint = () => {
|
|
30
|
+
const s = useShape()
|
|
31
|
+
const onCalled = useCallback(({window}) => {
|
|
32
|
+
const breakpoint = calculateBreakPoint(window)
|
|
23
33
|
|
|
24
|
-
if (breakpoint != s.s.breakpoint) {
|
|
34
|
+
if (breakpoint.name != s.s.breakpoint.name) {
|
|
25
35
|
s.set({breakpoint})
|
|
26
36
|
}
|
|
27
37
|
}, [])
|
|
28
38
|
|
|
29
39
|
s.useStates({
|
|
30
|
-
breakpoint: () => calculateBreakPoint()
|
|
40
|
+
breakpoint: () => calculateBreakPoint(Dimensions.get("window"))
|
|
31
41
|
})
|
|
32
42
|
|
|
33
43
|
useLayoutEffect(() => {
|
|
34
|
-
|
|
44
|
+
const subscription = Dimensions.addEventListener("change", onCalled)
|
|
35
45
|
|
|
36
|
-
return () =>
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
}, [])
|
|
46
|
+
return () => subscription?.remove()
|
|
47
|
+
})
|
|
40
48
|
|
|
41
|
-
return
|
|
49
|
+
return s.s.breakpoint
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
export default useBreakpoint
|