@kaspernj/api-maker 1.0.304 → 1.0.306
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/inputs/input-wrapper.jsx +1 -1
- package/src/super-admin/edit-page.jsx +100 -0
- package/src/super-admin/index-page.jsx +12 -19
- package/src/super-admin/index.jsx +67 -57
- package/src/super-admin/layout/header/index.jsx +40 -52
- package/src/super-admin/layout/index.jsx +75 -100
- package/src/super-admin/layout/menu/index.jsx +53 -68
- package/src/super-admin/layout/menu/menu-content.jsx +29 -33
- package/src/super-admin/layout/menu/menu-item/index.jsx +22 -24
- package/src/super-admin/layout/menu/style.scss +2 -0
- package/src/super-admin/layout/no-access.jsx +14 -13
- package/src/super-admin/model-class-table.jsx +40 -30
- package/src/super-admin/show-nav.jsx +25 -25
- package/src/super-admin/show-page/belongs-to-attribute-row.jsx +16 -18
- package/src/super-admin/show-page/index.jsx +31 -43
- package/src/super-admin/show-reflection-page.jsx +32 -43
- package/src/use-current-user.mjs +1 -1
- package/src/use-model.mjs +10 -6
|
@@ -1,77 +1,17 @@
|
|
|
1
1
|
import "./style"
|
|
2
|
-
import {
|
|
2
|
+
import {memo, useCallback, useRef} from "react"
|
|
3
3
|
import Link from "../../../link"
|
|
4
4
|
import MenuContent from "./menu-content"
|
|
5
5
|
import MenuItem from "./menu-item"
|
|
6
|
-
import React from "react"
|
|
7
6
|
import PropTypes from "prop-types"
|
|
8
7
|
import PropTypesExact from "prop-types-exact"
|
|
9
|
-
import
|
|
8
|
+
import useCurrentUser from "../../../use-current-user"
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
currentUser: PropTypes.instanceOf(User),
|
|
15
|
-
noAccess: PropTypes.bool.isRequired,
|
|
16
|
-
onRequestMenuClose: PropTypes.func.isRequired,
|
|
17
|
-
triggered: PropTypes.bool.isRequired
|
|
18
|
-
})
|
|
10
|
+
const ComponentsAdminLayoutMenu = ({active, noAccess, triggered}) => {
|
|
11
|
+
const currentUser = useCurrentUser()
|
|
12
|
+
const rootRef = useRef()
|
|
19
13
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
render() {
|
|
23
|
-
const {rootRef} = digs(this, "rootRef")
|
|
24
|
-
const {active} = this.props
|
|
25
|
-
const {
|
|
26
|
-
currentUser,
|
|
27
|
-
noAccess,
|
|
28
|
-
triggered
|
|
29
|
-
} = digs(
|
|
30
|
-
this.props,
|
|
31
|
-
"currentUser",
|
|
32
|
-
"noAccess",
|
|
33
|
-
"triggered"
|
|
34
|
-
)
|
|
35
|
-
return (
|
|
36
|
-
<div className="components--admin--layout--menu" data-triggered={triggered} ref={rootRef}>
|
|
37
|
-
<div className="menu-logo">
|
|
38
|
-
<Link className="menu-logo-link" to={Params.withParams({})}>
|
|
39
|
-
Admin
|
|
40
|
-
</Link>
|
|
41
|
-
</div>
|
|
42
|
-
<div className="menu-items-center">
|
|
43
|
-
{!noAccess &&
|
|
44
|
-
<MenuContent active={active} />
|
|
45
|
-
}
|
|
46
|
-
</div>
|
|
47
|
-
<div className="menu-items-bottom">
|
|
48
|
-
{currentUser &&
|
|
49
|
-
<div className="menu-user-section">
|
|
50
|
-
<div className="menu-user-icon">
|
|
51
|
-
<i className="fa fa-user" />
|
|
52
|
-
</div>
|
|
53
|
-
<div className="menu-user-name">
|
|
54
|
-
<div className="menu-user-name-container">
|
|
55
|
-
{currentUser.name()}
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
</div>
|
|
59
|
-
}
|
|
60
|
-
{currentUser &&
|
|
61
|
-
<MenuItem
|
|
62
|
-
active
|
|
63
|
-
className="sign-out-menu-item"
|
|
64
|
-
icon="sign-out-alt"
|
|
65
|
-
label={I18n.t("js.api_maker.super_admin.layout.menu.sign_out", {defaultValue: "Sign out"})}
|
|
66
|
-
onClick={digg(this, "onSignOutClicked")}
|
|
67
|
-
/>
|
|
68
|
-
}
|
|
69
|
-
</div>
|
|
70
|
-
</div>
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
onSignOutClicked = async (e) => {
|
|
14
|
+
const onSignOutClicked = useCallback(async (e) => {
|
|
75
15
|
e.preventDefault()
|
|
76
16
|
|
|
77
17
|
try {
|
|
@@ -80,8 +20,53 @@ class ComponentsAdminLayoutMenu extends React.PureComponent {
|
|
|
80
20
|
} catch (error) {
|
|
81
21
|
FlashMessage.errorResponse(error)
|
|
82
22
|
}
|
|
83
|
-
}
|
|
23
|
+
}, [])
|
|
84
24
|
|
|
25
|
+
return (
|
|
26
|
+
<div className="components--admin--layout--menu" data-triggered={triggered} ref={rootRef}>
|
|
27
|
+
<div className="menu-logo">
|
|
28
|
+
<Link className="menu-logo-link" to={Params.withParams({})}>
|
|
29
|
+
Admin
|
|
30
|
+
</Link>
|
|
31
|
+
</div>
|
|
32
|
+
<div className="menu-items-center">
|
|
33
|
+
{!noAccess &&
|
|
34
|
+
<MenuContent active={active} />
|
|
35
|
+
}
|
|
36
|
+
</div>
|
|
37
|
+
<div className="menu-items-bottom">
|
|
38
|
+
{currentUser &&
|
|
39
|
+
<div className="menu-user-section">
|
|
40
|
+
<div className="menu-user-icon">
|
|
41
|
+
<i className="fa fa-user" />
|
|
42
|
+
</div>
|
|
43
|
+
<div className="menu-user-name">
|
|
44
|
+
<div className="menu-user-name-container">
|
|
45
|
+
{currentUser.name()}
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</div>
|
|
49
|
+
}
|
|
50
|
+
{currentUser &&
|
|
51
|
+
<MenuItem
|
|
52
|
+
active
|
|
53
|
+
className="sign-out-menu-item"
|
|
54
|
+
icon="sign-out-alt"
|
|
55
|
+
label={I18n.t("js.api_maker.super_admin.layout.menu.sign_out", {defaultValue: "Sign out"})}
|
|
56
|
+
onClick={onSignOutClicked}
|
|
57
|
+
/>
|
|
58
|
+
}
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
61
|
+
)
|
|
85
62
|
}
|
|
86
63
|
|
|
87
|
-
|
|
64
|
+
ComponentsAdminLayoutMenu.propTypes = PropTypesExact({
|
|
65
|
+
active: PropTypes.string,
|
|
66
|
+
currentUser: PropTypes.instanceOf(User),
|
|
67
|
+
noAccess: PropTypes.bool.isRequired,
|
|
68
|
+
onRequestMenuClose: PropTypes.func.isRequired,
|
|
69
|
+
triggered: PropTypes.bool.isRequired
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
export default memo(ComponentsAdminLayoutMenu)
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {digg
|
|
1
|
+
import CanCan from "../../../can-can"
|
|
2
|
+
import {digg} from "diggerize"
|
|
3
|
+
import {memo, useMemo} from "react"
|
|
3
4
|
import MenuItem from "./menu-item"
|
|
4
5
|
import models from "../../models"
|
|
5
6
|
import Params from "../../../params"
|
|
6
7
|
import PropTypes from "prop-types"
|
|
7
8
|
import PropTypesExact from "prop-types-exact"
|
|
9
|
+
import withCanCan from "@kaspernj/api-maker/src/with-can-can"
|
|
8
10
|
|
|
9
11
|
const abilities = []
|
|
10
12
|
|
|
@@ -14,37 +16,31 @@ for (const model of models) {
|
|
|
14
16
|
)
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
state = {
|
|
23
|
-
canCan: undefined
|
|
24
|
-
}
|
|
19
|
+
const ComponentsAdminLayoutMenuContent = ({active, canCan}) => {
|
|
20
|
+
const sortedModels = useMemo(
|
|
21
|
+
() => models.sort((a, b) => a.modelName().human({count: 2}).toLowerCase().localeCompare(b.modelName().human({count: 2}).toLowerCase())),
|
|
22
|
+
[]
|
|
23
|
+
)
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
return (
|
|
26
|
+
<>
|
|
27
|
+
{sortedModels.map((model) => canCan?.can("index", model) &&
|
|
28
|
+
<MenuItem
|
|
29
|
+
active={active}
|
|
30
|
+
icon="sitemap"
|
|
31
|
+
identifier={digg(model.modelClassData(), "name")}
|
|
32
|
+
label={model.modelName().human({count: 2})}
|
|
33
|
+
key={model.modelClassData().name}
|
|
34
|
+
to={Params.withParams({model: model.modelClassData().name})}
|
|
35
|
+
/>
|
|
36
|
+
)}
|
|
37
|
+
</>
|
|
38
|
+
)
|
|
39
|
+
}
|
|
29
40
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<MenuItem
|
|
35
|
-
active={active}
|
|
36
|
-
icon="sitemap"
|
|
37
|
-
identifier={digg(model.modelClassData(), "name")}
|
|
38
|
-
label={model.modelName().human({count: 2})}
|
|
39
|
-
key={model.modelClassData().name}
|
|
40
|
-
to={Params.withParams({model: model.modelClassData().name})}
|
|
41
|
-
/>
|
|
42
|
-
)}
|
|
43
|
-
</>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
41
|
+
ComponentsAdminLayoutMenuContent.propTypes = PropTypesExact({
|
|
42
|
+
active: PropTypes.string,
|
|
43
|
+
canCan: PropTypes.instanceOf(CanCan)
|
|
44
|
+
})
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
return models.sort((a, b) => a.modelName().human({count: 2}).toLowerCase().localeCompare(b.modelName().human({count: 2}).toLowerCase()))
|
|
49
|
-
}
|
|
50
|
-
}
|
|
46
|
+
export default withCanCan(memo(ComponentsAdminLayoutMenuContent), abilities)
|
|
@@ -1,31 +1,29 @@
|
|
|
1
1
|
import "./style"
|
|
2
2
|
import classNames from "classnames"
|
|
3
3
|
import Link from "../../../../link"
|
|
4
|
+
import {memo} from "react"
|
|
4
5
|
import PropTypes from "prop-types"
|
|
5
|
-
import React from "react"
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
const ComponentsAdminLayoutMenuMenuItem = ({active, children, className, icon, identifier, label, to, ...restProps}) => {
|
|
8
|
+
return (
|
|
9
|
+
<Link
|
|
10
|
+
className={classNames("components--admin--layout--menu--menu-item", className)}
|
|
11
|
+
data-active={active === true || active == identifier}
|
|
12
|
+
data-identifier={identifier}
|
|
13
|
+
to={to || "#"}
|
|
14
|
+
{...restProps}
|
|
15
|
+
>
|
|
16
|
+
<i className={`fa fa-fw fa-${icon} menu-item-icon`} />
|
|
17
|
+
{children || label}
|
|
18
|
+
</Link>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
to={to || "#"}
|
|
24
|
-
{...restProps}
|
|
25
|
-
>
|
|
26
|
-
<i className={`fa fa-fw fa-${icon} menu-item-icon`} />
|
|
27
|
-
{children || label}
|
|
28
|
-
</Link>
|
|
29
|
-
)
|
|
30
|
-
}
|
|
22
|
+
ComponentsAdminLayoutMenuMenuItem.propTypes = {
|
|
23
|
+
active: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
|
|
24
|
+
className: PropTypes.string,
|
|
25
|
+
icon: PropTypes.string.isRequired,
|
|
26
|
+
label: PropTypes.node
|
|
31
27
|
}
|
|
28
|
+
|
|
29
|
+
export default memo(ComponentsAdminLayoutMenuMenuItem)
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {currentUser} = digs(this.props, "currentUser")
|
|
1
|
+
import {memo} from "react"
|
|
2
|
+
import useCurrentUser from "../../use-current-user"
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
const ComponentsAdminLayoutNoAccess = () => {
|
|
5
|
+
const currentUser = useCurrentUser()
|
|
6
|
+
|
|
7
|
+
return (
|
|
8
|
+
<div
|
|
9
|
+
className="components--admin--layout-no-access"
|
|
10
|
+
data-user-roles={currentUser?.userRoles()?.loaded()?.map((userRole) => userRole.role()?.identifier()).join(", ")}
|
|
11
|
+
>
|
|
12
|
+
{I18n.t("js.api_maker.super_admin.layout.no_access.you_dont_have_no_access_to_this_page", {defaultValue: "You don't have access to this page."})}
|
|
13
|
+
</div>
|
|
14
|
+
)
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export default
|
|
17
|
+
export default memo(ComponentsAdminLayoutNoAccess)
|
|
@@ -1,46 +1,56 @@
|
|
|
1
1
|
import ConfigReader from "./config-reader"
|
|
2
|
-
import {digg
|
|
2
|
+
import {digg} from "diggerize"
|
|
3
3
|
import * as inflection from "inflection"
|
|
4
4
|
import Params from "../params"
|
|
5
5
|
import PropTypes from "prop-types"
|
|
6
|
-
import
|
|
6
|
+
import {memo, useCallback} from "react"
|
|
7
7
|
import Table from "../table/table"
|
|
8
|
+
import useCurrentUser from "../use-current-user"
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
queryParams: PropTypes.object.isRequired
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
render() {
|
|
17
|
-
const {currentUser, modelClass, queryParams, ...restProps} = this.props
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<Table
|
|
21
|
-
columns={digg(this, "columns")}
|
|
22
|
-
currentUser={currentUser}
|
|
23
|
-
modelClass={modelClass}
|
|
24
|
-
viewModelPath={digg(this, "viewModelPath")}
|
|
25
|
-
{...restProps}
|
|
26
|
-
/>
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
columns = () => {
|
|
31
|
-
const {modelClass} = digs(this.props, "modelClass")
|
|
10
|
+
const ApiMakerSuperAdminModelClassTable = ({modelClass, ...restProps}) => {
|
|
11
|
+
const currentUser = useCurrentUser()
|
|
12
|
+
|
|
13
|
+
const columns = useCallback(() => {
|
|
32
14
|
const configReader = ConfigReader.forModel(modelClass)
|
|
33
15
|
|
|
34
16
|
return configReader.tableColumns()
|
|
35
|
-
}
|
|
17
|
+
}, [modelClass])
|
|
18
|
+
|
|
19
|
+
const editModelPath = useCallback((args) => {
|
|
20
|
+
const argName = inflection.camelize(digg(modelClass.modelClassData(), "name"), true)
|
|
21
|
+
const model = digg(args, argName)
|
|
22
|
+
|
|
23
|
+
return Params.withParams({
|
|
24
|
+
model: modelClass.modelClassData().name,
|
|
25
|
+
model_id: model.primaryKey(),
|
|
26
|
+
mode: "edit"
|
|
27
|
+
})
|
|
28
|
+
})
|
|
36
29
|
|
|
37
|
-
viewModelPath = (args) => {
|
|
38
|
-
const argName = inflection.camelize(digg(
|
|
30
|
+
const viewModelPath = useCallback((args) => {
|
|
31
|
+
const argName = inflection.camelize(digg(modelClass.modelClassData(), "name"), true)
|
|
39
32
|
const model = digg(args, argName)
|
|
40
33
|
|
|
41
34
|
return Params.withParams({
|
|
42
|
-
model:
|
|
35
|
+
model: modelClass.modelClassData().name,
|
|
43
36
|
model_id: model.primaryKey()
|
|
44
37
|
})
|
|
45
|
-
}
|
|
38
|
+
}, [modelClass])
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Table
|
|
42
|
+
columns={columns}
|
|
43
|
+
currentUser={currentUser}
|
|
44
|
+
editModelPath={editModelPath}
|
|
45
|
+
modelClass={modelClass}
|
|
46
|
+
viewModelPath={viewModelPath}
|
|
47
|
+
{...restProps}
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
46
50
|
}
|
|
51
|
+
|
|
52
|
+
ApiMakerSuperAdminModelClassTable.propTypes = {
|
|
53
|
+
modelClass: PropTypes.func.isRequired
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export default memo(ApiMakerSuperAdminModelClassTable)
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import {digg
|
|
1
|
+
import {digg} from "diggerize"
|
|
2
2
|
import Link from "../link"
|
|
3
3
|
import PropTypes from "prop-types"
|
|
4
4
|
import PropTypesExact from "prop-types-exact"
|
|
5
5
|
import React from "react"
|
|
6
|
+
import useQueryParams from "on-location-changed/src/use-query-params"
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
modelClass: PropTypes.func.isRequired,
|
|
11
|
-
queryParams: PropTypes.object.isRequired
|
|
12
|
-
})
|
|
8
|
+
const ApiMakerSuperAdminShowNav = ({model, modelClass}) => {
|
|
9
|
+
const queryParams = useQueryParams()
|
|
10
|
+
const reflections = modelClass.reflections()
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const reflections = modelClass.reflections()
|
|
17
|
-
|
|
18
|
-
return (
|
|
12
|
+
return (
|
|
13
|
+
<div>
|
|
19
14
|
<div>
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
<Link to={Params.withParams({model: modelClass.modelClassData().name, model_id: queryParams.model_id})}>
|
|
16
|
+
{I18n.t("js.api_maker.suprt_admin.show_reflection_page.general", {defaultValue: "General"})}
|
|
17
|
+
</Link>
|
|
18
|
+
</div>
|
|
19
|
+
{model && reflections.filter((reflection) => reflection.macro() == "has_many").map((reflection) =>
|
|
20
|
+
<div key={reflection.name()}>
|
|
21
|
+
<Link to={Params.withParams({model: digg(modelClass.modelClassData(), "name"), model_id: model.primaryKey(), model_reflection: reflection.name()})}>
|
|
22
|
+
{modelClass.humanAttributeName(reflection.name())}
|
|
23
23
|
</Link>
|
|
24
24
|
</div>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
{modelClass.humanAttributeName(reflection.name())}
|
|
29
|
-
</Link>
|
|
30
|
-
</div>
|
|
31
|
-
)}
|
|
32
|
-
</div>
|
|
33
|
-
)
|
|
34
|
-
}
|
|
25
|
+
)}
|
|
26
|
+
</div>
|
|
27
|
+
)
|
|
35
28
|
}
|
|
29
|
+
|
|
30
|
+
ApiMakerSuperAdminShowNav.propTypes = PropTypesExact({
|
|
31
|
+
model: PropTypes.object.isRequired,
|
|
32
|
+
modelClass: PropTypes.func.isRequired
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
export default React.memo(ApiMakerSuperAdminShowNav)
|
|
@@ -1,25 +1,23 @@
|
|
|
1
1
|
import AttributeRow from "../../bootstrap/attribute-row"
|
|
2
|
-
import {digs} from "diggerize"
|
|
3
2
|
import * as inflection from "inflection"
|
|
4
3
|
import Link from "../../link"
|
|
5
4
|
import Params from "../../params"
|
|
6
|
-
import
|
|
5
|
+
import {memo} from "react"
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const reflectionMethodName = inflection.camelize(reflection.name(), true)
|
|
12
|
-
const subModel = model[reflectionMethodName]()
|
|
7
|
+
const ApiMakerSuperAdminShowPageBelongsToAttributeRow = ({model, modelClass, reflection}) => {
|
|
8
|
+
const reflectionMethodName = inflection.camelize(reflection.name(), true)
|
|
9
|
+
const subModel = model[reflectionMethodName]()
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
11
|
+
return (
|
|
12
|
+
<AttributeRow label={modelClass.humanAttributeName(inflection.camelize(reflection.name(), true))}>
|
|
13
|
+
{subModel &&
|
|
14
|
+
<Link to={Params.withParams({model: subModel.modelClassData().name, model_id: subModel.primaryKey()})}>
|
|
15
|
+
{subModel && "name" in subModel && subModel.name()}
|
|
16
|
+
{subModel && !("name" in subModel) && subModel?.id()}
|
|
17
|
+
</Link>
|
|
18
|
+
}
|
|
19
|
+
</AttributeRow>
|
|
20
|
+
)
|
|
25
21
|
}
|
|
22
|
+
|
|
23
|
+
export default memo(ApiMakerSuperAdminShowPageBelongsToAttributeRow)
|
|
@@ -1,54 +1,42 @@
|
|
|
1
1
|
import AttributeRows from "../../bootstrap/attribute-rows"
|
|
2
2
|
import BelongsToAttributeRow from "./belongs-to-attribute-row"
|
|
3
3
|
import ConfigReader from "../config-reader"
|
|
4
|
-
import {digg
|
|
4
|
+
import {digg} from "diggerize"
|
|
5
5
|
import * as inflection from "inflection"
|
|
6
|
+
import Link from "../../link"
|
|
6
7
|
import PropTypes from "prop-types"
|
|
7
|
-
import
|
|
8
|
+
import {memo} from "react"
|
|
8
9
|
import ShowNav from "../show-nav"
|
|
9
10
|
import withModel from "../../with-model"
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{model
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{model && modelClass.reflections().filter((reflection) => reflection.macro() == "belongs_to").map((reflection) =>
|
|
37
|
-
<BelongsToAttributeRow key={reflection.name()} model={model} modelClass={modelClass} reflection={reflection} />
|
|
38
|
-
)}
|
|
39
|
-
{model && extraContent && extraContent(modelArgs)}
|
|
40
|
-
</div>
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
attributes = () => this.configReader.attributesToShow()
|
|
45
|
-
|
|
46
|
-
model() {
|
|
47
|
-
const {modelClass} = digs(this.props, "modelClass")
|
|
48
|
-
const camelizedLower = digg(modelClass.modelClassData(), "camelizedLower")
|
|
12
|
+
const ApiMakerSuperAdminShowPage = ({modelClass, ...restProps}) => {
|
|
13
|
+
const configReader = ConfigReader.forModel(modelClass)
|
|
14
|
+
const attributes = configReader.attributesToShow()
|
|
15
|
+
const camelizedLower = digg(modelClass.modelClassData(), "camelizedLower")
|
|
16
|
+
const model = digg(restProps, camelizedLower)
|
|
17
|
+
const extraContent = configReader.modelConfig?.show?.extraContent
|
|
18
|
+
const modelArgs = {}
|
|
19
|
+
|
|
20
|
+
modelArgs[inflection.camelize(modelClass.modelClassData().name, true)] = model
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<div className="super-admin--show-page">
|
|
24
|
+
{model &&
|
|
25
|
+
<ShowNav model={model} modelClass={modelClass} />
|
|
26
|
+
}
|
|
27
|
+
{attributes && model &&
|
|
28
|
+
<AttributeRows attributes={attributes} model={model} />
|
|
29
|
+
}
|
|
30
|
+
{model && modelClass.reflections().filter((reflection) => reflection.macro() == "belongs_to").map((reflection) =>
|
|
31
|
+
<BelongsToAttributeRow key={reflection.name()} model={model} modelClass={modelClass} reflection={reflection} />
|
|
32
|
+
)}
|
|
33
|
+
{model && extraContent && extraContent(modelArgs)}
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
49
37
|
|
|
50
|
-
|
|
51
|
-
|
|
38
|
+
ApiMakerSuperAdminShowPage.propTypes = {
|
|
39
|
+
modelClass: PropTypes.func.isRequired
|
|
52
40
|
}
|
|
53
41
|
|
|
54
42
|
const modelClassResolver = {callback: ({queryParams}) => {
|
|
@@ -59,7 +47,7 @@ const modelClassResolver = {callback: ({queryParams}) => {
|
|
|
59
47
|
}}
|
|
60
48
|
|
|
61
49
|
export default withModel(
|
|
62
|
-
ApiMakerSuperAdminShowPage,
|
|
50
|
+
memo(ApiMakerSuperAdminShowPage),
|
|
63
51
|
modelClassResolver,
|
|
64
52
|
({modelClass}) => {
|
|
65
53
|
const preload = []
|