Skip to content

Commit

Permalink
Version Widget - version items are not loaded after opening the widge… (
Browse files Browse the repository at this point in the history
#4946)

* Version Widget - version items are not loaded after opening the widget #4945

-catching errors from promises
-added NPE check in ContextView.ts that was spawning error with loading history items (and was not catched without catch clause)

* Version Widget - version items are not loaded after opening the widget #4945
  • Loading branch information
ashklianko authored and alansemenov committed Aug 16, 2022
1 parent 708ab96 commit 2926dfc
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ export class ContentBrowsePanel
//
}

protected updateContextView(item: ContentSummaryAndCompareStatus) {
this.contextView.setItem(item);
protected updateContextView(item: ContentSummaryAndCompareStatus): Q.Promise<void> {
return this.contextView.setItem(item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {BrowseItemPanel} from '@enonic/lib-admin-ui/app/browse/BrowseItemPanel';
import * as Q from 'q';
import {ViewItem} from '@enonic/lib-admin-ui/app/view/ViewItem';
import {SplitPanelSize} from '@enonic/lib-admin-ui/ui/panel/SplitPanelSize';
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler';

export abstract class ResponsiveBrowsePanel extends BrowsePanel {

Expand Down Expand Up @@ -73,7 +74,7 @@ export abstract class ResponsiveBrowsePanel extends BrowsePanel {
super.updatePreviewItem();

const item: ViewItem = this.treeGrid.getLastSelectedOrHighlightedItem();
this.updateContextView(item);
this.updateContextView(item).catch(DefaultErrorHandler.handle);

if (this.treeGrid.hasHighlightedNode()) {
if (this.contextSplitPanel.isMobileMode()) {
Expand All @@ -96,7 +97,7 @@ export abstract class ResponsiveBrowsePanel extends BrowsePanel {
}
}

protected abstract updateContextView(item: ViewItem);
protected abstract updateContextView(item: ViewItem): Q.Promise<void>;

doRender(): Q.Promise<boolean> {
return super.doRender().then((rendered) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {ReloadActiveWidgetEvent} from './ReloadActiveWidgetEvent';
import {ContentId} from '../../content/ContentId';
import {WidgetItemView} from './WidgetItemView';
import {VersionContext} from './widget/version/VersionContext';
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler';

export class ContextView
extends DivEl {
Expand Down Expand Up @@ -105,7 +106,7 @@ export class ContextView
this.onRemoved(() => ApplicationEvent.un(handleApplicationEvents));

VersionContext.onActiveVersionChanged((contentId: string, version: string) => {
if (this.item.getId() === contentId && this.isVisible() && this.activeWidget === this.versionsWidgetView) {
if (this.item?.getId() === contentId && this.isVisible() && this.activeWidget === this.versionsWidgetView) {
this.updateActiveWidget();
}
});
Expand Down Expand Up @@ -155,7 +156,7 @@ export class ContextView

ReloadActiveWidgetEvent.on(() => {
if (this.activeWidget) {
this.activeWidget.updateWidgetItemViews();
this.activeWidget.updateWidgetItemViews().catch(DefaultErrorHandler.handle);
}
});
}
Expand Down Expand Up @@ -309,7 +310,7 @@ export class ContextView
}
}

public setItem(item: ContentSummaryAndCompareStatus): Q.Promise<any> {
public setItem(item: ContentSummaryAndCompareStatus): Q.Promise<void> {
if (ContextView.debug) {
console.debug('ContextView.setItem: ', item);
}
Expand All @@ -336,7 +337,7 @@ export class ContextView
return ['contentstudio.contextpanel'];
}

updateActiveWidget(): Q.Promise<any> {
updateActiveWidget(): Q.Promise<void> {
if (ContextView.debug) {
console.debug('ContextView.updateWidgetsForItem');
}
Expand All @@ -347,7 +348,8 @@ export class ContextView

return this.activeWidget.updateWidgetItemViews().then(() => {
this.activeWidget.slideIn();
});
return Q.resolve();
}).catch(DefaultErrorHandler.handle);
}

public showLoadMask() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {ContextPanel} from './ContextPanel';
import {ContextView} from './ContextView';
import {DivEl} from '@enonic/lib-admin-ui/dom/DivEl';
import {ContextPanelState} from './ContextPanelState';
import {ContextPanelStateEvent} from './ContextPanelStateEvent';
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler';

export class DockedContextPanel
extends ContextPanel {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler';
import {ContextPanel} from './ContextPanel';
import {ContextView} from './ContextView';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {WidgetItemView} from './WidgetItemView';
import {UriHelper} from '../../rendering/UriHelper';
import {ContentSummaryAndCompareStatus} from '../../content/ContentSummaryAndCompareStatus';
import {Widget} from '@enonic/lib-admin-ui/content/Widget';
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler';

export enum InternalWidgetType {
INFO,
Expand Down Expand Up @@ -69,7 +70,7 @@ export class WidgetView
this.applyConfig();

this.onActivated(() => {
this.updateWidgetItemViews();
this.updateWidgetItemViews().catch(DefaultErrorHandler.handle);
});
}

Expand All @@ -90,7 +91,7 @@ export class WidgetView
let updateWidgetItemViewsHandler = () => {
let containerWidth = this.contextView.getEl().getWidth();
if (this.contextView.getItem() && containerWidth !== this.containerWidth) {
this.updateWidgetItemViews();
this.updateWidgetItemViews().catch(DefaultErrorHandler.handle);
}
};
this.contextView.onPanelSizeChanged(() => {
Expand All @@ -110,7 +111,7 @@ export class WidgetView
return UriHelper.getAdminUri(this.widget.getUrl(), '/');
}

private updateCustomWidgetItemViews(): Q.Promise<any>[] {
private updateCustomWidgetItemViews(): Q.Promise<void>[] {
let promises = [];

this.url = this.getWidgetUrl();
Expand All @@ -122,7 +123,7 @@ export class WidgetView
return promises;
}

public updateWidgetItemViews(): Q.Promise<any> {
public updateWidgetItemViews(): Q.Promise<void[]> {
const content = this.contextView.getItem();
let promises = [];

Expand All @@ -148,7 +149,7 @@ export class WidgetView
private createDefaultWidgetItemView() {
this.widgetItemViews.push(new WidgetItemView());
if (this.contextView.getItem()) {
this.updateWidgetItemViews();
this.updateWidgetItemViews().catch(DefaultErrorHandler.handle);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {ContentId} from '../../../../content/ContentId';
import {ContentVersionsConverter} from './ContentVersionsConverter';
import {ContentVersions} from '../../../../ContentVersions';
import {VersionContext} from './VersionContext';
import {DefaultErrorHandler} from '@enonic/lib-admin-ui/DefaultErrorHandler';

export class VersionHistoryView extends WidgetItemView {

Expand Down Expand Up @@ -67,7 +68,7 @@ export class VersionHistoryView extends WidgetItemView {
return content.getStatusText();
}

public setContentAndUpdateView(content: ContentSummaryAndCompareStatus): Q.Promise<any> {
public setContentAndUpdateView(content: ContentSummaryAndCompareStatus): Q.Promise<void> {
if (VersionHistoryView.debug) {
console.debug('VersionsWidgetItemView.setItem: ', content);
}
Expand Down Expand Up @@ -101,7 +102,7 @@ export class VersionHistoryView extends WidgetItemView {
});
}

private reloadActivePanel(): Q.Promise<any> {
private reloadActivePanel(): Q.Promise<void> {
if (VersionHistoryView.debug) {
console.debug('VersionsWidgetItemView.reloadActivePanel');
}
Expand Down

0 comments on commit 2926dfc

Please sign in to comment.