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

@uppy/utils: fix relativePath when drag&dropping a folder #4043

Merged
merged 1 commit into from Aug 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions e2e/cypress/integration/dashboard-ui.spec.ts
Expand Up @@ -33,5 +33,8 @@ describe('dashboard-ui', () => {
cy.get('.uppy-Dashboard-Item-previewImg')
.should('have.length', 3)
.each((element) => expect(element).attr('src').to.include('blob:'))
cy.window().then(({ uppy }) => {
expect(JSON.stringify(uppy.getFiles().map(file => file.meta.relativePath))).to.be.equal('[null,null,null,null]')
})
})
})

This file was deleted.

@@ -1,4 +1,3 @@
import getRelativePath from './getRelativePath.js'
import getFilesAndDirectoriesFromDirectory from './getFilesAndDirectoriesFromDirectory.js'

/**
Expand All @@ -9,6 +8,7 @@ function getAsFileSystemHandleFromEntry (entry, logDropError) {
return {
// eslint-disable-next-line no-nested-ternary
kind: entry.isFile ? 'file' : entry.isDirectory ? 'directory' : undefined,
name: entry.name,
getFile () {
return new Promise((resolve, reject) => entry.file(resolve, reject))
},
Expand All @@ -25,17 +25,17 @@ function getAsFileSystemHandleFromEntry (entry, logDropError) {
}
}

async function* createPromiseToAddFileOrParseDirectory (entry) {
async function* createPromiseToAddFileOrParseDirectory (entry, relativePath) {
// For each dropped item, - make sure it's a file/directory, and start deepening in!
if (entry.kind === 'file') {
const file = await entry.getFile()
if (file !== null) {
file.relativePath = getRelativePath(entry)
file.relativePath = relativePath ? `${relativePath}/${entry.name}` : null
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use ?? here instead?

Copy link
Member

Choose a reason for hiding this comment

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

You only can if we would take relativePath as is, since we don't, it has to be a ternary.

yield file
}
} else if (entry.kind === 'directory') {
for await (const handle of entry.values()) {
yield* createPromiseToAddFileOrParseDirectory(handle)
yield* createPromiseToAddFileOrParseDirectory(handle, `${relativePath}/${entry.name}`)
}
}
}
Expand All @@ -53,7 +53,7 @@ export default async function* getFilesFromDataTransfer (dataTransfer, logDropEr
// :entry can be null when we drop the url e.g.
if (entry != null) {
try {
yield* createPromiseToAddFileOrParseDirectory(entry, logDropError)
yield* createPromiseToAddFileOrParseDirectory(entry, '')
} catch (err) {
if (lastResortFile) {
yield lastResortFile
Expand Down