Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -194,19 +194,31 @@ export default defineComponent({
type: Object,
required: false,
default: null
},
paginationPages: {
type: Number,
required: false,
default: null
},
paginationPage: {
type: Number,
required: false,
default: null
}
},
setup() {
setup(props) {
const capabilityStore = useCapabilityStore()
const configStore = useConfigStore()
const { getMatchingSpace } = useGetMatchingSpace()
const { loadPreview } = useLoadPreview()

const { paginationPages, paginationPage } = useResourcesViewDefaults<
IncomingShareResource,
any,
any[]
>()
const {
paginationPages: defaultPaginationPages,
paginationPage: defaultPaginationPage
} = useResourcesViewDefaults<IncomingShareResource, any, any[]>()

const paginationPages = computed(() => props.paginationPages ?? unref(defaultPaginationPages))
const paginationPage = computed(() => props.paginationPage ?? unref(defaultPaginationPage))

const { triggerDefaultAction } = useFileActions()
const { actions: hideShareActions } = useFileActionsToggleHideShare()
Expand Down
66 changes: 56 additions & 10 deletions packages/web-app-files/src/views/shares/SharedWithMe.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
areHiddenFilesShown ? $gettext('No hidden shares') : $gettext('No shares')
"
:grouping-settings="groupingSettings"
:pagination-pages="paginationPages"
:pagination-page="paginationPage"
/>
</template>
</files-view-wrapper>
Expand All @@ -101,13 +103,14 @@ import {
FileSideBar,
InlineFilterOption,
ItemFilter,
usePagination,
useAppsStore,
useResourcesStore
} from '@ownclouders/web-pkg'
import { AppBar, ItemFilterInline } from '@ownclouders/web-pkg'
import { queryItemAsString, useRouteQuery } from '@ownclouders/web-pkg'
import { queryItemAsString, useRouteQuery, useRouter } from '@ownclouders/web-pkg'
import SharedWithMeSection from '../../components/Shares/SharedWithMeSection.vue'
import { computed, defineComponent, onMounted, ref, unref, watch } from 'vue'
import { computed, defineComponent, onMounted, ref, unref, watch, nextTick } from 'vue'
import FilesViewWrapper from '../../components/FilesViewWrapper.vue'
import { useGetMatchingSpace, useSort } from '@ownclouders/web-pkg'
import { useGroupingSettings } from '@ownclouders/web-pkg'
Expand All @@ -134,6 +137,8 @@ export default defineComponent({
const appsStore = useAppsStore()
const resourcesStore = useResourcesStore()

const router = useRouter()

const {
areResourcesLoading,
sortFields,
Expand All @@ -143,10 +148,14 @@ export default defineComponent({
selectedResourcesIds,
sideBarActivePanel,
isSideBarOpen,
paginatedResources,
scrollToResourceFromRoute
} = useResourcesViewDefaults<IncomingShareResource, any, any>()

// Use all active resources as the base — filtering must happen before pagination
const allResources = computed(
() => resourcesStore.activeResources as unknown as IncomingShareResource[]
)

const { $gettext } = useGettext()

const areHiddenFilesShown = ref(false)
Expand All @@ -167,8 +176,8 @@ export default defineComponent({
resourcesStore.resetSelection()
}

const visibleShares = computed(() => unref(paginatedResources).filter((r) => !r.hidden))
const hiddenShares = computed(() => unref(paginatedResources).filter((r) => r.hidden))
const visibleShares = computed(() => unref(allResources).filter((r) => !r.hidden))
const hiddenShares = computed(() => unref(allResources).filter((r) => r.hidden))
const currentItems = computed(() => {
return unref(areHiddenFilesShown) ? unref(hiddenShares) : unref(visibleShares)
})
Expand Down Expand Up @@ -217,11 +226,31 @@ export default defineComponent({
}
})

const { sortBy, sortDir, items, handleSort } = useSort({
const { sortBy, sortDir, items: sortedFilteredItems, handleSort } = useSort({
items: filteredItems,
fields: sortFields
})

const {
items: paginatedFilteredItems,
total: paginationPages,
page: paginationPage
} = usePagination({ items: sortedFilteredItems, perPageStoragePrefix: 'files' })

// Reset to page 1 whenever the active filter set changes to avoid landing on an empty page
watch(
[selectedShareTypesQuery, selectedSharedByQuery, filterTerm, areHiddenFilesShown],
async () => {
await nextTick()
if (unref(paginationPage) > unref(paginationPages)) {
router.push({ query: { ...router.currentRoute.value.query, page: 1 } })
}
}
)

// Keep items alias for backward compat (e.g. scrollToResourceFromRoute)
const items = paginatedFilteredItems

const { getMatchingSpace } = useGetMatchingSpace()

const selectedShareSpace = computed(() => {
Expand All @@ -235,7 +264,7 @@ export default defineComponent({
const openWithDefaultAppQuery = useRouteQuery('openWithDefaultApp')
const performLoaderTask = async () => {
await loadResourcesTask.perform()
scrollToResourceFromRoute(unref(items), 'files-app-bar')
scrollToResourceFromRoute(unref(sortedFilteredItems), 'files-app-bar')
if (queryItemAsString(unref(openWithDefaultAppQuery)) === 'true') {
openWithDefaultApp({
space: unref(selectedShareSpace),
Expand All @@ -245,7 +274,7 @@ export default defineComponent({
}

const shareTypes = computed(() => {
const uniqueShareTypes = uniq(unref(paginatedResources).flatMap((i) => i.shareTypes))
const uniqueShareTypes = uniq(unref(allResources).flatMap((i) => i.shareTypes))

const ocmAvailable = appsStore.appIds.includes('open-cloud-mesh')
if (ocmAvailable && !uniqueShareTypes.includes(ShareTypes.remote.value)) {
Expand All @@ -262,10 +291,25 @@ export default defineComponent({
})

const fileOwners = computed(() => {
const flatList = unref(paginatedResources)
const flatList = unref(allResources)
.map((i) => i.sharedBy)
.flat()
return [...new Map(flatList.map((item) => [item.displayName, item])).values()]
// Deduplicate by id so users with the same display name are not merged
const uniqueById = [...new Map(flatList.map((item) => [item.id, item])).values()]
// Count how many distinct ids share the same display name
const nameCounts = uniqueById.reduce(
(acc, item) => {
acc[item.displayName] = (acc[item.displayName] || 0) + 1
return acc
},
{} as Record<string, number>
)
// Append the account id when two users share the same display name
return uniqueById.map((item) =>
nameCounts[item.displayName] > 1
? { ...item, displayName: `${item.displayName} (${item.id})` }
: item
)
})

onMounted(() => {
Expand Down Expand Up @@ -296,6 +340,8 @@ export default defineComponent({
sortBy,
sortDir,
items,
paginationPages,
paginationPage,

// CERN
...useGroupingSettings({ sortBy: sortBy, sortDir: sortDir })
Expand Down
73 changes: 47 additions & 26 deletions packages/web-app-files/src/views/spaces/DriveRedirect.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<template>
<div class="oc-flex oc-width-1-1">
<app-loading-spinner />
<div class="oc-width-1-1">
<not-found-message v-if="showNotFound" />
<app-loading-spinner v-else />
</div>
</template>

<script lang="ts">
import { computed, defineComponent, unref } from 'vue'
import { useRoute, useRouter, useSpacesStore } from '@ownclouders/web-pkg'
import { computed, defineComponent, ref, unref, watchEffect } from 'vue'
import { useRoute, useRouter, useSpacesLoading, useSpacesStore } from '@ownclouders/web-pkg'
import { AppLoadingSpinner } from '@ownclouders/web-pkg'
import { urlJoin } from '@ownclouders/web-client'
import { createFileRouteOptions } from '@ownclouders/web-pkg'
import { createLocationSpaces } from '@ownclouders/web-pkg'
import NotFoundMessage from '../../components/FilesList/NotFoundMessage.vue'

// 'personal/home' is used as personal drive alias from static contexts
// (i.e. places where we can't load the actual personal space)
Expand All @@ -19,7 +20,8 @@ const fakePersonalDriveAlias = 'personal/home'
export default defineComponent({
name: 'DriveRedirect',
components: {
AppLoadingSpinner
AppLoadingSpinner,
NotFoundMessage
},
props: {
driveAliasAndItem: {
Expand All @@ -32,36 +34,55 @@ export default defineComponent({
const router = useRouter()
const route = useRoute()
const spacesStore = useSpacesStore()
const { areSpacesLoading } = useSpacesLoading()
const showNotFound = ref(false)

const personalSpace = computed(() => {
return spacesStore.spaces.find((space) => space.driveType === 'personal')
})

const isPersonalAlias = computed(() => {
return (
props.driveAliasAndItem.startsWith(fakePersonalDriveAlias) ||
props.driveAliasAndItem === 'personal' ||
props.driveAliasAndItem === ''
)
})

const itemPath = computed(() => {
return props.driveAliasAndItem.startsWith(fakePersonalDriveAlias)
? urlJoin(props.driveAliasAndItem.slice(fakePersonalDriveAlias.length))
: '/'
return urlJoin(props.driveAliasAndItem.slice(fakePersonalDriveAlias.length))
})

if (!unref(personalSpace)) {
router.replace(createLocationSpaces('files-spaces-projects'))
} else {
const { params, query } = createFileRouteOptions(unref(personalSpace), {
path: unref(itemPath)
})
watchEffect(() => {
if (unref(areSpacesLoading)) {
showNotFound.value = false
return
}

router
.replace({
...unref(route),
params: {
...unref(route).params,
...params
},
query
if (unref(isPersonalAlias) && unref(personalSpace)) {
showNotFound.value = false
const { params, query } = createFileRouteOptions(unref(personalSpace), {
path: unref(itemPath)
})
// avoid NavigationDuplicated error in console
.catch(() => {})
}

router
.replace({
...unref(route),
params: {
...unref(route).params,
...params
},
query
})
// avoid NavigationDuplicated error in console
.catch(() => {})
return
}

showNotFound.value = !unref(isPersonalAlias) || !unref(personalSpace)
})

return { showNotFound }
}
})
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ vi.mock('../../../../src/composables/resourcesViewDefaults')
vi.mock('@ownclouders/web-pkg', async (importOriginal) => ({
...(await importOriginal<any>()),
useSort: vi.fn().mockImplementation(() => useSortMock()),
usePagination: vi.fn().mockImplementation(({ items }) => ({
items,
total: ref(1),
page: ref(1),
perPage: ref(100)
})),
queryItemAsString: vi.fn(),
useRouteQuery: vi.fn(),
useOpenWithDefaultApp: vi.fn()
Expand Down Expand Up @@ -196,8 +202,11 @@ function getMountedWrapper({
mocks: defaultMocks,
wrapper: mount(SharedWithMe, {
global: {
plugins: [...defaultPlugins()],
plugins: [
...defaultPlugins({ piniaOptions: { resourcesStore: { resources: files } } })
],
mocks: defaultMocks,
provide: defaultMocks,
stubs: { ...defaultStubs, itemFilterInline: true, ItemFilter: true }
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,47 @@ import {
} from '@ownclouders/web-test-helpers'

describe('DriveRedirect view', () => {
it('redirects to "projects" route if no personal space exist', () => {
const { mocks } = getMountedWrapper()
expect(mocks.$router.replace).toHaveBeenCalledWith({
name: 'files-spaces-projects'
it('shows not found when no personal space exists for a personal alias', () => {
const { wrapper } = getMountedWrapper({
driveAliasAndItem: 'personal',
spacesInitialized: true,
spacesLoading: false
})
expect(wrapper.vm.showNotFound).toBe(true)
})

it('shows loading spinner while spaces are still loading', () => {
const { wrapper } = getMountedWrapper({
driveAliasAndItem: 'personal',
spacesInitialized: false,
spacesLoading: true
})
expect(wrapper.vm.showNotFound).toBe(false)
})
})

function getMountedWrapper({ currentRouteName = 'files-spaces-generic' } = {}) {
function getMountedWrapper({
currentRouteName = 'files-spaces-generic',
driveAliasAndItem = '',
spacesInitialized = false,
spacesLoading = false
} = {}) {
const mocks = {
...defaultComponentMocks({ currentRoute: mock<RouteLocation>({ name: currentRouteName }) })
}

return {
mocks,
wrapper: mount(DriveRedirect, {
props: { driveAliasAndItem },
global: {
plugins: [...defaultPlugins()],
plugins: [
...defaultPlugins({
piniaOptions: {
spacesState: { spacesInitialized, spacesLoading }
}
})
],
stubs: defaultStubs,
mocks,
provide: mocks
Expand Down
3 changes: 2 additions & 1 deletion packages/web-client/src/helpers/resource/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ const convertObjectToCamelCaseKeys = (data: Record<string, any>) => {
}

export function buildResource(resource: WebDavResponseResource): Resource {
const name = resource.props[DavProperty.Name]?.toString() || basename(resource.filename)
const name =
resource.basename || resource.props[DavProperty.Name]?.toString() || basename(resource.filename)
const id = resource.props[DavProperty.FileId]

const isFolder = resource.type === 'directory'
Expand Down
2 changes: 1 addition & 1 deletion packages/web-pkg/src/helpers/router/routeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const createFileRouteOptions = (
const config = options?.configStore || useConfigStore()
return {
params: {
driveAliasAndItem: space.getDriveAliasAndItem({ path: target.path || '' } as Resource)
driveAliasAndItem: space?.getDriveAliasAndItem({ path: target.path || '' } as Resource)
},
query: {
...(isShareSpaceResource(space) && { shareId: space.id }),
Expand Down
Loading