Skip to content

Commit

Permalink
fix: scope when clicking "Show n results"
Browse files Browse the repository at this point in the history
Prevents the search scope from getting lost when clicking "Show n results" in the search preview.
  • Loading branch information
JammingBen committed Mar 21, 2024
1 parent 891c7c7 commit c5c0ab8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 47 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-scope-loss-search-results
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Scope loss when showing search results

Clicking "Show n results" in the search preview no longer loses the search scope.

https://github.com/owncloud/web/issues/10634
https://github.com/owncloud/web/pull/10653
86 changes: 39 additions & 47 deletions packages/web-app-search/src/portals/SearchBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<li class="oc-text-truncate oc-flex oc-flex-between oc-text-muted provider-details">
<span class="display-name" v-text="$gettext(provider.displayName)" />
<span v-if="!!provider.listSearch">
<router-link class="more-results" :to="getMoreResultsLinkForProvider(provider)">
<router-link class="more-results" :to="getSearchResultLocation(provider.id)">
<span>{{ getMoreResultsDetailsTextForProvider(provider) }}</span>
</router-link>
</span>
Expand Down Expand Up @@ -104,7 +104,8 @@
import {
createLocationCommon,
isLocationCommonActive,
isLocationSpacesActive
isLocationSpacesActive,
queryItemAsString
} from '@ownclouders/web-pkg'
import Mark from 'mark.js'
import { debounce } from 'lodash-es'
Expand Down Expand Up @@ -165,27 +166,32 @@ export default defineComponent({
return unref(optionsDropRef) as InstanceType<GlobalComponents['OcDrop']>
})
const scope = computed(() => {
const currentFolder = store.getters['Files/currentFolder']
if (unref(currentFolderAvailable) && currentFolder?.fileId) {
return currentFolder.fileId
}
return queryItemAsString(unref(scopeQueryValue))
})
const useScope = computed(() => {
return (
unref(currentFolderAvailable) &&
unref(locationFilterId) === SearchLocationFilterConstants.currentFolder
)
})
const search = async () => {
searchResults.value = []
if (!unref(term)) {
return
}
const terms = [`name:"*${unref(term)}*"`]
if (
unref(currentFolderAvailable) &&
unref(locationFilterId) === SearchLocationFilterConstants.currentFolder
) {
const currentFolder = store.getters['Files/currentFolder']
let scope
if (currentFolder?.fileId) {
scope = currentFolder?.fileId
} else {
scope = unref(scopeQueryValue)
}
terms.push(`scope:${scope}`)
if (unref(useScope)) {
terms.push(`scope:${unref(scope)}`)
}
loading.value = true
Expand All @@ -211,29 +217,7 @@ export default defineComponent({
}
if (unref(activePreviewIndex) === null) {
const currentQuery = unref(router.currentRoute).query
const currentFolder = store.getters['Files/currentFolder']
let scope
if (unref(currentFolderAvailable) && currentFolder?.fileId) {
scope = currentFolder?.fileId
} else {
scope = unref(scopeQueryValue)
}
const useScope =
unref(currentFolderAvailable) &&
unref(locationFilterId) === SearchLocationFilterConstants.currentFolder
router.push(
createLocationCommon('files-common-search', {
query: {
...(currentQuery && { ...currentQuery }),
term: unref(term),
...(scope && { scope }),
useScope: useScope.toString(),
provider: 'files.sdk'
}
})
)
router.push(getSearchResultLocation('files.sdk'))
}
if (unref(activePreviewIndex) !== null) {
unref(optionsDrop)
Expand All @@ -242,6 +226,20 @@ export default defineComponent({
}
}
const getSearchResultLocation = (providerId: string) => {
const currentQuery = unref(router.currentRoute).query
return createLocationCommon('files-common-search', {
query: {
...(currentQuery && { ...currentQuery }),
term: unref(term),
...(unref(scope) && { scope: unref(scope) }),
useScope: unref(useScope).toString(),
provider: providerId
}
})
}
const onLocationFilterChange = (event) => {
locationFilterId.value = event.value.id
if (!unref(term)) {
Expand Down Expand Up @@ -292,7 +290,8 @@ export default defineComponent({
availableProviders,
search,
showPreview,
updateTerm
updateTerm,
getSearchResultLocation
}
},
Expand Down Expand Up @@ -423,13 +422,6 @@ export default defineComponent({
getSearchResultForProvider(provider) {
return this.searchResults.find(({ providerId }) => providerId === provider.id)?.result
},
getMoreResultsLinkForProvider(provider) {
const currentQuery = unref(this.$router.currentRoute).query
return createLocationCommon('files-common-search', {
query: { ...(currentQuery && { ...currentQuery }), term: this.term, provider: provider.id }
})
},
parseRouteQuery(route, initialLoad = false) {
const currentFolderAvailable =
(isLocationSpacesActive(this.$router, 'files-spaces-generic') || !!this.scopeQueryValue) &&
Expand Down

0 comments on commit c5c0ab8

Please sign in to comment.