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

refactor(Upload): convert to TypeScript, impove docs and tests, close #4622 #4841

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FairyYang
Copy link
Collaborator

@FairyYang FairyYang commented May 13, 2024

close #4622

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

这是您为 Fusion/Next 提的第一个 pr,感谢您为 Fusion 做出的贡献,我们会尽快进行处理。

@eternalsky eternalsky self-requested a review May 14, 2024 02:03
@FairyYang FairyYang changed the title Upload typeScript refactor(Upload): convert to TypeScript, impove docs and tests, close #4622 May 14, 2024
components/upload/__docs__/demo/after-select/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/after-select/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/after-select/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/base/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/beforeupload/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/paste/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/paste/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/submit/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/submit/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/text/index.tsx Outdated Show resolved Hide resolved
@FairyYang FairyYang force-pushed the form-update branch 2 times, most recently from 6e7820e to 4abb28c Compare June 11, 2024 06:55
cypress/fixtures/742.png Outdated Show resolved Hide resolved
components/upload/__docs__/demo/after-select/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/crop/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/extra/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/extra/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/demo/submit/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/theme/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/theme/index.tsx Outdated Show resolved Hide resolved
components/upload/__docs__/theme/index.tsx Outdated Show resolved Hide resolved
components/upload/__tests__/card-spec.tsx Outdated Show resolved Hide resolved
components/upload/__tests__/card-spec.tsx Outdated Show resolved Hide resolved
components/upload/card.tsx Outdated Show resolved Hide resolved
components/upload/card.tsx Outdated Show resolved Hide resolved
components/upload/card.tsx Outdated Show resolved Hide resolved
components/upload/card.tsx Outdated Show resolved Hide resolved
components/upload/card.tsx Outdated Show resolved Hide resolved
@FairyYang
Copy link
Collaborator Author

重新提交了一版

@FairyYang
Copy link
Collaborator Author

重新打开PR

saveUploaderRef = ref => {
uploaderRef: ReturnType<InstanceType<typeof Upload>['getInstance']>;

saveUploaderRef = (ref: InstanceType<typeof Upload>) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个 ref 还可能是 null


it('should support change Data/Action/Headers in BeforeUpload', () => {
class App extends React.Component {
constructor(props: object) {
Copy link
Contributor

Choose a reason for hiding this comment

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

object 在 ts 里并不是代表 js 里的 Object,这里其实可以把 state 从 constructor 里拿出去,然后 constructor 删掉,类似 demo

assert(fileToObject(file).uid === file.uid);
});

it('getFileItem', () => {
const file = { uid: 1, 1: 1 };
const files = [file, { uid: 2, 2: 2 }];
const file = { uid: 1, 1: 1 } as unknown as OriginalFile;
Copy link
Contributor

Choose a reason for hiding this comment

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

这里还是有很多 as unknown,理论上 as known 应该都不存在

@@ -161,23 +135,24 @@ class Card extends Base {
showDownload,
} = this.props;

// @ts-expect-error limit可能为undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

这里用判空就可以了。

@@ -194,7 +169,7 @@ class Card extends Base {
listType="card"
closable
locale={locale}
value={this.state.value}
value={this.state.value as UploadFile[]}
Copy link
Contributor

Choose a reason for hiding this comment

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

state.value 本身不就是 UploadFile[] 吗,这里为什么还需要 as


componentDidMount() {
const { props } = this;
const options = this.getUploadOptions(props);
this.uploader = new Uploader(options);
this.uploader = new Uploader(options as unknown as UploadOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

不要出现 as unknown

@@ -89,7 +56,7 @@ export default class Html5Uploader extends Component {
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
if (options[key] !== preOptions[key]) {
this.uploader.setOptions(options);
this.uploader.setOptions(options as unknown as UploadOptions);
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

} else {
formData.append(option.filename, option.file);
formData.append(option.filename!, option.file as unknown as Blob);
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

xhr.onerror = function error(e) {
option.onError(e);
xhr.onerror = function error(e: ProgressEvent<EventTarget>) {
option.onError!(e as unknown as UploadError);
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

const reader = new FileReader();
reader.onloadend = () => callback(reader.result);
reader.readAsDataURL(file);
reader.readAsDataURL(file as unknown as Blob);
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

@FairyYang
Copy link
Collaborator Author

提交了一个commit,修复了上面的问题

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

Successfully merging this pull request may close these issues.

【Technical upgrade】Upload
2 participants