@kaspernj/api-maker 1.0.360 → 1.0.361

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.360",
3
+ "version": "1.0.361",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "index.js",
@@ -50,7 +50,7 @@
50
50
  "eslint-find-rules": "^4.0.0",
51
51
  "eslint-plugin-jest": "^28.2.0",
52
52
  "eslint-plugin-react": "^7.23.2",
53
- "i18n-on-steroids": "^1.0.7",
53
+ "i18n-on-steroids": "^1.0.12",
54
54
  "jest": "^29.0.1",
55
55
  "jsdom": "^24.0.0"
56
56
  }
@@ -9,11 +9,11 @@ import ModelRow from "./live-table/model-row"
9
9
  import Paginate from "./paginate"
10
10
  import Params from "../params"
11
11
  import PropTypes from "prop-types"
12
- import React from "react"
13
- import Shape from "set-state-compare/src/shape"
12
+ import React, {memo} from "react"
13
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
14
14
  import SortLink from "./sort-link"
15
15
 
16
- export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
16
+ export default memo(shapeComponent(class ApiMakerBootstrapLiveTable extends ShapeComponent {
17
17
  static defaultProps = {
18
18
  card: true,
19
19
  destroyEnabled: true,
@@ -62,17 +62,15 @@ export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
62
62
  viewModelPath: PropTypes.func
63
63
  }
64
64
 
65
- constructor (props) {
66
- super(props)
67
-
68
- let queryName = props.queryName
65
+ setup() {
66
+ let queryName = this.props.queryName
69
67
 
70
68
  if (!queryName) {
71
- queryName = digg(props.modelClass.modelClassData(), "collectionKey")
69
+ queryName = digg(this.props.modelClass.modelClassData(), "collectionKey")
72
70
  }
73
71
 
74
- this.shape = new Shape(this, {
75
- columns: this.columnsAsArray(),
72
+ this.useStates({
73
+ columns: () => this.columnsAsArray(),
76
74
  models: undefined,
77
75
  overallCount: undefined,
78
76
  query: undefined,
@@ -106,7 +104,7 @@ export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
106
104
  showNoRecordsAvailableContent,
107
105
  showNoRecordsFoundContent
108
106
  } = digs(
109
- this.shape,
107
+ this.state,
110
108
  "overallCount",
111
109
  "qParams",
112
110
  "query",
@@ -222,7 +220,7 @@ export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
222
220
  viewModelPath,
223
221
  ...restProps
224
222
  } = this.props
225
- const {models, qParams, query, result} = digs(this.shape, "models", "qParams", "query", "result")
223
+ const {models, qParams, query, result} = digs(this.state, "models", "qParams", "query", "result")
226
224
 
227
225
  let controlsContent, headerContent, PaginationComponent
228
226
 
@@ -278,7 +276,7 @@ export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
278
276
  const {submitFilterDebounce} = digs(this, "submitFilterDebounce")
279
277
  const {filterContent, filterSubmitButton} = digs(this.props, "filterContent", "filterSubmitButton")
280
278
  const {filterSubmitLabel} = this.props
281
- const {qParams} = digs(this.shape, "qParams")
279
+ const {qParams} = digs(this.state, "qParams")
282
280
 
283
281
  return (
284
282
  <form className="live-table--filter-form" onSubmit={this.onFilterFormSubmit} ref="filterForm">
@@ -299,13 +297,13 @@ export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
299
297
  }
300
298
 
301
299
  tableContent () {
302
- const {query, models} = this.shape
300
+ const {query, models} = this.state
303
301
 
304
302
  return (
305
303
  <>
306
304
  <thead>
307
305
  <tr>
308
- {this.shape.columns && this.headersContentFromColumns()}
306
+ {this.state.columns && this.headersContentFromColumns()}
309
307
  {this.props.headersContent && this.props.headersContent({query})}
310
308
  <th />
311
309
  </tr>
@@ -329,7 +327,7 @@ export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
329
327
  }
330
328
 
331
329
  headersContentFromColumns () {
332
- const {columns} = digs(this.shape, "columns")
330
+ const {columns} = digs(this.state, "columns")
333
331
 
334
332
  return columns.map((column) =>
335
333
  <th
@@ -337,10 +335,10 @@ export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
337
335
  data-identifier={this.identifierForColumn(column)}
338
336
  key={this.identifierForColumn(column)}
339
337
  >
340
- {column.sortKey && this.shape.query &&
341
- <SortLink attribute={column.sortKey} query={this.shape.query} title={this.headerLabelForColumn(column)} />
338
+ {column.sortKey && this.state.query &&
339
+ <SortLink attribute={column.sortKey} query={this.state.query} title={this.headerLabelForColumn(column)} />
342
340
  }
343
- {(!column.sortKey || !this.shape.query) &&
341
+ {(!column.sortKey || !this.state.query) &&
344
342
  this.headerLabelForColumn(column)
345
343
  }
346
344
  </th>
@@ -388,7 +386,7 @@ export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
388
386
  submitFilter = () => {
389
387
  const {appHistory} = this.props
390
388
  const qParams = Params.serializeForm(this.refs.filterForm)
391
- const {queryQName} = this.shape
389
+ const {queryQName} = this.state
392
390
 
393
391
  const changeParamsParams = {}
394
392
  changeParamsParams[queryQName] = JSON.stringify(qParams)
@@ -397,4 +395,4 @@ export default class ApiMakerBootstrapLiveTable extends React.PureComponent {
397
395
  }
398
396
 
399
397
  submitFilterDebounce = debounce(digg(this, "submitFilter"))
400
- }
398
+ }))
@@ -3,11 +3,12 @@ import FilterForm from "./filter-form"
3
3
  import LoadSearchModal from "./load-search-modal"
4
4
  import SaveSearchModal from "./save-search-modal"
5
5
  import PropTypes from "prop-types"
6
- import React from "react"
7
- import Shape from "set-state-compare/src/shape"
8
- import withQueryParams from "on-location-changed/src/with-query-params"
6
+ import React, {memo} from "react"
7
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
8
+ import useI18n from "i18n-on-steroids/src/use-i18n.mjs"
9
+ import useQueryParams from "on-location-changed/src/use-query-params"
9
10
 
10
- class ApiMakerTableFilter extends React.PureComponent {
11
+ const ApiMakerTableFilter = memo(shapeComponent(class ApiMakerTableFilter extends ShapeComponent {
11
12
  static propTypes = {
12
13
  a: PropTypes.string.isRequired,
13
14
  filterIndex: PropTypes.number.isRequired,
@@ -54,27 +55,32 @@ class ApiMakerTableFilter extends React.PureComponent {
54
55
 
55
56
  this.props.onRemoveClicked({filterIndex})
56
57
  }
57
- }
58
+ }))
58
59
 
59
- class ApiMakerTableFilters extends React.PureComponent {
60
+ export default memo(shapeComponent(class ApiMakerTableFilters extends ShapeComponent {
60
61
  static propTypes = {
61
62
  currentUser: PropTypes.object,
62
63
  modelClass: PropTypes.func.isRequired,
63
64
  queryName: PropTypes.string.isRequired,
64
- querySName: PropTypes.string.isRequired,
65
- queryParams: PropTypes.object.isRequired
65
+ querySName: PropTypes.string.isRequired
66
66
  }
67
67
 
68
- shape = new Shape(this, {
69
- filter: undefined,
70
- showLoadSearchModal: false,
71
- showSaveSearchModal: false
72
- })
68
+ setup() {
69
+ const {t} = useI18n({namespace: "js.api_maker.table.filters"})
70
+
71
+ this.queryParams = useQueryParams()
72
+ this.t = t
73
+ this.useStates({
74
+ filter: undefined,
75
+ showLoadSearchModal: false,
76
+ showSaveSearchModal: false
77
+ })
78
+ }
73
79
 
74
80
  render() {
75
81
  const {modelClass, querySName} = digs(this.props, "modelClass", "querySName")
76
82
  const {currentUser} = this.props
77
- const {filter, showLoadSearchModal, showSaveSearchModal} = digs(this.shape, "filter", "showLoadSearchModal", "showSaveSearchModal")
83
+ const {filter, showLoadSearchModal, showSaveSearchModal} = digs(this.state, "filter", "showLoadSearchModal", "showSaveSearchModal")
78
84
  const currentFilters = this.currentFilters()
79
85
 
80
86
  return (
@@ -97,7 +103,11 @@ class ApiMakerTableFilters extends React.PureComponent {
97
103
  />
98
104
  }
99
105
  {showSaveSearchModal &&
100
- <SaveSearchModal currentFilters={digg(this, "currentFilters")} currentUser={currentUser} onRequestClose={digg(this, "onRequestCloseSaveSearchModal")} />
106
+ <SaveSearchModal
107
+ currentFilters={digg(this, "currentFilters")}
108
+ currentUser={currentUser}
109
+ onRequestClose={digg(this, "onRequestCloseSaveSearchModal")}
110
+ />
101
111
  }
102
112
  {currentFilters?.map((filterData, filterIndex) =>
103
113
  <ApiMakerTableFilter
@@ -110,15 +120,15 @@ class ApiMakerTableFilters extends React.PureComponent {
110
120
  )}
111
121
  <div className="filter-actions">
112
122
  <button className="add-new-filter-button" onClick={digg(this, "onAddFilterClicked")}>
113
- {I18n.t("js.api_maker.table.filters.add_new_filter", {defaultValue: "Add new filter"})}
123
+ {this.t(".add_new_filter", {defaultValue: "Add new filter"})}
114
124
  </button>
115
125
  {currentUser &&
116
126
  <>
117
127
  <button className="save-search-button" onClick={digg(this, "onSaveSearchClicked")}>
118
- {I18n.t("js.api_maker.table.filters.save_search", {defaultValue: "Save search"})}
128
+ {this.t(".save_search", {defaultValue: "Save search"})}
119
129
  </button>
120
130
  <button className="load-search-button" onClick={digg(this, "onLoadSearchClicked")}>
121
- {I18n.t("js.api_maker.table.filters.load_search", {defaultValue: "Load search"})}
131
+ {this.t(".load_search", {defaultValue: "Load search"})}
122
132
  </button>
123
133
  </>
124
134
  }
@@ -128,8 +138,8 @@ class ApiMakerTableFilters extends React.PureComponent {
128
138
  }
129
139
 
130
140
  currentFilters = () => {
131
- const {queryParams, querySName} = digs(this.props, "queryParams", "querySName")
132
- const currentFilters = queryParams[querySName] || []
141
+ const {querySName} = digs(this.props, "querySName")
142
+ const currentFilters = this.queryParams[querySName] || []
133
143
 
134
144
  return currentFilters.map((currentFilter) => JSON.parse(currentFilter))
135
145
  }
@@ -139,19 +149,19 @@ class ApiMakerTableFilters extends React.PureComponent {
139
149
 
140
150
  const newFilterIndex = this.currentFilters().length
141
151
 
142
- this.shape.set({
152
+ this.setState({
143
153
  filter: {
144
154
  filterIndex: newFilterIndex
145
155
  }
146
156
  })
147
157
  }
148
158
 
149
- onApplyClicked = () => this.shape.set({filter: undefined})
150
- onFilterClicked = (args) => this.shape.set({filter: args})
159
+ onApplyClicked = () => this.setState({filter: undefined})
160
+ onFilterClicked = (args) => this.setState({filter: args})
151
161
 
152
162
  onLoadSearchClicked = (e) => {
153
163
  e.preventDefault()
154
- this.shape.set({
164
+ this.setState({
155
165
  showLoadSearchModal: true
156
166
  })
157
167
  }
@@ -168,25 +178,23 @@ class ApiMakerTableFilters extends React.PureComponent {
168
178
 
169
179
  Params.changeParams(newParams)
170
180
 
171
- this.shape.set({
181
+ this.setState({
172
182
  filter: undefined
173
183
  })
174
184
  }
175
185
 
176
- onRequestCloseLoadSearchModal = () => this.shape.set({showLoadSearchModal: false})
177
- onRequestCloseSaveSearchModal = () => this.shape.set({showSaveSearchModal: false})
186
+ onRequestCloseLoadSearchModal = () => this.setState({showLoadSearchModal: false})
187
+ onRequestCloseSaveSearchModal = () => this.setState({showSaveSearchModal: false})
178
188
 
179
189
  onSaveSearchClicked = (e) => {
180
190
  e.preventDefault()
181
191
 
182
192
  if (this.hasAnyFilters()) {
183
- this.shape.set({showSaveSearchModal: true})
193
+ this.setState({showSaveSearchModal: true})
184
194
  } else {
185
- FlashMessage.alert(I18n.t("js.api_maker.table.filters.no_filters_has_been_set", {defaultValue: "No filters has been set"}))
195
+ FlashMessage.alert(this.t(".no_filters_has_been_set", {defaultValue: "No filters has been set"}))
186
196
  }
187
197
  }
188
198
 
189
199
  hasAnyFilters = () => Object.keys(this.currentFilters()).length > 0
190
- }
191
-
192
- export default withQueryParams(ApiMakerTableFilters)
200
+ }))
@@ -1,51 +1,60 @@
1
1
  import apiMakerConfig from "@kaspernj/api-maker/src/config.mjs"
2
+ import Checkbox from "@kaspernj/api-maker/src/bootstrap/checkbox"
2
3
  import {digg} from "diggerize"
3
4
  import Input from "../../bootstrap/input"
5
+ import {shapeComponent, ShapeComponent} from "set-state-compare/src/shape-component.js"
4
6
  import {TableSearch} from "../../models.mjs.erb"
5
- import {useCallback} from "react"
7
+ import {memo} from "react"
8
+ import useI18n from "i18n-on-steroids/src/use-i18n.mjs"
6
9
 
7
- const ApiMakerTableFiltersSaveSearchModal = (props) => {
8
- const {currentFilters, currentUser, onRequestClose, ...restProps} = props
9
- const Modal = apiMakerConfig.getModal()
10
+ export default memo(shapeComponent(class ApiMakerTableFiltersSaveSearchModal extends ShapeComponent {
11
+ setup() {
12
+ const {t} = useI18n({namespace: "js.api_maker.table.filters.save_search_modal"})
10
13
 
11
- const onSaveSearchSubmit = useCallback(async (e) => {
14
+ this.t = t
15
+ }
16
+
17
+ render() {
18
+ const {currentFilters, currentUser, onRequestClose, ...restProps} = this.props
19
+ const Modal = apiMakerConfig.getModal()
20
+
21
+ return (
22
+ <Modal onRequestClose={onRequestClose} {...restProps}>
23
+ <form onSubmit={this.onSaveSearchSubmit}>
24
+ <Input
25
+ id="table_search_name"
26
+ label={this.t(".search_name", {defaultValue: "Search name"})}
27
+ name="table_search[name]"
28
+ />
29
+ <Checkbox
30
+ id="table_search_public"
31
+ label={this.t(".public", {defaultValue: "Public"})}
32
+ name="table_search[public]"
33
+ />
34
+ <button className="save-search-submit-button">
35
+ {this.t(".save_search", {defaultValue: "Save search"})}
36
+ </button>
37
+ </form>
38
+ </Modal>
39
+ )
40
+ }
41
+
42
+ onSaveSearchSubmit = async (e) => {
12
43
  e.preventDefault()
13
44
 
14
45
  const form = digg(e, "target")
15
46
  const formData = new FormData(form)
16
47
  const tableSearch = new TableSearch()
17
48
 
18
- formData.append("table_search[query_params]", JSON.stringify(currentFilters()))
19
- formData.append("table_search[user_type]", digg(currentUser.modelClassData(), "className"))
20
- formData.append("table_search[user_id]", currentUser.id())
49
+ formData.append("table_search[query_params]", JSON.stringify(this.props.currentFilters()))
50
+ formData.append("table_search[user_type]", digg(this.props.currentUser.modelClassData(), "className"))
51
+ formData.append("table_search[user_id]", this.props.currentUser.id())
21
52
 
22
53
  try {
23
54
  await tableSearch.saveRaw(formData, {form})
24
- onRequestClose()
55
+ this.props.onRequestClose()
25
56
  } catch (error) {
26
57
  FlashMessage.errorResponse(error)
27
58
  }
28
- })
29
-
30
- return (
31
- <Modal onRequestClose={onRequestClose} {...restProps}>
32
- <form onSubmit={onSaveSearchSubmit}>
33
- <Input
34
- id="table_search_name"
35
- label={I18n.t("js.api_maker.table.filters.save_search_modal.search_name", {defaultValue: "Search name"})}
36
- name="table_search[name]"
37
- />
38
- <Checkbox
39
- id="table_search_public"
40
- label={I18n.t("js.api_maker.table.filters.save_search_modal.public", {defaultValue: "Public"})}
41
- name="table_search[public]"
42
- />
43
- <button className="save-search-submit-button">
44
- {I18n.t("js.api_maker.table.filters.save_search_modal.save_search", {defaultValue: "Save search"})}
45
- </button>
46
- </form>
47
- </Modal>
48
- )
49
- }
50
-
51
- export default ApiMakerTableFiltersSaveSearchModal
59
+ }
60
+ }))
@@ -12,7 +12,7 @@ import ModelRow from "./model-row"
12
12
  import Paginate from "../bootstrap/paginate"
13
13
  import Params from "../params"
14
14
  import PropTypes from "prop-types"
15
- import React, {useEffect, useRef} from "react"
15
+ import React, {memo, useEffect, useRef} from "react"
16
16
  import selectCalculator from "./select-calculator"
17
17
  import Select from "../inputs/select"
18
18
  import Settings from "./settings"
@@ -26,7 +26,7 @@ import useCollection from "../use-collection"
26
26
  const paginationOptions = [30, 60, 90, ["All", "all"]]
27
27
  const WorkerPluginsCheckAllCheckbox = React.lazy(() => import("./worker-plugins-check-all-checkbox"))
28
28
 
29
- export default shapeComponent(class ApiMakerTable extends ShapeComponent {
29
+ export default memo(shapeComponent(class ApiMakerTable extends ShapeComponent {
30
30
  static defaultProps = {
31
31
  card: true,
32
32
  destroyEnabled: true,
@@ -620,4 +620,4 @@ export default shapeComponent(class ApiMakerTable extends ShapeComponent {
620
620
  }
621
621
 
622
622
  submitFilterDebounce = debounce(digg(this, "submitFilter"))
623
- })
623
+ }))