@kaspernj/api-maker 1.0.242 → 1.0.244

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 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 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.242",
19
+ "version": "1.0.244",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -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", "name"))))
19
+ const modelClass = modelClassRequire(inflection.singularize(inflection.camelize(digg(this, "reflectionData", "resource_name"))))
20
20
 
21
21
  return modelClass
22
22
  }
@@ -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
- currentModelClass = currentModelClass.ransackableAssociations().find((reflection) => reflection.name() == pathPart).modelClass()
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 pathPartTranslation = currentModelClass.humanAttributeName(pathPart)
226
+ const camelizedPathPart = inflection.camelize(pathPart, true)
227
+ const pathPartTranslation = currentModelClass.humanAttributeName(camelizedPathPart)
218
228
 
219
- currentModelClass = currentModelClass.ransackableAssociations().find((reflection) => reflection.name() == pathPart).modelClass()
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,
@@ -0,0 +1,11 @@
1
+ export default function apiMakerTranslatedAttributes(attributeNames, availableLocales) {
2
+ translatedAttributes = []
3
+
4
+ for (const attribute of attributeNames) {
5
+ for (const locale of availableLocales) {
6
+ translatedAttributes.push(`${attribute}${locale.substring(0, 1).toUpperCase()}${locale.substring(1, 99)}`)
7
+ }
8
+ }
9
+
10
+ return translatedAttributes
11
+ }