fix(slots) : filter slot select options server-side instead of client-side
PieceSelect, ProductSelect and ComposantSelect were loading up to 200 items then filtering client-side by typeId. If the matching items were not in the first 200, the dropdown appeared empty. Now each select component uses API Platform filters (typePiece, typeProduct, typeComposant) to fetch only relevant items server-side, with local state to avoid overwriting the global catalog cache. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, watch } from 'vue'
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import SearchSelect from '~/components/common/SearchSelect.vue'
|
||||
import { useComposants } from '~/composables/useComposants'
|
||||
|
||||
@@ -52,43 +52,39 @@ const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: string | null): void
|
||||
}>()
|
||||
|
||||
const { composants, loading, loadComposants } = useComposants()
|
||||
const { loading: globalLoading, loadComposants } = useComposants()
|
||||
|
||||
const composantOptions = computed(() => {
|
||||
const baseOptions = Array.isArray(composants.value) ? composants.value : []
|
||||
if (!props.typeComposantId) {
|
||||
return baseOptions
|
||||
const localComposants = ref<any[]>([])
|
||||
const localLoading = ref(false)
|
||||
const loading = computed(() => localLoading.value || globalLoading.value)
|
||||
|
||||
const composantOptions = computed(() => localComposants.value)
|
||||
|
||||
const loadFilteredComposants = async () => {
|
||||
if (!props.typeComposantId) return
|
||||
localLoading.value = true
|
||||
try {
|
||||
const result = await loadComposants({ typeComposantId: props.typeComposantId, itemsPerPage: 500, force: true })
|
||||
if (result.success && result.data?.items) {
|
||||
localComposants.value = result.data.items
|
||||
}
|
||||
}
|
||||
|
||||
const allowedTypeId = String(props.typeComposantId)
|
||||
return baseOptions.filter((composant: any) => {
|
||||
const typeId =
|
||||
composant?.typeComposantId ||
|
||||
composant?.typeComposant?.id ||
|
||||
null
|
||||
return typeId ? String(typeId) === allowedTypeId : false
|
||||
})
|
||||
})
|
||||
catch (error: unknown) {
|
||||
console.error('Erreur lors du chargement des composants:', error)
|
||||
}
|
||||
finally {
|
||||
localLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (composantOptions.value.length === 0) {
|
||||
loadComposants({ itemsPerPage: 200 }).catch((error: unknown) => {
|
||||
console.error('Erreur lors du chargement des composants:', error)
|
||||
})
|
||||
}
|
||||
loadFilteredComposants()
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
if (typeof value === 'string' && value) {
|
||||
const exists = composantOptions.value.some((c: any) => c.id === value)
|
||||
if (!exists && !loading.value) {
|
||||
loadComposants({ itemsPerPage: 200, force: true }).catch((error: unknown) => {
|
||||
console.error('Erreur lors du chargement des composants:', error)
|
||||
})
|
||||
}
|
||||
}
|
||||
() => props.typeComposantId,
|
||||
() => {
|
||||
loadFilteredComposants()
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user