|
|
@@ -279,7 +279,7 @@ const expandParentsOfSelectedItems = () => {
|
|
|
if (!item) continue
|
|
|
|
|
|
let parentId = null
|
|
|
- if(props.nbLevel === 3){
|
|
|
+ if (props.nbLevel === 3) {
|
|
|
// Trouver la sous-catégorie
|
|
|
const subcategory = normalizedItems.value.find(
|
|
|
(i) => i.id === item.parentId,
|
|
|
@@ -288,15 +288,13 @@ const expandParentsOfSelectedItems = () => {
|
|
|
expandedSubcategories.value.add(subcategory.id)
|
|
|
parentId = subcategory.parentId
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
parentId = item.parentId
|
|
|
}
|
|
|
|
|
|
if (parentId) {
|
|
|
// Trouver la catégorie
|
|
|
- const category = normalizedItems.value.find(
|
|
|
- (i) => i.id === parentId,
|
|
|
- )
|
|
|
+ const category = normalizedItems.value.find((i) => i.id === parentId)
|
|
|
if (category) {
|
|
|
expandedCategories.value.add(category.id)
|
|
|
}
|
|
|
@@ -398,12 +396,14 @@ const onSearchInput = () => {
|
|
|
// Trouver tous les éléments qui correspondent à la recherche
|
|
|
const matchingItems = normalizedItems.value.filter(
|
|
|
(item) =>
|
|
|
- item.type === 'item' && item.level === (props.nbLevel - 1) && itemMatchesSearch(item),
|
|
|
+ item.type === 'item' &&
|
|
|
+ item.level === props.nbLevel - 1 &&
|
|
|
+ itemMatchesSearch(item),
|
|
|
)
|
|
|
// Pour chaque élément correspondant, ajouter ses parents aux ensembles d'expansion
|
|
|
for (const item of matchingItems) {
|
|
|
let category
|
|
|
- if(props.nbLevel === 3){
|
|
|
+ if (props.nbLevel === 3) {
|
|
|
// Trouver et ajouter la sous-catégorie parente
|
|
|
const subcategory = normalizedItems.value.find(
|
|
|
(i) => i.id === item.parentId,
|
|
|
@@ -416,11 +416,9 @@ const onSearchInput = () => {
|
|
|
(i) => i.id === subcategory.parentId,
|
|
|
)
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
// Trouver et ajouter la catégorie parente
|
|
|
- category = normalizedItems.value.find(
|
|
|
- (i) => i.id === item.parentId,
|
|
|
- )
|
|
|
+ category = normalizedItems.value.find((i) => i.id === item.parentId)
|
|
|
}
|
|
|
|
|
|
if (category) {
|
|
|
@@ -489,7 +487,7 @@ const itemMatchesSearch = (item: SelectItem): boolean => {
|
|
|
if (!itemWithNormalizedLabel) return false
|
|
|
|
|
|
// Si c'est un élément de niveau nbLevel - 1, vérifier son label et les labels de ses parents
|
|
|
- if (item.type === 'item' && item.level === (props.nbLevel - 1)) {
|
|
|
+ if (item.type === 'item' && item.level === props.nbLevel - 1) {
|
|
|
// Vérifier le label de l'élément
|
|
|
if (
|
|
|
anyWordStartsWith(
|
|
|
@@ -500,11 +498,9 @@ const itemMatchesSearch = (item: SelectItem): boolean => {
|
|
|
return true
|
|
|
|
|
|
let parentId = item.parentId
|
|
|
- if(props.nbLevel === 3){
|
|
|
+ if (props.nbLevel === 3) {
|
|
|
// Trouver et vérifier le label de la sous-catégorie parente
|
|
|
- const subcategory = normalizedItems.value.find(
|
|
|
- (i) => i.id === parentId,
|
|
|
- )
|
|
|
+ const subcategory = normalizedItems.value.find((i) => i.id === parentId)
|
|
|
if (
|
|
|
subcategory &&
|
|
|
anyWordStartsWith(subcategory.normalizedLabel!, normalizedSearch)
|
|
|
@@ -513,20 +509,17 @@ const itemMatchesSearch = (item: SelectItem): boolean => {
|
|
|
|
|
|
// Trouver et vérifier le label de la catégorie parente
|
|
|
if (subcategory && subcategory.parentId) {
|
|
|
- parentId = subcategory.parentId
|
|
|
+ parentId = subcategory.parentId
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Trouver et vérifier le label de la catégorie parente
|
|
|
- const category = normalizedItems.value.find(
|
|
|
- (i) => i.id === parentId,
|
|
|
- )
|
|
|
- if (
|
|
|
- category &&
|
|
|
- anyWordStartsWith(category.normalizedLabel!, normalizedSearch)
|
|
|
- )
|
|
|
- return true
|
|
|
-
|
|
|
+ const category = normalizedItems.value.find((i) => i.id === parentId)
|
|
|
+ if (
|
|
|
+ category &&
|
|
|
+ anyWordStartsWith(category.normalizedLabel!, normalizedSearch)
|
|
|
+ )
|
|
|
+ return true
|
|
|
|
|
|
return false
|
|
|
}
|
|
|
@@ -546,7 +539,9 @@ const itemMatchesSearch = (item: SelectItem): boolean => {
|
|
|
const findMatchingLevel2Items = (): SelectItem[] => {
|
|
|
return normalizedItems.value.filter(
|
|
|
(item) =>
|
|
|
- item.type === 'item' && item.level === (props.nbLevel - 1) && itemMatchesSearch(item),
|
|
|
+ item.type === 'item' &&
|
|
|
+ item.level === props.nbLevel - 1 &&
|
|
|
+ itemMatchesSearch(item),
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -564,11 +559,9 @@ const buildSearchResultsList = (matchingItems: SelectItem[]): SelectItem[] => {
|
|
|
|
|
|
for (const item of matchingItems) {
|
|
|
let parentId = item.parentId
|
|
|
- if(props.nbLevel === 3){
|
|
|
+ if (props.nbLevel === 3) {
|
|
|
// Trouver la sous-catégorie parente
|
|
|
- const subcategory = normalizedItems.value.find(
|
|
|
- (i) => i.id === parentId,
|
|
|
- )
|
|
|
+ const subcategory = normalizedItems.value.find((i) => i.id === parentId)
|
|
|
if (!subcategory) continue
|
|
|
|
|
|
// Ajouter la sous-catégorie si elle n'est pas déjà présente
|
|
|
@@ -581,9 +574,7 @@ const buildSearchResultsList = (matchingItems: SelectItem[]): SelectItem[] => {
|
|
|
}
|
|
|
|
|
|
// Trouver la catégorie parente
|
|
|
- const category = normalizedItems.value.find(
|
|
|
- (i) => i.id === parentId,
|
|
|
- )
|
|
|
+ const category = normalizedItems.value.find((i) => i.id === parentId)
|
|
|
if (!category) continue
|
|
|
|
|
|
// Ajouter la catégorie si elle n'est pas déjà présente
|
|
|
@@ -618,8 +609,10 @@ const processItemsRecursively = (
|
|
|
result.push(item)
|
|
|
if (expandedCategories.value.has(item.id)) {
|
|
|
const subcategories = normalizedItems.value.filter(
|
|
|
- (i) => i.parentId === item.id
|
|
|
- && ((props.nbLevel == 2 && i.type === 'item') || (props.nbLevel == 3 && i.type === 'subcategory')),
|
|
|
+ (i) =>
|
|
|
+ i.parentId === item.id &&
|
|
|
+ ((props.nbLevel == 2 && i.type === 'item') ||
|
|
|
+ (props.nbLevel == 3 && i.type === 'subcategory')),
|
|
|
)
|
|
|
processItemsRecursively(subcategories, result, true)
|
|
|
}
|