feat: Enhance community search logic in CommunityAutocomplete by adding detailed logging and refining matching criteria for improved accuracy in filtering, including handling of baseAS and colon-separated values.
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m55s
Publish Fast Tabler Docker image / build-and-push-fast (push) Successful in 1m55s
This commit is contained in:
@@ -82,6 +82,10 @@ function CommunityAutocomplete({ label, value, onChange, communities = [], requi
|
||||
setInputValue(value || '');
|
||||
}, [value]);
|
||||
|
||||
useEffect(() => {
|
||||
console.log('[CommunityAutocomplete] baseAS:', baseAS, 'communities:', communities.length);
|
||||
}, [baseAS, communities]);
|
||||
|
||||
// Фильтруем communities по введённому тексту
|
||||
const filteredCommunities = communities.filter(c => {
|
||||
const search = inputValue.toLowerCase().trim();
|
||||
@@ -89,47 +93,53 @@ function CommunityAutocomplete({ label, value, onChange, communities = [], requi
|
||||
|
||||
const cValue = (c.value || '').toLowerCase();
|
||||
|
||||
// Нормализуем значение из справочника с учётом baseAS
|
||||
// Если в справочнике просто число (например "120"), считаем его как "baseAS:120"
|
||||
const normalizedCValue = cValue.includes(':') ? cValue : `${baseAS}:${cValue}`;
|
||||
|
||||
// Нормализуем поисковый запрос
|
||||
// Если введено просто число, считаем его как "baseAS:число"
|
||||
const normalizedSearch = search.includes(':') ? search : `${baseAS}:${search}`;
|
||||
|
||||
// Поиск по полному значению (с нормализацией)
|
||||
if (normalizedCValue.includes(search)) return true;
|
||||
if (cValue.includes(search)) return true;
|
||||
|
||||
// Поиск нормализованного значения
|
||||
if (normalizedCValue === normalizedSearch) return true;
|
||||
if (normalizedCValue.includes(normalizedSearch)) return true;
|
||||
|
||||
// Поиск по части после двоеточия (например, "120" найдёт "65001:120")
|
||||
if (cValue.includes(':')) {
|
||||
const parts = cValue.split(':');
|
||||
if (parts[1] && parts[1].includes(search)) return true;
|
||||
if (parts[0] && parts[0].includes(search)) return true;
|
||||
// Отладка первых 3 элементов
|
||||
if (communities.indexOf(c) < 3 && inputValue) {
|
||||
console.log(`[Filter] search="${search}", cValue="${cValue}", baseAS="${baseAS}"`);
|
||||
}
|
||||
|
||||
// Обратный поиск: "65001:120" найдёт "120" в справочнике
|
||||
if (search.includes(':')) {
|
||||
const searchParts = search.split(':');
|
||||
// Если в справочнике просто число, проверяем совпадение с частью после двоеточия
|
||||
if (searchParts[1] && cValue === searchParts[1]) return true;
|
||||
// Также проверяем частичное совпадение
|
||||
if (searchParts[1] && cValue.includes(searchParts[1])) return true;
|
||||
}
|
||||
|
||||
// Поиск просто по числу без AS
|
||||
if (!search.includes(':') && !cValue.includes(':')) {
|
||||
if (cValue.includes(search)) return true;
|
||||
}
|
||||
|
||||
// Поиск по названию и описанию
|
||||
// 1. Поиск по названию и описанию
|
||||
if (c.name && c.name.toLowerCase().includes(search)) return true;
|
||||
if (c.description && c.description.toLowerCase().includes(search)) return true;
|
||||
|
||||
// 2. Прямое совпадение по значению
|
||||
if (cValue === search) return true;
|
||||
if (cValue.includes(search)) return true;
|
||||
|
||||
// 3. Если ввели "65001:120", ищем "120" в справочнике
|
||||
if (search.includes(':')) {
|
||||
const searchParts = search.split(':');
|
||||
const searchAS = searchParts[0];
|
||||
const searchNum = searchParts[1];
|
||||
|
||||
// Точное совпадение числовой части
|
||||
if (searchNum && cValue === searchNum) return true;
|
||||
|
||||
// Если в справочнике тоже формат AS:NUM, сравниваем части
|
||||
if (cValue.includes(':')) {
|
||||
const cParts = cValue.split(':');
|
||||
if (cParts[1] === searchNum) return true;
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Если ввели "120", ищем и "120" и "65001:120"
|
||||
if (!search.includes(':')) {
|
||||
// Ищем как просто число
|
||||
if (cValue === search) return true;
|
||||
|
||||
// Ищем в формате AS:NUM
|
||||
if (cValue.includes(':')) {
|
||||
const cParts = cValue.split(':');
|
||||
if (cParts[1] && cParts[1].includes(search)) return true;
|
||||
if (cParts[0] && cParts[0].includes(search)) return true;
|
||||
}
|
||||
|
||||
// Также ищем с baseAS
|
||||
const withBaseAS = `${baseAS.toLowerCase()}:${search}`;
|
||||
if (cValue === withBaseAS) return true;
|
||||
if (cValue.includes(withBaseAS)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -672,8 +682,11 @@ function FilterManager() {
|
||||
try {
|
||||
const res = await api.get('/ui-settings');
|
||||
const data = res?.data || {};
|
||||
if (data?.baseAS) setBaseAS(String(data.baseAS));
|
||||
const loadedBaseAS = String(data?.baseAS || '65001');
|
||||
console.log('[FilterManager] Загружена baseAS:', loadedBaseAS);
|
||||
setBaseAS(loadedBaseAS);
|
||||
} catch (e) {
|
||||
console.warn('[FilterManager] Не удалось загрузить baseAS, используем 65001');
|
||||
// мягко игнорируем, используем значение по умолчанию
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user