@kaspernj/api-maker 1.0.323 → 1.0.325
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 +37 -26
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"
|
|
@@ -45,21 +46,23 @@ const useCollection = (
|
|
|
45
46
|
|
|
46
47
|
if (!queryName) queryName = digg(modelClass.modelClassData(), "collectionKey")
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
s.useStates({
|
|
50
|
+
models: undefined,
|
|
51
|
+
overallCount: undefined,
|
|
52
|
+
query: undefined,
|
|
53
|
+
queryName,
|
|
54
|
+
queryPerKey: `${queryName}_per`,
|
|
55
|
+
queryQName: `${queryName}_q`,
|
|
56
|
+
querySName: `${queryName}_s`,
|
|
57
|
+
queryPageName: `${queryName}_page`,
|
|
58
|
+
qParams: undefined,
|
|
59
|
+
result: undefined,
|
|
60
|
+
searchParams: undefined,
|
|
61
|
+
showNoRecordsAvailableContent: false,
|
|
62
|
+
showNoRecordsFoundContent: false
|
|
63
|
+
})
|
|
64
|
+
|
|
61
65
|
const queryParams = useQueryParams()
|
|
62
|
-
const modelIds = s.s.models?.map((model) => model.id())
|
|
63
66
|
|
|
64
67
|
let modelIdsCacheString
|
|
65
68
|
|
|
@@ -68,7 +71,7 @@ const useCollection = (
|
|
|
68
71
|
} else if (s.s.models.length === 0) {
|
|
69
72
|
modelIdsCacheString = "no-models"
|
|
70
73
|
} else {
|
|
71
|
-
modelIdsCacheString =
|
|
74
|
+
modelIdsCacheString = s.s.models.map((model) => model.cacheKey())?.join("---")
|
|
72
75
|
}
|
|
73
76
|
|
|
74
77
|
s.updateMeta({queryParams})
|
|
@@ -77,9 +80,11 @@ const useCollection = (
|
|
|
77
80
|
const baseQuery = s.p.collection || s.p.modelClass.all()
|
|
78
81
|
const overallCount = await baseQuery.count()
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
s.set({
|
|
84
|
+
overallCount,
|
|
85
|
+
showNoRecordsAvailableContent: showNoRecordsAvailableContent({overallCount}),
|
|
86
|
+
showNoRecordsFoundContent: showNoRecordsFoundContent({overallCount})
|
|
87
|
+
})
|
|
83
88
|
}, [])
|
|
84
89
|
|
|
85
90
|
const hasQParams = useCallback(() => {
|
|
@@ -106,8 +111,10 @@ const useCollection = (
|
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
113
|
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
s.set({
|
|
115
|
+
qParams: qParamsToSet,
|
|
116
|
+
searchParams
|
|
117
|
+
})
|
|
111
118
|
}, [])
|
|
112
119
|
|
|
113
120
|
const loadModels = useCallback(async () => {
|
|
@@ -159,16 +166,20 @@ const useCollection = (
|
|
|
159
166
|
})
|
|
160
167
|
}
|
|
161
168
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
169
|
+
s.set({
|
|
170
|
+
models: result.models(),
|
|
171
|
+
query,
|
|
172
|
+
result,
|
|
173
|
+
showNoRecordsAvailableContent: showNoRecordsAvailableContent({models}),
|
|
174
|
+
showNoRecordsFoundContent: showNoRecordsFoundContent({models})
|
|
175
|
+
})
|
|
167
176
|
}, [])
|
|
168
177
|
|
|
169
178
|
const loadModelsDebounce = useCallback(debounce(loadModels), [])
|
|
170
179
|
const onModelDestroyed = useCallback((args) => {
|
|
171
|
-
|
|
180
|
+
s.set({
|
|
181
|
+
models: s.s.models.filter((model) => model.id() != args.model.id())
|
|
182
|
+
})
|
|
172
183
|
}, [])
|
|
173
184
|
|
|
174
185
|
const onModelUpdated = useCallback((args) => {
|