Skip to content

Commit

Permalink
Fix global search component reroute
Browse files Browse the repository at this point in the history
  • Loading branch information
hvangeffen committed Jan 14, 2025
1 parent f31a1ed commit 82f4236
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
7 changes: 1 addition & 6 deletions src/components/general/GlobalSearchComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,14 @@
<script lang="ts" setup>
import { useGlobalSearchState } from '@/stores/globalSearch'
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { useDisplay } from 'vuetify'
const { mobile } = useDisplay()
const state = useGlobalSearchState()
const search = ref('')
const router = useRouter()
function itemClick(item: any) {
router.replace({
name: 'TopologySpatialTimeSeriesDisplay',
params: { locationId: item.id },
})
state.selectedItem = item
state.active = false
}
</script>
Expand Down
12 changes: 8 additions & 4 deletions src/components/wms/LocationsSearchControl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ const showLocations = defineModel<boolean>('showLocations', { default: true })
const state = useGlobalSearchState()
watch(
() => state.selectedItem,
(item) => onSelectLocationId(item?.id),
)
const emit = defineEmits(['changeLocationId'])
const selectedLocation = ref<Location | null>(null)
Expand Down Expand Up @@ -82,11 +87,10 @@ watch(
() => (selectedLocation.value = getLocationFromId(props.selectedLocationId)),
)
watch(selectedLocation, onSelectLocation)
function onSelectLocation(newValue: Location | null) {
if (newValue === null) {
function onSelectLocationId(id: string | undefined) {
if (id === undefined) {
return
}
emit('changeLocationId', newValue.locationId)
emit('changeLocationId', id)
}
</script>
2 changes: 2 additions & 0 deletions src/stores/globalSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface GlobalSearchState {
active: boolean
type: 'locations' | 'parameters' | 'nodes'
items: GlobalSearchItem[]
selectedItem: GlobalSearchItem | null
}

interface GlobalSearchItem {
Expand All @@ -16,6 +17,7 @@ const useGlobalSearchState = defineStore('globalSearchState', {
active: false,
type: 'locations',
items: [],
selectedItem: null,
}),

actions: {},
Expand Down

0 comments on commit 82f4236

Please sign in to comment.