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(upload-files): do file upload on components too #14724

Merged
merged 6 commits into from
Nov 25, 2022

Conversation

nathan-pichon
Copy link
Member

@nathan-pichon nathan-pichon commented Oct 26, 2022

What does it do?

The files related to the components were never linked to them. This fix allows to manage the files sent to be linked to the components.

Giving the full entity with components allow the uploadFiles to works on components level too.

Why is it needed?

Because we need to be able to attach files to components

How to test it?

See issue #14126

Related issue(s)/PR(s)

#14126

@codecov
Copy link

codecov bot commented Oct 26, 2022

Codecov Report

Base: 59.61% // Head: 59.69% // Increases project coverage by +0.07% 🎉

Coverage data is based on head (4e6a8bf) compared to base (9fc8653).
Patch coverage: 75.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14724      +/-   ##
==========================================
+ Coverage   59.61%   59.69%   +0.07%     
==========================================
  Files        1340     1340              
  Lines       32639    32641       +2     
  Branches     6225     6225              
==========================================
+ Hits        19459    19486      +27     
+ Misses      11316    11297      -19     
+ Partials     1864     1858       -6     
Flag Coverage Δ
back 49.96% <75.00%> (+0.25%) ⬆️
front 64.13% <ø> (ø)
unit_back 49.96% <75.00%> (+0.25%) ⬆️
unit_front 64.13% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...s/core/strapi/lib/services/entity-service/index.js 75.00% <75.00%> (+4.57%) ⬆️
packages/core/utils/lib/traverse-entity.js 70.00% <0.00%> (+8.33%) ⬆️
...e/strapi/lib/services/entity-service/components.js 37.83% <0.00%> (+9.45%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@nathan-pichon nathan-pichon added source: core:upload Source is core/upload package pr: fix This PR is fixing a bug labels Oct 27, 2022
@nathan-pichon nathan-pichon marked this pull request as ready for review October 28, 2022 08:49
@nathan-pichon nathan-pichon self-assigned this Oct 28, 2022
if (files && Object.keys(files).length > 0) {
await this.uploadFiles(uid, entity, files);
await this.uploadFiles(uid, Object.assign(entityData, entity), files);
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, this works well for me. I'm just wondering if we could use entityData directly in the uploadFiles function? To me it seems to already contain the properties of entity + the component fields we need for this fix. There may be something I'm missing though, WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't really know.
I have done this way to change the fewer things I could in the function and keep the current behavior.
Do we want the function to return the entity + component ?

Edit: Sorry, morning 😅 , we didn't have the ID of the entity in entityData. Also, if anything is in entity and not in entityData, I prefer to ensure that uploadFiles(...) got all the data by merging those two. What do you think?

Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

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

Well done ! :)
Could you create some tests with it?
Some already exist in packages/core/upload/tests/content-api/upload.test.e2e.js. It would be similar to the one called "Create an entity with a file".

@nathan-pichon
Copy link
Member Author

Well done ! :) Could you create some tests with it? Some already exist in packages/core/upload/tests/content-api/upload.test.e2e.js. It would be similar to the one called "Create an entity with a file".

Was on it, but only unit tests.
Will do integration too

Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

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

It looks good to me!
I tested with :

  • single component
  • repeatable components
  • dynamic-zones

One case that didn't work is when, for a single component, I put nothing in data for the component and only upload a file. It can happen if the component only has one field which is a media or when we just don't put values for the other fields.
But I think we can ignore that for the moment.

I added a few questions

qs: {
populate: ['todo', 'todo.docs'],
},
});
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want you can also put the populate param on the POST request to have the response populated so you don't have to use newlyCreatedTodolist.
But if it was intended (to test that the changes were correctly made up to the GET I guess) it's perfect too 👌

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know that you could add the populate parameter in the entity creation. I guess that it's also a way to achieve the test.
I don't know if it's better to have only the POST call in the test or if adding the GET adds unwanted complexity to the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have a strong opinion on that. I just wanted to let you know. As you wish :)

@petersg83 petersg83 self-requested a review November 9, 2022 16:33
petersg83
petersg83 previously approved these changes Nov 9, 2022
Copy link
Contributor

@petersg83 petersg83 left a comment

Choose a reason for hiding this comment

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

LGTM 👌

Copy link
Contributor

@MarionLemaire MarionLemaire left a comment

Choose a reason for hiding this comment

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

After pair-testing session today with :

Tested on Getstarted using Mac on Postman tool : OK
image

@nathan-pichon nathan-pichon merged commit 15127e8 into main Nov 25, 2022
@nathan-pichon nathan-pichon deleted the fix/file-upload-components branch November 25, 2022 11:00
@petersg83 petersg83 linked an issue Nov 29, 2022 that may be closed by this pull request
@petersg83 petersg83 mentioned this pull request Nov 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: fix This PR is fixing a bug source: core:upload Source is core/upload package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File upload Issue
5 participants