react-core-ts 2.1.36 → 2.1.37

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-core-ts",
3
- "version": "2.1.36",
3
+ "version": "2.1.37",
4
4
  "description": "React Components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,6 +12,7 @@ import { useSuggestions } from './utilities/autosuggestions';
12
12
  import { debounce } from './utilities/debounce';
13
13
  import { deepEqual } from './utilities/deepEqual';
14
14
  import { filterSuggestions } from './utilities/filterSuggestions';
15
+ import { isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
15
16
  import { Close, DropArrow, Search, Spinner } from './utilities/icons';
16
17
  import Tooltip from './utilities/tooltip';
17
18
 
@@ -283,12 +284,12 @@ const AutoComplete = forwardRef<HTMLInputElement, AutoSuggestionInputProps>(
283
284
  selectedItems: ValueProps[] | string,
284
285
  ): boolean => {
285
286
  if (Array.isArray(selectedItems)) {
286
- return selectedItems.some(
287
- (selectedItem) => selectedItem[desc] === item[desc],
287
+ return selectedItems.some((selectedItem) =>
288
+ isSelectionMatch(selectedItem, item, desc, descId),
288
289
  );
289
- } else {
290
- return item[desc] === selectedItems;
291
290
  }
291
+
292
+ return isSelectionMatchValue(item, selectedItems, desc, descId);
292
293
  };
293
294
 
294
295
  const handleLoadMore = () => {
@@ -18,7 +18,7 @@ import { deepEqual } from './utilities/deepEqual';
18
18
  import { filterSuggestions } from './utilities/filterSuggestions';
19
19
  import { AllDropArrow, DropArrow, Search, Spinner } from './utilities/icons';
20
20
  import { default as Tooltip } from './utilities/NewTooltip';
21
- import { getKeyValue, safeToLowerString } from './utilities/getKeyValue';
21
+ import { getKeyValue, isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
22
22
  import {
23
23
  clampDropdownToViewportPreferRightAlign,
24
24
  MAX_DROPDOWN_WIDTH_WITH_TABS_PX,
@@ -648,17 +648,12 @@ const AutoCompleteWithSelectedList = forwardRef<
648
648
  selectedItems: ValueProps[] | string
649
649
  ): boolean => {
650
650
  if (Array.isArray(selectedItems)) {
651
- return selectedItems.some(
652
- (selectedItem) =>
653
- getKeyValue(selectedItem, desc, 'name') === getKeyValue(item, desc, 'name') ||
654
- getKeyValue(selectedItem, descId, 'id') === getKeyValue(item, descId, 'id')
655
- );
656
- } else {
657
- return (
658
- getKeyValue(item, desc, 'name') === safeToLowerString(selectedItems) ||
659
- getKeyValue(item, descId, 'id') === safeToLowerString(selectedItems)
651
+ return selectedItems.some((selectedItem) =>
652
+ isSelectionMatch(selectedItem, item, desc, descId),
660
653
  );
661
654
  }
655
+
656
+ return isSelectionMatchValue(item, selectedItems, desc, descId);
662
657
  };
663
658
 
664
659
  const handleLoadMore = () => {
@@ -16,7 +16,7 @@ import { deepEqual } from './utilities/deepEqual';
16
16
  import { filterSuggestions } from './utilities/filterSuggestions';
17
17
  import { AllDropArrow, DropArrow, Search, Spinner, Tools } from './utilities/icons';
18
18
  import { default as Tooltip } from './utilities/NewTooltip';
19
- import { getKeyValue, safeToLowerString } from './utilities/getKeyValue';
19
+ import { getKeyValue, isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
20
20
  import {
21
21
  clampDropdownToViewportPreferRightAlign,
22
22
  MAX_DROPDOWN_WIDTH_WITH_TABS_PX,
@@ -710,17 +710,12 @@ const AutoCompleteWithTabFilter = forwardRef<
710
710
  selectedItems: ValueProps[] | string
711
711
  ): boolean => {
712
712
  if (Array.isArray(selectedItems)) {
713
- return selectedItems.some(
714
- (selectedItem) =>
715
- getKeyValue(selectedItem, desc, 'name') === getKeyValue(item, desc, 'name') ||
716
- getKeyValue(selectedItem, descId, 'id') === getKeyValue(item, descId, 'id')
717
- );
718
- } else {
719
- return (
720
- getKeyValue(item, desc, 'name') === safeToLowerString(selectedItems) ||
721
- getKeyValue(item, descId, 'id') === safeToLowerString(selectedItems)
713
+ return selectedItems.some((selectedItem) =>
714
+ isSelectionMatch(selectedItem, item, desc, descId),
722
715
  );
723
716
  }
717
+
718
+ return isSelectionMatchValue(item, selectedItems, desc, descId);
724
719
  };
725
720
 
726
721
  const handleLoadMore = () => {
@@ -10,6 +10,7 @@ import { buildTree } from './utilities/convertFlatArraytoTreeStructure';
10
10
  import { deepEqual } from './utilities/deepEqual';
11
11
  import { default as Tooltip } from './utilities/expandableTootltip';
12
12
  import { Search, Spinner } from './utilities/icons';
13
+ import { isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
13
14
 
14
15
  type ValueProps = {
15
16
  [key: string]: string;
@@ -196,14 +197,12 @@ const AutoCompleteWithTreeStructure = forwardRef<
196
197
  selectedItems: ValueProps[] | string
197
198
  ): boolean => {
198
199
  if (Array.isArray(selectedItems)) {
199
- return selectedItems.some(
200
- (selectedItem) =>
201
- selectedItem[desc] === item[desc] ||
202
- selectedItem[descId] === item[descId]
200
+ return selectedItems.some((selectedItem) =>
201
+ isSelectionMatch(selectedItem, item, desc, descId),
203
202
  );
204
- } else {
205
- return item[desc] === selectedItems;
206
203
  }
204
+
205
+ return isSelectionMatchValue(item, selectedItems, desc, descId);
207
206
  };
208
207
  useEffect(() => {
209
208
  if (!deepEqual(selectedItems, propsSeelctedItems))
@@ -19,7 +19,7 @@ import { deepEqual } from './utilities/deepEqual';
19
19
  import { default as Tooltip } from './utilities/NewTooltip';
20
20
  import { filterSuggestions } from './utilities/filterSuggestions';
21
21
  import { AllDropArrow, Search, Spinner } from './utilities/icons';
22
- import { getKeyValue, safeToLowerString } from './utilities/getKeyValue';
22
+ import { getKeyValue, isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
23
23
 
24
24
 
25
25
  type ValueProps = {
@@ -456,17 +456,12 @@ const ExpandableAutoComplete = forwardRef<
456
456
  selectedItems: ValueProps[] | string
457
457
  ): boolean => {
458
458
  if (Array.isArray(selectedItems)) {
459
- return selectedItems.some(
460
- (selectedItem) =>
461
- getKeyValue(selectedItem, desc, 'name') === getKeyValue(item, desc, 'name') ||
462
- getKeyValue(selectedItem, descId, 'id') === getKeyValue(item, descId, 'id')
463
- );
464
- } else {
465
- return (
466
- getKeyValue(item, desc, 'name') === safeToLowerString(selectedItems) ||
467
- getKeyValue(item, descId, 'id') === safeToLowerString(selectedItems)
459
+ return selectedItems.some((selectedItem) =>
460
+ isSelectionMatch(selectedItem, item, desc, descId),
468
461
  );
469
462
  }
463
+
464
+ return isSelectionMatchValue(item, selectedItems, desc, descId);
470
465
  };
471
466
 
472
467
  const handleLoadMore = () => {
@@ -17,7 +17,7 @@ import { deepEqual } from './utilities/deepEqual';
17
17
  import { filterSuggestions } from './utilities/filterSuggestions';
18
18
  import { AllDropArrow, DropArrow, Search, Spinner } from './utilities/icons';
19
19
  import { default as Tooltip } from './utilities/NewTooltip';
20
- import { getKeyValue, safeToLowerString } from './utilities/getKeyValue';
20
+ import { getKeyValue, isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
21
21
  import {
22
22
  clampDropdownToViewportPreferRightAlign,
23
23
  MAX_DROPDOWN_WIDTH_WITH_TABS_PX,
@@ -736,19 +736,11 @@ const DropdownFilterTabs = forwardRef<
736
736
  }
737
737
  }
738
738
 
739
- return (
740
- getKeyValue(selectedItem, desc, 'name') ===
741
- getKeyValue(item, desc, 'name') ||
742
- getKeyValue(selectedItem, descId, 'id') ===
743
- getKeyValue(item, descId, 'id')
744
- );
739
+ return isSelectionMatch(selectedItem, item, desc, descId);
745
740
  });
746
- } else {
747
- return (
748
- getKeyValue(item, desc, 'name') === safeToLowerString(selectedItems) ||
749
- getKeyValue(item, descId, 'id') === safeToLowerString(selectedItems)
750
- );
751
741
  }
742
+
743
+ return isSelectionMatchValue(item, selectedItems, desc, descId);
752
744
  }, [tab, currentTabId, desc, descId]);
753
745
 
754
746
  const handleLoadMore = () => {
@@ -9,6 +9,7 @@ import { debounce } from './utilities/debounce';
9
9
  import { deepEqual } from './utilities/deepEqual';
10
10
  import { default as Tooltip } from './utilities/expandableTootltip';
11
11
  import { filterSuggestions } from './utilities/filterSuggestions';
12
+ import { isSelectionMatch, isSelectionMatchValue } from './utilities/getKeyValue';
12
13
  import { DropArrow, Search, Spinner } from './utilities/icons';
13
14
 
14
15
  const AutoCompleteWithSelectedList = forwardRef<
@@ -333,12 +334,12 @@ const AutoCompleteWithSelectedList = forwardRef<
333
334
  selectedItems: ValueProps[] | string
334
335
  ): boolean => {
335
336
  if (Array.isArray(selectedItems)) {
336
- return selectedItems.some(
337
- (selectedItem) => selectedItem[desc] === item[desc]
337
+ return selectedItems.some((selectedItem) =>
338
+ isSelectionMatch(selectedItem, item, desc, descId),
338
339
  );
339
- } else {
340
- return item[desc] === selectedItems;
341
340
  }
341
+
342
+ return isSelectionMatchValue(item, selectedItems, desc, descId);
342
343
  };
343
344
 
344
345
  const handleLoadMore = () => {
@@ -11,4 +11,38 @@ export function getKeyValue(obj: any, key: any, fallbackKey: string): string {
11
11
  export function safeToLowerString(val: any): string {
12
12
  if (val === undefined || val === null) return '';
13
13
  return String(val).toLowerCase();
14
+ }
15
+
16
+ /** Match selected item to a suggestion — id when both exist, otherwise desc. */
17
+ export function isSelectionMatch(
18
+ selectedItem: any,
19
+ item: any,
20
+ desc: string,
21
+ descId: string,
22
+ ): boolean {
23
+ const selectedId = getKeyValue(selectedItem, descId, 'id');
24
+ const itemId = getKeyValue(item, descId, 'id');
25
+
26
+ if (selectedId && itemId) {
27
+ return selectedId === itemId;
28
+ }
29
+
30
+ return (
31
+ getKeyValue(selectedItem, desc, 'name') === getKeyValue(item, desc, 'name')
32
+ );
33
+ }
34
+
35
+ /** Match a suggestion to a string value (single-select input). */
36
+ export function isSelectionMatchValue(
37
+ item: any,
38
+ selectedValue: string,
39
+ desc: string,
40
+ descId: string,
41
+ ): boolean {
42
+ const normalized = safeToLowerString(selectedValue);
43
+ const itemId = getKeyValue(item, descId, 'id');
44
+ if (itemId && itemId === normalized) {
45
+ return true;
46
+ }
47
+ return getKeyValue(item, desc, 'name') === normalized;
14
48
  }