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

feat(upload): support custom request #1474

Merged
merged 16 commits into from
Nov 28, 2021
Merged

Conversation

Volankey
Copy link
Collaborator

closes: #1389
先提一下,感觉 customRequest里面的参数需要再讨论一下

@vercel
Copy link

vercel bot commented Oct 28, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tusimple/naive-ui/E69GawvJgywCd1E8fD6CGzfVHqb4
✅ Preview: https://naive-ui-git-fork-volankey-customrequest-tusimple.vercel.app

@codecov
Copy link

codecov bot commented Oct 28, 2021

Codecov Report

Merging #1474 (d4adafe) into main (dd844bb) will decrease coverage by 0.16%.
The diff coverage is 4.76%.

❗ Current head d4adafe differs from pull request most recent head 83bdae4. Consider uploading reports for the commit 83bdae4 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1474      +/-   ##
==========================================
- Coverage   64.88%   64.71%   -0.17%     
==========================================
  Files         886      886              
  Lines       17198    17181      -17     
  Branches     4072     4059      -13     
==========================================
- Hits        11159    11119      -40     
- Misses       5278     5299      +21     
- Partials      761      763       +2     
Impacted Files Coverage Δ
src/upload/src/interface.ts 100.00% <ø> (ø)
src/upload/src/Upload.tsx 66.29% <4.76%> (-8.40%) ⬇️
src/log/src/LogLine.tsx 39.13% <0.00%> (-47.83%) ⬇️
src/log/src/LogLoader.tsx 57.14% <0.00%> (-42.86%) ⬇️
src/log/src/Log.tsx 41.30% <0.00%> (-3.27%) ⬇️
src/date-picker/src/panel/daterange.tsx 58.97% <0.00%> (-2.57%) ⬇️
src/date-picker/src/panel/datetimerange.tsx 58.13% <0.00%> (-2.33%) ⬇️
src/_internal/scrollbar/src/ScrollBar.tsx 42.75% <0.00%> (-0.37%) ⬇️
src/_styles/common/dark.ts 100.00% <0.00%> (ø)
src/_styles/common/light.ts 100.00% <0.00%> (ø)
... and 9 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dd844bb...83bdae4. Read the comment docs.

package.json Outdated
@@ -121,6 +121,7 @@
"@types/lodash": "^4.14.170",
"@types/lodash-es": "^4.17.4",
"async-validator": "^4.0.1",
"axios": "^0.24.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

能用 fetch 么?不想引入个依赖

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fetch没有 onProgress 的功能

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

得依赖 xhr 而且大部分还都用的 axios,要不我在这个demo里面引一个axios 的 script 标签?

Copy link
Collaborator

@07akioni 07akioni Nov 1, 2021

Choose a reason for hiding this comment

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

那也应该是放进 devDeps。

https://rollupjs.org/guide/en/#outputmanualchunks
研究一下这个,把 axios 单独开一个 chunk 出来(试试,未必最终要这么做,试好了先提上来)

@Volankey

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这个放到了devDeps里面了,也单独拆了chunk

Comment on lines 116 to 118
onProgress?: (e: ProgressEvent, file: FileInfo) => void
onFinish?: (e: ProgressEvent, file: FileInfo) => void
onError?: (e: ProgressEvent, file: FileInfo) => void
Copy link
Collaborator

Choose a reason for hiding this comment

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

该必传的得必传,不要让用户判断空

src/upload/src/Upload.tsx Outdated Show resolved Hide resolved
@Volankey
Copy link
Collaborator Author

Volankey commented Nov 2, 2021

好了 @07akioni ,不过 axios 引入得问题还得讨论一下

package.json Outdated
@@ -121,6 +121,7 @@
"@types/lodash": "^4.14.170",
"@types/lodash-es": "^4.17.4",
"async-validator": "^4.0.1",
"axios": "^0.24.0",
Copy link
Collaborator

@07akioni 07akioni Nov 1, 2021

Choose a reason for hiding this comment

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

那也应该是放进 devDeps。

https://rollupjs.org/guide/en/#outputmanualchunks
研究一下这个,把 axios 单独开一个 chunk 出来(试试,未必最终要这么做,试好了先提上来)

@Volankey

withCredentials?: boolean
headers?: FuncOrRecordOrUndef
onProgress: (e: CustomUploadProgressEvent) => void
onFinish: (body?: T) => void
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
onFinish: (body?: T) => void
onFinish: (payload?: T) => void

Copy link
Collaborator

Choose a reason for hiding this comment

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

考虑一下 body 存在的必要性,我没看出来

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

on-finish 事件

Copy link
Collaborator

Choose a reason for hiding this comment

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

这里是把用户传进来的又传回去了?我觉得🈚️必要的样子

src/upload/src/interface.ts Show resolved Hide resolved
src/upload/src/Upload.tsx Show resolved Hide resolved
Comment on lines 147 to 149
const event = {
body
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

为啥需要这个东西?body 是用户传来的,这样会搞乱 change 回调的类型,如果真的非常需要的话让用户用闭包做就好了。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

inst.onFinish 需要 event

Copy link
Collaborator

@07akioni 07akioni Nov 3, 2021

Choose a reason for hiding this comment

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

这个 event 可以传出去个空的,但是没必要用户传进来我们再丢出去吧?这样类型也不好看

@07akioni
Copy link
Collaborator

07akioni commented Nov 2, 2021

昨天 review 完忘了提交了,尴尬

CHANGELOG.en-US.md Outdated Show resolved Hide resolved
package.json Outdated
@@ -109,7 +109,8 @@
"typescript": "^4.4.2",
"vite": "^2.1.3",
"vue": "^3.2.12",
"vue-router": "^4.0.5"
"vue-router": "^4.0.5",
"axios": "^0.24.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

devDeps

Copy link
Collaborator

Choose a reason for hiding this comment

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

这个没解决呢

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

这个放到了devDeps里面了,也单独拆了chunk

src/upload/demos/enUS/index.demo-entry.md Outdated Show resolved Hide resolved
src/upload/demos/zhCN/index.demo-entry.md Outdated Show resolved Hide resolved
src/upload/demos/enUS/index.demo-entry.md Outdated Show resolved Hide resolved
data?: FuncOrRecordOrUndef
withCredentials?: boolean
headers?: FuncOrRecordOrUndef
onProgress: (e: {percent: number}) => void
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
onProgress: (e: {percent: number}) => void
onProgress: (e: { percent: number }) => void

src/upload/src/interface.ts Show resolved Hide resolved
headers?: FuncOrRecordOrUndef
onProgress: (e: CustomUploadProgressEvent) => void
onFinish: () => void
onError: (error: ProgressEvent) => void
Copy link
Collaborator

Choose a reason for hiding this comment

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

我感觉这里也不是必须要 error 这个参数,这个 onError 是我们传给用户的,我们依赖用户的从 onError 传回来的东西吗?感觉并不需要

@07akioni
Copy link
Collaborator

@JiwenBai

@07akioni
Copy link
Collaborator

@Volankey

Volankey and others added 2 commits November 24, 2021 14:44
Co-authored-by: 07akioni <07akioni2@gmail.com>
Co-authored-by: 07akioni <07akioni2@gmail.com>
@Volankey
Copy link
Collaborator Author

好了 @07akioni

Comment on lines +110 to +112
export interface CustomUploadProgressEvent {
percent: number
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export interface CustomUploadProgressEvent {
percent: number
}

src/upload/src/interface.ts Show resolved Hide resolved
method,
customRequest
} = options
const { doChange, XhrMap } = options.inst
Copy link
Collaborator

Choose a reason for hiding this comment

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

XhrMap 要这个干啥子呢

Copy link
Collaborator

Choose a reason for hiding this comment

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

这不是自定义逻辑吗?

@07akioni
Copy link
Collaborator

07akioni commented Nov 28, 2021

完整改动参考 ddb2326

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[upload]: custom request
3 participants