@indigina/ui-kit 1.1.468 → 1.1.469
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.
|
@@ -10665,7 +10665,7 @@ class KitFilterCheckboxComponent {
|
|
|
10665
10665
|
ngOnInit() {
|
|
10666
10666
|
this.initializeSelectedValues();
|
|
10667
10667
|
this.updateItemsState();
|
|
10668
|
-
if (this.showPopupOnInit() && !this.
|
|
10668
|
+
if (this.showPopupOnInit() && !this.filter().value) {
|
|
10669
10669
|
requestAnimationFrame(() => this.onPopupToggle());
|
|
10670
10670
|
}
|
|
10671
10671
|
}
|
|
@@ -10689,17 +10689,10 @@ class KitFilterCheckboxComponent {
|
|
|
10689
10689
|
})));
|
|
10690
10690
|
}
|
|
10691
10691
|
applyFilter() {
|
|
10692
|
-
const
|
|
10693
|
-
const
|
|
10694
|
-
|
|
10695
|
-
|
|
10696
|
-
field: (this.filter().type === KitFilterType.GUID && this.guidField()) || this.filter().field,
|
|
10697
|
-
operator: KitFilterOperator.EQ,
|
|
10698
|
-
value,
|
|
10699
|
-
})),
|
|
10700
|
-
};
|
|
10701
|
-
this.filterChanged.emit(checked);
|
|
10702
|
-
this.selectedValues.set(this.checkedItems);
|
|
10692
|
+
const checkedItems = this.checkedItems;
|
|
10693
|
+
const filterValue = this.buildFilterValue(checkedItems);
|
|
10694
|
+
this.filterChanged.emit(filterValue);
|
|
10695
|
+
this.selectedValues.set(checkedItems);
|
|
10703
10696
|
}
|
|
10704
10697
|
onPopupToggle() {
|
|
10705
10698
|
requestAnimationFrame(() => this.popup()?.toggle());
|
|
@@ -10727,11 +10720,76 @@ class KitFilterCheckboxComponent {
|
|
|
10727
10720
|
checked: values.includes(item.value) ? isChecked : item.checked,
|
|
10728
10721
|
})));
|
|
10729
10722
|
}
|
|
10723
|
+
buildFilterValue(checkedItems) {
|
|
10724
|
+
const field = (this.filter().type === KitFilterType.GUID && this.guidField()) || this.filter().field;
|
|
10725
|
+
const allItems = this.items();
|
|
10726
|
+
const totalCount = allItems.length;
|
|
10727
|
+
const checkedCount = checkedItems.length;
|
|
10728
|
+
if (checkedCount === totalCount) {
|
|
10729
|
+
return this.buildIsNotNullFilter(field);
|
|
10730
|
+
}
|
|
10731
|
+
if (checkedCount > totalCount / 2) {
|
|
10732
|
+
const uncheckedValues = allItems.filter(item => !item.checked).map(item => item.value);
|
|
10733
|
+
return this.buildNeqFilter(field, uncheckedValues);
|
|
10734
|
+
}
|
|
10735
|
+
return this.buildEqFilter(field, checkedItems);
|
|
10736
|
+
}
|
|
10737
|
+
buildIsNotNullFilter(field) {
|
|
10738
|
+
return {
|
|
10739
|
+
logic: KitFilterLogic.AND,
|
|
10740
|
+
filters: [{ field, operator: KitFilterOperator.IS_NOT_NULL, value: null }],
|
|
10741
|
+
};
|
|
10742
|
+
}
|
|
10743
|
+
buildNeqFilter(field, uncheckedValues) {
|
|
10744
|
+
return {
|
|
10745
|
+
logic: KitFilterLogic.AND,
|
|
10746
|
+
filters: [
|
|
10747
|
+
{ field, operator: KitFilterOperator.IS_NOT_NULL, value: null },
|
|
10748
|
+
...uncheckedValues.map(value => ({ field, operator: KitFilterOperator.NEQ, value })),
|
|
10749
|
+
],
|
|
10750
|
+
};
|
|
10751
|
+
}
|
|
10752
|
+
buildEqFilter(field, checkedItems) {
|
|
10753
|
+
return {
|
|
10754
|
+
logic: KitFilterLogic.OR,
|
|
10755
|
+
filters: checkedItems.map(item => ({ field, operator: KitFilterOperator.EQ, value: item.value })),
|
|
10756
|
+
};
|
|
10757
|
+
}
|
|
10730
10758
|
initializeSelectedValues() {
|
|
10731
|
-
this.
|
|
10759
|
+
const filterValue = this.filter().value;
|
|
10760
|
+
if (!filterValue?.filters.length) {
|
|
10761
|
+
this.selectedValues.set([]);
|
|
10762
|
+
return;
|
|
10763
|
+
}
|
|
10764
|
+
const isNotNullOnly = filterValue.filters.length === 1
|
|
10765
|
+
&& filterValue.filters[0].operator === KitFilterOperator.IS_NOT_NULL;
|
|
10766
|
+
const hasNeq = filterValue.filters.some(f => f.operator === KitFilterOperator.NEQ);
|
|
10767
|
+
if (isNotNullOnly) {
|
|
10768
|
+
this.selectedValues.set(this.allItemsAsSelected());
|
|
10769
|
+
}
|
|
10770
|
+
else if (hasNeq) {
|
|
10771
|
+
this.selectedValues.set(this.itemsExcluding(filterValue.filters));
|
|
10772
|
+
}
|
|
10773
|
+
else {
|
|
10774
|
+
this.selectedValues.set(this.itemsFromEqFilters(filterValue.filters));
|
|
10775
|
+
}
|
|
10776
|
+
}
|
|
10777
|
+
allItemsAsSelected() {
|
|
10778
|
+
return this.items().map(item => ({ title: item.title, value: item.value }));
|
|
10779
|
+
}
|
|
10780
|
+
itemsExcluding(filters) {
|
|
10781
|
+
const excludedValues = new Set(filters
|
|
10782
|
+
.filter(f => f.operator === KitFilterOperator.NEQ)
|
|
10783
|
+
.map(f => f.value));
|
|
10784
|
+
return this.items()
|
|
10785
|
+
.filter(item => !excludedValues.has(item.value))
|
|
10786
|
+
.map(item => ({ title: item.title, value: item.value }));
|
|
10787
|
+
}
|
|
10788
|
+
itemsFromEqFilters(filters) {
|
|
10789
|
+
return filters.map(filter => ({
|
|
10732
10790
|
title: this.items().find(item => item.value === filter.value)?.title ?? filter.value,
|
|
10733
10791
|
value: filter.value,
|
|
10734
|
-
}))
|
|
10792
|
+
}));
|
|
10735
10793
|
}
|
|
10736
10794
|
updateItemsState() {
|
|
10737
10795
|
this.items.update(items => items.map(item => ({
|