@kaspernj/api-maker 1.0.378 → 1.0.379

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaspernj/api-maker",
3
- "version": "1.0.378",
3
+ "version": "1.0.379",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -1,10 +1,10 @@
1
1
  import BaseComponent from "../base-component"
2
- import {digg} from "diggerize"
3
2
  import Link from "../link"
4
3
  import PropTypes from "prop-types"
5
4
  import PropTypesExact from "prop-types-exact"
6
5
  import {memo} from "react"
7
6
  import {shapeComponent} from "set-state-compare/src/shape-component.js"
7
+ import ShowReflectionLink from "./show-reflection-link"
8
8
  import useQueryParams from "on-location-changed/src/use-query-params"
9
9
 
10
10
  export default memo(shapeComponent(class ApiMakerSuperAdminShowNav extends BaseComponent {
@@ -27,9 +27,7 @@ export default memo(shapeComponent(class ApiMakerSuperAdminShowNav extends BaseC
27
27
  </div>
28
28
  {model && reflections.filter((reflection) => reflection.macro() == "has_many").map((reflection) =>
29
29
  <div key={reflection.name()}>
30
- <Link to={Params.withParams({model: digg(modelClass.modelClassData(), "name"), model_id: model.primaryKey(), model_reflection: reflection.name()})}>
31
- {modelClass.humanAttributeName(reflection.name())}
32
- </Link>
30
+ <ShowReflectionLink model={model} modelClass={modelClass} reflection={reflection} />
33
31
  </div>
34
32
  )}
35
33
  </div>
@@ -0,0 +1,33 @@
1
+ import BaseComponent from "../base-component"
2
+ import {digg} from "diggerize"
3
+ import {shapeComponent} from "set-state-compare/src/shape-component.js"
4
+ import {useMemo} from "react"
5
+
6
+ export default memo(shapeComponent(class ApiMakerSuperAdminShowReflectionLink extends BaseComponent {
7
+ setup() {
8
+ this.useStates({count: undefined})
9
+
10
+ useMemo(() => {
11
+ this.countRelationship()
12
+ }, [])
13
+ }
14
+
15
+ countRelationship = async () => {
16
+ const {model, reflection} = this.p
17
+ const query = model[reflection.name()]()
18
+ const count = await query.ransack().count()
19
+
20
+ this.setState({count})
21
+ }
22
+
23
+ render() {
24
+ const {model, modelClass, reflection} = this.p
25
+ const {count} = this.s
26
+
27
+ return (
28
+ <Link to={Params.withParams({model: digg(modelClass.modelClassData(), "name"), model_id: model.primaryKey(), model_reflection: reflection.name()})}>
29
+ {modelClass.humanAttributeName(reflection.name())} ({count})
30
+ </Link>
31
+ )
32
+ }
33
+ }))