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

Composer page not showing errors #1615

Conversation

jeromeengeln
Copy link
Contributor

@jeromeengeln jeromeengeln commented Sep 19, 2022

Proposition to help with issue "Composer page not showing errors"

See #1495 (comment)

I added some JS to catch json errors and display below form fields.
To make it work I also modified the sonata admin bundle CRUDController :
https://github.com/sonata-project/SonataAdminBundle/blob/eb006137a91100ea416a05818f47172022337912/src/Controller/CRUDController.php#L1356

by adding information about what field trigger an error ($errorsByOrigin) :

protected function handleXmlHttpRequestErrorResponse(Request $request, FormInterface $form): ?JsonResponse
    {
        if ([] === array_intersect(['application/json', '*/*'], $request->getAcceptableContentTypes())) {
            return $this->renderJson([], Response::HTTP_NOT_ACCEPTABLE);
        }

        $errors = [];
        $errorsByOrigin = [];
        foreach ($form->getErrors(true) as $error) {
            $errors[] = $error->getMessage();
            if (!isset($errorsByOrigin[$error->getOrigin()->getName()])) {
                $errorsByOrigin[$error->getOrigin()->getName()] = [];
            }
            $errorsByOrigin[$error->getOrigin()->getName()][] = $error->getMessage();
        }

        return $this->renderJson([
            'result' => 'error',
            'errors' => $errors,
            'errorsByOrigin' => $errorsByOrigin,
        ], Response::HTTP_BAD_REQUEST);
    }

=> this is an example, If you have some ideas to avoid a sonata admin bundle modification.
I hope it can help to move forward with 4.x release

Actual result after submit rss block creation :
Capture d’écran 2022-09-20 à 00 38 18


@jordisala1991
Copy link
Member

I am already working on the SonataAdminBundle part: sonata-project/SonataAdminBundle#7922

You can take a look at how is the output suposed to be. You need to install symfony/serializer to get the nice output.

@eerison
Copy link
Contributor

eerison commented Sep 20, 2022

Thank you for your PR ❤️

But before start to work just comment in #1495, because we can avoid more the on person work in the same thing.

@jordisala1991
Copy link
Member

I have pushed some commits to make it work with my PR on admin bundle.

Also have removed usage of more jQuery, and fixed edit. There are some missing pieces:

  • take a look at the rest of ajax calls
  • edit for some reason doesn't work properly, at some point the save button is disabled and I didn't figure out yet how to enable it again, or who is disabling it.
  • when you edit and close + reopen the block, the edit is still in place (I am not sure if that is expected or not, probably here @eerison knows better how it worked on 3.x)

@eerison
Copy link
Contributor

eerison commented Sep 21, 2022

I have pushed some commits to make it work with my PR on admin bundle.

Also have removed usage of more jQuery, and fixed edit. There are some missing pieces:

  • take a look at the rest of ajax calls
  • edit for some reason doesn't work properly, at some point the save button is disabled and I didn't figure out yet how to enable it again, or who is disabling it.
  • when you edit and close + reopen the block, the edit is still in place (I am not sure if that is expected or not, probably here @eerison knows better how it worked on 3.x)

I'll test this branch :)

@eerison
Copy link
Contributor

eerison commented Sep 21, 2022

Hey @jordisala1991 I tested this branch and it's working as expect ❤️

Edit 1: I just saw a small issue when I'm updating But I guess it's fine!

@eerison
Copy link
Contributor

eerison commented Sep 21, 2022

Screen.Recording.2022-09-21.at.10.15.13.mov

if there are some invalid field, the edit button is blocked, and I need to refresh the page to make this work again

@jordisala1991
Copy link
Member

Yes, is already detected:

edit for some reason doesn't work properly, at some point the save button is disabled and I didn't figure out yet how to enable it again, or who is disabling it.

from my previous comment.

@jeromeengeln
Copy link
Contributor Author

I added 2 commit :

  • Styling errors as they were in previous version
    Capture d’écran 2022-09-21 à 12 04 56
  • Remove disabled attribute on submit button if edit form contains errors:
    => I need more time to see if there is an other fix but it seems to come from a bootstrap function

@jordisala1991
Copy link
Member

I know where is the disabled behavior, (It is inside sonata), but there are still one thing to understand, why this doesn't happen on creation, I am investigating..

@eerison
Copy link
Contributor

eerison commented Sep 23, 2022

and what is it mean 😄 ?
is it missing something else 👀 ?

@jordisala1991
Copy link
Member

and what is it mean 😄 ? is it missing something else 👀 ?

It is ready now, but it misses the admin-bundle PR. That needs to be polished and merged and released before we can merge this one.

composer.json Outdated Show resolved Hide resolved
composer.json Outdated Show resolved Hide resolved
@jordisala1991
Copy link
Member

2 things missing:

  1. browser test for validation error (one simple test that tries to save rss block without setting the url and ensures it shows some errors)
  2. release for admin-bundle 4.18.

composer.json Outdated Show resolved Hide resolved
@eerison
Copy link
Contributor

eerison commented Sep 28, 2022

2 things missing:

  1. browser test for validation error (one simple test that tries to save rss block without setting the url and ensures it shows some errors)
  2. release for admin-bundle 4.18.

I'm testing!

@eerison
Copy link
Contributor

eerison commented Sep 28, 2022

Screen.Recording.2022-09-28.at.08.37.23.mov

Nice work @jordisala1991 composer page is working quite nice, create and update work as expected ❤️

eerison
eerison previously approved these changes Sep 28, 2022
@eerison eerison mentioned this pull request Sep 28, 2022
36 tasks
@jordisala1991
Copy link
Member

I just added a browser test to ensure errors are thrown as expected.

Screen.Recording.2022-09-28.at.08.37.23.mov
Nice work @jordisala1991 composer page is working quite nice, create and update work as expected ❤️

Also nice work to @JeromeEngelnAdeliom for starting the PR. :)

@jeromeengeln
Copy link
Contributor Author

I just added a browser test to ensure errors are thrown as expected.

Screen.Recording.2022-09-28.at.08.37.23.mov
Nice work @jordisala1991 composer page is working quite nice, create and update work as expected ❤️

Also nice work to @JeromeEngelnAdeliom for starting the PR. :)

Thank you @jordisala1991 ;)
I wanted to do at least the test but you already did, you are too fast !
Always a pleasure to start a PR

@VincentLanglet VincentLanglet merged commit d3b9eaa into sonata-project:4.x Sep 28, 2022
@VincentLanglet
Copy link
Member

Thanks

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

Successfully merging this pull request may close these issues.

4 participants