@kaspernj/api-maker 1.0.317 → 1.0.318
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
|
@@ -8,7 +8,7 @@ import useCurrentUser from "../use-current-user"
|
|
|
8
8
|
import useModel from "../use-model"
|
|
9
9
|
import useQueryParams from "on-location-changed/src/use-query-params"
|
|
10
10
|
|
|
11
|
-
const EditAttributeInput = ({attributeName, id, inputs, label, model, name}) => {
|
|
11
|
+
const EditAttributeInput = memo(({attributeName, id, inputs, label, model, name}) => {
|
|
12
12
|
if (!(attributeName in model)) {
|
|
13
13
|
throw new Error(`${attributeName} isn't set on the resource ${model.modelClassData().name}`)
|
|
14
14
|
}
|
|
@@ -42,9 +42,9 @@ const EditAttributeInput = ({attributeName, id, inputs, label, model, name}) =>
|
|
|
42
42
|
</View>
|
|
43
43
|
</View>
|
|
44
44
|
)
|
|
45
|
-
}
|
|
45
|
+
})
|
|
46
46
|
|
|
47
|
-
const EditAttributeContent = ({attribute, id, inputs, model, name}) => {
|
|
47
|
+
const EditAttributeContent = memo(({attribute, id, inputs, model, name}) => {
|
|
48
48
|
if (!(attribute.attribute in model)) {
|
|
49
49
|
throw new Error(`${attribute.attribute} isn't set on the resource ${model.modelClassData().name}`)
|
|
50
50
|
}
|
|
@@ -70,9 +70,9 @@ const EditAttributeContent = ({attribute, id, inputs, model, name}) => {
|
|
|
70
70
|
})
|
|
71
71
|
|
|
72
72
|
return attribute.content(contentArgs())
|
|
73
|
-
}
|
|
73
|
+
})
|
|
74
74
|
|
|
75
|
-
const EditAttribute = ({attribute, inputs, model, modelClass}) => {
|
|
75
|
+
const EditAttribute = memo(({attribute, inputs, model, modelClass}) => {
|
|
76
76
|
const availableLocales = Locales.availableLocales()
|
|
77
77
|
const camelizedLower = digg(modelClass.modelClassData(), "camelizedLower")
|
|
78
78
|
|
|
@@ -81,7 +81,7 @@ const EditAttribute = ({attribute, inputs, model, modelClass}) => {
|
|
|
81
81
|
{attribute.content &&
|
|
82
82
|
<EditAttributeContent
|
|
83
83
|
attribute={attribute}
|
|
84
|
-
id={`${camelizedLower}_${inflection.underscore(attribute.attribute)}`}
|
|
84
|
+
id={`${inflection.underscore(camelizedLower)}_${inflection.underscore(attribute.attribute)}`}
|
|
85
85
|
inputs={inputs}
|
|
86
86
|
model={model}
|
|
87
87
|
name={inflection.underscore(attribute.attribute)}
|
|
@@ -90,7 +90,7 @@ const EditAttribute = ({attribute, inputs, model, modelClass}) => {
|
|
|
90
90
|
{!attribute.content && attribute.translated && availableLocales.map((locale) =>
|
|
91
91
|
<EditAttributeInput
|
|
92
92
|
attributeName={`${attribute.attribute}${inflection.camelize(locale)}`}
|
|
93
|
-
id={`${camelizedLower}_${inflection.underscore(attribute.attribute)}_${locale}`}
|
|
93
|
+
id={`${inflection.underscore(camelizedLower)}_${inflection.underscore(attribute.attribute)}_${locale}`}
|
|
94
94
|
inputs={inputs}
|
|
95
95
|
label={`${modelClass.humanAttributeName(attribute.attribute)} (${locale})`}
|
|
96
96
|
model={model}
|
|
@@ -101,7 +101,7 @@ const EditAttribute = ({attribute, inputs, model, modelClass}) => {
|
|
|
101
101
|
{!attribute.content && !attribute.translated &&
|
|
102
102
|
<EditAttributeInput
|
|
103
103
|
attributeName={attribute.attribute}
|
|
104
|
-
id={`${camelizedLower}_${inflection.underscore(attribute.attribute)}`}
|
|
104
|
+
id={`${inflection.underscore(camelizedLower)}_${inflection.underscore(attribute.attribute)}`}
|
|
105
105
|
inputs={inputs}
|
|
106
106
|
label={modelClass.humanAttributeName(attribute.attribute)}
|
|
107
107
|
model={model}
|
|
@@ -110,7 +110,7 @@ const EditAttribute = ({attribute, inputs, model, modelClass}) => {
|
|
|
110
110
|
}
|
|
111
111
|
</>
|
|
112
112
|
)
|
|
113
|
-
}
|
|
113
|
+
})
|
|
114
114
|
|
|
115
115
|
const EditPage = ({modelClass}) => {
|
|
116
116
|
const availableLocales = Locales.availableLocales()
|
|
@@ -128,6 +128,10 @@ const EditPage = ({modelClass}) => {
|
|
|
128
128
|
|
|
129
129
|
selectedAttributes[modelClassName] = selectedModelAttributes
|
|
130
130
|
|
|
131
|
+
if (!attributes) {
|
|
132
|
+
throw new Error(`No 'attributes' given from edit config for ${modelClass.modelClassData().name}`)
|
|
133
|
+
}
|
|
134
|
+
|
|
131
135
|
for (const attribute of attributes) {
|
|
132
136
|
if (attribute.translated) {
|
|
133
137
|
for (const locale of availableLocales) {
|
|
@@ -8,6 +8,7 @@ import {useCallback, useEffect, useState} from "react"
|
|
|
8
8
|
import ShowPage from "./show-page"
|
|
9
9
|
import ShowReflectionActions from "./show-reflection-actions"
|
|
10
10
|
import ShowReflectionPage from "./show-reflection-page"
|
|
11
|
+
import useCanCan from "../use-can-can"
|
|
11
12
|
import useQueryParams from "on-location-changed/src/use-query-params"
|
|
12
13
|
|
|
13
14
|
const ApiMakerSuperAdmin = () => {
|
|
@@ -19,6 +20,7 @@ const ApiMakerSuperAdmin = () => {
|
|
|
19
20
|
const modelId = queryParams.model_id
|
|
20
21
|
const modelName = modelClass?.modelClassData()?.name
|
|
21
22
|
const [model, setModel] = useState()
|
|
23
|
+
const canCan = useCanCan(() => [[modelClass, ["new"]]])
|
|
22
24
|
|
|
23
25
|
const loadModel = useCallback(async () => {
|
|
24
26
|
if (modelId && modelClass) {
|
|
@@ -73,9 +75,13 @@ const ApiMakerSuperAdmin = () => {
|
|
|
73
75
|
const actions = useMemo(
|
|
74
76
|
() => <>
|
|
75
77
|
{modelClass && pageToShow == "index" &&
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
<>
|
|
79
|
+
{canCan?.can("new", modelClass) &&
|
|
80
|
+
<Link className="create-new-model-link" to={Params.withParams({model: modelName, mode: "new"})}>
|
|
81
|
+
Create new
|
|
82
|
+
</Link>
|
|
83
|
+
}
|
|
84
|
+
</>
|
|
79
85
|
}
|
|
80
86
|
{model && pageToShow == "show" &&
|
|
81
87
|
<>
|
|
@@ -95,7 +101,7 @@ const ApiMakerSuperAdmin = () => {
|
|
|
95
101
|
<ShowReflectionActions model={model} modelClass={modelClass} reflectionName={queryParams.model_reflection} />
|
|
96
102
|
}
|
|
97
103
|
</>,
|
|
98
|
-
[model, modelClass, pageToShow]
|
|
104
|
+
[canCan, model, modelClass, pageToShow]
|
|
99
105
|
)
|
|
100
106
|
|
|
101
107
|
return (
|
|
@@ -6,6 +6,7 @@ const SuperAdminShowReflectionActions = ({model, modelClass, reflectionName}) =>
|
|
|
6
6
|
const modelClassName = digg(reflection, "reflectionData", "className")
|
|
7
7
|
const modelData = {}
|
|
8
8
|
const dataParamName = inflection.singularize(reflection.reflectionData.collectionName)
|
|
9
|
+
const canCan = useCanCan(() => [[reflection.modelClass(), ["new"]]])
|
|
9
10
|
|
|
10
11
|
modelData[reflection.foreignKey()] = model?.id()
|
|
11
12
|
|
|
@@ -17,9 +18,13 @@ const SuperAdminShowReflectionActions = ({model, modelClass, reflectionName}) =>
|
|
|
17
18
|
linkParams[dataParamName] = modelData
|
|
18
19
|
|
|
19
20
|
return (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
<>
|
|
22
|
+
{canCan?.can("new", reflection.modelClass()) &&
|
|
23
|
+
<Link className="create-new-model-link" to={Params.withParams(linkParams)}>
|
|
24
|
+
Create new
|
|
25
|
+
</Link>
|
|
26
|
+
}
|
|
27
|
+
</>
|
|
23
28
|
)
|
|
24
29
|
}
|
|
25
30
|
|