@kaspernj/api-maker 1.0.426 → 1.0.428

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.426",
3
+ "version": "1.0.428",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -4,10 +4,13 @@ import Checkbox from "../../bootstrap/checkbox"
4
4
  import {digg} from "diggerize"
5
5
  import {Form} from "../../form"
6
6
  import Input from "../../bootstrap/input"
7
+ import modelClassRequire from "../../model-class-require.mjs"
7
8
  import {shapeComponent} from "set-state-compare/src/shape-component.js"
8
9
  import {memo} from "react"
9
10
  import useI18n from "i18n-on-steroids/src/use-i18n.mjs"
10
11
 
12
+ const TableSearch = modelClassRequire("TableSearch")
13
+
11
14
  export default memo(shapeComponent(class ApiMakerTableFiltersSaveSearchModal extends BaseComponent {
12
15
  setup() {
13
16
  const {t} = useI18n({namespace: "js.api_maker.table.filters.save_search_modal"})
@@ -46,16 +49,21 @@ export default memo(shapeComponent(class ApiMakerTableFiltersSaveSearchModal ext
46
49
  onSaveSearchSubmit = async () => {
47
50
  const formData = this.s.form.asObject()
48
51
  const {currentFilters, currentUser, onRequestClose, search} = this.p
52
+ const hasUserTypeColumn = Boolean(TableSearch.attributes().find((attribute) => attribute.name() == "user_type"))
49
53
 
50
54
  if (search.isNewRecord()) {
51
55
  formData.table_search.query_params = JSON.stringify(currentFilters())
52
56
  }
53
57
 
54
- formData.table_search.user_type = digg(currentUser.modelClassData(), "className")
58
+ if (hasUserTypeColumn) {
59
+ formData.table_search.user_type = digg(currentUser.modelClassData(), "className")
60
+ }
61
+
55
62
  formData.table_search.user_id = currentUser.id()
56
63
 
57
64
  try {
58
65
  await search.saveRaw(formData)
66
+ FlashMessage.success(this.t(".", {defaultValue: "The search was saved."}))
59
67
  onRequestClose()
60
68
  } catch (error) {
61
69
  FlashMessage.errorResponse(error)
package/src/use-model.mjs CHANGED
@@ -22,6 +22,12 @@ const useModel = (modelClassArg, argsArg = {}) => {
22
22
  notFound: undefined
23
23
  })
24
24
 
25
+ if ("active" in s.props && !s.props.active) {
26
+ s.meta.active = false
27
+ } else {
28
+ s.meta.active = true
29
+ }
30
+
25
31
  if (typeof modelClassArg == "object") {
26
32
  modelClass = modelClassArg.callback({queryParams})
27
33
  } else {
@@ -83,7 +89,7 @@ const useModel = (modelClassArg, argsArg = {}) => {
83
89
  }, [])
84
90
 
85
91
  const loadModel = useCallback(async () => {
86
- if ("active" in s.props && !s.props.active) {
92
+ if (!s.m.active) {
87
93
  // Not active - don't do anything
88
94
  } else if (s.props.newIfNoId && !s.m.modelId) {
89
95
  return await loadNewModel()