Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indicate that a file is uploading because user has chosen a folder #2605

Closed
wants to merge 11 commits into from
41 changes: 35 additions & 6 deletions packages/@uppy/provider-views/src/ProviderView/ProviderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ module.exports = class ProviderView {
this.lastCheckbox = undefined
}

addFile (file) {
addFile (file, meta) {
const tagFile = {
id: this.providerFileToId(file),
source: this.plugin.id,
data: file,
data: {
...file,
path: file.requestPath
},
name: file.name || file.id,
type: file.mimeType,
isRemote: true,
Expand All @@ -171,7 +174,8 @@ module.exports = class ProviderView {
fileId: file.id
},
providerOptions: this.provider.opts
}
},
...(Boolean(meta) && { meta })
}

const fileType = getFileType(tagFile)
Expand Down Expand Up @@ -321,10 +325,23 @@ module.exports = class ProviderView {
}
folders[folderId] = { loading: true, files: [] }
this.plugin.setPluginState({ selectedFolders: { ...folders } })
return this.listAllFiles(folder.requestPath).then((files) => {

folder.relativePath = folder.relativePath || ''
const filesRelativePath = `${folder.relativePath}/${folder.name}`

return this.listAllFiles(
folder.requestPath,
null,
{ previousRelativePath: folder.relativePath, currentFolder: folder }
).then((files) => {
let count = 0
files.forEach((file) => {
const success = this.addFile(file)
const success = this.addFile(file, {
relativePath: filesRelativePath,
// Indicates that this file was selected through
// folder selection.
isSelectedFromFolder: true
})
if (success) count++
})
const ids = files.map(this.providerFileToId)
Expand Down Expand Up @@ -430,11 +447,23 @@ module.exports = class ProviderView {
}
}

listAllFiles (path, files = null) {
listAllFiles (path, files = null, meta = undefined) {
files = files || []
return new Promise((resolve, reject) => {
this.provider.list(path).then((res) => {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This res is where we'd need currentFolderName. Currently, if moreFiles === true, this implementation won't reproduce the correct parent's folder names for Google Drive and OneDrive since their IDs are unique, hashed strings instead of folder names (IMHO, Dropbox took the cleverest approach here).

FWIW, the relativePath in the data object is giving /{fileId}; and this is the reason that the above statement is relevant.

Read more at #2605 (comment).

let itemsRelativePath

if (meta) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My idea on having this condition here is that if there's a meta, then there's a previousRelativePath and a currentFolder. That's why I skipped checking those individual properties.

const { previousRelativePath, currentFolder } = meta

itemsRelativePath = `${previousRelativePath}/${currentFolder.name}`
}

res.items.forEach((item) => {
if (itemsRelativePath) {
item.relativePath = itemsRelativePath
}

if (!item.isFolder) {
files.push(item)
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/@uppy/utils/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ declare module '@uppy/utils' {
[key: string]: T
[key: number]: T
}
export type InternalMetadata = { name: string; type?: string }
export type InternalMetadata = { name: string; type?: string; isSelectedFromFolder?: boolean; relativePath?: string; }
export interface UppyFile<
TMeta = IndexedObject<any>,
TBody = IndexedObject<any>
Expand Down