@kaspernj/api-maker 1.0.322 → 1.0.324
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 +1 -1
- package/src/use-collection.mjs +29 -20
package/package.json
CHANGED
package/src/use-collection.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Collection from "./collection.mjs"
|
|
2
2
|
import debounce from "debounce"
|
|
3
3
|
import {digg} from "diggerize"
|
|
4
|
+
import * as inflection from "inflection"
|
|
4
5
|
import ModelEvents from "./model-events.mjs"
|
|
5
6
|
import PropTypes from "prop-types"
|
|
6
7
|
import PropTypesExact from "prop-types-exact"
|
|
@@ -8,22 +9,25 @@ import {useCallback, useEffect} from "react"
|
|
|
8
9
|
import useShape from "set-state-compare/src/use-shape.js"
|
|
9
10
|
import useQueryParams from "on-location-changed/src/use-query-params.js"
|
|
10
11
|
|
|
11
|
-
const useCollection = (
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
const useCollection = (
|
|
13
|
+
{
|
|
14
|
+
abilities,
|
|
15
|
+
collection,
|
|
16
|
+
defaultParams,
|
|
17
|
+
groupBy = ["id"],
|
|
18
|
+
modelClass,
|
|
19
|
+
noRecordsAvailableContent = undefined,
|
|
20
|
+
noRecordsFoundContent = undefined,
|
|
21
|
+
onModelsLoaded,
|
|
22
|
+
pagination = false,
|
|
23
|
+
preloads = [],
|
|
24
|
+
queryMethod,
|
|
25
|
+
queryName,
|
|
26
|
+
select = {},
|
|
27
|
+
selectColumns
|
|
28
|
+
},
|
|
29
|
+
cacheKeys = []
|
|
30
|
+
) => {
|
|
27
31
|
const s = useShape({
|
|
28
32
|
abilities,
|
|
29
33
|
collection,
|
|
@@ -216,10 +220,13 @@ const useCollection = ({
|
|
|
216
220
|
if (models.length === 0 && s.p.noRecordsFoundContent) return true
|
|
217
221
|
}, [])
|
|
218
222
|
|
|
219
|
-
useEffect(
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
+
useEffect(
|
|
224
|
+
() => {
|
|
225
|
+
loadQParams()
|
|
226
|
+
loadModels()
|
|
227
|
+
},
|
|
228
|
+
[queryParams[s.s.queryQName], queryParams[s.s.queryPageName], queryParams[s.s.queryPerKey], queryParams[s.s.querySName], collection].concat(cacheKeys)
|
|
229
|
+
)
|
|
223
230
|
|
|
224
231
|
useEffect(() => {
|
|
225
232
|
if (s.p.noRecordsAvailableContent) loadOverallCount()
|
|
@@ -251,8 +258,10 @@ const useCollection = ({
|
|
|
251
258
|
}, [modelIdsCacheString])
|
|
252
259
|
|
|
253
260
|
const result = Object.assign({}, s.state)
|
|
261
|
+
const modelVariableName = inflection.pluralize(inflection.camelize(modelClass.modelClassData().name, true))
|
|
254
262
|
|
|
255
263
|
result.modelIdsCacheString = modelIdsCacheString
|
|
264
|
+
result[modelVariableName] = s.s.models
|
|
256
265
|
|
|
257
266
|
return result
|
|
258
267
|
}
|