@things-factory/product-ui 4.3.100 → 4.3.105-alpha.0

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.
@@ -298,6 +298,7 @@ class ProductBundleLinkPopup extends localize(i18next)(LitElement) {
298
298
  records:
299
299
  items.map(itm => {
300
300
  return {
301
+ id: itm.id,
301
302
  productSku: itm.product.sku,
302
303
  productName: itm.product.name,
303
304
  productDescription: itm.product.description,
@@ -4,6 +4,7 @@ import '@things-factory/grist-ui'
4
4
 
5
5
  import gql from 'graphql-tag'
6
6
  import { css, html } from 'lit'
7
+ import isEmpty from 'lodash-es/isEmpty'
7
8
 
8
9
  import { getCodeByName } from '@things-factory/code-base'
9
10
  import { i18next, localize } from '@things-factory/i18n-base'
@@ -107,7 +108,7 @@ class ProductBundleList extends localize(i18next)(PageView) {
107
108
  ]
108
109
 
109
110
  this.productGristConfig = {
110
- pagination: { limit: 50, pages: [20, 50, 100, 500, 999] },
111
+ pagination: { limit: 50, pages: [50, 100, 200, 500] },
111
112
  list: { fields: ['sku', 'name', 'description', 'type', 'packingType'] },
112
113
  rows: {
113
114
  selectable: { multiple: true }
@@ -125,7 +126,7 @@ class ProductBundleList extends localize(i18next)(PageView) {
125
126
  {
126
127
  type: 'string',
127
128
  name: 'sku',
128
- header: i18next.t('field.sku'),
129
+ header: `*${i18next.t('field.sku')}`,
129
130
  sortable: false,
130
131
  record: { editable: true },
131
132
  width: 150
@@ -141,7 +142,7 @@ class ProductBundleList extends localize(i18next)(PageView) {
141
142
  {
142
143
  type: 'string',
143
144
  name: 'name',
144
- header: i18next.t('field.name'),
145
+ header: `*${i18next.t('field.name')}`,
145
146
  sortable: false,
146
147
  record: { editable: true },
147
148
  width: 200
@@ -182,7 +183,7 @@ class ProductBundleList extends localize(i18next)(PageView) {
182
183
  {
183
184
  type: 'select',
184
185
  name: 'packingType',
185
- header: i18next.t('field.packing_type'),
186
+ header: `*${i18next.t('field.packing_type')}`,
186
187
  record: {
187
188
  editable: true,
188
189
  options: ['', ...Object.keys(packingType).map(key => packingType[key].name)]
@@ -274,34 +275,71 @@ class ProductBundleList extends localize(i18next)(PageView) {
274
275
  }
275
276
 
276
277
  async _saveProductBundles(patches) {
277
- if (patches && patches.length) {
278
- const response = await client.mutate({
279
- mutation: gql`
280
- mutation updateMultipleProductBundle($patches: [ProductBundlePatch!]!) {
281
- updateMultipleProductBundle(patches: $patches) {
282
- sku
283
- refCode
284
- name
285
- description
286
- type
287
- packingType
288
- status
278
+ try {
279
+ if (patches && patches.length) {
280
+ this._validate()
281
+ const response = await client.mutate({
282
+ mutation: gql`
283
+ mutation updateMultipleProductBundle($patches: [ProductBundlePatch!]!) {
284
+ updateMultipleProductBundle(patches: $patches) {
285
+ sku
286
+ refCode
287
+ name
288
+ description
289
+ type
290
+ packingType
291
+ status
292
+ }
289
293
  }
290
- }
291
- `,
292
- variables: { patches },
293
- context: gqlContext()
294
- })
294
+ `,
295
+ variables: { patches },
296
+ context: gqlContext()
297
+ })
295
298
 
296
- if (!response.errors) {
297
- this.dataGrist.fetch()
298
- this._showToast(i18next.t('text.data_updated_successfully'))
299
+ if (!response.errors) {
300
+ this.dataGrist.fetch()
301
+ this._showToast(i18next.t('text.data_updated_successfully'))
302
+ }
303
+ } else {
304
+ CustomAlert({
305
+ title: i18next.t('text.nothing_changed'),
306
+ text: i18next.t('text.there_is_nothing_to_save')
307
+ })
299
308
  }
300
- } else {
301
- CustomAlert({
302
- title: i18next.t('text.nothing_changed'),
303
- text: i18next.t('text.there_is_nothing_to_save')
304
- })
309
+ } catch (e) {
310
+ this._showToast(e.message)
311
+ }
312
+ }
313
+
314
+ _validate() {
315
+ let errors = []
316
+
317
+ let data = this.dataGrist._data.records.map(itm => {
318
+ itm.error = false
319
+
320
+ if (isEmpty(itm.sku) || '') {
321
+ itm.error = true
322
+ if (!errors.find(err => err.type == 'sku')) errors.push({ type: 'sku', value: 'SKU is required' })
323
+ }
324
+ if (isEmpty(itm.name) || '') {
325
+ itm.error = true
326
+ if (!errors.find(err => err.type == 'name')) errors.push({ type: 'name', value: 'name is required' })
327
+ }
328
+ if (isEmpty(itm.packingType) || '') {
329
+ itm.error = true
330
+ if (!errors.find(err => err.type == 'packingType'))
331
+ errors.push({ type: 'packingType', value: 'packing type is required' })
332
+ }
333
+ return itm
334
+ })
335
+
336
+ if (errors.length > 0) {
337
+ this._data = {
338
+ ...this.dataGrist.dirtyData,
339
+ records: data
340
+ }
341
+
342
+ throw new Error(errors.map(itm => itm.value).join(', '))
305
343
  }
306
344
  }
307
345
 
@@ -184,7 +184,7 @@ export class ProductDetailsPopup extends localize(i18next)(LitElement) {
184
184
  {
185
185
  type: 'select',
186
186
  name: 'packingType',
187
- header: i18next.t('field.packing_type'),
187
+ header: `*${i18next.t('field.packing_type')}`,
188
188
  record: {
189
189
  editable: true,
190
190
  options: ['', ...Object.keys(packingType).map(key => packingType[key].name)]
@@ -198,14 +198,14 @@ export class ProductDetailsPopup extends localize(i18next)(LitElement) {
198
198
  editable: true,
199
199
  options: ['', ...Object.keys(uom).map(key => uom[key].name)]
200
200
  },
201
- header: `${i18next.t('field.uom')}`,
201
+ header: `*${i18next.t('field.uom')}`,
202
202
  width: 80
203
203
  },
204
204
  {
205
205
  type: 'float',
206
206
  name: 'uomValue',
207
207
  record: { editable: true, options: { min: 0 } },
208
- header: `${i18next.t('field.uom_value')}`,
208
+ header: `*${i18next.t('field.uom_value')}`,
209
209
  width: 100
210
210
  },
211
211
  {
@@ -884,7 +884,7 @@ class ProductList extends localize(i18next)(PageView) {
884
884
  this.dataGrist.fetch()
885
885
  }
886
886
  } catch (error) {
887
- this.showToast(error)
887
+ this.showToast(error.message)
888
888
  }
889
889
  }
890
890
 
@@ -926,7 +926,7 @@ class ProductList extends localize(i18next)(PageView) {
926
926
  this.dataGrist.fetch()
927
927
  }
928
928
  } catch (error) {
929
- this.showToast(error)
929
+ this.showToast(error.message)
930
930
  }
931
931
  }
932
932
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/product-ui",
3
- "version": "4.3.100",
3
+ "version": "4.3.105-alpha.0",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -24,13 +24,13 @@
24
24
  "migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
25
25
  },
26
26
  "dependencies": {
27
- "@things-factory/form-ui": "^4.3.99",
28
- "@things-factory/grist-ui": "^4.3.99",
29
- "@things-factory/i18n-base": "^4.3.99",
30
- "@things-factory/import-ui": "^4.3.99",
31
- "@things-factory/layout-base": "^4.3.99",
32
- "@things-factory/product-base": "^4.3.100",
33
- "@things-factory/shell": "^4.3.99"
27
+ "@things-factory/form-ui": "^4.3.105-alpha.0",
28
+ "@things-factory/grist-ui": "^4.3.105-alpha.0",
29
+ "@things-factory/i18n-base": "^4.3.105-alpha.0",
30
+ "@things-factory/import-ui": "^4.3.105-alpha.0",
31
+ "@things-factory/layout-base": "^4.3.105-alpha.0",
32
+ "@things-factory/product-base": "^4.3.105-alpha.0",
33
+ "@things-factory/shell": "^4.3.105-alpha.0"
34
34
  },
35
- "gitHead": "1b1d640b6e91ae9e15a158c13ff08cca19e02a83"
35
+ "gitHead": "3bf9a95c5f77324220346e5109880a171ee2a13d"
36
36
  }