Skip to content
Merged
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 @@ -6,7 +6,7 @@ import { useFileActionsRestore } from './useFileActionsRestore'
import { storeToRefs } from 'pinia'
import { useCapabilityStore, useClientService } from '../../'
import { isPersonalSpaceResource, isProjectSpaceResource } from '@opencloud-eu/web-client'
import { isMacOs } from '../../../helpers'
import { isItemInCurrentFolder, isMacOs } from '../../../helpers'

type UndoActionOptions = FileActionOptions & { callback?: () => void }

Expand All @@ -21,7 +21,7 @@ export const useFileActionsUndoDelete = () => {
const { actions: restoreActions } = useFileActionsRestore({
showSuccessMessage: false,
onRestoreComplete: async ({ space, resources }) => {
if (unref(currentFolder)?.id === resources[0].parentFolderId) {
if (isItemInCurrentFolder({ resourcesStore, parentFolderId: resources[0].parentFolderId })) {
// update local folder
const { children } = await webdav.listFiles(space, { path: unref(currentFolder).path })
resourcesStore.upsertResources(
Expand Down
1 change: 1 addition & 0 deletions packages/web-pkg/src/helpers/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export * from './sameResource'
export * from './conflictHandling'
export * from './filter'
export * from './icon'
export * from './isItemInCurrentFolder'
export * from './renameResource'
29 changes: 29 additions & 0 deletions packages/web-pkg/src/helpers/resource/isItemInCurrentFolder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { extractNodeId } from '@opencloud-eu/web-client'
import { ResourcesStore } from '../../composables'

export const isItemInCurrentFolder = ({
resourcesStore,
parentFolderId
}: {
resourcesStore: ResourcesStore
parentFolderId: string
}) => {
const currentFolder = resourcesStore.currentFolder
if (!currentFolder || !currentFolder.id) {
return false
}

if (!extractNodeId(currentFolder.id)) {
// if we don't have a nodeId here, we have a space (root) as current folder and can only check against the storageId
const spaceNodeId = currentFolder.id.split('$')[1]
if (`${currentFolder.id}!${spaceNodeId}` !== parentFolderId) {
return false
}
} else {
if (currentFolder.id !== parentFolderId) {
return false
}
}

return true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Resource, SpaceResource } from '@opencloud-eu/web-client'
import { createTestingPinia } from '@opencloud-eu/web-test-helpers'
import { mock } from 'vitest-mock-extended'
import { isItemInCurrentFolder, useResourcesStore } from '../../../../src'

describe('helpers', () => {
describe('method "isItemInCurrentFolder"', () => {
it('returns "true" when item is in current folder', () => {
const mocks = getMocks()
expect(
isItemInCurrentFolder({
resourcesStore: mocks.resourcesStore,
parentFolderId: 'currentFolder!currentFolder'
})
).toBeTruthy()
})
it('returns "false" when item is not in current folder', () => {
const mocks = getMocks()
expect(
isItemInCurrentFolder({
resourcesStore: mocks.resourcesStore,
parentFolderId: 'differentFolder!differentFolder'
})
).toBeFalsy()
})
describe('current folder is space', () => {
it('returns "true" when item is in current folder', () => {
const mocks = getMocks({
currentFolder: mock<SpaceResource>({
id: 'bbf8b91f-54be-45f0-935e-a50c4922db21$c96eb07d-54a5-47bf-8402-64ad9a007797'
})
})
expect(
isItemInCurrentFolder({
resourcesStore: mocks.resourcesStore,
parentFolderId:
'bbf8b91f-54be-45f0-935e-a50c4922db21$c96eb07d-54a5-47bf-8402-64ad9a007797!c96eb07d-54a5-47bf-8402-64ad9a007797'
})
).toBeTruthy()
})
it('returns "false" when item is not in current folder', () => {
const mocks = getMocks({
currentFolder: mock<SpaceResource>({
id: 'bbf8b91f-54be-45f0-935e-a50c4922db21$c96eb07d-54a5-47bf-8402-64ad9a007797'
})
})
expect(
isItemInCurrentFolder({
resourcesStore: mocks.resourcesStore,
parentFolderId: 'differentFolder!differentFolder'
})
).toBeFalsy()
})
})
})
})

const getMocks = ({
currentFolder = mock<Resource>({
id: 'currentFolder!currentFolder',
isFolder: true,
storageId: 'space1'
})
}: { currentFolder?: Resource } = {}) => {
createTestingPinia()
const resourcesStore = useResourcesStore()
resourcesStore.currentFolder = currentFolder

return {
resourcesStore
}
}
7 changes: 5 additions & 2 deletions packages/web-runtime/src/container/sse/files.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createFileRouteOptions, ImageDimension } from '@opencloud-eu/web-pkg'
import {
createFileRouteOptions,
ImageDimension,
isItemInCurrentFolder
} from '@opencloud-eu/web-pkg'
import { SSEEventOptions } from './types'
import { isItemInCurrentFolder } from './helpers'

export const onSSEItemRenamedEvent = async ({
sseData,
Expand Down
28 changes: 0 additions & 28 deletions packages/web-runtime/src/container/sse/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { ResourcesStore } from '@opencloud-eu/web-pkg'
import { extractNodeId } from '@opencloud-eu/web-client'
import { eventSchema, SseEventWrapperOptions } from './types'

export const sseEventWrapper = (options: SseEventWrapperOptions) => {
Expand All @@ -13,29 +11,3 @@ export const sseEventWrapper = (options: SseEventWrapperOptions) => {
console.error(`Unable to process sse event ${topic}`, e)
}
}
export const isItemInCurrentFolder = ({
resourcesStore,
parentFolderId
}: {
resourcesStore: ResourcesStore
parentFolderId: string
}) => {
const currentFolder = resourcesStore.currentFolder
if (!currentFolder || !currentFolder.id) {
return false
}

if (!extractNodeId(currentFolder.id)) {
// if we don't have a nodeId here, we have a space (root) as current folder and can only check against the storageId
const spaceNodeId = currentFolder.id.split('$')[1]
if (`${currentFolder.id}!${spaceNodeId}` !== parentFolderId) {
return false
}
} else {
if (currentFolder.id !== parentFolderId) {
return false
}
}

return true
}
8 changes: 6 additions & 2 deletions packages/web-runtime/src/container/sse/shares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import {
buildOutgoingShareResource,
ShareTypes
} from '@opencloud-eu/web-client'
import { eventBus, isLocationSharesActive, isLocationSpacesActive } from '@opencloud-eu/web-pkg'
import {
eventBus,
isLocationSharesActive,
isLocationSpacesActive,
isItemInCurrentFolder
} from '@opencloud-eu/web-pkg'
import { SSEEventOptions } from './types'
import { isItemInCurrentFolder } from './helpers'

export const onSSESpaceMemberAddedEvent = async ({
sseData,
Expand Down
53 changes: 2 additions & 51 deletions packages/web-runtime/tests/unit/container/sse/helpers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Resource, SpaceResource } from '@opencloud-eu/web-client'
import { Resource } from '@opencloud-eu/web-client'
import { createTestingPinia } from '@opencloud-eu/web-test-helpers'
import {
ClientService,
Expand All @@ -11,7 +11,7 @@ import {
useUserStore
} from '@opencloud-eu/web-pkg'
import { mock, mockDeep } from 'vitest-mock-extended'
import { isItemInCurrentFolder, sseEventWrapper } from '../../../../src/container/sse'
import { sseEventWrapper } from '../../../../src/container/sse'
import PQueue from 'p-queue'
import { Language } from 'vue3-gettext'
import { Router } from 'vue-router'
Expand Down Expand Up @@ -46,55 +46,6 @@ describe('helpers', () => {
expect(console.error).toHaveBeenCalledWith(`Unable to process sse event ${topic}`, error)
})
})
describe('method "isItemInCurrentFolder"', () => {
it('returns "true" when item is in current folder', () => {
const mocks = getMocks()
expect(
isItemInCurrentFolder({
resourcesStore: mocks.resourcesStore,
parentFolderId: 'currenFolder!currentFolder'
})
).toBeTruthy()
})
it('returns "false" when item is not in current folder', () => {
const mocks = getMocks()
expect(
isItemInCurrentFolder({
resourcesStore: mocks.resourcesStore,
parentFolderId: 'differentFolder!differentFolder'
})
).toBeFalsy()
})
describe('current folder is space', () => {
it('returns "true" when item is in current folder', () => {
const mocks = getMocks({
currentFolder: mock<SpaceResource>({
id: 'bbf8b91f-54be-45f0-935e-a50c4922db21$c96eb07d-54a5-47bf-8402-64ad9a007797'
})
})
expect(
isItemInCurrentFolder({
resourcesStore: mocks.resourcesStore,
parentFolderId:
'bbf8b91f-54be-45f0-935e-a50c4922db21$c96eb07d-54a5-47bf-8402-64ad9a007797!c96eb07d-54a5-47bf-8402-64ad9a007797'
})
).toBeTruthy()
})
it('returns "false" when item is not in current folder', () => {
const mocks = getMocks({
currentFolder: mock<SpaceResource>({
id: 'bbf8b91f-54be-45f0-935e-a50c4922db21$c96eb07d-54a5-47bf-8402-64ad9a007797'
})
})
expect(
isItemInCurrentFolder({
resourcesStore: mocks.resourcesStore,
parentFolderId: 'differentFolder!differentFolder'
})
).toBeFalsy()
})
})
})
})

const getMocks = ({
Expand Down