@kaspernj/api-maker 1.0.351 → 1.0.352
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
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import ConfigReader from "./config-reader.jsx"
|
|
2
|
+
|
|
3
|
+
const hasEditConfig = (modelClass) => {
|
|
4
|
+
const configReader = ConfigReader.forModel(modelClass)
|
|
5
|
+
const extraContent = configReader.modelConfig?.edit?.extraContentconst
|
|
6
|
+
const attributes = configReader.modelConfig?.edit?.attributes
|
|
7
|
+
|
|
8
|
+
if (attributes || extraContent) {
|
|
9
|
+
return true
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return false
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default hasEditConfig
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import EditPage from "./edit-page"
|
|
2
|
+
import hasEditConfig from "./has-edit-config.js"
|
|
2
3
|
import IndexPage from "./index-page"
|
|
3
4
|
import Layout from "./layout"
|
|
4
5
|
import Link from "../link"
|
|
@@ -9,9 +10,11 @@ import ShowPage from "./show-page"
|
|
|
9
10
|
import ShowReflectionActions from "./show-reflection-actions"
|
|
10
11
|
import ShowReflectionPage from "./show-reflection-page"
|
|
11
12
|
import useCanCan from "../use-can-can"
|
|
13
|
+
import useCurrentUser from "../use-current-user.mjs"
|
|
12
14
|
import useQueryParams from "on-location-changed/src/use-query-params"
|
|
13
15
|
|
|
14
16
|
const ApiMakerSuperAdmin = () => {
|
|
17
|
+
const currentUser = useCurrentUser()
|
|
15
18
|
const queryParams = useQueryParams()
|
|
16
19
|
let modelClass, pageToShow
|
|
17
20
|
|
|
@@ -20,13 +23,16 @@ const ApiMakerSuperAdmin = () => {
|
|
|
20
23
|
const modelId = queryParams.model_id
|
|
21
24
|
const modelName = modelClass?.modelClassData()?.name
|
|
22
25
|
const [model, setModel] = useState()
|
|
23
|
-
const canCan = useCanCan(
|
|
24
|
-
|
|
26
|
+
const canCan = useCanCan(
|
|
27
|
+
() => {
|
|
28
|
+
const abilities = []
|
|
25
29
|
|
|
26
|
-
|
|
30
|
+
if (modelClass) abilities.push([modelClass, ["new"]])
|
|
27
31
|
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
return abilities
|
|
33
|
+
},
|
|
34
|
+
[currentUser?.id(), modelClass]
|
|
35
|
+
)
|
|
30
36
|
|
|
31
37
|
const loadModel = useCallback(async () => {
|
|
32
38
|
if (modelId && modelClass) {
|
|
@@ -82,7 +88,7 @@ const ApiMakerSuperAdmin = () => {
|
|
|
82
88
|
() => <>
|
|
83
89
|
{modelClass && pageToShow == "index" &&
|
|
84
90
|
<>
|
|
85
|
-
{canCan?.can("new", modelClass) &&
|
|
91
|
+
{canCan?.can("new", modelClass) && hasEditConfig(modelClass) &&
|
|
86
92
|
<Link className="create-new-model-link" to={Params.withParams({model: modelName, mode: "new"})}>
|
|
87
93
|
Create new
|
|
88
94
|
</Link>
|
|
@@ -91,7 +97,7 @@ const ApiMakerSuperAdmin = () => {
|
|
|
91
97
|
}
|
|
92
98
|
{model && pageToShow == "show" &&
|
|
93
99
|
<>
|
|
94
|
-
{model.can("edit") &&
|
|
100
|
+
{model.can("edit") && hasEditConfig(modelClass) &&
|
|
95
101
|
<Link className="edit-model-link" to={Params.withParams({model: modelName, model_id: modelId, mode: "edit"})}>
|
|
96
102
|
Edit
|
|
97
103
|
</Link>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import ConfigReader from "./config-reader"
|
|
1
|
+
import ConfigReader from "./config-reader.jsx"
|
|
2
2
|
import {digg} from "diggerize"
|
|
3
|
+
import hasEditConfig from "./has-edit-config.js"
|
|
3
4
|
import * as inflection from "inflection"
|
|
4
5
|
import Params from "../params"
|
|
5
6
|
import PropTypes from "prop-types"
|
|
@@ -45,7 +46,7 @@ const ApiMakerSuperAdminModelClassTable = (props) => {
|
|
|
45
46
|
<Table
|
|
46
47
|
columns={columns}
|
|
47
48
|
currentUser={currentUser}
|
|
48
|
-
editModelPath={editModelPath}
|
|
49
|
+
editModelPath={hasEditConfig(modelClass) ? editModelPath : undefined}
|
|
49
50
|
modelClass={modelClass}
|
|
50
51
|
viewModelPath={viewModelPath}
|
|
51
52
|
{...tableProps}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import AttributeRow from "../../bootstrap/attribute-row"
|
|
2
2
|
import BelongsToAttributeRow from "./belongs-to-attribute-row"
|
|
3
|
-
import ConfigReader from "../config-reader"
|
|
3
|
+
import ConfigReader from "../config-reader.jsx"
|
|
4
4
|
import {digg} from "diggerize"
|
|
5
5
|
import * as inflection from "inflection"
|
|
6
6
|
import PropTypes from "prop-types"
|