-
Notifications
You must be signed in to change notification settings - Fork 78
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
added onSuccessAction prop to Upload Widget #487
added onSuccessAction prop to Upload Widget #487
Conversation
@JoshuaRotimi is attempting to deploy a commit to the Cloudinary DevX Team on Vercel. A member of the Team first needs to authorize it. |
hey @JoshuaRotimi thanks for putting this together. have a few requests:
![]()
it's not unreasonable to think that we could add onto that by doing osmething like:
wdyt? |
Hello @colbyfayock Okay, I will add more information about the feature to the PR. About the JSON/FormData, I think we could switch to JSON, it makes the code more readable without the Object.entries loop, I thought you may have had a definite reason why FormData was the best option. If we want to automate the action creation the way you stated, we would have to add types for all the other instances like Okay, I can add the same functionality to the |
The reason was really just because ive only ever really seen FormData examples, so i was thinking it was the standard, but looking into it more it appears that you can pass anything, and didnt see any objections when i asked around about it on twitter (tho not many responses) i think adding the types for each one makes sense, we're already doing that for the standard ones, wish there was a way to automate that as well. i think it would make the implementation more complete and more useful for people thanks Josh! and apologies for the delay, currently traveling |
Yeah I figured you've been busy as I also did not receive last week's newsletter in my email haha. Hope your trip is going good? Okay that sounds great. I've made some updates to the code as regards to what we spoke about. Please let me know if everything looks great and then I can implement the same for the |
@@ -57,6 +58,8 @@ const CldUploadWidget = ({ | |||
|
|||
const signed = !!signatureEndpoint; | |||
|
|||
const { onSuccessAction } = props; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont think this is needed anymore
|
||
if ( widgetEventAction && typeof props[widgetEventAction] === 'function' ) { | ||
const action = props[widgetEventAction] as CldUploadEventAction; | ||
uploadResult.event === 'success' && action(uploadResult); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we can remove the 'success' check here right? as long as the function exists and its under the watched events, which at this point i believe both should be true, we should be good, right?
@@ -34,6 +34,20 @@ export interface CldUploadWidgetProps { | |||
options?: CloudinaryUploadWidgetOptions; | |||
signatureEndpoint?: URL | RequestInfo; | |||
uploadPreset?: string; | |||
onSuccessAction?: CldUploadEventAction; | |||
onUploadAction?: CldUploadEventAction; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the onUpload
function is deprecated and will be removed in a later version (likely a major?), so thinking we probably shouldnt add this as an option. while it will technically work if someone tries because the actions are automatically created, we don't want to document or promote its use as a valid option only for it to be pulled out soon
Looks good! Added a few comments. Hopefully a lot will transfer through the
props for the Button. And when you get a chance if we can make sure to add
it to the documentation 🙏 thank you!
--
*colbyfayock.com <http://colbyfayock.com>*
Twitter <http://twitter.com/colbyfayock> Youtube
<https://youtube.com/colbyfayock> Github <http://github.com/colbyfayock>
Email Newsletter <https://www.colbyfayock.com/newsletter/>
…On Thu, Jul 25, 2024 at 2:47 PM Joshua Olorunnipa ***@***.***> wrote:
Yeah I figured you've been busy as I also did not receive last week's
newsletter in my email haha. Hope your trip is going good?
Okay that sounds great. I've made some updates to the code as regards to
what we spoke about. Please let me know if everything looks great and then
I can implement the same for the CloudUploadButton component. Thanks
—
Reply to this email directly, view it on GitHub
<#487 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAH7GGW3JW4KKBXMM6WWU4DZODXUNAVCNFSM6AAAAABKLDS5ASVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJQGIZTQMZSGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Okay sounds great. I'll make the changes and push again. For the docs update, do we want to add all the new methods like |
yeah i think under Events makes sense, and that could either be in the same group as Functions or a separate Actions, i dont have a strong opinion there, but maybe a separate Actions section under Events makes sense im thinking about the differentiator between Actions and Functions here. originally the biggest differentiator was the FormData, but now we're passing the same javascript object as the first argument, but not passing the 2nd argument of the options. we can't pass that 2nd argument because it has javascript instances in there, but mainly, its the same except fro that second argument any thoughts any anything else we can use to differentiate the two aside from that? for instance, if someone is working clientside, why would they want to use an action vs a function? should someone always use a Function unless they are using Actions, which then its the same but limited functionality? (no options argument) mostly thinking out loud, thats probably fine, but wondering if we have an opportunity to provide any additional useful information or capabilities as part of the Actions workflow |
as far as the More Info link, i think we can link to the same spot, as its primarily at this time meant to link to the information about the event that triggers it |
at a minimum, at the top of the Events section, we can simply state the difference at this time is that the Action doesn't pass in the options argument that includes the widget and instance methods to allow it to function as an Action |
Yes the difference is in the arguments from both functions. Okay that makes sense. I will add that to the docs. One quick question, can we add a function like this to avoid repetitiveness in the const actionProps = Object.keys(props)
.filter(key => key.endsWith('Action'))
.reduce((result, key) => {
//@ts-ignore
result[key] = props[key];
return result;
}, {}); and then in the return statement, we can just spread the actionProps object. |
honestly i can't think of a good reason why we don't pass in the entire it's no different than creating a |
Okay that's fair. Maybe we can create that as a separate issue? Refactoring now may cause some typescript problems. |
Yup np
colbyfayock.com
…On Fri, Jul 26, 2024 at 11:08 AM Joshua Olorunnipa ***@***.***> wrote:
Okay that's fair. Maybe we can create that as a separate issue?
Refactoring now may cause some typescript problems.
—
Reply to this email directly, view it on GitHub
<#487 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAH7GGT65D46I42VX46LS2TZOJQ6BAVCNFSM6AAAAABKLDS5ASVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENJSHE3DIMZVGE>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Made the changes and pushed the code. |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -33,13 +33,21 @@ const CldUploadButton = ({ | |||
...props | |||
}: CldUploadButtonProps) => { | |||
|
|||
const actionProps = Object.keys(props) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we can just pass through all of the props
at this point and avoid filtering them down here
this will allow the Button to always inherit any available options on the UploadWidget without having to add it in both places, unless you're doing this because of the TS issue you mentioned before
just noticed an issue when testing htis out locally. it looks like as it currently stands, the rest of the Because the action props are not being destructured from that ![]() this makes me unsure of whether we should pass through the so for now, i believe we may need to, unfortunately, destructure all of the Action props similar to what we're doing with the callback function props, unless you have a different idea that said, i tested it out and its working, so hooray! 🙌 ![]() |
this is working great now!! thanks @JoshuaRotimi for the PR and your patience as we worked through it |
🎉 This PR is included in version 6.7.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Awesome. Always happy to contribute! |
Description
This PR adds an onSuccessAction prop to the CloudUploadWidget component.
The feature makes a few changes to the
CloudUploadWidget
andCloudUploadButton
components by adding a newonSuccessAction
prop where a server action can be passed as a function to be called on the success of an image upload.Issue Ticket Number
Fixes #486
Fixes: #486
Type of change