From f879fddd9566e0954e9c06bbb08071b9649ec140 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Sun, 2 Mar 2025 13:54:25 -0500 Subject: [PATCH] Fix VM search displaying --- .../src/components/general/VMSearchBar.vue | 62 +++++++++++-- .../src/components/pages/vms/VMOverview.vue | 90 +++++++++++-------- pvc-vue/src/views/VMs.vue | 5 ++ 3 files changed, 114 insertions(+), 43 deletions(-) diff --git a/pvc-vue/src/components/general/VMSearchBar.vue b/pvc-vue/src/components/general/VMSearchBar.vue index 3cbc2e4..a55b3f2 100644 --- a/pvc-vue/src/components/general/VMSearchBar.vue +++ b/pvc-vue/src/components/general/VMSearchBar.vue @@ -14,7 +14,7 @@
@@ -130,9 +130,22 @@ const props = defineProps({ selectedVM: { type: String, default: '' + }, + vmFromUrl: { + type: String, + default: '' } }); +// Direct debug log of props +console.log('VMSearchBar props:', { + modelValue: props.modelValue, + showList: props.showList, + selectedVM: props.selectedVM, + vmFromUrl: props.vmFromUrl, + vmListLength: props.vmList.length +}); + const emit = defineEmits([ 'update:modelValue', 'search', @@ -159,6 +172,31 @@ const appliedFilters = ref({ // Add new ref for tracking search active state const searchActive = ref(false); +// Local ref to track input value +const inputValue = ref(''); + +// Watch both showList and selectedVM to update input value +watch([() => props.showList, () => props.selectedVM, () => props.vmFromUrl], + ([showList, selectedVM, vmFromUrl]) => { + console.log('Watch triggered:', { showList, selectedVM, vmFromUrl }); + const effectiveVM = selectedVM || vmFromUrl; + if (!showList && effectiveVM) { + // When list is closed, show selected VM or VM from URL + inputValue.value = effectiveVM; + } else { + // When list is open, show search query + inputValue.value = props.modelValue || ''; + } + }, { immediate: true } +); + +// Watch modelValue to update input when searching +watch(() => props.modelValue, (newVal) => { + if (props.showList) { + inputValue.value = newVal || ''; + } +}); + // Calculate available states from vmList const availableStates = computed(() => { const states = new Set(); @@ -274,9 +312,11 @@ const filteredVMs = computed(() => { // Methods const handleSearch = (event) => { - searchActive.value = true; - emit('update:modelValue', event.target.value); - emit('search', event.target.value); + if (props.showList) { + searchActive.value = true; + emit('update:modelValue', event.target.value); + emit('search', event.target.value); + } }; const handleFocus = (event) => { @@ -294,6 +334,7 @@ const clearSearch = () => { }; const toggleList = () => { + console.log('toggleList called, showList:', props.showList); searchActive.value = false; if (props.showList) { // If we're closing the list, clear the search @@ -303,6 +344,8 @@ const toggleList = () => { }; const handleVMSelect = (vm) => { + console.log('handleVMSelect called with:', vm); + emit('update:modelValue', ''); // Clear search query emit('select-vm', vm); }; @@ -347,6 +390,15 @@ onMounted(() => { onUnmounted(() => { document.removeEventListener('click', handleClickOutside); }); + +// Add a watcher for selectedVM with a debug log +watch(() => props.selectedVM, (newVal, oldVal) => { + console.log('VMSearchBar selectedVM changed:', { newVal, oldVal }); + // Update input value when selectedVM changes + if (!props.showList && newVal) { + inputValue.value = newVal; + } +}, { immediate: true });