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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
<item name="mediaGalleryListingFilters" xsi:type="string">media_gallery_listing.media_gallery_listing.listing_top.listing_filters</item>
<item name="listingPaging" xsi:type="string">media_gallery_listing.media_gallery_listing.listing_top.listing_paging</item>
<item name="sortByComponentName" xsi:type="string">adobe_stock_images_listing.adobe_stock_images_listing.listing_top.sorting</item>
<item name="bookmarksProvider" xsi:type="string">adobe_stock_images_listing.adobe_stock_images_listing.listing_top.bookmarks</item>
</item>
</argument>
<settings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
<item name="mediaGalleryListingFilters" xsi:type="string">standalone_media_gallery_listing.standalone_media_gallery_listing.listing_top.listing_filters</item>
<item name="listingPaging" xsi:type="string">standalone_media_gallery_listing.standalone_media_gallery_listing.listing_top.listing_paging</item>
<item name="sortByComponentName" xsi:type="string">standalone_adobe_stock_images_listing.standalone_adobe_stock_images_listing.listing_top.sorting</item>
<item name="bookmarksProvider" xsi:type="string">standalone_adobe_stock_images_listing.standalone_adobe_stock_images_listing.listing_top.bookmarks</item>
</item>
</argument>
<settings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ define([
mediaGallerySelector: '.media-gallery-modal:has(#search_adobe_stock)',
adobeStockModalSelector: '.adobe-search-images-modal',
activeMediaGallerySelector: 'aside.modal-slide.adobe-stock-modal._show',
bookmarksProvider: 'componentType = bookmark, ns = ${ $.ns }',
modules: {
keywords: '${ $.name }_keywords',
related: '${ $.name }_related',
actions: '${ $.name }_actions'
actions: '${ $.name }_actions',
bookmarks: '${ $.bookmarksProvider }'
},
viewConfig: [
{
Expand All @@ -50,10 +52,57 @@ define([
}
],
listens: {
'${ $.sortByComponentName }:applied': 'hide'
'${ $.sortByComponentName }:applied': 'hide',
'${ $.bookmarksProvider }:activeIndex': 'onActiveIndexChange',
'${ $.bookmarksProvider }:current': 'onStateChange'
}
},

/**
* 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()]);
            }
        },

if (this.bookmarks().getActiveView().index === 'default') {
this.hide();

return;
}
this.subscribeImagePreview();
},

/**
* Listener of the activeIndex property.
* To open image preview with the correct image when switching to a saved view
* from another page without reverting back to default view.
*/
onStateChange: function () {
if (this.bookmarks().getActiveView().index !== 'default') {
this.subscribeImagePreview();
}
},

/**
* Subscribe image preview
*/
subscribeImagePreview: function () {
var subscription,
rowIndex,
record;

subscription = this.masonry().rows.subscribe(function () {
subscription.dispose();
rowIndex = this.lastOpenedImage();

if (rowIndex === false) {
return;
}

record = this.masonry().rows()[rowIndex];
this.hide();
this.show(record);
}.bind(this));
},

/**
* Initialize the component
*
Expand Down