Skip to content

Commit

Permalink
Fix spaces in search results
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed May 12, 2023
1 parent 327dd53 commit f330e9b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-spaces-in-search-results
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: Spaces in search results

Spaces in search results are no longer being displyed as folder resources, fixing wrong icons and sidebar panels.

https://github.com/owncloud/web/issues/9022
https://github.com/owncloud/web/pull/9026
16 changes: 13 additions & 3 deletions packages/web-app-files/src/search/sdk/list.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
import { SearchList, SearchResult } from 'web-app-search/src/types'
import ListComponent from '../../components/Search/List.vue'
import { ClientService } from 'web-pkg/src/services'
import { buildResource } from 'web-client/src/helpers'
import { ProjectSpaceResource, buildResource, isProjectSpaceResource } from 'web-client/src/helpers'
import { Component } from 'vue'
import { DavProperties } from 'web-client/src/webdav/constants'
import { DavProperties, DavProperty } from 'web-client/src/webdav/constants'
import { Store } from 'vuex'
import { computed, Ref, unref } from 'vue'

export const searchLimit = 200

export default class List implements SearchList {
public readonly component: Component
private readonly store: Store<any>
private readonly clientService: ClientService
private readonly projectSpaces: Ref<ProjectSpaceResource[]>

constructor(store: Store<any>, clientService: ClientService) {
this.component = ListComponent
this.store = store
this.clientService = clientService
this.projectSpaces = computed(() =>
this.store.getters['runtime/spaces/spaces'].filter((s) => isProjectSpaceResource(s))
)
}

getMatchingSpace(resourceId): ProjectSpaceResource {
return unref(this.projectSpaces).find(({ id }) => resourceId.startsWith(id))
}

async search(term: string): Promise<SearchResult> {
Expand All @@ -36,7 +45,8 @@ export default class List implements SearchList {
return {
totalResults: range ? parseInt(range?.split('/')[1]) : null,
values: results.map((result) => {
const resource = buildResource(result)
const matchingSpace = this.getMatchingSpace(result.fileInfo[DavProperty.FileId])
const resource = !!matchingSpace ? matchingSpace : buildResource(result)
// info: in oc10 we have no storageId in resources. All resources are mounted into the personal space.
if (!resource.storageId) {
resource.storageId = this.store.getters.user.id
Expand Down
1 change: 1 addition & 0 deletions packages/web-client/src/helpers/space/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export function buildSpace(data): SpaceResource {
mdate: data.lastModifiedDateTime,
size: data.quota?.used,
indicators: [],
tags: [],
permissions: '',
starred: false,
etag: '',
Expand Down

0 comments on commit f330e9b

Please sign in to comment.