Fix catalog: selection panels instead of modals, remove duplicate QuoteForm
All checks were successful
Build Docker Image / build (push) Successful in 3m55s
All checks were successful
Build Docker Image / build (push) Successful in 3m55s
- Add SelectionPanel.vue for product/hub/supplier selection lists - Remove QuoteForm from QuotePanel (header already has controls) - Show SelectionPanel when selectMode is active - Connect search button in header to page via shared state
This commit is contained in:
@@ -9,92 +9,29 @@
|
||||
:show-panel="showPanel"
|
||||
@select="onMapSelect"
|
||||
>
|
||||
<!-- Panel slot - shows Quote form or selection list -->
|
||||
<!-- Panel slot - shows selection list OR quote results -->
|
||||
<template #panel>
|
||||
<!-- Selection mode: show list for picking product/hub/supplier -->
|
||||
<SelectionPanel
|
||||
v-if="selectMode"
|
||||
:select-mode="selectMode"
|
||||
:products="products"
|
||||
:hubs="hubs"
|
||||
:suppliers="suppliers"
|
||||
:loading="selectionLoading"
|
||||
@select="onSelectItem"
|
||||
@close="cancelSelect"
|
||||
/>
|
||||
|
||||
<!-- Quote results: show offers after search -->
|
||||
<QuotePanel
|
||||
:product-id="productId"
|
||||
:product-label="getFilterLabel('product', productId)"
|
||||
:hub-id="hubId"
|
||||
:hub-label="getFilterLabel('hub', hubId)"
|
||||
:supplier-id="supplierId"
|
||||
:supplier-label="getFilterLabel('supplier', supplierId)"
|
||||
:quantity="quantity"
|
||||
:can-search="canSearch"
|
||||
:show-results="showQuoteResults"
|
||||
v-else-if="showQuoteResults"
|
||||
:loading="offersLoading"
|
||||
:offers="offers"
|
||||
@edit-filter="onEditFilter"
|
||||
@remove-filter="onRemoveFilter"
|
||||
@update-quantity="onUpdateQuantity"
|
||||
@search="onSearch"
|
||||
@clear-all="onClearAll"
|
||||
@select-offer="onSelectOffer"
|
||||
/>
|
||||
</template>
|
||||
</CatalogPage>
|
||||
|
||||
<!-- Product selection modal -->
|
||||
<dialog ref="productModalRef" class="modal modal-bottom sm:modal-middle">
|
||||
<div class="modal-box max-w-2xl max-h-[80vh]">
|
||||
<h3 class="font-bold text-lg mb-4">{{ t('catalog.quote.selectProduct') }}</h3>
|
||||
<div class="overflow-y-auto max-h-[60vh]">
|
||||
<div v-if="productsLoading" class="flex justify-center py-8">
|
||||
<span class="loading loading-spinner loading-md" />
|
||||
</div>
|
||||
<div v-else class="flex flex-col gap-2">
|
||||
<button
|
||||
v-for="product in products"
|
||||
:key="product.uuid"
|
||||
class="btn btn-ghost justify-start"
|
||||
@click="selectProduct(product)"
|
||||
>
|
||||
<Icon name="lucide:package" size="16" />
|
||||
{{ product.name }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-action">
|
||||
<form method="dialog">
|
||||
<button class="btn">{{ t('common.cancel') }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
|
||||
<!-- Hub selection modal -->
|
||||
<dialog ref="hubModalRef" class="modal modal-bottom sm:modal-middle">
|
||||
<div class="modal-box max-w-2xl max-h-[80vh]">
|
||||
<h3 class="font-bold text-lg mb-4">{{ t('catalog.quote.selectHub') }}</h3>
|
||||
<div class="overflow-y-auto max-h-[60vh]">
|
||||
<div v-if="hubsLoading" class="flex justify-center py-8">
|
||||
<span class="loading loading-spinner loading-md" />
|
||||
</div>
|
||||
<div v-else class="flex flex-col gap-2">
|
||||
<button
|
||||
v-for="hub in hubs"
|
||||
:key="hub.uuid"
|
||||
class="btn btn-ghost justify-start"
|
||||
@click="selectHub(hub)"
|
||||
>
|
||||
<Icon name="lucide:map-pin" size="16" />
|
||||
{{ hub.name }}
|
||||
<span v-if="hub.country" class="text-base-content/60 text-sm ml-auto">{{ hub.country }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-action">
|
||||
<form method="dialog">
|
||||
<button class="btn">{{ t('common.cancel') }}</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<form method="dialog" class="modal-backdrop">
|
||||
<button>close</button>
|
||||
</form>
|
||||
</dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@@ -111,44 +48,58 @@ const localePath = useLocalePath()
|
||||
|
||||
const {
|
||||
catalogMode,
|
||||
selectMode,
|
||||
productId,
|
||||
supplierId,
|
||||
hubId,
|
||||
quantity,
|
||||
canSearch,
|
||||
mapViewMode,
|
||||
entityColors,
|
||||
selectItem,
|
||||
removeFilter,
|
||||
clearAll,
|
||||
setLabel,
|
||||
filterLabels
|
||||
cancelSelect,
|
||||
setLabel
|
||||
} = useCatalogSearch()
|
||||
|
||||
// Composables for data
|
||||
// Composables for data (initialize immediately when selectMode changes)
|
||||
const { items: products, isLoading: productsLoading, init: initProducts } = useCatalogProducts()
|
||||
const { items: hubs, isLoading: hubsLoading, init: initHubs } = useCatalogHubs()
|
||||
const { items: suppliers, isLoading: suppliersLoading, init: initSuppliers } = useCatalogSuppliers()
|
||||
|
||||
// Modal refs
|
||||
const productModalRef = ref<HTMLDialogElement | null>(null)
|
||||
const hubModalRef = ref<HTMLDialogElement | null>(null)
|
||||
// Selection loading state
|
||||
const selectionLoading = computed(() => {
|
||||
if (selectMode.value === 'product') return productsLoading.value
|
||||
if (selectMode.value === 'hub') return hubsLoading.value
|
||||
if (selectMode.value === 'supplier') return suppliersLoading.value
|
||||
return false
|
||||
})
|
||||
|
||||
// Initialize data when selectMode changes
|
||||
watch(selectMode, async (mode) => {
|
||||
if (mode === 'product') await initProducts()
|
||||
if (mode === 'hub') await initHubs()
|
||||
if (mode === 'supplier') await initSuppliers()
|
||||
}, { immediate: true })
|
||||
|
||||
// Offers data for quote results
|
||||
const offers = ref<any[]>([])
|
||||
const offersLoading = ref(false)
|
||||
const showQuoteResults = ref(false)
|
||||
|
||||
// Watch for search trigger from topnav
|
||||
const searchTrigger = useState<number>('catalog-search-trigger', () => 0)
|
||||
watch(searchTrigger, () => {
|
||||
if (canSearch.value) {
|
||||
onSearch()
|
||||
}
|
||||
})
|
||||
|
||||
// Loading state
|
||||
const isLoading = computed(() => offersLoading.value)
|
||||
const isLoading = computed(() => offersLoading.value || selectionLoading.value)
|
||||
|
||||
// Show panel when in Quote mode
|
||||
const showPanel = computed(() => catalogMode.value === 'quote')
|
||||
|
||||
// Get filter label from cache
|
||||
const getFilterLabel = (type: string, id: string | undefined): string | undefined => {
|
||||
if (!id) return undefined
|
||||
return filterLabels.value[type]?.[id]
|
||||
}
|
||||
// Show panel when selecting OR when showing quote results
|
||||
const showPanel = computed(() => {
|
||||
return selectMode.value !== null || showQuoteResults.value
|
||||
})
|
||||
|
||||
// Cluster node type based on map view mode
|
||||
const clusterNodeType = computed(() => {
|
||||
@@ -170,58 +121,19 @@ const mapPointColor = computed(() => {
|
||||
const onMapSelect = (item: any) => {
|
||||
// Navigate to offer detail page if in quote mode with results
|
||||
if (catalogMode.value === 'quote' && item.uuid) {
|
||||
// Could navigate to offer detail
|
||||
console.log('Selected from map:', item)
|
||||
}
|
||||
}
|
||||
|
||||
// Edit filter - open modal
|
||||
const onEditFilter = async (type: string) => {
|
||||
if (type === 'product') {
|
||||
await initProducts()
|
||||
productModalRef.value?.showModal()
|
||||
} else if (type === 'hub') {
|
||||
await initHubs()
|
||||
hubModalRef.value?.showModal()
|
||||
// Handle selection from SelectionPanel
|
||||
const onSelectItem = (type: string, item: any) => {
|
||||
if (item.uuid && item.name) {
|
||||
selectItem(type, item.uuid, item.name)
|
||||
showQuoteResults.value = false
|
||||
offers.value = []
|
||||
}
|
||||
}
|
||||
|
||||
// Remove filter
|
||||
const onRemoveFilter = (type: string) => {
|
||||
removeFilter(type)
|
||||
showQuoteResults.value = false
|
||||
offers.value = []
|
||||
}
|
||||
|
||||
// Update quantity
|
||||
const onUpdateQuantity = (value: string) => {
|
||||
// Store in URL
|
||||
const route = useRoute()
|
||||
const newQuery = { ...route.query }
|
||||
if (value) {
|
||||
newQuery.qty = value
|
||||
} else {
|
||||
delete newQuery.qty
|
||||
}
|
||||
router.push({ query: newQuery })
|
||||
}
|
||||
|
||||
// Select product from modal
|
||||
const selectProduct = (product: any) => {
|
||||
selectItem('product', product.uuid, product.name)
|
||||
productModalRef.value?.close()
|
||||
showQuoteResults.value = false
|
||||
offers.value = []
|
||||
}
|
||||
|
||||
// Select hub from modal
|
||||
const selectHub = (hub: any) => {
|
||||
selectItem('hub', hub.uuid, hub.name)
|
||||
hubModalRef.value?.close()
|
||||
showQuoteResults.value = false
|
||||
offers.value = []
|
||||
}
|
||||
|
||||
// Search for offers
|
||||
const onSearch = async () => {
|
||||
if (!canSearch.value) return
|
||||
@@ -256,13 +168,6 @@ const onSearch = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// Clear all filters
|
||||
const onClearAll = () => {
|
||||
clearAll()
|
||||
showQuoteResults.value = false
|
||||
offers.value = []
|
||||
}
|
||||
|
||||
// Select offer - navigate to detail page
|
||||
const onSelectOffer = (offer: any) => {
|
||||
if (offer.uuid && offer.productUuid) {
|
||||
|
||||
Reference in New Issue
Block a user