@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 +1 -1
- package/src/model-load-wrapper.jsx +12 -2
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ export default (WrappedComponent, ModelClass, args = {}) => class modelLoadWrapp
|
|
|
8
8
|
|
|
9
9
|
state = {
|
|
10
10
|
model: undefined,
|
|
11
|
-
modelId: this.
|
|
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
|
|
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)
|