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: allow passthrough of accepted image file types to display in image upload UI #304

Merged
merged 8 commits into from
Apr 24, 2024

Conversation

kristinalustig
Copy link
Collaborator

@kristinalustig kristinalustig commented Apr 12, 2024

As discussed, this PR introduces a method by which users can pass through a list of strings representing different allowed media types. It then constructs an appropriate string listing out those media types and puts them into the image uploader dialog. Note that I am not sure what types of tests would be appropriate for this sort of change, if any, so if you think this change is large enough to require one, please let me know and I will update.

PR Checklist

  • All new/changed functionality includes unit and (optionally) e2e tests as appropriate
  • All new/changed functions have /** ... */ docs
  • I've added the bug/enhancement and other labels as appropriate

Additional context

For reference, this pairs with SO codebase changes PR # 19347 - this one has to be in first so the build doesn't fail for SO.

@kristinalustig kristinalustig added the enhancement New feature or request label Apr 12, 2024
@kristinalustig kristinalustig self-assigned this Apr 12, 2024
Copy link

netlify bot commented Apr 12, 2024

Deploy Preview for stacks-editor ready!

Name Link
🔨 Latest commit c03eb65
🔍 Latest deploy log https://app.netlify.com/sites/stacks-editor/deploys/6622d863cee06c0007ea8643
😎 Deploy Preview https://deploy-preview-304--stacks-editor.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@dancormier dancormier requested a review from a team April 12, 2024 16:20
Copy link
Contributor

@dancormier dancormier left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on @kristinalustig!

We currently have a disconnect between the input and validation. Currently, we set the accept attribute on the input to image/* (so, any image type). When the user tries to upload something else, we show a validation message with jpeg, png, gif hardcoded:

image

In this PR, we don't address that but we are adding a field to pass file types. Right now, this is only used to generate caption text in the UI, but I think it can be used to populate the accept attribute on the input and ensure the validation message lines up with the file types we're accepting.

I've created #305 targeting this PR as a proposal for a slightly different approach to what's in this PR (I ran out of time on Friday so I haven't added a PR description yet). I think it matches the mocks/requirements and just needs a test or two added to image-upload.test.ts. Check it out when you get a chance and we'll see if this is a worthwhile approach. I'm happy to chat or pair with you on Monday to go over any details if you'd like.

* Refactor `acceptedFileTypes` to affect validation

* Add function to generate the caption element

* Minor tweaks so I can run tests

* Add default accepted file types value
@dancormier dancormier requested a review from giamir April 18, 2024 22:21
Copy link
Contributor

@dancormier dancormier left a comment

Choose a reason for hiding this comment

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

I made some updates to how we handle the acceptedFileTypes option and how the they're displayed when rendered as text. I think this is in a good place to get merged.

Since I had a hand in much of these changes, I'd like to have @giamir give this a quick look just to make sure that I didn't do anything too funky and that the tests are sufficient.

Copy link
Contributor

@giamir giamir left a comment

Choose a reason for hiding this comment

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

Overall looks good. Great job. 👏

I left a couple of small requests. One is challenging the product/design requirements to add an or (which is currently hardcoded). @kristinalustig you can explain to your designer, PM that the juice is likely not worth the squeeze for that or. Let us know if you need support in that conversation. 🙂

Tests are probably good enough I would say Dan. 👍

src/shared/prosemirror-plugins/image-upload.ts Outdated Show resolved Hide resolved
src/shared/prosemirror-plugins/image-upload.ts Outdated Show resolved Hide resolved
src/shared/prosemirror-plugins/image-upload.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@dancormier dancormier left a comment

Choose a reason for hiding this comment

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

@kristinalustig I removed the getAcceptedFileTypesString function since it was no only joining strings and removing image/ in two spots. All tests pass and this looks good to me 🎉

@giamir
Copy link
Contributor

giamir commented Apr 22, 2024

@kristinalustig we can merge this, do you want us to cut a new editor release with the changes straight away? @dancormier or I can do that instead of waiting till next week's "regular" release cycle. Let us know.

Thank you for contributing to the editor codebase. 🎉

@kristinalustig
Copy link
Collaborator Author

@giamir Ideally we can get it out sooner rather than later, but if that is a huge hassle it should be okay to wait until next week.

@giamir
Copy link
Contributor

giamir commented Apr 23, 2024

@giamir Ideally we can get it out sooner rather than later, but if that is a huge hassle it should be okay to wait until next week.

No, either @dancormier or myself will cut a release today or tomorrow. No reason to wait.

@giamir giamir merged commit 93bf622 into main Apr 24, 2024
5 checks passed
@giamir giamir deleted the klustig/dynamic-accepted-file-types branch April 24, 2024 08:31
@giamir
Copy link
Contributor

giamir commented Apr 24, 2024

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

Successfully merging this pull request may close these issues.

3 participants