feat(search) : add server-side multi-field search (name + reference) for pieces, components and products
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -44,6 +44,7 @@
|
|||||||
:empty-text="`Aucun ${entityLabelLower} disponible dans cette catégorie`"
|
:empty-text="`Aucun ${entityLabelLower} disponible dans cette catégorie`"
|
||||||
:option-label="entityOptionLabel"
|
:option-label="entityOptionLabel"
|
||||||
:option-description="entityOptionDescription"
|
:option-description="entityOptionDescription"
|
||||||
|
@search="handleEntitySearch"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -187,6 +188,30 @@ watch(selectedTypeId, async () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let searchDebounce: ReturnType<typeof setTimeout> | null = null
|
||||||
|
|
||||||
|
const handleEntitySearch = (term: string) => {
|
||||||
|
if (searchDebounce) clearTimeout(searchDebounce)
|
||||||
|
searchDebounce = setTimeout(async () => {
|
||||||
|
if (!selectedTypeName.value) return
|
||||||
|
loadingEntities.value = true
|
||||||
|
try {
|
||||||
|
if (props.entityKind === 'component') {
|
||||||
|
const result = await loadComposants({ typeName: selectedTypeName.value, search: term.trim(), itemsPerPage: 200 })
|
||||||
|
entities.value = result?.data?.items || []
|
||||||
|
} else if (props.entityKind === 'piece') {
|
||||||
|
const result = await loadPieces({ typeName: selectedTypeName.value, search: term.trim(), itemsPerPage: 200 })
|
||||||
|
entities.value = result?.data?.items || []
|
||||||
|
} else {
|
||||||
|
const result = await loadProducts({ typeName: selectedTypeName.value, search: term.trim(), itemsPerPage: 200 })
|
||||||
|
entities.value = result?.data?.items || []
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
loadingEntities.value = false
|
||||||
|
}
|
||||||
|
}, 300)
|
||||||
|
}
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
resetState()
|
resetState()
|
||||||
emit('close')
|
emit('close')
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ export function useComposants() {
|
|||||||
params.set('page', String(page))
|
params.set('page', String(page))
|
||||||
|
|
||||||
if (search && search.trim()) {
|
if (search && search.trim()) {
|
||||||
params.set('q', search.trim())
|
params.set('search', search.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeName && typeName.trim()) {
|
if (typeName && typeName.trim()) {
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ export function usePieces() {
|
|||||||
params.set('page', String(page))
|
params.set('page', String(page))
|
||||||
|
|
||||||
if (search && search.trim()) {
|
if (search && search.trim()) {
|
||||||
params.set('q', search.trim())
|
params.set('search', search.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeName && typeName.trim()) {
|
if (typeName && typeName.trim()) {
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ export function useProducts() {
|
|||||||
params.set('page', String(page))
|
params.set('page', String(page))
|
||||||
|
|
||||||
if (search && search.trim()) {
|
if (search && search.trim()) {
|
||||||
params.set('q', search.trim())
|
params.set('search', search.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeName && typeName.trim()) {
|
if (typeName && typeName.trim()) {
|
||||||
|
|||||||
@@ -105,9 +105,9 @@ export function useStructureAssignmentFetch(deps: StructureAssignmentFetchDeps)
|
|||||||
definition.typeComposantId || definition.modelId || definition.typeComposant?.id || null
|
definition.typeComposantId || definition.modelId || definition.typeComposant?.id || null
|
||||||
|
|
||||||
const params = new URLSearchParams()
|
const params = new URLSearchParams()
|
||||||
params.set('itemsPerPage', '50')
|
params.set('itemsPerPage', '200')
|
||||||
if (term.trim()) {
|
if (term.trim()) {
|
||||||
params.set('name', term.trim())
|
params.set('search', term.trim())
|
||||||
}
|
}
|
||||||
if (requiredTypeId) {
|
if (requiredTypeId) {
|
||||||
params.set('typeComposant', typeIri(requiredTypeId))
|
params.set('typeComposant', typeIri(requiredTypeId))
|
||||||
@@ -173,9 +173,9 @@ export function useStructureAssignmentFetch(deps: StructureAssignmentFetchDeps)
|
|||||||
definition.typePieceId || definition.typePiece?.id || null
|
definition.typePieceId || definition.typePiece?.id || null
|
||||||
|
|
||||||
const params = new URLSearchParams()
|
const params = new URLSearchParams()
|
||||||
params.set('itemsPerPage', '50')
|
params.set('itemsPerPage', '200')
|
||||||
if (term.trim()) {
|
if (term.trim()) {
|
||||||
params.set('name', term.trim())
|
params.set('search', term.trim())
|
||||||
}
|
}
|
||||||
if (requiredTypeId) {
|
if (requiredTypeId) {
|
||||||
params.set('typePiece', typeIri(requiredTypeId))
|
params.set('typePiece', typeIri(requiredTypeId))
|
||||||
@@ -246,9 +246,9 @@ export function useStructureAssignmentFetch(deps: StructureAssignmentFetchDeps)
|
|||||||
definition.typeProductId || definition.typeProduct?.id || null
|
definition.typeProductId || definition.typeProduct?.id || null
|
||||||
|
|
||||||
const params = new URLSearchParams()
|
const params = new URLSearchParams()
|
||||||
params.set('itemsPerPage', '50')
|
params.set('itemsPerPage', '200')
|
||||||
if (term.trim()) {
|
if (term.trim()) {
|
||||||
params.set('name', term.trim())
|
params.set('search', term.trim())
|
||||||
}
|
}
|
||||||
if (requiredTypeId) {
|
if (requiredTypeId) {
|
||||||
params.set('typeProduct', typeIri(requiredTypeId))
|
params.set('typeProduct', typeIri(requiredTypeId))
|
||||||
|
|||||||
Reference in New Issue
Block a user