@tilde-nlp/ngx-common 8.0.4 → 8.0.6

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.
@@ -670,10 +670,10 @@ class SortHelper {
670
670
  });
671
671
  }
672
672
  /**
673
- * Transforms the input array of objects by sorting them based on the specified sortingValueKey.
674
- * @param values - An array of objects to be sorted.
675
- * @param sortingValueKey - The key by which the provided values should be sorted, leave it empty if you want to sort string[].
676
- */
673
+ * Transforms the input array of objects by sorting them based on the specified sortingValueKey.
674
+ * @param values - An array of objects to be sorted.
675
+ * @param sortingValueKey - The key by which the provided values should be sorted, leave it empty if you want to sort string[].
676
+ */
677
677
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
678
678
  static sortAlphabetically(values, sortingValueKey) {
679
679
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -688,27 +688,60 @@ class SortHelper {
688
688
  return values;
689
689
  }
690
690
  /**
691
- * Sorts an array of values by a specified numeric property or by their numeric value if no property is specified.
692
- * @param values - The array of values to be sorted. Can be an array of objects or primitive numeric values.
693
- * @param sortingValueKey - The key of the numeric property in the objects to sort by.
694
- * @param desc - Flag indicating whether to sort in descending (true) or ascending (false) order.
695
- */
696
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
691
+ * Sorts an array of values by a specified numeric property or by their numeric value if no property is specified.
692
+ * @param values - The array of values to be sorted. Can be an array of objects or primitive numeric values.
693
+ * @param sortingValueKey - The key of the numeric property in the objects to sort by.
694
+ * @param desc - Flag indicating whether to sort in descending (true) or ascending (false) order.
695
+ */
697
696
  static sortByNumber(values, sortingValueKey, desc = true) {
698
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
697
+ const getValueByKey = (obj, keyPath) => {
698
+ if (!keyPath)
699
+ return Number(obj ?? 0);
700
+ const keys = keyPath.split('.');
701
+ let value = obj;
702
+ for (const key of keys) {
703
+ if (value && typeof value === 'object' && key in value) {
704
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
705
+ value = value[key];
706
+ }
707
+ }
708
+ return Number(value ?? 0);
709
+ };
699
710
  values.sort((a, b) => {
700
- const numberA = sortingValueKey ? Number(a[sortingValueKey] ?? 0) : Number(a);
701
- const numberB = sortingValueKey ? Number(b[sortingValueKey] ?? 0) : Number(b);
702
- return desc ? numberA - numberB : numberB - numberA;
711
+ const numberA = getValueByKey(a, sortingValueKey);
712
+ const numberB = getValueByKey(b, sortingValueKey);
713
+ return desc ? numberB - numberA : numberA - numberB;
703
714
  });
704
715
  return values;
705
716
  }
706
717
  /**
707
- * This method is intended to be used with sorting methods like Array.sort(). It compares two strings, a and b, against a reference substring input.
708
- * @param a - The first string to be compared.
709
- * @param b - The second string to be compared.
710
- * @param input - The reference substring used to influence the sorting order.
711
- */
718
+ * Sorts an array of values by a specified boolean property or by their boolean value if no property is specified.
719
+ * @param values - The array of values to be sorted. Can be an array of objects or primitive boolean values.
720
+ * @param sortingValueKey - The key of the boolean property in the objects to sort by.
721
+ * @param desc - Flag indicating whether to sort in descending (true) or ascending (false) order.
722
+ */
723
+ static sortByBoolean(values, sortingValueKey, desc = true) {
724
+ const getValue = (item) => {
725
+ if (sortingValueKey) {
726
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
727
+ const value = item[sortingValueKey];
728
+ return Boolean(value);
729
+ }
730
+ return Boolean(item);
731
+ };
732
+ values.sort((a, b) => {
733
+ const valA = getValue(a) ? 1 : 0;
734
+ const valB = getValue(b) ? 1 : 0;
735
+ return desc ? valB - valA : valA - valB;
736
+ });
737
+ return values;
738
+ }
739
+ /**
740
+ * This method is intended to be used with sorting methods like Array.sort(). It compares two strings, a and b, against a reference substring input.
741
+ * @param a - The first string to be compared.
742
+ * @param b - The second string to be compared.
743
+ * @param input - The reference substring used to influence the sorting order.
744
+ */
712
745
  static sortByStartingLetter(a, b, input) {
713
746
  const startsWithInputA = a.toLowerCase().startsWith(input.toLowerCase());
714
747
  const startsWithInputB = b.toLowerCase().startsWith(input.toLowerCase());
@@ -3559,10 +3592,12 @@ class FilterBarComponent {
3559
3592
  setPanelWidth(filter) {
3560
3593
  // We must save panel width, so filtering does not affect it`s size.
3561
3594
  const selectPanel = document.querySelector('.cdk-overlay-pane');
3562
- const selectPanelWidth = selectPanel.clientWidth;
3563
- const filterObj = this.settings.filters?.find((item) => item.fieldName === filter.fieldName);
3564
- filterObj.maxPanelWidth = selectPanelWidth;
3565
- selectPanel.style.minWidth = `${selectPanelWidth}px`;
3595
+ setTimeout(() => {
3596
+ const selectPanelWidth = selectPanel.clientWidth;
3597
+ const filterObj = this.settings.filters?.find((item) => item.fieldName === filter.fieldName);
3598
+ filterObj.maxPanelWidth = selectPanelWidth;
3599
+ selectPanel.style.minWidth = `${selectPanelWidth}px`;
3600
+ });
3566
3601
  }
3567
3602
  emitFilters() {
3568
3603
  this.filterBarChange.next(this.filters);