Skip to content

Conversation

@octaedro
Copy link
Contributor

@octaedro octaedro commented Oct 27, 2022

All Submissions:

Changes proposed in this Pull Request:

This PR adds the code to allow users to open the file picker by clicking anywhere inside the product gallery card.

Screen Capture on 2022-11-01 at 16-22-58

Closes #35183.

How to test the changes in this Pull Request:

  1. Check out this branch and go to Products > Add New (MVP)
  2. Click the Drag and drop area (not the Choose images button).
  3. A file picker should be visible. Pick an image.
  4. The selected image should be visible now in the gallery.
  5. The tracks event wcadmin_product_images_add_via_file_upload_area should be recorded
  6. Continue with the product creation process. Confirm that it has been created correctly.

Storybook
Check that the storybook for the component FileUploadArea is working as expected.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions github-actions bot added focus: react admin package: @woocommerce/components issues related to @woocommerce/components plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Oct 27, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Oct 27, 2022

Test Results Summary

Commit SHA: 43c7366

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202611m 19s
E2E Tests186006019213m 56s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@octaedro octaedro changed the title Add/35183 open file picker by clicking card Open file picker by clicking card Nov 1, 2022
@octaedro octaedro requested a review from a team November 1, 2022 19:32
@octaedro octaedro marked this pull request as ready for review November 1, 2022 19:34
@octaedro octaedro requested review from a team and removed request for a team November 1, 2022 19:35
@@ -0,0 +1,29 @@
# FileUploadArea
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I planned to use the FormFileUpload component, but it renders everything inside a button. Since we needed to add another button inside the button, I leaned towards creating our own component to have a clickable area to upload files.

Copy link
Contributor

@joshuatf joshuatf left a comment

Choose a reason for hiding this comment

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

Starting to review this, but just have a general question on how this should work: should this open the file system's native file picker or the WP media modal to select files?

It's a tiny bit ambiguous to me based on discussion right now, but I would expect the media modal would be opened given that's what happens when clicking the button.

cc @jarekmorawski

@octaedro
Copy link
Contributor Author

octaedro commented Nov 2, 2022

Thank you @joshuatf,

how this should work: should this open the file system's native file picker or the WP media modal to select files?

From what I understood, the button Choose images will open the media modal, and clicking the drag and drop area should open the file picker.

Maybe @jarekmorawski could confirm whether that's correct or not.

@jarekmorawski
Copy link

From what I understood, the button Choose images will open the media modal, and clicking the drag and drop area should open the file picker.

That's correct! That's why the copy says Drag images here or click to upload. Upload = select from your device, Choose = select from the library.

Copy link
Contributor

@joshuatf joshuatf left a comment

Choose a reason for hiding this comment

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

Very nice work, Fernando! Testing well for me in the product screen. Left a couple of minor comments.

I think we may also need to update the "Mock media upload" example in Storybook as it's broken without the render function currently:

Screen Shot 2022-11-04 at 2 38 39 PM

] );
}
<FormFileUpload
accept="image/*"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might need to be updated to account for the allowedMediaTypes prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I changed that in the commit aae35d0

@octaedro octaedro force-pushed the add/35183_open_file_picker_by_clicking_card branch from 7839d0e to eddce5d Compare November 16, 2022 10:54
@github-actions github-actions bot removed the package: @woocommerce/components issues related to @woocommerce/components label Nov 16, 2022
@octaedro
Copy link
Contributor Author

Hey @joshuatf,

Thank you for reviewing this PR.

I think we may also need to update the "Mock media upload" example in Storybook as it's broken without the render function currently:

Screen Shot 2022-11-04 at 2 38 39 PM

That error doesn't look related to this PR. It didn't modify any package.

I addressed the other changes that you mentioned. Could you take another look at this PR?

@octaedro octaedro requested a review from joshuatf November 17, 2022 14:05
Copy link
Contributor

@joshuatf joshuatf left a comment

Choose a reason for hiding this comment

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

Looks great, Fernando! Testing well; left a few comments, but only 1 I think we really need to handle before merging.

...files,
] );
}
<FormFileUpload
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm good with this here for now, but just curious if we want all media upload components to have the same behavior with file uploading (cc @jarekmorawski).

If so, we could move this into the MediaUploader component. But we can save that for a follow-up if we need to do that.

Choose a reason for hiding this comment

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

Yes. We should use the same interactions across all media upload components. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we could move this into the MediaUploader component. But we can save that for a follow-up if we need to do that.

Good idea. @joshuatf since this PR has been open for so long, I would add that change in a follow-up PR.

allowedMediaTypes={ [
ALLOWED_MEDIA_TYPES,
] }
onError={ () => null }
Copy link
Contributor

Choose a reason for hiding this comment

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

Not directly related to this PR but we should probably add some error handling at some point. I'm not sure if @mdperez86 already has an issue open for this or not as I know he implemented some error handling previously.

.woocommerce-form-file-upload {
display: flex;
justify-content: center;
margin: -4em -2.5em -2.5em;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little hesitant on adding negative margins. This currently goes outside the parent container a bit.

Could we set .components-card__body to 0 padding when there are no images? We'll also need to set the margin on .woocommerce-sortable to 0 when there are no images.

@octaedro octaedro self-assigned this Nov 22, 2022
@octaedro octaedro force-pushed the add/35183_open_file_picker_by_clicking_card branch from a1e7681 to 981a553 Compare November 23, 2022 00:43
joshuatf
joshuatf previously approved these changes Nov 23, 2022
Copy link
Contributor

@joshuatf joshuatf left a comment

Choose a reason for hiding this comment

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

Changes look good and still testing well! 🚢

Can you handle opening a follow-up issue to move the file upload component and styles that we discussed here?

@octaedro
Copy link
Contributor Author

Hi @joshuatf,

I just rebased this PR and created the issue mentioned in this comment. Could you take another look at this PR?

@AnnaMag AnnaMag self-requested a review November 25, 2022 11:00
Copy link
Contributor

@AnnaMag AnnaMag left a comment

Choose a reason for hiding this comment

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

LGTM and tests well. 🚢

@octaedro octaedro merged commit 12121a4 into trunk Nov 25, 2022
@octaedro octaedro deleted the add/35183_open_file_picker_by_clicking_card branch November 25, 2022 12:07
@github-actions github-actions bot added this to the 7.3.0 milestone Nov 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: woocommerce Issues related to the WooCommerce Core plugin.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Enhancement]: Allow users to open the file picker by clicking anywhere inside the product gallery card

5 participants