rerobe-js-orm 4.0.4 → 4.0.5

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.
@@ -43,6 +43,8 @@ class ProductFromFormState extends ProductFactory_1.default {
43
43
  brand: props.fields.brand.selectedValue,
44
44
  measurementCategory: props.fields.measurementCategory.selectedValue,
45
45
  size: props.fields.size.selectedValue,
46
+ standardSize: props.fields.standardSize.selectedValue,
47
+ internationalSize: props.fields.internationalSize.selectedValue,
46
48
  clothingSize: props.fields.clothingSize.selectedValues,
47
49
  jeanSize: props.fields.jeanSize.selectedValue,
48
50
  shoeSize: props.fields.shoeSize.selectedValue,
@@ -12,6 +12,9 @@ export default class ProductFormState extends FormState {
12
12
  taxonomy: {
13
13
  [key: string]: any;
14
14
  };
15
+ sizeTaxonomy: {
16
+ [key: string]: any;
17
+ };
15
18
  brands: string[];
16
19
  colors: string[];
17
20
  sizes: string[];
@@ -48,6 +51,10 @@ export default class ProductFormState extends FormState {
48
51
  private setProductTypesFromPassedOptions;
49
52
  private setProductStylesFromCategoryAndType;
50
53
  private setProductStylesFromPassedOptions;
54
+ private measurementCategorySelectHandler;
55
+ private setStandardSizeOptionsFromGenderAndMeasurementCategory;
56
+ private standardSizeSelectHandler;
57
+ private setInternationalSizeOptionsFromPassedOptions;
51
58
  private discountTypeChangeHandler;
52
59
  private discountValueChangeHandler;
53
60
  private calculateSalePrice;
@@ -32,6 +32,8 @@ class ProductFormState extends FormState_1.default {
32
32
  this.fields.brand = this.fieldFactory('singleSelect', 'brand', options_1.brands);
33
33
  this.fields.measurementCategory = this.fieldFactory('singleSelect', 'measurementCategory', options_1.measurementCategoryOptions);
34
34
  this.fields.size = this.fieldFactory('singleSelect', 'size', options_1.clothingSizeOptions);
35
+ this.fields.standardSize = this.fieldFactory('singleSelect', 'standardSize', options_1.clothingSizeOptions);
36
+ this.fields.internationalSize = this.fieldFactory('singleSelect', 'internationalSize', []);
35
37
  this.fields.color = this.fieldFactory('singleSelect', 'color', options_1.colors);
36
38
  this.fields.condition = this.fieldFactory('singleSelect', 'condition', options_1.conditions);
37
39
  this.fields.gender = this.fieldFactory('singleSelect', 'gender', options_1.genderOptions);
@@ -433,6 +435,88 @@ class ProductFormState extends FormState_1.default {
433
435
  }
434
436
  return options;
435
437
  }
438
+ measurementCategorySelectHandler(value) {
439
+ // Mutate measurementCategory selectedValue and valid prop
440
+ this.fields.measurementCategory.selectedValue = value;
441
+ this.fields.measurementCategory.valid = !!value;
442
+ // Update standardSize fields based on new measurementCategory value and selected gender
443
+ this.fields.standardSize.options = this.setStandardSizeOptionsFromGenderAndMeasurementCategory(value, this.fields.gender.selectedValue);
444
+ this.fields.standardSize.hidden = !value;
445
+ this.fields.standardSize.valid = false;
446
+ this.fields.standardSize.selectedValue = '';
447
+ // Reset International Sizes
448
+ this.fields.internationalSize.options = [];
449
+ this.fields.internationalSize.selectedValue = '';
450
+ this.fields.internationalSize.valid = false;
451
+ this.fields.internationalSize.hidden = !value;
452
+ }
453
+ setStandardSizeOptionsFromGenderAndMeasurementCategory(measurementCategory, genderSelected) {
454
+ let options = [
455
+ 'One Size',
456
+ 'Adjustable',
457
+ 'XS',
458
+ 'S',
459
+ 'M',
460
+ 'L',
461
+ 'XL',
462
+ 'XXL',
463
+ '3XL',
464
+ ].map((v) => ({ label: v, value: v, internationalSizes: [] }));
465
+ if (measurementCategory &&
466
+ genderSelected &&
467
+ this.opts &&
468
+ this.opts.sizeTaxonomy &&
469
+ Object.keys(this.opts.sizeTaxonomy).length > 0) {
470
+ const t = this.opts.sizeTaxonomy;
471
+ const { [genderSelected]: { [measurementCategory]: standardSizeArr = [] } = {} } = t;
472
+ options = standardSizeArr;
473
+ }
474
+ let selectedStandardSizeOptions = [];
475
+ if (this.props.standardSize) {
476
+ selectedStandardSizeOptions = [
477
+ { label: this.props.standardSize, value: this.props.standardSize, internationalSizes: [] },
478
+ ];
479
+ if (!options.map((o) => o.value).includes(this.props.standardSize)) {
480
+ options.splice(0, 0, ...selectedStandardSizeOptions);
481
+ }
482
+ }
483
+ return options;
484
+ }
485
+ standardSizeSelectHandler(value) {
486
+ // Mutate standardSize selectedValue and valid prop
487
+ this.fields.standardSize.selectedValue = value;
488
+ this.fields.standardSize.valid = !!value;
489
+ // Update internationalSizes fields based on selected value and measurementCategory selected
490
+ // and resets other props
491
+ this.fields.internationalSize.options = this.setInternationalSizeOptionsFromPassedOptions(this.fields.measurementCategory.selectedValue, value);
492
+ this.fields.internationalSize.selectedValue = '';
493
+ this.fields.internationalSize.valid = false;
494
+ this.fields.internationalSize.hidden = false;
495
+ }
496
+ setInternationalSizeOptionsFromPassedOptions(measurementCategory, standardSize) {
497
+ let options = [];
498
+ if (this.opts &&
499
+ this.opts.sizeTaxonomy &&
500
+ Object.keys(this.opts.sizeTaxonomy).length > 0 &&
501
+ measurementCategory &&
502
+ standardSize) {
503
+ const t = this.opts.sizeTaxonomy;
504
+ const genderSelected = this.fields.gender.selectedValue;
505
+ const { [genderSelected]: { [measurementCategory]: standardSizeArr = [] } = {} } = t;
506
+ const [sSize] = standardSizeArr.filter((p) => p.value === standardSize);
507
+ if (sSize) {
508
+ options = sSize.internationalSizes.map((s) => ({ label: s, value: s }));
509
+ }
510
+ }
511
+ let selectedInternationalSizeOptions = [];
512
+ if (this.props.internationalSize) {
513
+ selectedInternationalSizeOptions = [{ label: this.props.internationalSize, value: this.props.internationalSize }];
514
+ if (!options.map((o) => o.value).includes(this.props.internationalSize)) {
515
+ options.splice(0, 0, ...selectedInternationalSizeOptions);
516
+ }
517
+ }
518
+ return options;
519
+ }
436
520
  discountTypeChangeHandler(val) {
437
521
  const prevVal = this.fields.discountType.selectedValue;
438
522
  if (val === 'amount' && prevVal === 'percentage' && this.fields.discountValue.inputValue) {
@@ -562,6 +646,25 @@ class ProductFormState extends FormState_1.default {
562
646
  hidden = !this.props.productCategory;
563
647
  onChangeHandler = (val) => this.productTypeSelectHandler(val);
564
648
  }
649
+ if (fieldKey === 'measurementCategory') {
650
+ let selectedOptions = [];
651
+ if (this.props.measurementCategory) {
652
+ selectedOptions = [{ label: this.props.measurementCategory, value: this.props.measurementCategory }];
653
+ if (!options.map((o) => o.value).includes(this.props.measurementCategory)) {
654
+ options.splice(0, 0, ...selectedOptions);
655
+ }
656
+ }
657
+ onChangeHandler = (val) => this.measurementCategorySelectHandler(val);
658
+ }
659
+ if (fieldKey === 'standardSize') {
660
+ options = this.setStandardSizeOptionsFromGenderAndMeasurementCategory(this.props.measurementCategory, this.props.gender);
661
+ hidden = !(this.props.measurementCategory && this.props.standardSize);
662
+ onChangeHandler = (val) => this.standardSizeSelectHandler(val);
663
+ }
664
+ if (fieldKey === 'internationalSize') {
665
+ options = this.setInternationalSizeOptionsFromPassedOptions(this.props.measurementCategory, this.props.standardSize);
666
+ hidden = !(this.props.measurementCategory && this.props.standardSize);
667
+ }
565
668
  if (fieldKey === 'size') {
566
669
  let selectedSizeOptions = [];
567
670
  if (this.props.size) {
@@ -639,15 +742,6 @@ class ProductFormState extends FormState_1.default {
639
742
  }
640
743
  }
641
744
  }
642
- if (fieldKey === 'measurementCategory') {
643
- let selectedOptions = [];
644
- if (this.props.measurementCategory) {
645
- selectedOptions = [{ label: this.props.measurementCategory, value: this.props.measurementCategory }];
646
- if (!options.map((o) => o.value).includes(this.props.measurementCategory)) {
647
- options.splice(0, 0, ...selectedOptions);
648
- }
649
- }
650
- }
651
745
  if (fieldKey === 'primaryAgeCategory') {
652
746
  let selectedPrimaryAgeCategoryOptions = [];
653
747
  if (this.props.primaryAgeCategory) {
@@ -23,6 +23,8 @@ export default class Product extends Base {
23
23
  brand: string;
24
24
  color: string;
25
25
  size: string;
26
+ standardSize: string;
27
+ internationalSize: string;
26
28
  materialComposition: MaterialComposition;
27
29
  salePrice: string;
28
30
  isOnSale: string;
@@ -50,6 +50,8 @@ class Product extends Base_1.default {
50
50
  jeanSize: (props === null || props === void 0 ? void 0 : props.jeanSize) || '',
51
51
  shoeSize: (props === null || props === void 0 ? void 0 : props.shoeSize) || '',
52
52
  size: (props === null || props === void 0 ? void 0 : props.size) || '',
53
+ standardSize: this.utilities.sanitizeString(props === null || props === void 0 ? void 0 : props.standardSize) || '',
54
+ internationalSize: this.utilities.sanitizeString(props === null || props === void 0 ? void 0 : props.internationalSize) || '',
53
55
  measurementCategory: (props === null || props === void 0 ? void 0 : props.measurementCategory) || '',
54
56
  productCategory: (props === null || props === void 0 ? void 0 : props.productCategory) || '',
55
57
  productType: (props === null || props === void 0 ? void 0 : props.productType) || '',
@@ -290,6 +292,8 @@ class Product extends Base_1.default {
290
292
  const stagedObj = {
291
293
  brand: this.utilities.sanitizeString(this.filterAttributes.brand),
292
294
  size: this.utilities.sanitizeString(this.filterAttributes.size),
295
+ standardSize: this.utilities.sanitizeString(this.filterAttributes.standardSize),
296
+ internationalSize: this.utilities.sanitizeString(this.filterAttributes.standardSize),
293
297
  clothingSize: this.utilities.sanitzeStringArr(this.filterAttributes.clothingSize),
294
298
  jeanSize: this.utilities.sanitizeString(this.filterAttributes.jeanSize),
295
299
  shoeSize: this.utilities.sanitizeString(this.filterAttributes.shoeSize),
@@ -403,6 +407,8 @@ class Product extends Base_1.default {
403
407
  brand: this.filterAttributes.brand,
404
408
  color: this.filterAttributes.color,
405
409
  size: this.filterAttributes.size,
410
+ standardSize: this.filterAttributes.standardSize,
411
+ internationalSize: this.filterAttributes.internationalSize,
406
412
  materialComposition: this.filterAttributes.materialComposition,
407
413
  salePrice: this.consignmentAttributes.salePrice,
408
414
  isOnSale: this.consignmentAttributes.isOnSale,
@@ -629,30 +635,21 @@ class Product extends Base_1.default {
629
635
  },
630
636
  {
631
637
  facet: true,
632
- name: 'clothingSize',
633
- type: 'string[]',
634
- },
635
- {
636
- facet: true,
637
- name: 'jeanSize',
638
+ name: 'standardSize',
638
639
  type: 'string',
640
+ optional: true,
639
641
  },
640
642
  {
641
643
  facet: true,
642
- name: 'shoeSize',
644
+ name: 'internationalSize',
643
645
  type: 'string',
646
+ optional: true,
644
647
  },
645
648
  {
646
649
  facet: true,
647
650
  name: 'condition',
648
651
  type: 'string',
649
652
  },
650
- {
651
- facet: true,
652
- optional: true,
653
- name: 'featuredCollections',
654
- type: 'string[]',
655
- },
656
653
  {
657
654
  facet: true,
658
655
  optional: true,
@@ -35,6 +35,8 @@ type ProductFilterAttributes = {
35
35
  documentId: string;
36
36
  brand: string;
37
37
  size: string;
38
+ standardSize: string;
39
+ internationalSize: string;
38
40
  clothingSize: string[];
39
41
  shoeSize: string;
40
42
  jeanSize: string;
@@ -175,6 +177,8 @@ type ProductAttributesFormFields = {
175
177
  type ProductFilterAttributesFormFields = {
176
178
  brand: SingleSelectFormField<string>;
177
179
  size: SingleSelectFormField<string>;
180
+ standardSize: SingleSelectFormField<string>;
181
+ internationalSize: SingleSelectFormField<string>;
178
182
  clothingSize: MultiSelectFormField<string>;
179
183
  jeanSize: SingleSelectFormField<string>;
180
184
  shoeSize: SingleSelectFormField<string>;
@@ -258,6 +262,8 @@ type InventoryLocation = {
258
262
  type TypesenseProductObj = {
259
263
  brand: string;
260
264
  size: string;
265
+ standardSize: string;
266
+ internationalSize: string;
261
267
  clothingSize: string[];
262
268
  jeanSize: string;
263
269
  shoeSize: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rerobe-js-orm",
3
- "version": "4.0.4",
3
+ "version": "4.0.5",
4
4
  "description": "ReRobe's Javascript ORM Framework",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",