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

[WIP] #1387: "Uncaught TypeError: Cannot read property 'complete' of undefined" appears in dev console if save Previewed image as a new View and open this View on another page #1765

Conversation

joweecaquicla
Copy link

@joweecaquicla joweecaquicla commented Aug 18, 2020

Description (*)

This PR will introduce the modifications on image-preview.js to fix the issue of a wrong image showing in image preview section when switching views.

Fixed Issues (if relevant)

  1. Fixes magento/adobe-stock-integration "Uncaught TypeError: Cannot read property 'complete' of undefined" appears in dev console if save Previewed image as a new View and open this View on another page #1387: "Uncaught TypeError: Cannot read property 'complete' of undefined" appears in dev console if save Previewed image as a new View and open this View on another page
  2. ...

Related PR (*)

  1. #1387: "Uncaught TypeError: Cannot read property 'complete' of undefined" appears in dev console if save Previewed image as a new View and open this View on another page magento2#29639

Manual testing scenarios (*)

  1. Go to Content - Media Gallery
  2. Click Search Adobe Stock
  3. Go to the first page from the grid, and select any image to open its Preview
  4. Click on Default View (bookmarks view)
  5. Click Save View As...,
  6. Click Save all Changes ➡️
  7. Switch to the Default View
  8. Go to the second page in Adobe Stock grid
  9. Switch to the previously created New View

…undefined appears in dev console if save Previewed image as a new View and open this View on another page - modification on image-preview.js to fix issue of wrong image showing in image preview section when switching views
…undefined appears in dev console if save Previewed image as a new View and open this View on another page - added new listener to bookmark provider
/**
* Listener of the activeIndex property.
*/
onActiveIndexChange: function () {
Copy link
Member

Choose a reason for hiding this comment

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

I'd apply this fix to magento2 image-preview and actually subscribe to lastOpenedImage instead of bookmarks index change:

in initialize method:

            this.lastOpenedImage.subscribe(function (newValue) {
                if (newValue === false && _.isNull(this.visibleRecord())) {
                    return;
                }
                if (newValue === this.visibleRecord()) {
                    return;
                }

                if (newValue === false) {
                    this.hide();
                    return;
                }

                this.show(this.masonry().rows()[newValue]);
            }.bind(this));

The outdated preview displayed image can be also fixed in the magento2 image-preview by adding a listener '${ $.provider }:data.items': 'updateDisplayedRecord' and updating the preview (if it is opened) contents when the data provider is updated:

        updateDisplayedRecord: function (items) {
            if (!_.isNull(this.visibleRecord())) {
                this.displayedRecord(items[this.visibleRecord()]);
            }
        },

@joweecaquicla
Copy link
Author

Closing PR as the changes were applied in magento2 image-preview .
PR link: magento/magento2#29639

@ghost
Copy link

ghost commented Aug 19, 2020

Hi @joweecaquicla, 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
2 participants