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(components): [upload] before-upload change data in promise #12575

Merged
merged 12 commits into from
May 8, 2023

Conversation

GenerQAQ
Copy link
Contributor

@GenerQAQ GenerQAQ commented Apr 23, 2023

closed #12340

Please make sure these boxes are checked before submitting your PR, thank you!

  • Make sure you follow contributing guide English | (中文 | Español | Français).
  • Make sure you are merging your commits to dev branch.
  • Add some descriptions and refer to relative issues for your PR.

@pull-request-triage
Copy link

👋 @GenerQAQ, seems like this is your first time contribution to element-plus.

  • Please make sure that you have read our guidelines and code of conduct before making a contribution.
  • You can comment with /label Components:[component_name] to add a label for which component you are working on.
  • You may join our Discord for staying tuned.

@pull-request-triage pull-request-triage bot added 1st contribution Their very first contribution Needs Review labels Apr 23, 2023
@github-actions
Copy link

Hello @GenerQAQ, thank you for contributing to element-plus, please see our guideline to see how to make contribution

@github-actions
Copy link

github-actions bot commented Apr 23, 2023

@btea
Copy link
Collaborator

btea commented Apr 24, 2023

Hi, thank you for your contribution. However, the relevant pr seems to already exist. #12344

@GenerQAQ
Copy link
Contributor Author

Hi, thank you for your contribution. However, the relevant pr seems to already exist. #12344

Yes~I saw that his submission was quite complex, and I feel that my one is quite elegant, hahaha

@btea
Copy link
Collaborator

btea commented Apr 24, 2023

@chenxch what do you think?

@GenerQAQ
Copy link
Contributor Author

@chenxch pls~

@github-actions github-actions bot added the CommitMessage::Qualified Qualified commit message label Apr 24, 2023
@github-actions
Copy link

github-actions bot commented Apr 24, 2023

🧪 Playground Preview: https://element-plus.run/?pr=12575
Please comment the example via this playground if needed.

@chenxch
Copy link
Member

chenxch commented Apr 24, 2023

@GenerQAQ Good job, would you mind adding a test case, the case is as follows:

  1. First upload the file test-file.txt
  2. Upload files test-file.txt, test-file2.txt
    Finally, save the keyList as [test-file.txt, test-file.txt, test-file2.txt]

@GenerQAQ
Copy link
Contributor Author

@GenerQAQ Good job, would you mind adding a test case, the case is as follows:

  1. First upload the file test-file.txt
  2. Upload files test-file.txt, test-file2.txt
    Finally, save the keyList as [test-file.txt, test-file.txt, test-file2.txt]

No problem, later today~

@GenerQAQ
Copy link
Contributor Author

@GenerQAQ Good job, would you mind adding a test case, the case is as follows:

  1. First upload the file test-file.txt
  2. Upload files test-file.txt, test-file2.txt
    Finally, save the keyList as [test-file.txt, test-file.txt, test-file2.txt]

Added case

@GenerQAQ
Copy link
Contributor Author

@GenerQAQ Good job, would you mind adding a test case, the case is as follows:

  1. First upload the file test-file.txt
  2. Upload files test-file.txt, test-file2.txt
    Finally, save the keyList as [test-file.txt, test-file.txt, test-file2.txt]

Modified a case error

@GenerQAQ
Copy link
Contributor Author

@GenerQAQ Good job, would you mind adding a test case, the case is as follows:

  1. First upload the file test-file.txt
  2. Upload files test-file.txt, test-file2.txt
    Finally, save the keyList as [test-file.txt, test-file.txt, test-file2.txt]

Corrected lint error, thx~

@GenerQAQ
Copy link
Contributor Author

@chenxch I submitted an incorrect PR and it has now been restored. Sorry!

Copy link
Member

@chenxch chenxch left a comment

Choose a reason for hiding this comment

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

LGTM.

@btea btea requested a review from emojiiii April 26, 2023 15:31
@btea btea requested review from ryuhangyeong and removed request for emojiiii April 29, 2023 00:14
@ryuhangyeong ryuhangyeong changed the title fix(components): [upload] befroe-upload change data in promise fix(components): [upload] before-upload change data in promise Apr 29, 2023
@GenerQAQ
Copy link
Contributor Author

GenerQAQ commented May 8, 2023

@chenxch @btea @ryuhangyeong May I ask what further steps are required to merge this PR?

@btea
Copy link
Collaborator

btea commented May 8, 2023

I think there seems to be no problem.

@btea btea merged commit deba6c8 into element-plus:dev May 8, 2023
10 checks passed
@GenerQAQ GenerQAQ deleted the fix/upload-promise branch May 10, 2023 10:41
This was referenced May 19, 2023
@lyhczz
Copy link

lyhczz commented Jun 28, 2023

image
Hello, I have the above problem. Failed to modify data in the beforeUpload method. The difference is that promises also have an asynchronous method inside them.
@GenerQAQ

@JustGenius-s
Copy link

JustGenius-s commented Jul 3, 2023

@lyhczz Same question, but i havd made a solution to make this code work well.

Modify the file of node_modules\element-plus\es\components\upload\src\upload-content2.mjs

In function upload:

const upload = async (rawFile) => {
      ...
      try {
        const originData = props.data;
        const beforeUploadPromise = props.beforeUpload(rawFile);
        hookResult = await beforeUploadPromise; // Change the order of calling this statement before to update `beforeData`
        beforeData = isObject(props.data) ? cloneDeep(props.data) : props.data;
        if (isObject(props.data) && isEqual(originData, beforeData)) {
          beforeData = cloneDeep(props.data);
        }
      } catch (e) {
        hookResult = false;
      }
      ...
    };

After that, manually import this component form node_modules\element-plus\es\components\upload\index in ur vue component. And enjoy use it!

import { ElUpload } from "element-plus/es/components/upload/index"

But i wonder if i should make a PR to slove this prolem.

@chenxch
Copy link
Member

chenxch commented Jul 3, 2023

/cc @GenerQAQ Would you please take a look at this question? Thank you very much.

@GenerQAQ
Copy link
Contributor Author

GenerQAQ commented Jul 3, 2023

@chenxch @lyhczz Received! I will reproduce the question tonight. Thank you

@xiaoshawangzi
Copy link

This issue seems to have not been resolved yet. My version is 2.3.8, El-Upload reactivity of 'data' attribute has been broken in 2.3.2 onwards

consultation-applio pushed a commit to consultation-applio/element-plus that referenced this pull request Nov 10, 2023
…nt-plus#12575)

* fix(components): [upload] befroe-upload change data in promise

closed element-plus#12340

* fix(components): [upload] befroe-upload change data in promise

closed element-plus#12340
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Component] [upload] [el-upload] 升级到2.3.2后,上传组件上传全线报错,无法使用
7 participants