From a8cb4d1ac04c9ff89b78a4b4c1a4ed7b215a11a0 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Fri, 23 Jan 2026 23:29:40 +0100 Subject: [PATCH] wip: dynamic search for component create --- .../ComponentStructureAssignmentNode.vue | 237 +++++++++++++++--- app/components/common/SearchSelect.vue | 3 +- app/pages/component/create.vue | 37 ++- 3 files changed, 242 insertions(+), 35 deletions(-) diff --git a/app/components/ComponentStructureAssignmentNode.vue b/app/components/ComponentStructureAssignmentNode.vue index 0baff5d..2d6b86c 100644 --- a/app/components/ComponentStructureAssignmentNode.vue +++ b/app/components/ComponentStructureAssignmentNode.vue @@ -17,12 +17,13 @@ @@ -45,22 +46,23 @@ >

- {{ describePieceRequirement(pieceAssignment.definition) }} + {{ describePieceRequirement(pieceAssignment) }}

-

+

Aucune pièce disponible pour cette famille.

@@ -83,22 +85,23 @@ >

- {{ describeProductRequirement(productAssignment.definition) }} + {{ describeProductRequirement(productAssignment) }}

-

+

Aucun produit disponible pour cette catégorie.

@@ -131,8 +134,9 @@ diff --git a/app/components/common/SearchSelect.vue b/app/components/common/SearchSelect.vue index ebc1248..c56de77 100644 --- a/app/components/common/SearchSelect.vue +++ b/app/components/common/SearchSelect.vue @@ -122,7 +122,7 @@ const props = defineProps({ } }) -const emit = defineEmits(['update:modelValue']) +const emit = defineEmits(['update:modelValue', 'search']) const searchTerm = ref('') const openDropdown = ref(false) @@ -267,6 +267,7 @@ function handleInput () { if (!openDropdown.value) { openDropdown.value = true } + emit('search', searchTerm.value) } function closeDropdown () { diff --git a/app/pages/component/create.vue b/app/pages/component/create.vue index db90535..4e3b860 100644 --- a/app/pages/component/create.vue +++ b/app/pages/component/create.vue @@ -212,6 +212,9 @@ :pieces-loading="piecesLoading" :products-loading="productsLoading" :components-loading="componentsLoading" + :piece-type-label-map="pieceTypeLabelMap" + :product-type-label-map="productTypeLabelMap" + :component-type-label-map="componentTypeLabelMap" />

Impossible de générer les emplacements définis par le squelette. @@ -349,7 +352,9 @@ import SearchSelect from '~/components/common/SearchSelect.vue' import { useComponentTypes } from '~/composables/useComponentTypes' import { useComposants } from '~/composables/useComposants' import { usePieces } from '~/composables/usePieces' +import { usePieceTypes } from '~/composables/usePieceTypes' import { useProducts } from '~/composables/useProducts' +import { useProductTypes } from '~/composables/useProductTypes' import { useToast } from '~/composables/useToast' import { useCustomFields } from '~/composables/useCustomFields' import { useDocuments } from '~/composables/useDocuments' @@ -372,20 +377,19 @@ const route = useRoute() const router = useRouter() const { componentTypes, loadComponentTypes, loadingComponentTypes } = useComponentTypes() +const { pieceTypes, loadPieceTypes } = usePieceTypes() +const { productTypes, loadProductTypes } = useProductTypes() const { createComposant, composants: componentCatalogRef, - loadComposants, loading: componentsLoading, } = useComposants() const { pieces: pieceCatalogRef, - loadPieces, loading: piecesLoading, } = usePieces() const { products: productCatalogRef, - loadProducts, loading: productsLoading, } = useProducts() const toast = useToast() @@ -414,6 +418,28 @@ const structureDataLoading = computed( () => piecesLoading.value || componentsLoading.value || productsLoading.value, ) +const pieceTypeLabelMap = computed(() => + Object.fromEntries( + (pieceTypes.value || []) + .filter((type: any) => type?.id) + .map((type: any) => [type.id, type.name || type.code || '']), + ), +) +const productTypeLabelMap = computed(() => + Object.fromEntries( + (productTypes.value || []) + .filter((type: any) => type?.id) + .map((type: any) => [type.id, type.name || type.code || '']), + ), +) +const componentTypeLabelMap = computed(() => + Object.fromEntries( + (componentTypes.value || []) + .filter((type: any) => type?.id) + .map((type: any) => [type.id, type.name || type.code || '']), + ), +) + watch( () => route.query.typeId, (value) => { @@ -934,9 +960,8 @@ const submitCreation = async () => { onMounted(async () => { await Promise.allSettled([ loadComponentTypes(), - loadPieces(), - loadComposants(), - loadProducts(), + loadPieceTypes(), + loadProductTypes(), ]) })