feat(component-edit) : add interactive slot selectors for pieces, products and subcomponents
Replace read-only selections display with PieceSelect, ProductSelect, ComposantSelect components that allow changing the assigned item in each slot directly from the edit page. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
116
app/components/ComposantSelect.vue
Normal file
116
app/components/ComposantSelect.vue
Normal file
@@ -0,0 +1,116 @@
|
||||
<template>
|
||||
<div class="space-y-1">
|
||||
<SearchSelect
|
||||
:model-value="modelValue ?? undefined"
|
||||
:options="composantOptions"
|
||||
:loading="loading"
|
||||
:placeholder="placeholder"
|
||||
:empty-text="emptyText"
|
||||
size="sm"
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
:disabled="disabled"
|
||||
@update:modelValue="updateValue"
|
||||
>
|
||||
<template #option-description="{ option }">
|
||||
<span class="text-xs text-base-content/60">
|
||||
{{ formatDescription(option) }}
|
||||
</span>
|
||||
</template>
|
||||
</SearchSelect>
|
||||
<p v-if="helperText" class="text-xs text-base-content/60">
|
||||
{{ helperText }}
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, watch } from 'vue'
|
||||
import SearchSelect from '~/components/common/SearchSelect.vue'
|
||||
import { useComposants } from '~/composables/useComposants'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: string | null
|
||||
placeholder?: string
|
||||
emptyText?: string
|
||||
helperText?: string
|
||||
disabled?: boolean
|
||||
typeComposantId?: string | null
|
||||
}>(),
|
||||
{
|
||||
modelValue: '',
|
||||
placeholder: 'Sélectionner un composant…',
|
||||
emptyText: 'Aucun composant disponible',
|
||||
helperText: '',
|
||||
disabled: false,
|
||||
typeComposantId: null,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: string | null): void
|
||||
}>()
|
||||
|
||||
const { composants, loading, loadComposants } = useComposants()
|
||||
|
||||
const composantOptions = computed(() => {
|
||||
const baseOptions = Array.isArray(composants.value) ? composants.value : []
|
||||
if (!props.typeComposantId) {
|
||||
return baseOptions
|
||||
}
|
||||
|
||||
const allowedTypeId = String(props.typeComposantId)
|
||||
return baseOptions.filter((composant: any) => {
|
||||
const typeId =
|
||||
composant?.typeComposantId ||
|
||||
composant?.typeComposant?.id ||
|
||||
null
|
||||
return typeId ? String(typeId) === allowedTypeId : false
|
||||
})
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (composantOptions.value.length === 0) {
|
||||
loadComposants({ itemsPerPage: 200 }).catch((error: unknown) => {
|
||||
console.error('Erreur lors du chargement des composants:', error)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
if (typeof value === 'string') {
|
||||
const exists = composantOptions.value.some((c: any) => c.id === value)
|
||||
if (!exists && composantOptions.value.length === 0 && !loading.value) {
|
||||
loadComposants({ itemsPerPage: 200 }).catch((error: unknown) => {
|
||||
console.error('Erreur lors du chargement des composants:', error)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
const updateValue = (value: string | number | null | undefined) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
emit('update:modelValue', null)
|
||||
return
|
||||
}
|
||||
emit('update:modelValue', String(value))
|
||||
}
|
||||
|
||||
const formatDescription = (option: any) => {
|
||||
const parts: string[] = []
|
||||
if (option?.reference) {
|
||||
parts.push(option.reference)
|
||||
}
|
||||
if (option?.prix !== undefined && option.prix !== null) {
|
||||
const price = Number(option.prix)
|
||||
if (!Number.isNaN(price)) {
|
||||
parts.push(`${price.toFixed(2)} €`)
|
||||
}
|
||||
}
|
||||
return parts.length ? parts.join(' • ') : 'Sans référence'
|
||||
}
|
||||
</script>
|
||||
116
app/components/PieceSelect.vue
Normal file
116
app/components/PieceSelect.vue
Normal file
@@ -0,0 +1,116 @@
|
||||
<template>
|
||||
<div class="space-y-1">
|
||||
<SearchSelect
|
||||
:model-value="modelValue ?? undefined"
|
||||
:options="pieceOptions"
|
||||
:loading="loading"
|
||||
:placeholder="placeholder"
|
||||
:empty-text="emptyText"
|
||||
size="sm"
|
||||
option-value="id"
|
||||
option-label="name"
|
||||
:disabled="disabled"
|
||||
@update:modelValue="updateValue"
|
||||
>
|
||||
<template #option-description="{ option }">
|
||||
<span class="text-xs text-base-content/60">
|
||||
{{ formatDescription(option) }}
|
||||
</span>
|
||||
</template>
|
||||
</SearchSelect>
|
||||
<p v-if="helperText" class="text-xs text-base-content/60">
|
||||
{{ helperText }}
|
||||
</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, watch } from 'vue'
|
||||
import SearchSelect from '~/components/common/SearchSelect.vue'
|
||||
import { usePieces } from '~/composables/usePieces'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
modelValue?: string | null
|
||||
placeholder?: string
|
||||
emptyText?: string
|
||||
helperText?: string
|
||||
disabled?: boolean
|
||||
typePieceId?: string | null
|
||||
}>(),
|
||||
{
|
||||
modelValue: '',
|
||||
placeholder: 'Sélectionner une pièce…',
|
||||
emptyText: 'Aucune pièce disponible',
|
||||
helperText: '',
|
||||
disabled: false,
|
||||
typePieceId: null,
|
||||
},
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:modelValue', value: string | null): void
|
||||
}>()
|
||||
|
||||
const { pieces, loading, loadPieces } = usePieces()
|
||||
|
||||
const pieceOptions = computed(() => {
|
||||
const baseOptions = Array.isArray(pieces.value) ? pieces.value : []
|
||||
if (!props.typePieceId) {
|
||||
return baseOptions
|
||||
}
|
||||
|
||||
const allowedTypeId = String(props.typePieceId)
|
||||
return baseOptions.filter((piece: any) => {
|
||||
const typeId =
|
||||
piece?.typePieceId ||
|
||||
piece?.typePiece?.id ||
|
||||
null
|
||||
return typeId ? String(typeId) === allowedTypeId : false
|
||||
})
|
||||
})
|
||||
|
||||
onMounted(() => {
|
||||
if (pieceOptions.value.length === 0) {
|
||||
loadPieces({ itemsPerPage: 200 }).catch((error: unknown) => {
|
||||
console.error('Erreur lors du chargement des pièces:', error)
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
(value) => {
|
||||
if (typeof value === 'string') {
|
||||
const exists = pieceOptions.value.some((piece: any) => piece.id === value)
|
||||
if (!exists && pieceOptions.value.length === 0 && !loading.value) {
|
||||
loadPieces({ itemsPerPage: 200 }).catch((error: unknown) => {
|
||||
console.error('Erreur lors du chargement des pièces:', error)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
const updateValue = (value: string | number | null | undefined) => {
|
||||
if (value === undefined || value === null || value === '') {
|
||||
emit('update:modelValue', null)
|
||||
return
|
||||
}
|
||||
emit('update:modelValue', String(value))
|
||||
}
|
||||
|
||||
const formatDescription = (option: any) => {
|
||||
const parts: string[] = []
|
||||
if (option?.reference) {
|
||||
parts.push(option.reference)
|
||||
}
|
||||
if (option?.prix !== undefined && option.prix !== null) {
|
||||
const price = Number(option.prix)
|
||||
if (!Number.isNaN(price)) {
|
||||
parts.push(`${price.toFixed(2)} €`)
|
||||
}
|
||||
}
|
||||
return parts.length ? parts.join(' • ') : 'Sans référence'
|
||||
}
|
||||
</script>
|
||||
Reference in New Issue
Block a user