Skip to content

Commit

Permalink
WIP fix share routing
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Mar 28, 2022
1 parent a81667f commit 7373302
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
29 changes: 21 additions & 8 deletions packages/web-app-files/src/components/FilesList/ResourceTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ export default defineComponent({
required: false,
default: null
},
/**
* Mapping with template `<resource.field>:<targetRoute.param>` which maps a field of a resource to a param of the target route.
* Defaults to `storageId:storageId` to map the `storageId` field of a resource to the `storageId` param of the target route.
*/
targetRouteParamMapper: {
type: String,
required: false,
default: 'storageId:storageId'
},
/**
* Asserts whether clicking on the resource name triggers any action
*/
Expand Down Expand Up @@ -506,23 +515,27 @@ export default defineComponent({
this.$_rename_trigger({ resources: [item] })
},
folderLink(file) {
return this.createFolderLink(file.path, file.storageId)
return this.createFolderLink(file.path, file)
},
parentFolderLink(file) {
return this.createFolderLink(path.dirname(file.path), file.storageId)
return this.createFolderLink(path.dirname(file.path), file)
},
createFolderLink(path, storageId) {
createFolderLink(path, file) {
if (this.targetRoute === null) {
return {}
}
let params = {
item: path.replace(/^\//, ''),
...this.targetRoute.params,
}
const targetRouteParamMapper = this.targetRouteParamMapper.split(':')
if (file[targetRouteParamMapper[0]]) {
params[targetRouteParamMapper[1]] = file[targetRouteParamMapper[0]]
}
return {
name: this.targetRoute.name,
query: this.targetRoute.query,
params: {
item: path.replace(/^\//, ''),
...this.targetRoute.params,
...(storageId && { storageId })
}
params
}
},
fileDragged(file) {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-app-files/src/router/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const buildRoutes = (components: RouteComponents): RouteConfig[] => [
}
},
{
path: 'shares/:storageId?/:item*',
path: 'shares/:shareName?/:item*',
name: locationSpacesShare.name,
component: components.SharedResource,
meta: {
Expand Down
11 changes: 5 additions & 6 deletions packages/web-app-files/src/services/folder/loaderSharedWithMe.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FolderLoader, FolderLoaderTask, TaskContext } from '../folder'
import Router from 'vue-router'
import { useTask } from 'vue-concurrency'
import { aggregateResourceShares } from '../../helpers/resources'
import { aggregateResourceShares, buildWebDavSpacesPath } from '../../helpers/resources'
import { isLocationSharesActive } from '../../router'
import { Store } from 'vuex'
import get from 'lodash-es/get'
Expand Down Expand Up @@ -46,13 +46,12 @@ export class FolderLoaderSharedWithMe implements FolderLoader {
getToken
)

// FIXME, HACK 1: `/Shares` path prefix needs to be removed backend side. We remove it client side in the meantime.
// FIXME, HACK 2: webDavPath points to `files/<user>/Shares/xyz` but now needs to point to a shares webDavPath according to the storageId of the share. meh.
// FIXME, HACK 1: path needs to be empty because the share has it's own webdav endpoint (we access it's root and thus don't need any relative path). should ideally be removed backend side.
// FIXME, HACK 2: webDavPath points to `files/<user>/Shares/xyz` but now needs to point to a shares webdav root.
if (get(store, 'getters.capabilities.spaces.enabled', false)) {
resources.forEach((resource) => {
if (resource.path.startsWith('/Shares')) {
resource.path = resource.path.substring('/Shares'.length)
}
resource.path = ''
resource.webDavPath = buildWebDavSpacesPath(resource.storageId, '')
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ import { FolderLoader, FolderLoaderTask, TaskContext } from '../../folder'
import Router from 'vue-router'
import { useTask } from 'vue-concurrency'
import { DavProperties } from 'web-pkg/src/constants'
import {
buildResource,
buildWebDavFilesPath,
buildWebDavSpacesPath
} from '../../../helpers/resources'
import { buildResource, buildWebDavSpacesPath } from '../../../helpers/resources'
import { isLocationSpacesActive } from '../../../router'
import { Store } from 'vuex'
import { fetchResources } from '../util'
Expand Down
1 change: 1 addition & 0 deletions packages/web-app-files/src/views/shares/SharedWithMe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
:resources="sharesItems"
:are-resources-clickable="showsAcceptedShares"
:target-route="resourceTargetLocation"
target-route-param-mapper="name:shareName"
:header-position="fileListHeaderY"
:sort-by="sharesSortBy"
:sort-dir="sharesSortDir"
Expand Down

0 comments on commit 7373302

Please sign in to comment.