Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GShootList: Reflect search query in URL #1952

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 43 additions & 17 deletions frontend/src/views/GShootList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ SPDX-License-Identifier: Apache-2.0
density="compact"
class="g-table-search-field mr-3"
@update:model-value="onUpdateShootSearch"
@keyup.esc="resetShootSearch"
@keyup.esc="setShootSearch(null)"
/>
</template>
Search terms are <span class="font-weight-bold">ANDed</span>.<br>
Expand Down Expand Up @@ -231,12 +231,14 @@ import {
ref,
provide,
toRef,
watch,
} from 'vue'
import {
mapState,
mapWritableState,
mapActions,
} from 'pinia'
import { useUrlSearchParams } from '@vueuse/core'

import { useAuthnStore } from '@/store/authn'
import { useAuthzStore } from '@/store/authz'
Expand Down Expand Up @@ -290,13 +292,15 @@ export default {
})
},
beforeRouteUpdate (to, from, next) {
this.resetShootSearch()
if (to.path !== from.path) {
this.setShootSearch(null)
}
this.updateTableSettings()
this.focusModeInternal = false
next()
},
beforeRouteLeave (to, from, next) {
this.resetShootSearch()
this.setShootSearch(null)
this.focusModeInternal = false
next()
},
Expand All @@ -311,15 +315,49 @@ export default {
shootCustomFields,
} = useProjectShootCustomFields(projectItem)

const params = useUrlSearchParams('hash-params')
const shootSearch = ref(params.q)
const debouncedShootSearch = ref(shootSearch.value)

function setShootSearch (value) {
debouncedShootSearch.value = shootSearch.value = value
}

const setDebouncedShootSearch = debounce(() => {
debouncedShootSearch.value = shootSearch.value
}, 300)

watch(() => params.q, value => {
if (shootSearch.value !== value) {
setShootSearch(value)
}
})

watch(debouncedShootSearch, value => {
if (!value) {
params.q = null
} else if (params.q !== value) {
params.q = value
}
})

function onUpdateShootSearch (value) {
shootSearch.value = value

setDebouncedShootSearch()
}

return {
activePopoverKey,
shootCustomFields,
shootSearch,
debouncedShootSearch,
setShootSearch,
onUpdateShootSearch,
}
},
data () {
return {
shootSearch: '',
debouncedShootSearch: '',
dialog: null,
page: 1,
selectedColumns: undefined,
Expand Down Expand Up @@ -775,10 +813,6 @@ export default {
'setFocusMode',
'setSortBy',
]),
resetShootSearch () {
this.shootSearch = null
this.debouncedShootSearch = null
},
async showDialog (args) {
switch (args.action) {
case 'access':
Expand Down Expand Up @@ -841,14 +875,6 @@ export default {
const filters = this.shootListFilters
return get(filters, key, false)
},
onUpdateShootSearch (value) {
this.shootSearch = value

this.setDebouncedShootSearch()
},
setDebouncedShootSearch: debounce(function () {
this.debouncedShootSearch = this.shootSearch
}, 500),
},
}
</script>