@firestitch/filter 13.4.0 → 13.4.1

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.
@@ -521,85 +521,6 @@ function getRangeName(configCase, name, range) {
521
521
  }
522
522
  }
523
523
 
524
- class RangeItem extends BaseItem {
525
- static create(config, additionalConfig, filter) {
526
- return new RangeItem(config, additionalConfig, filter);
527
- }
528
- get value() {
529
- let value = clone(this.model);
530
- if (!isObject(this.model) ||
531
- (isEmpty(this.model.max, { zero: true }) && isEmpty(this.model.min, { zero: true }))) {
532
- value = undefined;
533
- }
534
- return value;
535
- }
536
- get queryObject() {
537
- const value = this.value;
538
- const name = this.name;
539
- const params = {};
540
- const paramMinName = getRangeName(this.case, name, 'min');
541
- const paramMaxName = getRangeName(this.case, name, 'max');
542
- if (isObject(value)) {
543
- params[paramMinName] = value.min || undefined;
544
- params[paramMaxName] = value.max || undefined;
545
- }
546
- else {
547
- params[paramMinName] = undefined;
548
- params[paramMaxName] = undefined;
549
- }
550
- return params;
551
- }
552
- get isChipVisible() {
553
- return this.model && (this.model.min !== undefined || this.model.max !== undefined);
554
- }
555
- getChipsContent(type) {
556
- if (type === 'from') {
557
- const min = this.model.min;
558
- return `${min}`;
559
- }
560
- else if (type === 'to') {
561
- const max = this.model.max;
562
- return `${max}`;
563
- }
564
- }
565
- clearRange(type = null, defaultValue = undefined) {
566
- if (type === 'from') {
567
- delete this.model.min;
568
- if (defaultValue?.min) {
569
- this.model.min = defaultValue.min;
570
- }
571
- this.model = { ...this.model };
572
- }
573
- else if (type === 'to') {
574
- delete this.model.max;
575
- if (defaultValue?.max) {
576
- this.model.max = defaultValue.max;
577
- }
578
- this.model = { ...this.model };
579
- }
580
- else {
581
- this.model = defaultValue ? { ...defaultValue } : {};
582
- }
583
- }
584
- _validateModel() {
585
- }
586
- _parseConfig(item) {
587
- this.options = item.options;
588
- this.prefix = item.prefix;
589
- this.suffix = item.suffix;
590
- this.case = this._additionalConfig?.case ?? 'camel';
591
- super._parseConfig(item);
592
- }
593
- _init() {
594
- if (!this.label) {
595
- this.label = ['Min', 'Max'];
596
- }
597
- if (!this.model) {
598
- this.model = this.defaultValue || {};
599
- }
600
- }
601
- }
602
-
603
524
  class BaseDateRangeItem extends BaseItem {
604
525
  get isTypeDateRange() {
605
526
  return this.type === ItemType.DateRange;
@@ -740,82 +661,83 @@ class DateTimeRangeItem extends BaseDateRangeItem {
740
661
  }
741
662
  }
742
663
 
743
- function parseItemValueFromStored(item, params, paramCase) {
744
- const param = params[item.name];
745
- switch (item.type) {
746
- case ItemType.Range: {
747
- const min = params[getRangeName(paramCase, item.name, 'min')];
748
- const max = params[getRangeName(paramCase, item.name, 'max')];
749
- return { min: min, max: max };
664
+ class RangeItem extends BaseItem {
665
+ static create(config, additionalConfig, filter) {
666
+ return new RangeItem(config, additionalConfig, filter);
667
+ }
668
+ get value() {
669
+ let value = clone(this.model);
670
+ if (!isObject(this.model) ||
671
+ (isEmpty(this.model.max, { zero: true }) && isEmpty(this.model.min, { zero: true }))) {
672
+ value = undefined;
750
673
  }
751
- case ItemType.DateRange:
752
- case ItemType.DateTimeRange: {
753
- const from = params[getRangeName(item.case, item.name, 'from')];
754
- const to = params[getRangeName(item.case, item.name, 'to')];
755
- return { from: from, to: to };
674
+ return value;
675
+ }
676
+ get queryObject() {
677
+ const value = this.value;
678
+ const name = this.name;
679
+ const params = {};
680
+ const paramMinName = getRangeName(this.case, name, 'min');
681
+ const paramMaxName = getRangeName(this.case, name, 'max');
682
+ if (isObject(value)) {
683
+ params[paramMinName] = value.min || undefined;
684
+ params[paramMaxName] = value.max || undefined;
756
685
  }
757
- case ItemType.Week: {
758
- const from = params[getRangeName('camel', item.name, 'from')];
759
- const to = params[getRangeName('camel', item.name, 'to')];
760
- const period = params[`${item.name}Period`];
761
- return { from, to, period };
686
+ else {
687
+ params[paramMinName] = undefined;
688
+ params[paramMaxName] = undefined;
762
689
  }
763
- case ItemType.Select: {
764
- if (item.multiple && !!param) {
765
- const values = param.split(',');
766
- if (item.isolate) {
767
- const isolatedValue = Array.isArray(item.isolate.value)
768
- ? item.isolate.value
769
- : [item.isolate.value];
770
- item.isolate.enabled = arraysHaveSameElements(isolatedValue, values);
771
- return item.isolate.enabled
772
- ? isolatedValue
773
- : values;
774
- }
775
- return values;
776
- }
777
- else {
778
- return param;
779
- }
690
+ return params;
691
+ }
692
+ get isChipVisible() {
693
+ return this.model && (this.model.min !== undefined || this.model.max !== undefined);
694
+ }
695
+ getChipsContent(type) {
696
+ if (type === 'from') {
697
+ const min = this.model.min;
698
+ return `${min}`;
780
699
  }
781
- case ItemType.Checkbox: {
782
- if (param === 'true') {
783
- return true === item.checked;
700
+ else if (type === 'to') {
701
+ const max = this.model.max;
702
+ return `${max}`;
703
+ }
704
+ }
705
+ clearRange(type = null, defaultValue = undefined) {
706
+ if (type === 'from') {
707
+ delete this.model.min;
708
+ if (defaultValue?.min) {
709
+ this.model.min = defaultValue.min;
784
710
  }
785
- else {
786
- return param === item.checked;
711
+ this.model = { ...this.model };
712
+ }
713
+ else if (type === 'to') {
714
+ delete this.model.max;
715
+ if (defaultValue?.max) {
716
+ this.model.max = defaultValue.max;
787
717
  }
718
+ this.model = { ...this.model };
788
719
  }
789
- case ItemType.AutoComplete: {
790
- const filterParts = filterFromQueryParam(param);
791
- return {
792
- name: filterParts[1],
793
- value: filterParts[0]
794
- };
720
+ else {
721
+ this.model = defaultValue ? { ...defaultValue } : {};
795
722
  }
796
- case ItemType.AutoCompleteChips:
797
- case ItemType.Chips: {
798
- const filterParts = param.split(',');
799
- return filterParts.reduce((arry, value) => {
800
- const chipParts = filterFromQueryParam(value);
801
- arry.push({
802
- name: chipParts[1],
803
- value: chipParts[0],
804
- });
805
- return arry;
806
- }, []);
723
+ }
724
+ _validateModel() {
725
+ }
726
+ _parseConfig(item) {
727
+ this.options = item.options;
728
+ this.prefix = item.prefix;
729
+ this.suffix = item.suffix;
730
+ this.case = this._additionalConfig?.case ?? 'camel';
731
+ super._parseConfig(item);
732
+ }
733
+ _init() {
734
+ if (!this.label) {
735
+ this.label = ['Min', 'Max'];
807
736
  }
808
- default: {
809
- return param;
737
+ if (!this.model) {
738
+ this.model = this.defaultValue || {};
810
739
  }
811
740
  }
812
- }
813
- function arraysHaveSameElements(arr1, arr2) {
814
- arr1 = [...arr1].sort();
815
- arr2 = [...arr2].sort();
816
- return arr1.some((item) => {
817
- return arr2.includes(item);
818
- });
819
741
  }
820
742
 
821
743
  function parseDate(value) {
@@ -911,6 +833,84 @@ class WeekItem extends BaseItem {
911
833
  }
912
834
  }
913
835
 
836
+ function parseItemValueFromStored(item, params, paramCase) {
837
+ const param = params[item.name];
838
+ switch (item.type) {
839
+ case ItemType.Range: {
840
+ const min = params[getRangeName(paramCase, item.name, 'min')];
841
+ const max = params[getRangeName(paramCase, item.name, 'max')];
842
+ return { min: min, max: max };
843
+ }
844
+ case ItemType.DateRange:
845
+ case ItemType.DateTimeRange: {
846
+ const from = params[getRangeName(item.case, item.name, 'from')];
847
+ const to = params[getRangeName(item.case, item.name, 'to')];
848
+ return { from: from, to: to };
849
+ }
850
+ case ItemType.Week: {
851
+ const from = params[getRangeName('camel', item.name, 'from')];
852
+ const to = params[getRangeName('camel', item.name, 'to')];
853
+ const period = params[`${item.name}Period`];
854
+ return { from, to, period };
855
+ }
856
+ case ItemType.Select: {
857
+ if (item.multiple && !!param) {
858
+ const values = param.split(',');
859
+ if (item.isolate) {
860
+ const isolatedValue = Array.isArray(item.isolate.value)
861
+ ? item.isolate.value
862
+ : [item.isolate.value];
863
+ item.isolate.enabled = arraysHaveSameElements(isolatedValue, values);
864
+ return item.isolate.enabled
865
+ ? isolatedValue
866
+ : values;
867
+ }
868
+ return values;
869
+ }
870
+ else {
871
+ return param;
872
+ }
873
+ }
874
+ case ItemType.Checkbox: {
875
+ if (param === 'true') {
876
+ return true === item.checked;
877
+ }
878
+ else {
879
+ return param === item.checked;
880
+ }
881
+ }
882
+ case ItemType.AutoComplete: {
883
+ const filterParts = filterFromQueryParam(param);
884
+ return {
885
+ name: filterParts[1],
886
+ value: filterParts[0]
887
+ };
888
+ }
889
+ case ItemType.AutoCompleteChips:
890
+ case ItemType.Chips: {
891
+ const filterParts = param.split(',');
892
+ return filterParts.reduce((arry, value) => {
893
+ const chipParts = filterFromQueryParam(value);
894
+ arry.push({
895
+ name: chipParts[1],
896
+ value: chipParts[0],
897
+ });
898
+ return arry;
899
+ }, []);
900
+ }
901
+ default: {
902
+ return param;
903
+ }
904
+ }
905
+ }
906
+ function arraysHaveSameElements(arr1, arr2) {
907
+ arr1 = [...arr1].sort();
908
+ arr2 = [...arr2].sort();
909
+ return arr1.some((item) => {
910
+ return arr2.includes(item);
911
+ });
912
+ }
913
+
914
914
  /**
915
915
  * We need this function because when we store persisted/query/remote filter values
916
916
  * it stores with different format, ex.: Range will be stored as RangeFrom && RangeTo
@@ -1551,6 +1551,9 @@ class FsFilterItemsStore {
1551
1551
  get items() {
1552
1552
  return this._items;
1553
1553
  }
1554
+ get itemNames() {
1555
+ return this._items.map((item) => item.name);
1556
+ }
1554
1557
  get visibleItems() {
1555
1558
  return this._visibleItems$.getValue();
1556
1559
  }
@@ -2158,15 +2161,32 @@ class ExternalParamsController {
2158
2161
  this._destroy$ = new Subject();
2159
2162
  }
2160
2163
  get params() {
2161
- const result = {};
2164
+ let result = {};
2162
2165
  if (this._persistanceStore.enabled) {
2163
- Object.assign(result, this._persistanceStore.value?.data);
2166
+ result = {
2167
+ ...result,
2168
+ ...this._persistanceStore.value?.data,
2169
+ };
2164
2170
  }
2165
2171
  if (this._savedFilters.enabled && this._savedFilters.activeFilter) {
2166
- Object.assign(result, this._savedFilters.activeFilterData);
2172
+ const query = Object.keys(result)
2173
+ .filter((key) => !this._itemsStore.itemNames.includes(key))
2174
+ .reduce((acc, key) => {
2175
+ return {
2176
+ ...acc,
2177
+ [key]: result[key],
2178
+ };
2179
+ }, {});
2180
+ result = {
2181
+ ...query,
2182
+ ...this._savedFilters.activeFilterData,
2183
+ };
2167
2184
  }
2168
- if (this._queryParams.enabled) {
2169
- Object.assign(result, this._queryParams.fetchedParams);
2185
+ else if (this._queryParams.enabled) {
2186
+ result = {
2187
+ ...result,
2188
+ ...this._queryParams.fetchedParams,
2189
+ };
2170
2190
  }
2171
2191
  return result;
2172
2192
  }