Skip to content

#1390 Add related content information to the delete asset warning #1401

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

Merged
merged 21 commits into from
Jun 15, 2020
Merged

#1390 Add related content information to the delete asset warning #1401

merged 21 commits into from
Jun 15, 2020

Conversation

ProkopovVitaliy
Copy link
Contributor

@ProkopovVitaliy ProkopovVitaliy commented May 30, 2020

Description (*)

This PR adds related content information to the delete asset warning

Fixed Issues (if relevant)

  1. Closes Add related content information to the delete asset warning #1390: Add related content information to the delete asset warning
  2. Closes Story 59: User sees warning when deleting image if it's used on storefront  #1310: Story 59: User sees warning when deleting image if it's used on storefront

Manual testing scenarios (*)

  1. Open Media Gallery
  2. Upload an image
  3. Insert the image to Page/Block/Product/Category wysiwyg field
  4. Delete the uploaded image

Expected result

The warning message appears with the information that the image is used in the content

Screenshot 2020-05-30 at 15 00 16

Copy link
Member

@Nazar65 Nazar65 left a comment

Choose a reason for hiding this comment

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

Thank you for the PR, could you please take a look at my review comments ?

* @return string
*/
getContentMessage: function(recordPath, recordRelatedContentCount) {
return $.mage.__('This image is used in '+ recordRelatedContentCount +' page(s). Are you sure you want to delete "' + recordPath + '" image?');
Copy link
Member

Choose a reason for hiding this comment

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

Image also can be used in blocks and products as well, i think we should create a proper message for all cases like in 1 page-pages block-blocks product-products.

Copy link
Contributor Author

@ProkopovVitaliy ProkopovVitaliy May 30, 2020

Choose a reason for hiding this comment

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

@Nazar65 could i use message like: "This image is used in 2 cms_page(s) or (cms_block, catalog_category, etc)" ? Just to use entity_type field from media_content_asset table.

Copy link
Member

Choose a reason for hiding this comment

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

I think it can be the same behaviour, as like this displayed in view details page

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Nazar65 created message for all cases. For example:

Screenshot 2020-06-01 at 09 52 20
Screenshot 2020-06-01 at 09 52 40

@Nazar65
Copy link
Member

Nazar65 commented May 30, 2020

@magento run all test

@Nazar65
Copy link
Member

Nazar65 commented May 30, 2020

@magento run all tests

@ProkopovVitaliy
Copy link
Contributor Author

@magento run all tests

@ProkopovVitaliy
Copy link
Contributor Author

@magento run all tests

Copy link
Contributor

@gabrieldagama gabrieldagama left a comment

Choose a reason for hiding this comment

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

Hi @ProkopovVitaliy, thanks for the pull request, it looks good!

I would suggest using the media_gallery/image/detailsendpoint to fetch details about the image when the delete button is triggered (similar to what we are doing on the Image Details button), that endpoint already has the information that we need to display the information on the modal. Using this approach we don't need to change the DataProvider and just use javascript to handle the messaging.

Please let me know if you have any questions, we can discuss it on further details.

@sivaschenko sivaschenko changed the base branch from 2.0.0-stabilization to 2.0-develop June 4, 2020 12:21
@sivaschenko
Copy link
Member

The base branch was changed from 2.0.0-stabilization to 2.0-develop as this PR is targeting the next release

@lenaorobei lenaorobei added this to the 2.1.0 - Part 1 milestone Jun 4, 2020
@lenaorobei lenaorobei linked an issue Jun 4, 2020 that may be closed by this pull request
@ProkopovVitaliy
Copy link
Contributor Author

ProkopovVitaliy commented Jun 8, 2020

@gabrieldagama Thank you for recommendation.

As i can see MediaGalleryUi/view/adminhtml/web/js/action/getDetails.js action returns much useful information, but how do you think will this information redundant in this case?

If i should to use MediaGalleryUi/view/adminhtml/web/js/action/getDetails.js in MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js to get details before confirmation window opens, don't you think it might slow down response?

@gabrieldagama
Copy link
Contributor

Hi @ProkopovVitaliy, thanks for your reply!

Yes, you are right, the MediaGalleryUi/view/adminhtml/web/js/action/getDetails.js does return more information than we actually need at the deletion of the image, but since we are returning information about just one image (not a collection) I believe the performance shouldn't be a problem.

We could implement a new endpoint to handle just the used in data, but I think the performance benefit over the already implemented controller will be small, what do you think?

@ProkopovVitaliy
Copy link
Contributor Author

ProkopovVitaliy commented Jun 8, 2020

We could implement a new endpoint to handle just the used in data, but I think the performance benefit over the already implemented controller will be small, what do you think?

@gabrieldagama I thinks new endpoint will be better. Yes performance benefit will be small but it could make functional more decoupled.
But if this is redundant for our goals, i will be use implemented action ( MediaGalleryUi/view/adminhtml/web/js/action/getDetails.js).

On the other hand, if we want to use MediaGalleryUi/view/adminhtml/web/js/action/getDetails.js inside MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js we are required to pass the parameter imageDetailsUrl to getDetails action. I don't see any other option to do it other than getDetails('/media_gallery/image/details', imgId) in MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js that will be a hardcoded. What do you you think about it ?

@gabrieldagama
Copy link
Contributor

HI @ProkopovVitaliy

Good point! I believe we can extract the baseContent (confirmation message) from MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js and have it as a parameter. By doing that we will be able to handle the getDetails call on the MediaGalleryUi/view/adminhtml/web/js/grid/columns/image/actions.js and avoid coupling the two actions, what do you think? Thanks!

@ProkopovVitaliy
Copy link
Contributor Author

@gabrieldagama This is cool idea. Thanks!
so can we also identify items for details array ? for example we get array like:
Screenshot 2020-06-08 at 16 51 35
There are no possible to identify what kind are each detail item. What if i implement next changes: MediaGalleryUi/etc/di.xml
from

        <arguments>
            <argument name="detailsProviders" xsi:type="array">
                <item name="10" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\Type</item>
                <item name="20" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\CreatedAt</item>
                <item name="30" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\UpdatedAt</item>
                <item name="40" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\Width</item>
                <item name="50" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\Height</item>
                <item name="60" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\Size</item>
                <item name="70" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\UsedIn</item>
            </argument>
        </arguments>
    </type>

to

<type name="Magento\MediaGalleryUi\Model\AssetDetailsProviderPool">
        <arguments>
            <argument name="detailsProviders" xsi:type="array">
                <item name="type" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\Type</item>
                <item name="created_at" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\CreatedAt</item>
                <item name="updated_at" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\UpdatedAt</item>
                <item name="width" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\Width</item>
                <item name="height" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\Height</item>
                <item name="size" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\Size</item>
                <item name="used_in" xsi:type="object">Magento\MediaGalleryUi\Model\AssetDetailsProvider\UsedIn</item>
            </argument>
        </arguments>
    </type>

As result we get an object with identifiable elements.
Screenshot 2020-06-08 at 18 21 31

It will be much easier to work with them in the future and now we will be able to get what we specifically need.
Can i implement this idea, how do you think ?

@gabrieldagama
Copy link
Contributor

Hi @ProkopovVitaliy,

Those numbers on the XML are used to define the array order that gets returned on the endpoint and used on the frontend, if you click on the context menu (...) besides the image, you have the View Details link, that modal has the information ordered based on the endpoint response.

I agree that string keys are more straight forward and clear, but since this is attached to another functionality I would suggest on this PR to use the numbers as key for now and we can look into refactoring that functionality later, it would require us to find another way to sort the endpoint response, or the frontend to know what order is correct.

For now, maybe we can just wrap the fetch of the Used In information on a function and when we change the endpoint will be easier for us to change how we are getting the information from the response.

Thanks!

@ProkopovVitaliy
Copy link
Contributor Author

@magento run all test

@ProkopovVitaliy
Copy link
Contributor Author

@magento run all tests

@ProkopovVitaliy
Copy link
Contributor Author

@gabrieldagama Hi.

Fixed QA remarks.

Since the image can be deleted from different files, I decided to create an action and implement the functionality in it.

This was done in order not to make dependencies between MediaGalleryUi/view/adminhtml/web/js/action/deleteImage.js and MediaGalleryUi/view/adminhtml/web/js/action/getDetails.js. I think this implementation will allow us to easily reuse the code.

Thanks.

@ProkopovVitaliy
Copy link
Contributor Author

@magento run all tests

@ProkopovVitaliy
Copy link
Contributor Author

@magento run Static Tests

1 similar comment
@ProkopovVitaliy
Copy link
Contributor Author

@magento run Static Tests

@ProkopovVitaliy
Copy link
Contributor Author

@magento run all tests

@ProkopovVitaliy
Copy link
Contributor Author

@magento run all tests

@ProkopovVitaliy
Copy link
Contributor Author

@magento run Functional Tests B2B

@ProkopovVitaliy
Copy link
Contributor Author

@gabrieldagama Hi. I fixed found bugs, could you please approve my changes ? Thanks.

Copy link
Contributor

@gabrieldagama gabrieldagama 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 the updates @ProkopovVitaliy! It looks great!

@chalov-anton
Copy link
Contributor

✔️ QA Passed

@ghost
Copy link

ghost commented Jun 15, 2020

Hi @ProkopovVitaliy, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

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.

Add related content information to the delete asset warning Story 59: User sees warning when deleting image if it's used on storefront
6 participants