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

Return tempFiles from PostAddFile result #11279

Merged
merged 1 commit into from
Oct 12, 2021

Conversation

matthewcare
Copy link
Contributor

@matthewcare matthewcare commented Oct 5, 2021

Add the response data to the return. Fixes #11278

Prerequisites

  • I have added steps to test this contribution in the description below

Fixes #11278

Description

Response data was not being included in the reutrn of PostAddFile, which caused notifications to not show correctly.

To test, upload new media, and observe the response from the post

Add the response data to the return. Fixes umbraco#11278
@nul800sebastiaan
Copy link
Member

Thanks @matthewcare! I am trying to figure out what this is actually fixing though? You mentioned notifications not working, but they seem fine? I believe you are noticing error notifications not coming through? How do you make it error so that we can observe that the behavior is now correctly fixed?

Thanks in advance!

Note: this behavior doesn't seem changed in v8, so we might need to backport this to v8 as well.

Ps. you are not required to make an issue before you create a PR. If there something to discuss before making the PR then an issue is good, but if you have code already then only a PR is fine as well. 👍

@umbrabot
Copy link

umbrabot commented Oct 5, 2021

Hi there @matthewcare, thank you for this contribution! 👍

While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@matthewcare
Copy link
Contributor Author

matthewcare commented Oct 5, 2021

Hi @nul800sebastiaan

In Umbraco 8, you'll notice that the MediaController action for this has a return result of
Request.CreateResponse(HttpStatusCode.OK, tempFiles);

Whereas in Umbraco 9 it has been ported to be Ok() which misses the tempFiles data.

I am currently fixing issue #11094, and found that the dropzone response data is an empty string as the tempFiles data is not returned.

So in the method inside of umbfiledropzone.directive.js

.success(function(data, status, headers, config) {
    if (data.notifications && data.notifications.length > 0) {
        // set error status on file
        file.uploadStatus = "error";
        // Throw message back to user with the cause of the error
        file.serverErrorMessage = data.notifications[0].message;
        // Put the file in the rejected pool
        scope.rejected.push(file);

all uploaded files are now accepted, even if there is an error.

Thanks for the info about not needing to create an issue. I'll bear in mind for the future

@matthewcare
Copy link
Contributor Author

matthewcare commented Oct 5, 2021

Sorry, I wasn't super clear on what the PR fixes. When you upload files via the dropzone, and have a media saving notificaiton handler which adds messages, the js in dropzone.directives.js is meant to (although currently incorrectly), display that message as an error.

This PR adds the data back to the response, so that these messages once again show.

image

You can add a notification handler

public class PostAddFile : INotificationHandler<MediaSavingNotification>
{
    public void Handle(MediaSavingNotification notification)
    {
        notification.Messages.Add(new EventMessage("Category", "Warning Message", EventMessageType.Warning));
    }
}

That shows that the message will not show without this PR

@nul800sebastiaan
Copy link
Member

@matthewcare Try as I might, I do not understand how to get the message to show. The message is "Info message" in your screenshot but "Warning Message" in your code, I assume that's just a different example. But in no way do I get to see "Warning message" next to the file(s) with or without returning tempFiles. I have made sure that the notification code does get hit but it's just not showing next to the uploaded files. It would also be kind of pointless to show it there, no? As soon as all files are uploaded, this whole page refreshes and you wouldn't even have a chance to read the message.

I'm sure I'm missing something but I don't know what 😅

11279.mp4

My updated code looks like this, as you can see in the log we're getting and handling the notifications just fine.

    public class PostAddFile : INotificationHandler<MediaSavingNotification>
    {
        private readonly ILogger<PostAddFile> _logger;

        public PostAddFile(ILogger<PostAddFile> logger)
        {
            _logger = logger;
        }

        public void Handle(MediaSavingNotification notification)
        {
            notification.Messages.Add(new EventMessage("Category", "Warning Message", EventMessageType.Warning));
            foreach(var ent in notification.SavedEntities)
                _logger.LogInformation("Saving a media item: " + ent.Name);
        }
    }

@nul800sebastiaan
Copy link
Member

Alright.. Ignore me! 🙈

I had removed tempFiles to test the before/after behavior and... Never put tempFiles back! Sorry, I see it working now!

image

@nul800sebastiaan
Copy link
Member

Thanks for this @matthewcare and congrats on your first accepted PR for Umbraco CMS! 🎉

If you have an Our Umbraco profile then I'd love to give you a contributor badge, if you can link your profile here then I'll get it done. 👍

@matthewcare
Copy link
Contributor Author

Hi @nul800sebastiaan
I've linked my github to Our Umbraco just now
https://our.umbraco.com/members/matthewcare/

Thanks :)

@nul800sebastiaan
Copy link
Member

Awesome, thanks @matthewcare! You now have a shiny new contributor badge! 🎖️ Thanks again!

@matthewcare matthewcare deleted the temp-11278 branch October 19, 2021 08:25
@umbrabot
Copy link

Hi there @matthewcare,

First of all: A big #H5YR for making an Umbraco related contribution during Hacktoberfest! We are very thankful for the huge amount of PRs submitted, and all the amazing work you've been doing 🥇

Due to the amazing work you and others in the community have been doing, we've had a bit of a hard time keeping up. 😅 While all of the PRs for Hacktoberfest might not have been merged yet, you still qualify for receiving some Umbraco swag, congratulations! 🎉

In the spirit of Hacktoberfest we've prepared some exclusive Umbraco swag for all our contributors - including you!

As an alternative choice this year, you can opt-out of receiving anything and ask us to help improve the planet instead by planting a tree on your behalf. 🌳

Receive your swag or plant a tree! 👈 Please follow this link to fill out and submit the form, before December 31st, 2021.

Following this date we'll be sending out all the swag, but please note that it might not reach your doorstep for a few months, so please bear with us and be patient 🙏

We have blogged about this year's hacktoberfest in a recap post, have a read about at all the achievements for this year!

The only thing left to say is thank you so much for participating in Hacktoberfest! We really appreciate the help!

Kind regards,
The various Umbraco Teams

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Response data is missing when adding new media
3 participants