@kaspernj/api-maker 1.0.392 → 1.0.393
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/form.jsx +2 -0
- package/src/inputs/input.jsx +1 -1
- package/src/super-admin/edit-page/edit-attribute-content.jsx +0 -10
- package/src/super-admin/edit-page/edit-attribute-input.jsx +5 -12
- package/src/super-admin/edit-page/edit-attribute.jsx +9 -4
- package/src/super-admin/edit-page.jsx +6 -11
package/package.json
CHANGED
package/src/form.jsx
CHANGED
package/src/inputs/input.jsx
CHANGED
|
@@ -5,7 +5,7 @@ import EventUpdated from "../event-updated"
|
|
|
5
5
|
import inputWrapper from "./input-wrapper"
|
|
6
6
|
import Money from "./money"
|
|
7
7
|
import PropTypes from "prop-types"
|
|
8
|
-
import {memo, useRef} from "react"
|
|
8
|
+
import {memo, useMemo, useRef} from "react"
|
|
9
9
|
import replaceall from "replaceall"
|
|
10
10
|
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
11
11
|
import strftime from "strftime"
|
|
@@ -4,15 +4,9 @@ import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
|
4
4
|
|
|
5
5
|
export default memo(shapeComponent(class EditAttributeContent extends BaseComponent {
|
|
6
6
|
setup() {
|
|
7
|
-
const {inputs, name} = this.p
|
|
8
|
-
|
|
9
7
|
this.useStates({
|
|
10
8
|
value: () => this.defaultValue()
|
|
11
9
|
})
|
|
12
|
-
|
|
13
|
-
useMemo(() => {
|
|
14
|
-
inputs[name] = this.s.value
|
|
15
|
-
}, [])
|
|
16
10
|
}
|
|
17
11
|
|
|
18
12
|
render() {
|
|
@@ -38,10 +32,6 @@ export default memo(shapeComponent(class EditAttributeContent extends BaseCompon
|
|
|
38
32
|
defaultValue = () => this.p.model[this.p.attribute.attribute]() || ""
|
|
39
33
|
|
|
40
34
|
onChangeValue = (newValue) => {
|
|
41
|
-
const {inputs, name} = this.p
|
|
42
|
-
|
|
43
|
-
inputs[name] = newValue
|
|
44
|
-
|
|
45
35
|
this.setState({value: newValue})
|
|
46
36
|
}
|
|
47
37
|
}))
|
|
@@ -1,19 +1,18 @@
|
|
|
1
|
+
import {memo, useMemo} from "react"
|
|
2
|
+
import {Text, TextInput, View} from "react-native"
|
|
1
3
|
import BaseComponent from "../../base-component"
|
|
2
|
-
import {useForm} from "../../form"
|
|
3
4
|
import PropTypes from "prop-types"
|
|
4
5
|
import propTypesExact from "prop-types-exact"
|
|
5
6
|
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
6
|
-
import {
|
|
7
|
-
import {memo, useMemo} from "react"
|
|
7
|
+
import {useForm} from "../../form"
|
|
8
8
|
|
|
9
9
|
export default memo(shapeComponent(class EditAttributeInput extends BaseComponent {
|
|
10
10
|
static propTypes = propTypesExact({
|
|
11
|
-
inputs: PropTypes.object.isRequired,
|
|
12
11
|
name: PropTypes.string.isRequired
|
|
13
12
|
})
|
|
14
13
|
|
|
15
14
|
setup() {
|
|
16
|
-
const {
|
|
15
|
+
const {name} = this.p
|
|
17
16
|
|
|
18
17
|
this.form = useForm()
|
|
19
18
|
this.useStates({
|
|
@@ -21,8 +20,6 @@ export default memo(shapeComponent(class EditAttributeInput extends BaseComponen
|
|
|
21
20
|
})
|
|
22
21
|
|
|
23
22
|
useMemo(() => {
|
|
24
|
-
inputs[name] = this.s.value
|
|
25
|
-
|
|
26
23
|
if (this.form) {
|
|
27
24
|
this.form.setValue(name, this.s.value)
|
|
28
25
|
}
|
|
@@ -59,12 +56,8 @@ export default memo(shapeComponent(class EditAttributeInput extends BaseComponen
|
|
|
59
56
|
}
|
|
60
57
|
|
|
61
58
|
onChangeText = (newValue) => {
|
|
62
|
-
const {inputs, name} = this.p
|
|
63
|
-
|
|
64
|
-
inputs[name] = newValue
|
|
65
|
-
|
|
66
59
|
if (this.form) {
|
|
67
|
-
this.form.setValue(name, newValue)
|
|
60
|
+
this.form.setValue(this.p.name, newValue)
|
|
68
61
|
}
|
|
69
62
|
|
|
70
63
|
this.setState({value: newValue})
|
|
@@ -5,11 +5,19 @@ import EditAttributeInput from "./edit-attribute-input"
|
|
|
5
5
|
import * as inflection from "inflection"
|
|
6
6
|
import Locales from "shared/locales"
|
|
7
7
|
import {memo} from "react"
|
|
8
|
+
import PropTypes from "prop-types"
|
|
9
|
+
import propTypesExact from "prop-types-exact"
|
|
8
10
|
import {shapeComponent} from "set-state-compare/src/shape-component.js"
|
|
9
11
|
|
|
10
12
|
export default memo(shapeComponent(class EditAttribute extends BaseComponent {
|
|
13
|
+
static propTypes = propTypesExact({
|
|
14
|
+
attribute: PropTypes.string,
|
|
15
|
+
model: PropTypes.object,
|
|
16
|
+
modelClass: PropTypes.func
|
|
17
|
+
})
|
|
18
|
+
|
|
11
19
|
render() {
|
|
12
|
-
const {attribute,
|
|
20
|
+
const {attribute, model, modelClass} = this.props
|
|
13
21
|
const availableLocales = Locales.availableLocales()
|
|
14
22
|
const camelizedLower = digg(modelClass.modelClassData(), "camelizedLower")
|
|
15
23
|
|
|
@@ -19,7 +27,6 @@ export default memo(shapeComponent(class EditAttribute extends BaseComponent {
|
|
|
19
27
|
<EditAttributeContent
|
|
20
28
|
attribute={attribute}
|
|
21
29
|
id={`${inflection.underscore(camelizedLower)}_${inflection.underscore(attribute.attribute)}`}
|
|
22
|
-
inputs={inputs}
|
|
23
30
|
model={model}
|
|
24
31
|
name={inflection.underscore(attribute.attribute)}
|
|
25
32
|
/>
|
|
@@ -28,7 +35,6 @@ export default memo(shapeComponent(class EditAttribute extends BaseComponent {
|
|
|
28
35
|
<EditAttributeInput
|
|
29
36
|
attributeName={`${attribute.attribute}${inflection.camelize(locale)}`}
|
|
30
37
|
id={`${inflection.underscore(camelizedLower)}_${inflection.underscore(attribute.attribute)}_${locale}`}
|
|
31
|
-
inputs={inputs}
|
|
32
38
|
label={`${modelClass.humanAttributeName(attribute.attribute)} (${locale})`}
|
|
33
39
|
model={model}
|
|
34
40
|
name={`${inflection.underscore(attribute.attribute)}_${locale}`}
|
|
@@ -39,7 +45,6 @@ export default memo(shapeComponent(class EditAttribute extends BaseComponent {
|
|
|
39
45
|
<EditAttributeInput
|
|
40
46
|
attributeName={attribute.attribute}
|
|
41
47
|
id={`${inflection.underscore(camelizedLower)}_${inflection.underscore(attribute.attribute)}`}
|
|
42
|
-
inputs={inputs}
|
|
43
48
|
label={modelClass.humanAttributeName(attribute.attribute)}
|
|
44
49
|
model={model}
|
|
45
50
|
name={inflection.underscore(attribute.attribute)}
|
|
@@ -19,8 +19,6 @@ export default memo(shapeComponent(class ApiMakerSuperAdminEditPage extends Base
|
|
|
19
19
|
modelClass: PropTypes.func.isRequired
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
inputs = {}
|
|
23
|
-
|
|
24
22
|
setup() {
|
|
25
23
|
const {modelClass} = this.p
|
|
26
24
|
const modelClassName = modelClass.modelClassData().name
|
|
@@ -75,7 +73,7 @@ export default memo(shapeComponent(class ApiMakerSuperAdminEditPage extends Base
|
|
|
75
73
|
<View dataSet={{class: "super-admin--edit-page"}}>
|
|
76
74
|
<Form setForm={this.setStates.form}>
|
|
77
75
|
{model && attributes?.map((attribute) =>
|
|
78
|
-
<EditAttribute attribute={attribute}
|
|
76
|
+
<EditAttribute attribute={attribute} key={attribute.attribute} model={model} modelClass={modelClass} />
|
|
79
77
|
)}
|
|
80
78
|
{extraContent && extraContent(modelArgs)}
|
|
81
79
|
<Pressable
|
|
@@ -102,16 +100,13 @@ export default memo(shapeComponent(class ApiMakerSuperAdminEditPage extends Base
|
|
|
102
100
|
|
|
103
101
|
onSubmit = async () => {
|
|
104
102
|
try {
|
|
105
|
-
const {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
const formObject = form.asObject()
|
|
109
|
-
const allInputs = Object.assign({}, inputs, formObject)
|
|
103
|
+
const {model} = this.tt
|
|
104
|
+
const formObject = this.s.form.asObject()
|
|
110
105
|
|
|
111
|
-
console.log({
|
|
106
|
+
console.log({formObject})
|
|
112
107
|
|
|
113
|
-
model.assignAttributes(
|
|
114
|
-
await model.save(
|
|
108
|
+
model.assignAttributes(formObject)
|
|
109
|
+
await model.save()
|
|
115
110
|
Params.changeParams({mode: undefined, model_id: model.id()})
|
|
116
111
|
} catch (error) {
|
|
117
112
|
FlashMessage.errorResponse(error)
|