@kaspernj/api-maker 1.0.424 → 1.0.426

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.424",
3
+ "version": "1.0.426",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
package/src/modal.jsx ADDED
@@ -0,0 +1,36 @@
1
+ import BaseComponent from "./base-component"
2
+ import {memo} from "react"
3
+ import {shapeComponent} from "set-state-compare/src/shape-component.js"
4
+ import {Modal, Pressable, View} from "react-native"
5
+
6
+ export default memo(shapeComponent(class ApiMakerModal extends BaseComponent {
7
+ render() {
8
+ const {children, onRequestClose, ...restProps} = this.props
9
+
10
+ return (
11
+ <Modal onRequestClose={onRequestClose} {...restProps}>
12
+ <View
13
+ style={{
14
+ alignItems: "center",
15
+ justifyContent: "center",
16
+ minWidth: "100%",
17
+ minHeight: "100%",
18
+ padding: 20,
19
+ }}
20
+ >
21
+ <Pressable
22
+ dataSet={{class: "modal-backdrop"}}
23
+ onPress={onRequestClose}
24
+ style={{
25
+ position: "absolute",
26
+ minWidth: "100%",
27
+ minHeight: "100%",
28
+ backgroundColor: "rgba(0, 0, 0, 0.5)"
29
+ }}
30
+ />
31
+ {children}
32
+ </View>
33
+ </Modal>
34
+ )
35
+ }
36
+ }))
@@ -74,6 +74,8 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
74
74
  this.increaseLoading()
75
75
 
76
76
  try {
77
+ if (!this.s.modelClassName) throw new Error("'modelClassName' not set in state")
78
+
77
79
  const result = await Services.current().sendRequest("Models::Associations", {model_class_name: this.s.modelClassName})
78
80
  const {associations, ransackableAttributes, ransackableScopes} = this.parseAssociationData(result)
79
81
 
@@ -96,9 +98,11 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
96
98
  }
97
99
 
98
100
  async loadInitialValues() {
101
+ if (!this.s.modelClassName) throw new Error("'modelClassName' not set in state")
102
+
99
103
  let result = await Services.current().sendRequest("Models::Associations", {model_class_name: this.s.modelClassName})
100
104
  let data = this.parseAssociationData(result)
101
- let modelClassName
105
+ let modelClassName = this.s.modelClassName
102
106
  const path = []
103
107
 
104
108
  for (const pathPart of this.props.filter.p) {
@@ -108,6 +112,12 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
108
112
 
109
113
  modelClassName = digg(reflection, "modelClassName")
110
114
 
115
+ if (!modelClassName) {
116
+ const pathNames = path.map((pathPart) => pathPart.name()).join(".")
117
+
118
+ throw new Error(`No model class name from ${pathNames}.${reflection.name()}`)
119
+ }
120
+
111
121
  result = await Services.current().sendRequest("Models::Associations", {model_class_name: modelClassName})
112
122
  data = this.parseAssociationData(result)
113
123
 
@@ -201,7 +211,7 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
201
211
  )}
202
212
  </View>
203
213
  <View>
204
- {predicates && !this.state.scope &&
214
+ {predicates && !this.s.scope &&
205
215
  <Select
206
216
  className="predicate-select"
207
217
  defaultValue={predicate?.name}
@@ -289,7 +299,6 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
289
299
  onAttributeClicked = ({attribute}) => {
290
300
  this.setState({
291
301
  attribute,
292
- predicate: undefined,
293
302
  scope: undefined
294
303
  })
295
304
  }
@@ -317,6 +326,7 @@ export default memo(shapeComponent(class ApiMakerTableFiltersFilterForm extends
317
326
  onScopeClicked = ({scope}) => {
318
327
  this.setState({
319
328
  attribute: undefined,
329
+ predicate: undefined,
320
330
  scope
321
331
  })
322
332
  }
@@ -29,7 +29,13 @@ export default memo(shapeComponent(class ApiMakerTableFilter extends BaseCompone
29
29
 
30
30
  return (
31
31
  <View style={{alignItems: "center", flexDirection: "row", backgroundColor: "grey", paddingVertical: 10, paddingHorizontal: 6}}>
32
- <Pressable dataSet={{class: "filter-label"}} onPress={this.tt.onFilterPressed}>
32
+ <Pressable
33
+ dataSet={{
34
+ attribute: a,
35
+ class: "filter-label"
36
+ }}
37
+ onPress={this.tt.onFilterPressed}
38
+ >
33
39
  <Text>
34
40
  {p.length > 0 &&
35
41
  `${p.join(".")}.`
@@ -3,10 +3,12 @@ import columnIdentifier from "../column-identifier.mjs"
3
3
  import ColumnRow from "./column-row"
4
4
  import DownloadAction from "./download-action"
5
5
  import {memo, useRef} from "react"
6
+ import Modal from "../../modal"
6
7
  import PropTypes from "prop-types"
7
8
  import propTypesExact from "prop-types-exact"
8
9
  import {shapeComponent} from "set-state-compare/src/shape-component.js"
9
- import {Modal, Text, View} from "react-native"
10
+ import {Text, View} from "react-native"
11
+ import useI18n from "i18n-on-steroids/src/use-i18n.mjs"
10
12
 
11
13
  export default memo(shapeComponent(class ApiMakerTableSettings extends BaseComponent {
12
14
  static propTypes = propTypesExact({
@@ -15,24 +17,26 @@ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseCompo
15
17
  })
16
18
 
17
19
  setup() {
20
+ const {t} = useI18n({namespace: "js.api_maker.table.settings"})
21
+
18
22
  this.rootRef = useRef()
23
+ this.t = t
19
24
  }
20
25
 
21
26
  tableSetting = () => this.p.table.s.tableSetting
22
27
 
23
28
  render() {
29
+ const {t} = this.tt
24
30
  const {table} = this.p
25
31
  const {preparedColumns} = table.s
26
32
 
27
33
  return (
28
- <Modal onBackdropPress={this.p.onRequestClose} onRequestClose={this.p.onRequestClose} transparent>
34
+ <Modal onBackdropPress={this.p.onRequestClose} onRequestClose={this.p.onRequestClose} style={{backgroundColor: "#000"}} transparent>
29
35
  <View
30
36
  dataSet={{class: "api-maker--table--settings"}}
31
37
  style={{
32
38
  width: "100%",
33
39
  maxWidth: 800,
34
- marginHorizontal: "auto",
35
- marginVertical: "auto",
36
40
  padding: 20,
37
41
  backgroundColor: "#fff",
38
42
  border: "1px solid black"
@@ -40,13 +44,13 @@ export default memo(shapeComponent(class ApiMakerTableSettings extends BaseCompo
40
44
  >
41
45
  <View style={{marginBottom: 5}}>
42
46
  <Text style={{fontSize: 16, fontWeight: "bold"}}>
43
- Settings
47
+ {t(".settings", {defaultValue: "Settings"})}
44
48
  </Text>
45
49
  </View>
46
50
  <DownloadAction table={table} />
47
51
  <View style={{marginBottom: 5}}>
48
52
  <Text style={{fontSize: 16, fontWeight: "bold"}}>
49
- Columns
53
+ {t(".columns", {defaultValue: "Columns"})}
50
54
  </Text>
51
55
  </View>
52
56
  {preparedColumns?.map(({column, tableSettingColumn}) =>