@kaspernj/api-maker 1.0.432 → 1.0.433

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.432",
3
+ "version": "1.0.433",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -1,5 +1,6 @@
1
- import {Pressable} from "react-native"
1
+ import {Pressable, View} from "react-native"
2
2
  import BaseComponent from "../base-component"
3
+ import ConfigReader from "./config-reader.jsx"
3
4
  import EditPage from "./edit-page"
4
5
  import hasEditConfig from "./has-edit-config.js"
5
6
  import IndexPage from "./index-page"
@@ -26,6 +27,7 @@ export default memo(shapeComponent(class ApiMakerSuperAdmin extends BaseComponen
26
27
  this.modelClass = null
27
28
  }
28
29
 
30
+ this.configReader = useMemo(() => this.modelClass && ConfigReader.forModel(this.modelClass), [this.modelClass])
29
31
  this.modelId = this.queryParams.model_id
30
32
  this.modelName = this.modelClass?.modelClassData()?.name
31
33
  this.currentUser = useCurrentUser()
@@ -51,18 +53,22 @@ export default memo(shapeComponent(class ApiMakerSuperAdmin extends BaseComponen
51
53
  }
52
54
 
53
55
  loadModel = async () => {
54
- const {modelClass, modelId, modelName} = this.tt
56
+ const {configReader, modelClass, modelId, modelName} = this.tt
55
57
 
56
58
  if (modelId && modelClass) {
57
59
  const abilities = {}
58
60
  const abilitiesForModel = ["destroy", "edit"]
61
+ const layoutSelect = configReader?.modelConfig?.layout?.select
59
62
 
60
63
  abilities[modelName] = abilitiesForModel
61
64
 
62
- const model = await modelClass
65
+ const query = await modelClass
63
66
  .ransack({id_eq: modelId})
64
67
  .abilities(abilities)
65
- .first()
68
+
69
+ if (layoutSelect) query.select(layoutSelect)
70
+
71
+ const model = await query.first()
66
72
 
67
73
  this.setState({model})
68
74
  } else {
@@ -71,8 +77,9 @@ export default memo(shapeComponent(class ApiMakerSuperAdmin extends BaseComponen
71
77
  }
72
78
 
73
79
  render() {
74
- const {canCan, modelClass, modelId, modelName, queryParams} = this.tt
80
+ const {canCan, configReader, modelClass, modelId, modelName, queryParams} = this.tt
75
81
  const {model} = this.s
82
+ const modelConfigActions = configReader?.modelConfig?.actions
76
83
  let pageToShow
77
84
 
78
85
  if (queryParams.model && queryParams.model_id && queryParams.model_reflection) {
@@ -90,11 +97,16 @@ export default memo(shapeComponent(class ApiMakerSuperAdmin extends BaseComponen
90
97
  }
91
98
 
92
99
  const actions = useMemo(
93
- () => <>
100
+ () => <View style={{flexDirection: "row", alignItems: "center"}}>
101
+ {model && modelConfigActions && modelConfigActions({model})}
94
102
  {modelClass && pageToShow == "index" &&
95
103
  <>
96
104
  {canCan?.can("new", modelClass) && hasEditConfig(modelClass) &&
97
- <Link dataSet={{class: "create-new-model-link"}} to={Params.withParams({model: modelName, mode: "new"})}>
105
+ <Link
106
+ dataSet={{class: "create-new-model-link"}}
107
+ style={{marginLeft: 10, marginRight: 10}}
108
+ to={Params.withParams({model: modelName, mode: "new"})}
109
+ >
98
110
  <Text>
99
111
  Create new
100
112
  </Text>
@@ -105,14 +117,22 @@ export default memo(shapeComponent(class ApiMakerSuperAdmin extends BaseComponen
105
117
  {model && pageToShow == "show" &&
106
118
  <>
107
119
  {model.can("edit") && hasEditConfig(modelClass) &&
108
- <Link dataSet={{class: "edit-model-link"}} to={Params.withParams({model: modelName, model_id: modelId, mode: "edit"})}>
120
+ <Link
121
+ dataSet={{class: "edit-model-link"}}
122
+ style={{marginLeft: 10, marginRight: 10}}
123
+ to={Params.withParams({model: modelName, model_id: modelId, mode: "edit"})}
124
+ >
109
125
  <Text>
110
126
  Edit
111
127
  </Text>
112
128
  </Link>
113
129
  }
114
130
  {model.can("destroy") &&
115
- <Pressable dataSet={{class: "destroy-model-link"}} onPress={this.tt.onDestroyClicked}>
131
+ <Pressable
132
+ dataSet={{class: "destroy-model-link"}}
133
+ onPress={this.tt.onDestroyClicked}
134
+ style={{marginLeft: 10, marginRight: 10}}
135
+ >
116
136
  <Text>
117
137
  Delete
118
138
  </Text>
@@ -123,8 +143,8 @@ export default memo(shapeComponent(class ApiMakerSuperAdmin extends BaseComponen
123
143
  {pageToShow == "show_reflection" &&
124
144
  <ShowReflectionActions model={model} modelClass={modelClass} reflectionName={queryParams.model_reflection} />
125
145
  }
126
- </>,
127
- [canCan, model, modelClass, pageToShow]
146
+ </View>,
147
+ [canCan, configReader?.actions, model, modelClass, pageToShow]
128
148
  )
129
149
 
130
150
  return (