Skip to content

Commit

Permalink
Keep sidebar menu selected for different kinds of personal volumes
Browse files Browse the repository at this point in the history
The current implementation hardcodes this and assumes that the personal volume always starts with `personal/`, which might not be the case.
  • Loading branch information
diocas committed Nov 21, 2024
1 parent db23e04 commit 7dd2fb8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
54 changes: 46 additions & 8 deletions packages/web-app-files/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ import { AppNavigationItem } from '@ownclouders/web-pkg'

// dirty: importing view from other extension within project
import SearchResults from '../../web-app-search/src/views/List.vue'
import { isPersonalSpaceResource, isShareSpaceResource } from '@ownclouders/web-client'
import {
isPersonalSpaceResource,
isShareSpaceResource,
isProjectSpaceResource,
isMountPointSpaceResource
} from '@ownclouders/web-client'
import { ComponentCustomProperties, unref } from 'vue'
import { extensionPoints } from './extensionPoints'

Expand Down Expand Up @@ -57,6 +62,19 @@ export const navItems = (context: ComponentCustomProperties): AppNavigationItem[
isActive: () => {
return !spacesStores.currentSpace || spacesStores.currentSpace?.isOwner(userStore.user)
},
activeFor: () => {
const personalSpace = spacesStores.spaces.find(
(drive) => isPersonalSpaceResource(drive) && drive.isOwner(userStore.user)
)

return personalSpace
? [
{
path: `/${appInfo.id}/spaces/${personalSpace.driveAlias}`
}
]
: []
},
isVisible() {
if (!spacesStores.spacesInitialized) {
return true
Expand Down Expand Up @@ -90,11 +108,21 @@ export const navItems = (context: ComponentCustomProperties): AppNavigationItem[
// last check is when fullShareOwnerPaths is enabled
return !space || isShareSpaceResource(space) || !space?.isOwner(userStore.user)
},
activeFor: [
{ path: `/${appInfo.id}/spaces/share` },
{ path: `/${appInfo.id}/spaces/ocm-share` },
{ path: `/${appInfo.id}/spaces/personal` }
],
activeFor: () => {
const shares = [
{ path: `/${appInfo.id}/spaces/share` },
{ path: `/${appInfo.id}/spaces/ocm-share` },
{ path: `/${appInfo.id}/spaces/personal` }
]
spacesStores.spaces.forEach((drive) => {
if (isMountPointSpaceResource(drive)) {
shares.push({
path: `/${appInfo.id}/spaces/${drive.root?.remoteItem?.driveAlias}`
})
}
})
return shares
},
isVisible() {
return capabilityStore.sharingApiEnabled !== false
},
Expand All @@ -106,7 +134,17 @@ export const navItems = (context: ComponentCustomProperties): AppNavigationItem[
route: {
path: `/${appInfo.id}/spaces/projects`
},
activeFor: [{ path: `/${appInfo.id}/spaces/project` }],
activeFor: () => {
const projects = [{ path: `/${appInfo.id}/spaces/project` }]
spacesStores.spaces.forEach((drive) => {
if (isProjectSpaceResource(drive)) {
projects.push({
path: `/${appInfo.id}/spaces/${drive.driveAlias}`
})
}
})
return projects
},
isVisible() {
return capabilityStore.spacesProjects
},
Expand All @@ -118,7 +156,7 @@ export const navItems = (context: ComponentCustomProperties): AppNavigationItem[
route: {
path: `/${appInfo.id}/trash/overview`
},
activeFor: [{ path: `/${appInfo.id}/trash` }],
activeFor: () => [{ path: `/${appInfo.id}/trash` }],
isVisible() {
return (
capabilityStore.davTrashbin === '1.0' &&
Expand Down
2 changes: 1 addition & 1 deletion packages/web-pkg/src/apps/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AppReadyHookArgs {

export interface AppNavigationItem {
isActive?: () => boolean
activeFor?: { name?: string; path?: string }[]
activeFor?: () => { name?: string; path?: string }[]
isVisible?: () => boolean
fillType?: IconFillType
icon?: string
Expand Down
3 changes: 2 additions & 1 deletion packages/web-runtime/src/layouts/Application.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ export default defineComponent({
let active = typeof item.isActive !== 'function' || item.isActive()
if (active) {
active = [item.route, ...(item.activeFor || [])].filter(Boolean).some((currentItem) => {
const activeFor = typeof item.activeFor === 'function' ? item.activeFor() : []
active = [item.route, ...activeFor].filter(Boolean).some((currentItem) => {
try {
const comparativeHref = router.resolve(currentItem).href
return currentHref.startsWith(comparativeHref)
Expand Down

0 comments on commit 7dd2fb8

Please sign in to comment.