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