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

fix(uploader): images should display when they've been successfully uploaded #2448

Merged
merged 7 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 6 additions & 9 deletions src/packages/uploader/uploader.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,26 +304,25 @@ const InternalUploader: ForwardRefRenderFunction<
uploadOption.onStart = (option: UploadOptions) => {
clearUploadQueue(index)
setFileList(
fileList.map((item) => {
[...fileList, fileItem].map((item) => {
Copy link

Choose a reason for hiding this comment

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

请考虑为新代码添加测试。

根据以前的学习记忆,当fileList状态有变更时,需要确保有相应的单元测试覆盖。

需要帮助生成单元测试代码或在GitHub上跟踪此任务吗?

if (item.uid === fileItem.uid) {
item.status = 'ready'
item.message = locale.uploader.readyUpload
}
return item
})
)
onStart && onStart(option)
onStart?.(option)
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
}

uploadOption.onProgress = (e: any, option: UploadOptions) => {
setFileList(
fileList.map((item) => {
[...fileList, fileItem].map((item) => {
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
if (item.uid === fileItem.uid) {
item.status = UPLOADING
item.message = locale.uploader.uploading
item.percentage = e.progress
onProgress &&
onProgress({ e, option, percentage: item.percentage as number })
onProgress?.({ e, option, percentage: item.percentage as number })
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
}
return item
})
Expand All @@ -334,7 +333,7 @@ const InternalUploader: ForwardRefRenderFunction<
responseText: XMLHttpRequest['responseText'],
option: UploadOptions
) => {
const list = fileList.map((item) => {
const list = [...fileList, fileItem].map((item) => {
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
if (item.uid === fileItem.uid) {
item.status = SUCCESS
item.message = locale.uploader.success
Expand Down Expand Up @@ -440,9 +439,7 @@ const InternalUploader: ForwardRefRenderFunction<
}
return true
})
if (oversizes.length) {
onOversize && onOversize(files as any)
}
oversizes.length && onOversize?.(files as any)
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved

const currentFileLength = filterFile.length + fileList.length
if (currentFileLength > maximum) {
Expand Down
18 changes: 6 additions & 12 deletions src/packages/uploader/uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@
clearUploadQueue()
},
}))

const clearUploadQueue = (index = -1) => {
if (index > -1) {
uploadQueue.splice(index, 1)
Expand Down Expand Up @@ -202,27 +201,27 @@
uploadOption.onStart = (option: UploadOptions) => {
clearUploadQueue(index)
setFileList(
fileList.map((item) => {
[...fileList, fileItem].map((item) => {

Check warning on line 204 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L204

Added line #L204 was not covered by tests
Copy link

Choose a reason for hiding this comment

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

请添加测试以覆盖新代码。

根据静态分析工具的警告,这一行新增的代码没有被测试覆盖。

Tools
GitHub Check: codecov/patch

[warning] 204-204: src/packages/uploader/uploader.tsx#L204
Added line #L204 was not covered by tests

if (item.uid === fileItem.uid) {
item.status = 'ready'
item.message = locale.uploader.readyUpload
}
return item
})
)
onStart && onStart(option)
onStart?.(option)

Check warning on line 212 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L212

Added line #L212 was not covered by tests
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
}
uploadOption.onProgress = (
e: ProgressEvent<XMLHttpRequestEventTarget>,
option: UploadOptions
) => {
setFileList(
fileList.map((item) => {
[...fileList, fileItem].map((item) => {

Check warning on line 219 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L219

Added line #L219 was not covered by tests
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
if (item.uid === fileItem.uid) {
item.status = UPLOADING
item.message = locale.uploader.uploading
item.percentage = ((e.loaded / e.total) * 100).toFixed(0)
onProgress && onProgress({ e, option, percentage: item.percentage })
onProgress?.({ e, option, percentage: item.percentage })

Check warning on line 224 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L224

Added line #L224 was not covered by tests
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
}
return item
})
Expand All @@ -232,7 +231,7 @@
responseText: XMLHttpRequest['responseText'],
option: UploadOptions
) => {
const list = fileList.map((item) => {
const list = [...fileList, fileItem].map((item) => {

Check warning on line 234 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L234

Added line #L234 was not covered by tests
Alex-huxiyang marked this conversation as resolved.
Show resolved Hide resolved
if (item.uid === fileItem.uid) {
item.status = SUCCESS
item.message = locale.uploader.success
Expand Down Expand Up @@ -293,7 +292,6 @@
fileItem.message = autoUpload
? locale.uploader.readyUpload
: locale.uploader.waitingUpload

executeUpload(fileItem, index)

if (preview && file.type?.includes('image')) {
Expand All @@ -319,9 +317,7 @@
}
return true
})
if (oversizes.length) {
onOversize && onOversize(files)
}
oversizes.length && onOversize?.(files)

Check warning on line 320 in src/packages/uploader/uploader.tsx

View check run for this annotation

Codecov / codecov/patch

src/packages/uploader/uploader.tsx#L320

Added line #L320 was not covered by tests
Copy link

Choose a reason for hiding this comment

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

请添加测试以覆盖新代码。

根据静态分析工具的警告,这一行新增的代码没有被测试覆盖。

Tools
GitHub Check: codecov/patch

[warning] 320-320: src/packages/uploader/uploader.tsx#L320
Added line #L320 was not covered by tests


if (filterFile.length > maximum) {
filterFile.splice(maximum, filterFile.length - maximum)
Expand Down Expand Up @@ -367,8 +363,6 @@
readFile(_files)
}

setFileList(fileList)
Copy link
Collaborator

Choose a reason for hiding this comment

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

关注一下数据源的处理位置是否有异常。


if (clearInput) {
clearInputValue($el)
}
Expand Down
Loading