rerobe-js-orm 2.4.90 → 2.4.91

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/README.md CHANGED
@@ -1 +1 @@
1
- #ReRobe Product
1
+ #Ribbn and ReRobe ORM
@@ -9,6 +9,9 @@ export default class ProductFormState extends FormState {
9
9
  value: string;
10
10
  }[];
11
11
  tags: string[];
12
+ taxonomy: {
13
+ [key: string]: any;
14
+ };
12
15
  };
13
16
  constructor(props?: any, opts?: any);
14
17
  autoCreateTitle(): string;
@@ -20,8 +23,11 @@ export default class ProductFormState extends FormState {
20
23
  private productCategorySelectHandler;
21
24
  private productTypeSelectHandler;
22
25
  private setPriceRangeFromPrice;
26
+ private setProductCategoreisFromGender;
23
27
  private setProductTypesFromCategory;
28
+ private setProductTypesFromPassedOptions;
24
29
  private setProductStylesFromCategoryAndType;
30
+ private setProductStylesFromPassedOptions;
25
31
  private discountTypeChangeHandler;
26
32
  private discountValueChangeHandler;
27
33
  private calculateSalePrice;
@@ -101,11 +101,12 @@ class ProductFormState extends FormState_1.default {
101
101
  this.fields.gender.selectedValue = value;
102
102
  this.fields.gender.valid = !!value;
103
103
  // Reset productCategory fields except options
104
+ this.fields.productCategory.options = this.setProductCategoreisFromGender(value);
104
105
  this.fields.productCategory.hidden = true;
105
106
  this.fields.productCategory.valid = false;
106
107
  this.fields.productCategory.selectedValue = '';
107
108
  // Resets productType fields
108
- this.fields.productType.options = this.setProductTypesFromCategory(this.fields.productCategory.selectedValue, value);
109
+ this.fields.productType.options = this.setProductTypesFromPassedOptions(this.fields.productCategory.selectedValue, value);
109
110
  this.fields.productType.hidden = true;
110
111
  this.fields.productType.selectedValue = '';
111
112
  this.fields.productType.valid = false;
@@ -220,7 +221,7 @@ class ProductFormState extends FormState_1.default {
220
221
  this.fields.productCategory.selectedValue = value;
221
222
  this.fields.productCategory.valid = !!value;
222
223
  // Update Product Type options based on new category value and selected gender
223
- this.fields.productType.options = this.setProductTypesFromCategory(value, this.fields.gender.selectedValue);
224
+ this.fields.productType.options = this.setProductTypesFromPassedOptions(value, this.fields.gender.selectedValue);
224
225
  this.fields.productType.hidden = !value;
225
226
  this.fields.productType.valid = false;
226
227
  this.fields.productType.selectedValue = '';
@@ -248,7 +249,7 @@ class ProductFormState extends FormState_1.default {
248
249
  this.fields.productType.valid = !!value;
249
250
  // Update productStyle options based on selected value and productCategory selected
250
251
  // and resets other props
251
- this.fields.productStyle.options = this.setProductStylesFromCategoryAndType(this.fields.productCategory.selectedValue, value);
252
+ this.fields.productStyle.options = this.setProductStylesFromPassedOptions(this.fields.productCategory.selectedValue, value);
252
253
  this.fields.productStyle.selectedValues = [];
253
254
  this.fields.productStyle.valid = false;
254
255
  this.fields.productStyle.hidden = !value;
@@ -274,6 +275,20 @@ class ProductFormState extends FormState_1.default {
274
275
  }
275
276
  return '1000+ SEK';
276
277
  }
278
+ setProductCategoreisFromGender(genderSelected) {
279
+ let productCategoryOptions = [];
280
+ if (this.opts && this.opts.taxonomy && Object.keys(this.opts.taxonomy).length > 0 && genderSelected) {
281
+ const t = this.opts.taxonomy;
282
+ const { [genderSelected]: genderObj = {} } = t;
283
+ productCategoryOptions = Object.keys(genderObj).map((k) => ({ label: k, value: k }));
284
+ }
285
+ else {
286
+ productCategoryOptions = options_1.productCategories;
287
+ }
288
+ const selectedCategoryOptions = this.props.productCategory ? [{ label: this.props.productCategory, value: this.props.productCategory }] : [];
289
+ const options = this.utilities.uniqObjArray([...productCategoryOptions, ...selectedCategoryOptions], 'value');
290
+ return options;
291
+ }
277
292
  setProductTypesFromCategory(productCategory, genderSelected) {
278
293
  switch (productCategory) {
279
294
  case 'Clothing':
@@ -320,6 +335,18 @@ class ProductFormState extends FormState_1.default {
320
335
  return [];
321
336
  }
322
337
  }
338
+ setProductTypesFromPassedOptions(productCategory, genderSelected) {
339
+ if (productCategory &&
340
+ genderSelected &&
341
+ this.opts &&
342
+ this.opts.taxonomy &&
343
+ Object.keys(this.opts.taxonomy).length > 0) {
344
+ const t = this.opts.taxonomy;
345
+ const { [genderSelected]: { [productCategory]: productTypeArr = [] } = {} } = t;
346
+ return productTypeArr;
347
+ }
348
+ return this.setProductTypesFromCategory(productCategory, genderSelected);
349
+ }
323
350
  setProductStylesFromCategoryAndType(productCategory, productType) {
324
351
  switch (productCategory) {
325
352
  case 'Clothing':
@@ -381,6 +408,23 @@ class ProductFormState extends FormState_1.default {
381
408
  return [];
382
409
  }
383
410
  }
411
+ setProductStylesFromPassedOptions(productCategory, productType) {
412
+ if (this.opts &&
413
+ this.opts.taxonomy &&
414
+ Object.keys(this.opts.taxonomy).length > 0 &&
415
+ productCategory &&
416
+ productType) {
417
+ const t = this.opts.taxonomy;
418
+ const genderSelected = this.fields.gender.selectedValue;
419
+ const { [genderSelected]: { [productCategory]: productTypeArr = [] } = {} } = t;
420
+ const [pType] = productTypeArr.filter((p) => p.value === productType);
421
+ if (pType) {
422
+ return pType.styles.map((s) => ({ label: s, value: s }));
423
+ }
424
+ return [];
425
+ }
426
+ return this.setProductStylesFromCategoryAndType(productCategory, productType);
427
+ }
384
428
  discountTypeChangeHandler(val) {
385
429
  const prevVal = this.fields.discountType.selectedValue;
386
430
  if (val === 'amount' && prevVal === 'percentage' && this.fields.discountValue.inputValue) {
@@ -473,10 +517,11 @@ class ProductFormState extends FormState_1.default {
473
517
  onChangeHandler = (val) => this.genderSelectHandler(val);
474
518
  }
475
519
  if (fieldKey === 'productCategory') {
520
+ options = this.setProductCategoreisFromGender(this.props.gender);
476
521
  onChangeHandler = (val) => this.productCategorySelectHandler(val);
477
522
  }
478
523
  if (fieldKey === 'productType') {
479
- options = this.setProductTypesFromCategory(this.props.productCategory, this.props.gender);
524
+ options = this.setProductTypesFromPassedOptions(this.props.productCategory, this.props.gender);
480
525
  hidden = !this.props.productCategory;
481
526
  onChangeHandler = (val) => this.productTypeSelectHandler(val);
482
527
  }
@@ -524,7 +569,7 @@ class ProductFormState extends FormState_1.default {
524
569
  if (fieldType === 'multiSelect') {
525
570
  let onChangeHandler = (val) => this.multiSelectChangeHandler(fieldKey, val);
526
571
  if (fieldKey === 'productStyle') {
527
- options = this.setProductStylesFromCategoryAndType(this.props.productCategory, this.props.productType);
572
+ options = this.setProductStylesFromPassedOptions(this.props.productCategory, this.props.productType);
528
573
  if (this.props.productStyle && this.props.productStyle.length > 0) {
529
574
  this.props.productStyle.forEach((productStyle) => {
530
575
  if (!options.map((o) => o.value).includes(productStyle)) {
@@ -1672,14 +1672,26 @@ const gender = [
1672
1672
  label: 'Woman',
1673
1673
  value: 'Woman',
1674
1674
  },
1675
+ {
1676
+ label: 'Girl',
1677
+ value: 'Girl',
1678
+ },
1675
1679
  {
1676
1680
  label: 'Man',
1677
1681
  value: 'Man',
1678
1682
  },
1683
+ {
1684
+ label: 'Boy',
1685
+ value: 'Boy',
1686
+ },
1679
1687
  {
1680
1688
  label: 'Unisex',
1681
1689
  value: 'Unisex',
1682
1690
  },
1691
+ {
1692
+ label: 'NA',
1693
+ value: 'NA',
1694
+ },
1683
1695
  ];
1684
1696
  exports.gender = gender;
1685
1697
  const jeanSizes = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "2.4.90",
3
+ "version": "2.4.91",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",