Improve product AI UX, category search, and card actions.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
d787a69195
commit
b743c09e4d
@@ -49,3 +49,22 @@ export function getAncestorIds(categories: Category[], id: string): string[] {
|
||||
|
||||
return ids
|
||||
}
|
||||
|
||||
/** Client-side filter by FA/EN name; keeps ancestors so the tree stays intact. */
|
||||
export function filterCategoriesByQuery(categories: Category[], query: string): Category[] {
|
||||
const normalized = query.trim().toLowerCase()
|
||||
if (!normalized) return categories
|
||||
|
||||
const matchedIds = new Set<string>()
|
||||
|
||||
for (const category of categories) {
|
||||
const haystack = `${category.nameFa} ${category.nameEn}`.toLowerCase()
|
||||
if (!haystack.includes(normalized)) continue
|
||||
matchedIds.add(category.id)
|
||||
for (const ancestorId of getAncestorIds(categories, category.id)) {
|
||||
matchedIds.add(ancestorId)
|
||||
}
|
||||
}
|
||||
|
||||
return categories.filter((category) => matchedIds.has(category.id))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user