Merge pull request 'feat: refs #6839 normalize search' (!936) from 6839-normalizeSearch into dev
gitea/salix-front/pipeline/head This commit looks good Details

Reviewed-on: #936
Reviewed-by: Alex Moreno <alexm@verdnatura.es>
This commit is contained in:
Jorge Penadés 2024-11-14 14:06:03 +00:00
commit 8d070edf8d
1 changed files with 19 additions and 4 deletions

View File

@ -34,18 +34,26 @@ const search = ref(null);
const filteredItems = computed(() => { const filteredItems = computed(() => {
if (!search.value) return items.value; if (!search.value) return items.value;
const normalizedSearch = normalize(search.value);
return items.value.filter((item) => { return items.value.filter((item) => {
const locale = t(item.title).toLowerCase(); const locale = normalize(t(item.title));
return locale.includes(search.value.toLowerCase()); return locale.includes(normalizedSearch);
}); });
}); });
const filteredPinnedModules = computed(() => { const filteredPinnedModules = computed(() => {
if (!search.value) return pinnedModules.value; if (!search.value) return pinnedModules.value;
const normalizedSearch = search.value
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase();
const map = new Map(); const map = new Map();
for (const [key, pinnedModule] of pinnedModules.value) { for (const [key, pinnedModule] of pinnedModules.value) {
const locale = t(pinnedModule.title).toLowerCase(); const locale = t(pinnedModule.title)
if (locale.includes(search.value.toLowerCase())) map.set(key, pinnedModule); .normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase();
if (locale.includes(normalizedSearch)) map.set(key, pinnedModule);
} }
return map; return map;
}); });
@ -147,6 +155,13 @@ async function togglePinned(item, event) {
const handleItemExpansion = (itemName) => { const handleItemExpansion = (itemName) => {
expansionItemElements[itemName].scrollToLastElement(); expansionItemElements[itemName].scrollToLastElement();
}; };
function normalize(text) {
return text
.normalize('NFD')
.replace(/[\u0300-\u036f]/g, '')
.toLowerCase();
}
</script> </script>
<template> <template>