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 @@ -142,6 +142,7 @@ const emitSelect = (): void => {
fileName: unref(fileName),
locationQuery: JSON.parse(JSON.stringify(routeToContextQuery(unref(router.currentRoute))))
})
return
}

// TODO: adjust type to embedModeLocationPickMessageData later (breaking)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('EmbedActions', () => {
contextRouteQuery: {}
}
})
expect(mocks.postMessageMock).toHaveBeenCalledTimes(1)
})
})

Expand Down
28 changes: 24 additions & 4 deletions packages/web-pkg/src/components/Modals/LocationPickerModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ import {
import { RouteLocationRaw } from 'vue-router'
import AppLoadingSpinner from '../AppLoadingSpinner.vue'

const { modal, parentFolderLink, submitButtonTitle, callbackFn } = defineProps<{
const {
modal,
parentFolderLink,
submitButtonTitle,
chooseFileName,
chooseFileNameSuggestion,
callbackFn
} = defineProps<{
modal: Modal
parentFolderLink: RouteLocationRaw
submitButtonTitle?: string
callbackFn: (resources: embedModeLocationPickMessageData['resources']) => void
chooseFileName?: boolean
chooseFileNameSuggestion?: string
callbackFn: (
resources: embedModeLocationPickMessageData['resources'],
options?: { fileName?: string }
) => void
}>()

const iframeRef = ref<HTMLIFrameElement>()
Expand All @@ -48,6 +60,12 @@ iframeUrl.searchParams.append('embed-delegate-authentication', 'false')
if (submitButtonTitle) {
iframeUrl.searchParams.append('embed-submit-button-title', submitButtonTitle)
}
if (chooseFileName) {
iframeUrl.searchParams.append('embed-choose-file-name', 'true')
}
if (chooseFileNameSuggestion) {
iframeUrl.searchParams.append('embed-choose-file-name-suggestion', chooseFileNameSuggestion)
}

const onLoad = () => {
isLoading.value = false
Expand All @@ -60,15 +78,17 @@ const onLocationPick = ({ data }: MessageEvent) => {
}

let resources = (data.data as embedModeLocationPickMessageData)?.resources
let fileName = (data.data as embedModeLocationPickMessageData)?.fileName
if (Array.isArray(data.data)) {
resources = data.data
resources = data.data as embedModeLocationPickMessageData['resources']
fileName = undefined
}

if (!resources?.length) {
return
}

callbackFn(resources)
callbackFn(resources, { fileName })
removeModal(modal.id)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ describe('LocationPickerModal', () => {
'http://localhost:3000/files-spaces-generic?hide-logo=true&embed=true&embed-target=location&embed-delegate-authentication=false&embed-submit-button-title=Move+here'
)
})
it('sets file name picker parameters in iframe src when provided', () => {
const { wrapper } = getWrapper({
chooseFileName: true,
chooseFileNameSuggestion: 'archive.zip'
})
expect((wrapper.vm as any).iframeSrc).toEqual(
'http://localhost:3000/files-spaces-generic?hide-logo=true&embed=true&embed-target=location&embed-delegate-authentication=false&embed-choose-file-name=true&embed-choose-file-name-suggestion=archive.zip'
)
})
})
describe('method "onLocationPick"', () => {
it('does nothing if the event message does not equal "opencloud-embed:select"', () => {
Expand All @@ -47,6 +56,24 @@ describe('LocationPickerModal', () => {
expect((wrapper.vm as any).callbackFn).toHaveBeenCalled()
expect(modalStore.removeModal).toHaveBeenCalled()
})
it('passes file name to the callback', () => {
const { wrapper } = getWrapper()
;(wrapper.vm as any).onLocationPick({
data: {
name: 'opencloud-embed:select',
data: {
resources: [mock<Resource>({ storageId: '1' })],
fileName: 'archive.zip'
}
}
} as MessageEvent)
expect((wrapper.vm as any).callbackFn).toHaveBeenCalledWith(
expect.any(Array),
expect.objectContaining({
fileName: 'archive.zip'
})
)
})
it('calls callback function for legacy array payload when message does equal "opencloud-embed:select"', () => {
const { wrapper } = getWrapper()
const modalStore = useModals()
Expand All @@ -64,7 +91,15 @@ describe('LocationPickerModal', () => {
})
})

function getWrapper({ submitButtonTitle }: { submitButtonTitle?: string } = {}) {
function getWrapper({
submitButtonTitle,
chooseFileName,
chooseFileNameSuggestion
}: {
submitButtonTitle?: string
chooseFileName?: boolean
chooseFileNameSuggestion?: string
} = {}) {
const mocks = defaultComponentMocks()

return {
Expand All @@ -74,6 +109,8 @@ function getWrapper({ submitButtonTitle }: { submitButtonTitle?: string } = {})
modal: mock<Modal>(),
callbackFn: vi.fn(),
submitButtonTitle,
chooseFileName,
chooseFileNameSuggestion,
parentFolderLink: {
name: 'files-spaces-generic',
params: {
Expand Down