@kaspernj/api-maker 1.0.243 → 1.0.245
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/.eslintrc.cjs +1 -0
- package/package.json +1 -1
- package/src/base-model/reflection.mjs +1 -1
- package/src/compose.js +11 -0
- package/src/table/filters/filter-form.jsx +14 -4
package/.eslintrc.cjs
CHANGED
|
@@ -75,6 +75,7 @@ module.exports = {
|
|
|
75
75
|
"jest/no-if": "error",
|
|
76
76
|
"jest/no-large-snapshots": "error",
|
|
77
77
|
"jest/no-restricted-matchers": "error",
|
|
78
|
+
"jest/no-restricted-jest-methods": "error",
|
|
78
79
|
"jest/no-test-return-statement": "error",
|
|
79
80
|
"jest/prefer-comparison-matcher": "error",
|
|
80
81
|
"jest/prefer-each": "error",
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@ export default class ApiMakerBaseModelReflection {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
modelClass() {
|
|
19
|
-
const modelClass = modelClassRequire(inflection.singularize(inflection.camelize(digg(this, "reflectionData", "
|
|
19
|
+
const modelClass = modelClassRequire(inflection.singularize(inflection.camelize(digg(this, "reflectionData", "resource_name"))))
|
|
20
20
|
|
|
21
21
|
return modelClass
|
|
22
22
|
}
|
package/src/compose.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default function apiMakerCompose(wrappedComponentClass, ...funcs) {
|
|
2
|
+
if (!wrappedComponentClass) throw new Error("No 'wrappedComponentClass' given")
|
|
3
|
+
|
|
4
|
+
let currentComponentClass = wrappedComponentClass
|
|
5
|
+
|
|
6
|
+
for (const func of funcs) {
|
|
7
|
+
currentComponentClass = func(currentComponentClass)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return currentComponentClass
|
|
11
|
+
}
|
|
@@ -196,7 +196,16 @@ export default class ApiMakerTableFiltersFilterForm extends React.PureComponent
|
|
|
196
196
|
let currentModelClass = modelClass
|
|
197
197
|
|
|
198
198
|
for (const pathPart of path) {
|
|
199
|
-
|
|
199
|
+
const camelizedPathPart = inflection.camelize(pathPart, true)
|
|
200
|
+
const association = currentModelClass.ransackableAssociations().find((reflection) => reflection.name() == camelizedPathPart)
|
|
201
|
+
|
|
202
|
+
if (!association) {
|
|
203
|
+
const ransackableAssociationNames = currentModelClass.ransackableAssociations().map((reflection) => reflection.name()).join(", ")
|
|
204
|
+
|
|
205
|
+
throw new Error(`Could not find a Ransackable association by that name: ${camelizedPathPart} in ${ransackableAssociationNames}`)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
currentModelClass = association.modelClass()
|
|
200
209
|
}
|
|
201
210
|
|
|
202
211
|
return currentModelClass
|
|
@@ -214,9 +223,10 @@ export default class ApiMakerTableFiltersFilterForm extends React.PureComponent
|
|
|
214
223
|
})
|
|
215
224
|
|
|
216
225
|
for (const pathPart of path) {
|
|
217
|
-
const
|
|
226
|
+
const camelizedPathPart = inflection.camelize(pathPart, true)
|
|
227
|
+
const pathPartTranslation = currentModelClass.humanAttributeName(camelizedPathPart)
|
|
218
228
|
|
|
219
|
-
currentModelClass = currentModelClass.ransackableAssociations().find((reflection) => reflection.name() ==
|
|
229
|
+
currentModelClass = currentModelClass.ransackableAssociations().find((reflection) => reflection.name() == camelizedPathPart).modelClass()
|
|
220
230
|
|
|
221
231
|
result.push({
|
|
222
232
|
modelClass: currentModelClass,
|
|
@@ -239,7 +249,7 @@ export default class ApiMakerTableFiltersFilterForm extends React.PureComponent
|
|
|
239
249
|
}
|
|
240
250
|
|
|
241
251
|
onReflectionClicked = ({reflection}) => {
|
|
242
|
-
const newPath = this.shape.path.concat([reflection.name()])
|
|
252
|
+
const newPath = this.shape.path.concat([inflection.underscore(reflection.name())])
|
|
243
253
|
|
|
244
254
|
this.shape.set({
|
|
245
255
|
attribute: undefined,
|