@indigina/ui-kit 1.1.614 → 1.1.615
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.
|
@@ -9531,35 +9531,46 @@ const mapGlobalSearchResult = (store, requiredPermission, dataFetcher, categoryN
|
|
|
9531
9531
|
})));
|
|
9532
9532
|
}));
|
|
9533
9533
|
};
|
|
9534
|
-
const findMatches = (obj, translatePrefix,
|
|
9535
|
-
|
|
9536
|
-
if (!search) {
|
|
9534
|
+
const findMatches = (obj, translatePrefix, searchableKeys, search, translateValueResolver) => {
|
|
9535
|
+
if (!search || !searchableKeys.length || !obj || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
9537
9536
|
return [];
|
|
9538
9537
|
}
|
|
9539
|
-
const
|
|
9540
|
-
|
|
9541
|
-
|
|
9542
|
-
|
|
9543
|
-
|
|
9544
|
-
|
|
9545
|
-
if (isMatch) {
|
|
9546
|
-
matches.push({
|
|
9547
|
-
path: currentPath,
|
|
9548
|
-
key,
|
|
9549
|
-
value: translateValueResolver?.(key, value) ?? value,
|
|
9550
|
-
translateKey: `${translatePrefix}${currentPath}`,
|
|
9551
|
-
});
|
|
9552
|
-
}
|
|
9553
|
-
traverse(value, currentPath);
|
|
9554
|
-
}
|
|
9538
|
+
const isStringArray = (value) => Array.isArray(value) && value.every(item => typeof item === 'string');
|
|
9539
|
+
const isRecord = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
9540
|
+
const getPathKey = (path) => path.split('.').pop() || path;
|
|
9541
|
+
const normalizedSearch = search.toLowerCase();
|
|
9542
|
+
const getValueByPath = (value, path) => {
|
|
9543
|
+
return path.split('.').reduce((current, segment) => isRecord(current) ? current[segment] : undefined, value);
|
|
9555
9544
|
};
|
|
9556
|
-
const
|
|
9557
|
-
if (
|
|
9558
|
-
|
|
9545
|
+
const getMatchValue = (value) => {
|
|
9546
|
+
if (typeof value === 'string') {
|
|
9547
|
+
return value.toLowerCase().includes(normalizedSearch)
|
|
9548
|
+
? { matchedValue: value, resolverValue: value }
|
|
9549
|
+
: null;
|
|
9550
|
+
}
|
|
9551
|
+
if (isStringArray(value)) {
|
|
9552
|
+
const matchedItems = value.filter(item => item.toLowerCase().includes(normalizedSearch));
|
|
9553
|
+
if (!matchedItems.length) {
|
|
9554
|
+
return null;
|
|
9555
|
+
}
|
|
9556
|
+
return { matchedValue: matchedItems.join(', '), resolverValue: matchedItems };
|
|
9559
9557
|
}
|
|
9558
|
+
return null;
|
|
9560
9559
|
};
|
|
9561
|
-
|
|
9562
|
-
|
|
9560
|
+
return Array.from(new Set(searchableKeys)).reduce((matches, path) => {
|
|
9561
|
+
const matchValue = getMatchValue(getValueByPath(obj, path));
|
|
9562
|
+
if (!matchValue) {
|
|
9563
|
+
return matches;
|
|
9564
|
+
}
|
|
9565
|
+
const key = getPathKey(path);
|
|
9566
|
+
matches.push({
|
|
9567
|
+
path,
|
|
9568
|
+
key,
|
|
9569
|
+
value: translateValueResolver?.(key, matchValue.resolverValue) ?? matchValue.matchedValue,
|
|
9570
|
+
translateKey: `${translatePrefix}${path}`,
|
|
9571
|
+
});
|
|
9572
|
+
return matches;
|
|
9573
|
+
}, []);
|
|
9563
9574
|
};
|
|
9564
9575
|
const changeFilterField = (filter, field) => ({
|
|
9565
9576
|
...filter,
|