@kaspernj/api-maker 1.0.208 → 1.0.209

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 CHANGED
@@ -16,7 +16,7 @@
16
16
  ]
17
17
  },
18
18
  "name": "@kaspernj/api-maker",
19
- "version": "1.0.208",
19
+ "version": "1.0.209",
20
20
  "type": "module",
21
21
  "description": "",
22
22
  "main": "index.js",
@@ -8,7 +8,7 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
8
8
 
9
9
  state = {
10
10
  model: undefined,
11
- modelId: this.props.match.params[this.paramsVariableName] || this.props.match.params.id,
11
+ modelId: this.getModelId(),
12
12
  notFound: undefined
13
13
  }
14
14
 
@@ -16,6 +16,16 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
16
16
  this.loadModel()
17
17
  }
18
18
 
19
+ componentDidUpdate() {
20
+ const newModelId = this.getModelId()
21
+
22
+ // The model ID was changed in the URL and a different model should be loaded
23
+ if (newModelId != this.state.modelId) {
24
+ this.setState({model: undefined, modelId: newModelId})
25
+ this.loadExistingModel()
26
+ }
27
+ }
28
+
19
29
  loadModel = async () => {
20
30
  if (args.newIfNoId && !this.getModelId()) {
21
31
  return await this.loadNewModel()
@@ -29,7 +39,7 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
29
39
  }
30
40
 
31
41
  loadExistingModel = async () => {
32
- const {modelId} = digs(this.state, "modelId")
42
+ const modelId = this.getModelId()
33
43
  const query = await ModelClass.ransack({id_eq: modelId})
34
44
 
35
45
  if (args.abilities) query.abilities(args.abilities)